, glm , . ?glm
For ‘binomial’ and ‘quasibinomial’ families the response can also
be specified as a ‘factor’ (when the first level denotes failure
and all others success) or as a two-column matrix with the columns
giving the numbers of successes and failures.
, Present/Absent.
( psueudo-code) c(success, failure).
, data.frame(Age= ..., Present = ..., Absent). example - , data.frame :
example_t <- as.data.frame(t(example))
example_df <- data.frame(example_t, Age=factor(row.names(example_t)))
Present Absent Age
>= 55 21 6 >= 55
<55 22 51 <55
glm:
glm(cbind(Present, Absent) ~ Age, example_df, family = 'binomial')
Call: glm(formula = cbind(Present, Absent) ~ Age, family = "binomial",
data = example_for_glm)
Coefficients:
(Intercept) Age<55
1.253 -2.094
Degrees of Freedom: 1 Total (i.e. Null); 0 Residual
Null Deviance: 18.7
Residual Deviance: -1.332e-15 AIC: 11.99
Adding
You can also get an answer here from @therimalaya. But this is only the first step
as.data.frame(as.table(example))
(only there you will be there partially)
Var1 Var2 Freq
1 Present >= 55 21
2 Absent >= 55 6
3 Present <55 22
4 Absent <55 51
but actually there is a column of successes and failures, you need to do something else. You can use tidyrto get there
as.data.frame(as.table(example)) %>% tidyr::spread(Var1, Freq)
similar to mine example_dfabove
Var2 Present Absent
1 >= 55 21 6
2 <55 22 51