Description Usage Arguments Details Value Author(s) References See Also Examples
cv.smog
conducts a greedy-search for optimal lambda's and yields a sparse
model given a provided model selection criterion. When type is ”nloglike”,
the method allows the nfolds
to be processed in parallel for speeding up
the cross-validation.
1 2 3 4 5 6 |
x |
a model matrix, or a data frame of dimensions n by p, in which the columns represents the predictor variables. |
y |
response variable, corresponds to the family description.
When family is ”gaussian” or ”binomial”, |
g |
a vector of group labels for the predictor variables. |
v |
a vector of binary values, represents whether or not the predictor variables are penalized. Note that 1 indicates penalization and 0 for not penalization. |
label |
a character vector, represents the type of predictors in terms of treatment, prognostic, and predictive effects by using ”t”, ”prog”, and ”pred”, respectively. |
type |
model selction criterion, should choose from ”nloglike”, ”cAIC”, ”AIC”, ”BIC”, and ”GCV”, respectively. |
family |
a description of the distribution family for the response variable variable. For continuous response variable, family is ”gaussian”; for multinomial or binary response variable, family is ”binomial”; for survival response variable, family is ”coxph”, respectively. |
lambda.max |
the maximum value for lambda's. If |
nlambda.max |
the maximum number of lambdas' shrunk down from the maximum lambda |
delta |
the damping rate for lambda's such that λ_k = δ^kλ_0. Default is 0.9. |
nfolds |
number of folds. One fold of the observations in the data are used as the testing, and the remaining are fitted for model training. Default is 5. |
parallel |
Whether or not process the |
ncores |
number of cpu's for parallel computing. See
|
... |
other arguments that can be supplied to |
When the type
is ”nloglike”, it requires doing nfolds
cross-validations.
For each cross-validation, evenly split the whole data into nfolds
, and one fold of
the observations are used as the testing data, and the remaining are used for model training.
After calculating the (deviance) residuals for each fold of testing data, return the average of the
(deviance) residuals. Note that we keep lambda2
=0 during the greedy search for lambda's.
Besides the n-fold cross-validation, cv.smog
provides several AIC based model selection criteria.
\frac{n}{2}log(|2*log-likelihood|) + \frac{n}{2} (\frac{1+k/n}{1-k+2/n})
log(|2*log-likelihood|/n) + 2\frac{k}{n}
log(|2*log-likelihood |/n) + 2\frac{k}{n}log(n)
|2*log-likelihood| / (n(1-k/n)^2)
Where k is the degrees of freedom DF
, which is related to the penalty parameters λ's.
Includes the profile containing a path of lambda's and the corresponding model
selectio criterion value, the optimal lambda's, and the optimal model, respectively.
The type
comes from a list of model selection criteria values, includes the
average of the negative log-likelihood values and the correction AIC for each fold of the data.
the fitted model based on the optimal lambda's.
the optimal lambda's which has the minimum model selection criterion.
a data frame contains the path of lambda's and the corresponding model selection
criterion, which is determined by the type
.
Chong Ma, chongma8903@gmail.com.
ma2019structuralsmog
smog.default
, smog.formula
, predict.smog
, plot.smog
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | # generate design matrix x
set.seed(2018)
n=100;p=20
s=10
x=matrix(0,n,1+2*p)
x[,1]=sample(c(0,1),n,replace = TRUE)
x[,seq(2,1+2*p,2)]=matrix(rnorm(n*p),n,p)
x[,seq(3,1+2*p,2)]=x[,seq(2,1+2*p,2)]*x[,1]
g=c(p+1,rep(1:p,rep(2,p))) # groups
v=c(0,rep(1,2*p)) # penalization status
label=c("t",rep(c("prog","pred"),p)) # type of predictor variables
# generate beta
beta=c(rnorm(13,0,2),rep(0,ncol(x)-13))
beta[c(2,4,7,9)]=0
# generate y
data=x%*%beta
noise=rnorm(n)
snr=as.numeric(sqrt(var(data)/(s*var(noise))))
y=data+snr*noise
cvfit=cv.smog(x,y,g,v,label,type = "GCV", family="gaussian")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.