I'm sorry this may be very simple and stupid but I'm new to R. I've tried everywhere on the net to find a solution but nothing.
I have this data set:
Table <- read.table(text=" age education wantsMore notUsing using
<25 low yes 53 6
<25 low no 10 4
<25 high yes 212 52
<25 high no 50 10
25-29 low yes 60 14
25-29 low no 19 10
25-29 high yes 155 54
25-29 high no 65 27
30-39 low yes 112 33
30-39 low no 77 80
30-39 high yes 118 46
30-39 high no 68 78
40-49 low yes 35 6
40-49 low no 46 48
40-49 high yes 8 8
40-49 high no 12 31", header=TRUE, stringsAsFactors=FALSE)
They show the distribution of 1607 women interviewed according to age, education, desire for more children and current use of contraception.
The task is to understand how contraceptive use depends on age, education, and fertility intentions.
I think I need to use logistic regression with the glm formula but I can't use the formula like this:
glm(using~age+education+wantsMore, family = binomial,data = Table)
Because "using" is not between 0 or 1, it shows frequencies. In class I've always had data set instead of this sort of contingency table. How can I solve this?
If I don't have a column with "0" and "1" I don't really know where to start.
I am really new to R so I apologize again but I really need to sort this out.
I've defined the explanatory variable with two levels: 1=notUsing, 0=using
contraception = as.factor(c(1,0))
response <- cbind(notUsing=c(53,10,212,50,60,19,155,65,112,77,118,68,35,46,8,12),
using=c(6,4,52,10,14,10,54,27,33,80,46,78,6,48,8,31))
regression <- glm(response~contraception, family=binomial)
But I have this error:
Error in model.frame.default(formula = response ~ contraception, drop.unused.levels = TRUE) : variable lengths differ (found for 'contraception')
This may not be the solution.