复杂抽样数据的限制性立方样条图
老师您好,我有个问题想请教你们一下,多有打扰!是这样的:我用一个复杂抽样的数据做一个限制性立方样条图,程序运行到预测or值那一步时总是出现z(我的自变量)不在model里面,语法如下,麻烦老师有时间帮我看看,非常感谢!!!
ddist <- datadist(data) #为后续程序设定数据环境
options(datadist='ddist') #为后续程序设定数据环境
data2<-svydesign(id = ~SDMVPSU, strata=~sdmvstra,weights =~weight_new,data =data, nest = TRUE)
fit <- svyglm(x1 ~ rcs(z, 3) + sex + age, design = data2, family=quasibinomial(link= "logit"))
fit
summary(fit)
anova(fit)
ddist$limits$z[2] <- min(data$z, na.rm = T)
fit = update(fit)
plot_z<-unique(na.omit(data$z))
or<-Predict(fit, z = plot_z, fun=exp, ref.zero = TRUE) ####预测OR值
or$x<-or$z
or_plot<- or %>% select(x, yhat, lower, upper)
or_plot<-data.frame(or_plot)
my_gam_plot(or_plot, "z", 10, "OR", 0.2, xmin = NULL, xmax = NULL, ymin = 0, ymax = NULL)