在svyglm函数中重置预测变量的基线水平

时间:2016-10-29 03:19:33

标签: r

我正在使用R中的调查包来进行复杂调查数据的建模。我试图重置逻辑回归中使用的某些预测变量的基线水平而没有成功。 以下是可重现的示例:

library(RCurl)
library(survey)
data <- getURL("https://raw.githubusercontent.com/cbenjamin1821/careertech-  ed/master/elsq1adj.csv")
elsq1ch <- read.csv(text = data)
#Specifying the svyrepdesign object which applies the BRR weights
elsq1ch_brr<-svrepdesign(variables = elsq1ch[,1:16], repweights = elsq1ch[,18:217], weights = elsq1ch[,17], combined.weights = TRUE, type = "BRR")
elsq1ch_brr
#Log. Reg. model
allCC <- svyglm(formula=F3ATTAINB~F1PARED+BYINCOME+F1RACE+F1SEX+F1RGPP2+F1HIMATH+F1RTRCC,family="binomial",design=elsq1ch_brr,subset=BYSCTRL==1&G10COHRT==1,na.action=na.omit)
summary(allCC)
##Attempting to reset baseline level for predictor variable to "PreAlg or Less"; the baseline level in the model is currently "Adv Alg"
#Both attempts did not work
elsq1ch$F1HIMATH <- C(elsq1ch$F1HIMATH,contr.treatment, base=1)
elsq1ch$F1HIMATH <- relevel(elsq1ch$F1HIMATH,"PreAlg or Less")
#Log. Reg. model with no changes in baseline levels for the predictor
allCC <- svyglm(formula=F3ATTAINB~F1PARED+BYINCOME+F1RACE+F1SEX+F1RGPP2+F1HIMATH+F1RTRCC,family="binomial",design=elsq1ch_brr,subset=BYSCTRL==1&G10COHRT==1,na.action=na.omit)
summary(allCC)

非常感谢任何指导。

1 个答案:

答案 0 :(得分:0)

Anthony Damico为我提供了这种方法:     elsq1ch_brr&lt; - update(elsq1ch_brr,F1HIMATH = relevel(F1HIMATH,&#34; PreAlg或更少&#34;))