Example: quiz answers

Package ‘leaps’ - R

Package leaps January 16, 2020 TitleRegression Subset Lumley based on Fortran code by Alan MillerDescriptionRegression subset selection, including exhaustive (>= 2)MaintainerThomas 17:50:05 UTCR topics documented:leaps ..4regsubsets ..5 Index8leapsall-subsets regressiomDescriptionleaps() performs an exhaustive search for the best subsets of the variables in x for predicting y inlinear regression, using an efficient branch-and-bound algorithm. It is a compatibility wrapper forregsubsetsdoes the same thing the algorithm returns a best model of each size, the results do not depend on a penalty modelfor model size: it doesn t make any difference whether you want to use AIC, BIC, CIC, DIC, ..12leapsUsageleaps(x=, y=, wt=rep(1, NROW(x)), int=TRUE, method=c("Cp", "adjr2", "r2"), nbest=10,names=NULL, df=NROW(x), )ArgumentsxA matrix of predictorsyA response vectorwtOptional weight vectorintAdd an intercept to the modelmethodCalculate Cp, adjusted R-squared or R-squarednbestNumber of subsets of each size to reportnamesvector of names for columns ofxdfTotal degrees of freedom to use instead ofnrow(x)in calculating Cp and ad-justed misfeatures of leaps() in SValueA list with componentswhichlogical matrix.

all.best Show all the best subsets or just one of each size matrix Show a matrix of the variables in each model or just summary statistics matrix.logical With matrix=TRUE, the …

Tags:

  Best, Packages, Pale, The best all, Package leaps

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Package ‘leaps’ - R

1 Package leaps January 16, 2020 TitleRegression Subset Lumley based on Fortran code by Alan MillerDescriptionRegression subset selection, including exhaustive (>= 2)MaintainerThomas 17:50:05 UTCR topics documented:leaps ..4regsubsets ..5 Index8leapsall-subsets regressiomDescriptionleaps() performs an exhaustive search for the best subsets of the variables in x for predicting y inlinear regression, using an efficient branch-and-bound algorithm. It is a compatibility wrapper forregsubsetsdoes the same thing the algorithm returns a best model of each size, the results do not depend on a penalty modelfor model size: it doesn t make any difference whether you want to use AIC, BIC, CIC, DIC, ..12leapsUsageleaps(x=, y=, wt=rep(1, NROW(x)), int=TRUE, method=c("Cp", "adjr2", "r2"), nbest=10,names=NULL, df=NROW(x), )ArgumentsxA matrix of predictorsyA response vectorwtOptional weight vectorintAdd an intercept to the modelmethodCalculate Cp, adjusted R-squared or R-squarednbestNumber of subsets of each size to reportnamesvector of names for columns ofxdfTotal degrees of freedom to use instead ofnrow(x)in calculating Cp and ad-justed misfeatures of leaps() in SValueA list with componentswhichlogical matrix.

2 Each row can be used to select the columns ofxin the respectivemodelsizeNumber of variables, including intercept if any, in the modelcporadjr2orr2is the value of the chosen model selection statistic for each modellabelvector of names for the columns of function will stop with an error ifxis not of full rank or if it hasmore than 31 columns. It will ignore the column names ofxeven ifnames==NULLand will replacethem with "0" to "9", "A" to "Z".ReferencesAlan Miller "Subset Selection in Regression" Chapman \& HallSee Alsoregsubsets, , <-matrix(rnorm(100),ncol=4)y<-rnorm(25)l eaps(x,y) functions for leaps(), subsets()DescriptionThese functions are used internally byregsubsetsandleaps. They are wrappers for Fortranroutines that construct and manipulate a QR (x,y,wt=rep(1,length(y)), , ,intercept=TRUE,nvmax=8,nbest=1, ) ( ) ( , ) ( ,nested) ( ,nested)ArgumentsxA matrix of predictorsyA response vectorwtOptional weight vectorinterceptAdd an intercept to the indicating variable that must be in the indicating variable that must not be in the modelnbestNumber of subsets of each size to reportnvmaxlargest subset size to ifxis not of full object of classleapsas produced before R gets sent off on a long uninterruptible computationnestedUse just the forward or backward selection models, not the models with vari-ables1:nvmaxconstructed for free in the setupSee Alsoregsubsets, table of best subsetsDescriptionPlots a table of models showing which variables are in each model.

3 The models are ordered by thespecified model selection statistic. This plot is particularly useful when there are more than ten orso models and the simple table produced too big to ## S3 method for class'regsubsets'plot(x, labels=obj$xnames, main=NULL, scale=c("bic", "Cp", "adjr2", "r2"),col=gray(seq(0, , length = 10)),..)Argumentsx regsubsetsobjectlabelsvariable namesmaintitle for plotscalewhich summary statistic to use for ordering plotscolColors: the last color should be close to but distinct from argumentsValueNoneAuthor(s)Thomas Lumley, based on a concept by Merlise ClydeSee Alsoregsubsets, (swiss)a<-regsubsets(Fertility~.,nbest=3 ,data=swiss)par(mfrow=c(1,2))plot(a)plot (a,scale="r2")regsubsets5regsubsetsfunct ions for model selectionDescriptionModel selection by exhaustive search, forward or backward stepwise, or sequential replacementUsageregsubsets(x=.)

4 ## S3 method for class'formula'regsubsets(x=, data=, weights=NULL, nbest=1, nvmax=8, , , intercept=TRUE,method=c("exhaustive", "backward", "forward", "seqrep"), ,nested=(nbest==1),..)## Default S3 method:regsubsets(x=, y=, weights=rep(1, length(y)), nbest=1, nvmax=8, , , intercept=TRUE,method=c("exhaustive","ba ckward", "forward", "seqrep"), ,nested=(nbest==1),..)## S3 method for class'biglm'regsubsets(x,nbest=1,nvmax=8 , ,method=c("exhaustive","backward", "forward", "seqrep"), ,nested=(nbest==1),..)## S3 method for class'regsubsets'summary(object, ,matrix=TRUE, ,df=NULL,..)## S3 method for class'regsubsets'coef(object,id,vcov=FAL SE,..)## S3 method for class'regsubsets'vcov(object,id,..)Argum entsxdesign matrix or model formula for full model, orbiglmobjectdataOptional data frameyresponse vectorweightsweight vectornbestnumber of subsets of each size to record6regsubsetsnvmaxmaximum size of subsets to to columns of design matrix that should be in all to columns of design matrix that should be in no modelsinterceptAdd an intercept?

5 MethodUse exhaustive search, forward selection, backward selection or sequential re-placement to be TRUE to perform exhaustive search on more than 50 the Note below: ifnested=FALSE, models with columns 1, 1 and 2, 1-3,and so on, will also be consideredobjectregsubsets all the best subsets or just one of each sizematrixShow a matrix of the variables in each model or just summary , the matrix is logicalTRUE/FALSEor string"*"/" "dfSpecify a number of degrees of freedom for the summary statistics. The defaultisn-1idWhich model or models (ordered as in the summary output) to return coefficientsand variance matrix forvcovIfTRUE, return the variance-covariance matrix as an arguments for future methodsDetailsSince this function returns separate best models of all sizes up tonvmaxand since different modelselection criteria such as AIC, BIC, CIC, DIC.

6 Differ only in how models of different sizes arecompared, the results do not depend on the choice of cost-complexity abiglmobject it is assumed to be the full model, not relevant. If thereis an intercept it is forced in by default; specify a logical vector withFALSEas thefirst element to allow the intercept to be model search does not actually fit each model, so the returned object does not contain coeffi-cients or standard errors. Coefficients and the variance-covariance matrix for one or model modelscan be obtained with an object of class "regsubsets" containing no user-serviceable parts. It is de-signed to be processed an object with elementswhichA logical matrix indicating which elements are in each modelrsqThe r-squared for each modelrssResidual sum of squares for each modeladjr2 Adjusted r-squaredcpMallows Cpregsubsets7bicSchwartz s information criterion, BICoutmatA version of thewhichcomponent that is formatted for printingobjA copy of theregsubsetsobjectThecoefmethod returns a coefficient vector or list of vectors, thevcovmethod returns a matrix orlist of part of the setup process, the code initially fits models with the first variable inx, the first two,the first three, and so on.

7 For forward and backward selection it is possible that the model with thekfirst variables will be better than the model withkvariables from the selection algorithm. If it is,the model with the firstkvariables will be returned, with a warning. This can happen for forwardand backward selection. It (obviously) can t for exhaustive can avoid these extra models withnested=TRUE, which is the AlsoleapsExamplesdata(swiss)a<-regsubset s( (swiss[,-1]),swiss[,1])summary(a)b<-regs ubsets(Fertility~.,data=swiss,nbest=2)su mmary(b)coef(a, 1:3)vcov(a, 3)Index , 4 Topicregressionleaps, , , 4regsubsets, (regsubsets), 5leaps, 1,3, ( ), ( ), ( ), ( ), , , (regsubsets), (regsubsets), 5regsubsets,1 4, , , ,4, (regsubsets), (regsubsets), 58


Related search queries