Skip to content

question about external validation #20

@fbwg

Description

@fbwg

Thank you for developing the dynamicLM package. I built a cross-validated landmark model with this package, but I encounter some error in the external validation process:
Firstly, I split my data into training data and validation data.

lss<-filter(all,study == 1)
arcin<-filter(all,study == 0)

then, I used lss data to build model.

# super dataset 
#(1)the outcome columns 
#(2)variable types (fixed vs. time-varying)  
outcome <- list(time = "years", status = "event")  
covars<-list(fixed=c("gender",  "cigsmok", "bmi_g2","bmi_g3","bmi_g4", "edu_g2", 
                     "edu_g3","edu_g4","race_g2","race_g3","race_g4","diagchas","diagchro",
                     "diagcopd","diagemph","famlc"), 
                varying=c("age_dynamic","pkyr","tsle_smok","nod_g5","nod_g7","nod_g8",
                       "maoci","ground","nod_loc",
                       "nod_new","nod_nega","benign_nod","linbajie","wall",
                       "consolidation","nod_growth","reticular"))

w <- 3 			# w-year prediction window
lms <- seq(0, 2, by =0.5)# landmarks
lmdata <- stack_data(lss, outcome, lms,w,
                     covars, format = "long", rtime = "tstart", id = "pid") 

lmdata <- add_interactions(lmdata, func_covars = c("linear", "quadratic"),
                           func_lms= c("linear", "quadratic")) 

# Fit coefficient path
path <- pen_lm(lmdata, alpha = 1)

par(mfrow = c(1, 2))
plot(path, all_causes = TRUE)


# Fit penalized supermodel
# Cross-validated model
cv_model <- cv.pen_lm(lmdata, alpha = 1) 
## Fitting a cross-validaton penalized landmark supermodel
supermodel_pen_cv<- dynamic_lm(cv_model, lambda = "lambda.1se")

### Prediction
p_cv<- predict(supermodel_pen_cv)
# External validation with test data 
lmdata_arcin <- stack_data(arcin, outcome, lms,w,
                covars, format = "long", rtime = "tstart", id = "pid") 

lmdata_arcin<- add_interactions(lmdata_arcin, func_covars = c("linear", "quadratic"),
                           func_lms= c("linear", "quadratic"))
par(mfrow = c(1,1))
outlist_arcin <- calplot(list("Supermodel" = supermodel_pen_cv), 
                   cause = 1, 
                   data = lmdata_arcin$data, 
                   lms="LM",
                   method = "quantile", q = 10, 
                   ylim = c(0, 0.25), xlim = c(0, 0.25))

however, an error was reported for the “outlist_arcin “ as follows:

> outlist_arcin <- calplot(list("Supermodel" = supermodel_pen_cv), 
+                    cause = 1, 
+                    data = lmdata_arcin$data, 
+                    lms="LM",
+                    method = "quantile", q = 10, 
+                    ylim = c(0, 0.25), xlim = c(0, 0.25))
错误于sum(sapply(bet_covars, function(coef_name) {: 
  'type'(list)参数无效

Would you please have a check for the above codes at your convenience?
Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions