##################################################################
######### DTI Data Example #########
##################################################################
## load and reassign the data;
data(DTI2)
Y <- DTI2$pasat ## PASAT outcome
id <- DTI2$id ## subject id
W1 <- DTI2$cca ## Corpus Callosum
W2 <- DTI2$rcst ## Right corticospinal
V <- DTI2$visit ## visit
## prep scalar covariate
visit.1.rest <- matrix(as.numeric(V > 1), ncol=1)
covar.in <- visit.1.rest
## kz -- put it too high and the computation time bogs down.
pfr.obj <- pfr(Y = Y, covariates=covar.in, funcs = list(W1), subj = id, kz = 10, kb = 50)
## first column is not using random effects; second column is
head(cbind(pfr.obj$fitted.vals.level.0, pfr.obj$fitted.vals.level.1))
## do some predictions with predict.pfr()
## run predict.pfr() on all rows of data -- hope for same results as pfr fit above.
same.inputs <- predict.pfr(pfr.obj, new.data = list(subj=id, covariates=covar.in, funcs=list(W1)))
head(cbind(same.inputs[[1]], same.inputs[[2]]))
## run predict.pfr() on first 300 rows of data
subset.inputs <- predict.pfr(pfr.obj,
new.data = list(subj=head(id,300),
covariates=head(covar.in,300),
funcs=list(W1[1:300,])))
head(cbind(subset.inputs[[1]], subset.inputs[[2]]))
## compare the first 300 vs. the original full data
plot(subset.inputs[[1]], same.inputs[[1]][1:300]); abline(a=0,b=1,col="blue")
summary(subset.inputs[[1]] - same.inputs[[1]][1:300])
## try one where we have different subjects for predictions
## ids 7:12 are new
## and we just double-down the covariates and funcs from the first 6 to the second.
## check level.1 and level.0 predictions
subset.inputs <- predict.pfr(pfr.obj,
new.data = list(subj=c(head(id,6), 7:12),
covariates=rbind(head(covar.in,6),head(covar.in,6)),
funcs=list(rbind(W1[1:6,],W1[1:6,]))))
## first 6 have both levels; the last 6 do not have subject-specific
head(cbind(subset.inputs[[1]], subset.inputs[[2]]),12)
## see that whether predicted on subset or full data, the predicted
## values are the same for individuals regardless of who is in
## prediction set
## compare the first 6 vs. the original full data: 6 on the 45 degree line and 6 off.
plot(subset.inputs[[1]], same.inputs[[1]][1:12]); abline(a=0,b=1,col="blue")
summary(subset.inputs[[1]] - same.inputs[[1]][1:12])
Run the code above in your browser using DataLab