cvGLM {cvDSA} | R Documentation |
'cvGLM' is used to select/fit linear/Logestic models.
cvGLM(y,x,ncv=5, yx.model=NULL, myfamily='gaussian', weight=NULL, detail=F, printout=F, rep.ID=F, ID=NULL)
y |
response variable: vector of length 'n'. |
x |
treatment variable: vector of length 'n'. |
yx.model |
a list description of the model, e.g., yx.model=list(Model=, Size=, Order=, Int= ). |
weight |
an optional vector of censoring weights to be used in the selecting/fitting process. |
ncv |
an integer of the number of fold for the V-fold cross-validation for selecting the model. |
detail |
if True, the details of the D/S/A set are printed. |
printout |
if True, intermediate results are printed. |
rep.ID |
a logical value indicating whether the observations have repeated IDs (not independent observations). |
ID |
a vector which identifies the clusters. |
If the model is not provided by the user, 'cvGLM' will return the best model fit and the cross-validation risk matrix.
If yx.model$Model is not given, the default values are: Size=8, Order=rep(1,times=), Int=1. $Model is a string formula indicating the linear combination of model; $Size should give the maximum number of terms in the model; $Order is a vector with the same length as the number of covariates, indicating the maximal power is allowed for each covariate; $Int indicates the maximal interactions allowed in the model.
cvMSM
, cvDCY
, cv.predict
, check.ETA
, create.obs.data
# Example 1. n<-2000; x1<-runif(n); x2<-runif(n); x3<-runif(n); x4<-runif(n); y<--1+x1+x2+x1*x3+rnorm(n,0,0.25); xmat<-cbind(x1,x2,x3,x4); model.example<-cvGLM(y,xmat,ncv=5, yx.model=list(Size=4, Int=2), printout=T) # Example 2. n <- 2000 w1 <- runif(n, 0, 1); w2 <- runif(n, 0, 1); w <- cbind(w1=w1, w2=w2); # g(A|W) = logit^(-1) (1 - W1 + W2) model.aw <- list(formula="w1+w2", coef=c(1,-1,1)); # Q(Y|A,W) = 1 + 2A + 1.5W1 + W2 - W1*W2 model.yaw <- list(formula="a+w1+w2+w1:w2", coef=c(1, 2, 1.5, 1, -1)); #library(cvDSA) obs.data <- create.obs.data(w, afamily='binomial', yfamily='gaussian', model.yaw, model.aw) a<-obs.data$a cv.model.aw <- cvGLM(y=a, x=w, ncv=5, yx.model=list(Size=3, Order=c(1,1), Int=2), myfamily='binomial', printout=T, detail=T) y<-obs.data$y cv.model.yaw <- cvGLM(y=y, x=cbind(a,w), ncv=5, yx.model=list(Size=5, Order=c(1,2,1,1,1), Int=2), printout=T)