{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Rforch09 - R Material for Chapter 09 > attach(bill.data >...

This preview shows pages 1–2. Sign up to view the full content.

R Material for Chapter 09 > attach(bill.data) > bill.data bill income persons sqft 1 228 3220 2 1160 ## our data 2 156 2750 1 1080 3 648 3620 2 1720 4 528 3940 1 1840 5 552 4510 3 2240 6 636 3990 4 2190 7 444 2430 1 830 8 144 3070 1 1150 9 744 3750 2 1570 10 1104 4790 5 2660 11 204 2490 1 900 12 420 3600 3 1680 13 876 5370 1 2550 14 840 3180 7 1770 15 876 5910 2 2960 16 276 320 2 1190 17 1236 5920 3 3130 18 372 3520 2 1560 19 276 3720 1 1510 20 450 4840 1 2190 All-Subsets Selection of a Model – Requires a Special Library > library(leaps) ## loads the special library of functions ## SEE THE END OF THIS DOCUMENT > subs <- regsubsets(bill~.,data=bill.data,nbest=3,method=c("exhaustive")) ## (response variable~., name of data set, number of best subsets per model size, ## “exhaustive” means all-subsets > summary(subs) Subset selection object Call: regsubsets.formula(bill ~ ., data = bill.data, nbest = 3, method = c("exhaustive")) 3 Variables (and intercept) Forced in Forced out income FALSE FALSE persons FALSE FALSE sqft FALSE FALSE 3 subsets of each size up to 3 Selection Algorithm: exhaustive income persons sqft 1 ( 1 ) " " " " "*" ## orders the one variable models by R^2 1 ( 2 ) "*" " " " " 1 ( 3 ) " " "*" " " 2 ( 1 ) " " "*" "*" ## orders the two variable models by R^2 2 ( 2 ) "*" " " "*" 2 ( 3 ) "*" "*" " " 3 ( 1 ) "*" "*" "*" ## the only three variable model > result1 <- with(bill.data,leaps(cbind(income, persons,sqft),bill,method="r2", nbest=3)) ## with(name of data set, leaps( list of predictors, response variable, selection ## criterion, number of best subsets per model size))

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}