How do you test for departure from linear trend across ordered categorical variables with logistic regression using R? -


i'm testing linear trend in log odds of binary outcome across ordered categorical independent variable. straightforwardly achieved treating independent variable continuous.

i'm trying test departure linear trend. understand comparing (a) model independent variable categorical (b) model independent variable treated continuous. i'm not sure how in r.

can help?

i've created reproducible example below. first 7 lines create dataset. model1 treats independent variable categorical; model2 continuous.

model2 provides strong evidence linear trend explains trend better no trend @ all, linear trend not explanation in case.

# create dataset 'a'  n <- 200 ngroups <- 7 <- data.frame(group = rep(letters[1:ngroups], n), group2 = rep(1: ngroups, n), n = runif(n * ngroups, 0, 1)) y <- data.frame(group = letters[1:ngroups], fac = 1/(1 + exp(-1 * 1:ngroups))) <- merge(a, y, = "group") a$n2 <- a$n * a$fac a$ind <- ifelse(a$n2 > quantile(a$n2)[4], 1, 0)  # run models  model1 <- glm(ind ~ group, data = a, family = "quasibinomial") model2 <- glm(ind ~ group2, data = a, family = "quasibinomial")  

answering own question...

you likelihood ratio test compare 2 models:

anova(model1, model2, test = "lrt") 

this give low p-value, suggesting models different, , there evidence non-linear trend fits data better linear trend.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -