Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

Hw8 - homework

Rating
-
Sold
-
Pages
32
Grade
A+
Uploaded on
15-10-2024
Written in
2024/2025

Exam of 32 pages for the course Intro to Analytics Modeling at Intro to Analytics Modeling (Hw8 - homework)

Institution
Intro To Analytics Modeling
Course
Intro to Analytics Modeling

Content preview

10/15/24, 9:22 Hw 8 - homew
AM ork




Hw
8


crime <- read.delim("http://www.statsci.org/data/general/uscrime.txt")

intercept <- lm(Crime ~ 1, data = crime) #intercept model
stepwise <- lm(Crime ~., data = crime) #model with all predictors


#performing stepwise regression below
forward <- step(intercept, direction = 'forward', scope=formula(stepwise), trace = 0)

forward$anova #Viewing results of forward stepwise regression

## Step Df Deviance Resid. Df Resid. Dev AIC
## 1 NA NA 46 6880928 561.0235
## 2 + Po1 -1 3253301.8 45 3627626 532.9352
## 3 + Ineq - 739818.6 44 2887807
1 524.2154
## 4 + Ed - 587049.8 43 2300757
1 515.5343
## 5 + M - 239404.6 42 2061353
1 512.3701
## 6 + Prob 258062.5 41 1803290
-1 508.0839
## 7 + U2 - 192233.4 40 1611057
1 504.7859

forward$coefficients #Looking at coefficients of final model

## (Intercept) Po1 Ineq Ed M Prob
## -5040.50498 115.02419 67.65322 196.47120 105.01957 -
3801.83628 ## U2
## 89.36604

Including in the variables above in our model that had significant reduction in AIC compared to intercept
only model.

backward <- step(stepwise, direction = "backward", scope=formula(stepwise), trace = 0)

backward$anova

## Step Df Deviance Resid. Df Resid. Dev AIC
## 1 N NA 31 1354946
A 514.6488
## 2 - So 1 28.57405 32 1354974
512.6498
## 3 - Time 1 10340.669 33 1365315
84 511.0072
## 4 - LF 1 10533.159 34 1375848
02 509.3684
## 5 - 1 11674.639 35 1387523
NW 91 507.7655
## 6 - Po2 1 16706.340 36 1404229
95 506.3280
## 7 - Pop 1 22345.366 37 1426575
38 505.0700
## 8 Wealt 1 26493.246 38 1453068
- h 77 503.9349



1




about:bl 1/

,10/15/24, 9:22 Hw 8 - homew
AM ork




backward$coefficients #showing coefficients of backward stepwise regression


## (Intercept) M Ed Po1 M.F
U1 ## -6426.10102 93.32155 180.12011
102.65316 22.33975 -6086.63315
## U2 Ineq
Prob ## 187.34512
61.33494 -3796.03183

#Doing both direction stepwise function
both <- step(intercept, direction = 'both', scope = formula(stepwise), trace=0)

both$anova

## Step Df Deviance Resid. Df Resid. Dev
AIC ## 1 NA NA 46
6880928 561.0235
## 2 + Po1 -1 3253301.8 45 3627626 532.9352
## 3 + Ineq -1 739818.6 44 2887807 524.2154
## 4 + Ed -1 587049.8 43 2300757 515.5343
## 5 + M -1 239404.6 42 2061353 512.3701
## 6 + Prob -1 258062.5 41 1803290 508.0839
## 7 + U2 -1 192233.4 40 1611057 504.7859

both$coefficients


## (Intercept) Po1 Ineq Ed M Pro
b
## -5040.50498 115.0241967.65322 196.47120 105.01957 -
3801.83628 ## U2
## 89.36604

This is final model coeffcients for Step wise regression. Using coefficients with reduction in AIC and low
AIC. The coefficients above are the most significant predictors according to the stepwise regression model.
Now we will do Lasso Regression on the dataset.

y <- crime %>%
select(Crime)
%>%
as.matrix()
# Response variable


#Defining matrix of predictor variables
x <- data.matrix(crime[,c('M','So','Ed', 'Po1', 'Po2', 'LF', 'M.F', 'Pop', 'NW','U1',
'U2', 'Wealth', '

y <- scale(y,scale =
TRUE) x <- scale(x,scale
= TRUE)

cv_model <- cv.glmnet(x,y, alpha = 1)

lambda1 <-
cv_model$lambda.min
lambda1

## [1] 0.0124536


2




about:bl 2/

,10/15/24, 9:22 Hw 8 - homew
AM ork




about:bl 3/

, 10/15/24, 9:22 Hw 8 - homew
AM ork




## + Fold1.Rep1: alpha=0.96599,
lambda=4.376948 ## - Fold1.Rep1:
alpha=0.96599, lambda=4.376948 ## +
Fold1.Rep1: alpha=0.11809,
lambda=0.083065 ## - Fold1.Rep1:
alpha=0.11809, lambda=0.083065 ## +
Fold1.Rep1: alpha=0.79847,
lambda=0.223218 ## - Fold1.Rep1:
alpha=0.79847, lambda=0.223218 ## +
Fold1.Rep1: alpha=0.96839,
lambda=0.073855 ## - Fold1.Rep1:
alpha=0.96839, lambda=0.073855 ## +
Fold1.Rep1: alpha=0.71521,
lambda=0.028772 ## - Fold1.Rep1:
alpha=0.71521, lambda=0.028772 ## +
Fold1.Rep1: alpha=0.86817,
lambda=0.793432 ## - Fold1.Rep1:
alpha=0.86817, lambda=0.793432 ## +
Fold1.Rep1: alpha=0.17557,
lambda=0.029739 ## - Fold1.Rep1:
alpha=0.17557, lambda=0.029739 ## +
Fold1.Rep1: alpha=0.05946,
lambda=0.001203 ## - Fold1.Rep1:
alpha=0.05946, lambda=0.001203 ## +
Fold1.Rep1: alpha=0.86951,
lambda=0.004495 ## - Fold1.Rep1:
alpha=0.86951, lambda=0.004495 ## +
Fold1.Rep1: alpha=0.09135,
lambda=4.797304 ## - Fold1.Rep1:
alpha=0.09135, lambda=4.797304 ## +
Fold1.Rep1: alpha=0.73483,
lambda=0.001937 ## - Fold1.Rep1:
alpha=0.73483, lambda=0.001937 ## +
Fold1.Rep1: alpha=0.64264,
lambda=0.942628 ## - Fold1.Rep1:
alpha=0.64264, lambda=0.942628 ## +
Fold1.Rep1: alpha=0.41315,
lambda=2.450919 ## - Fold1.Rep1:
alpha=0.41315, lambda=2.450919 ## +
Fold1.Rep1: alpha=0.89123,
lambda=1.278851 ## - Fold1.Rep1:
alpha=0.89123, lambda=1.278851 ## +
Fold1.Rep1: alpha=0.98832,
lambda=0.012198 ## - Fold1.Rep1:
alpha=0.98832, lambda=0.012198 ## +
Fold2.Rep1: alpha=0.15605,
lambda=0.398372 ## - Fold2.Rep1:
alpha=0.15605, lambda=0.398372 ## +
Fold2.Rep1: alpha=0.12382,
lambda=0.244664 ## - Fold2.Rep1:
alpha=0.12382, lambda=0.244664 ## +
Fold2.Rep1: alpha=0.74610,
lambda=0.005243 ## - Fold2.Rep1:
alpha=0.74610, lambda=0.005243 ## +
Fold2.Rep1: alpha=0.39539,
lambda=0.093521 ## - Fold2.Rep1:
alpha=0.39539, lambda=0.093521 ## +
Fold2.Rep1: alpha=0.83315,
lambda=7.311531 ## - Fold2.Rep1:
alpha=0.83315, lambda=7.311531 ## +
Fold2.Rep1: alpha=0.15201,
lambda=2.115407 ## - Fold2.Rep1:
alpha=0.15201, lambda=2.115407 ## +
Fold2.Rep1: alpha=0.26330,
lambda=0.198214 ## - Fold2.Rep1:
alpha=0.26330, lambda=0.198214 ## +
Fold2.Rep1: alpha=0.54814,
lambda=1.497670 ## - Fold2.Rep1:
alpha=0.54814, lambda=1.497670 ## +
Fold2.Rep1: alpha=0.45543,
lambda=0.259950 ## - Fold2.Rep1:
alpha=0.45543, lambda=0.259950 ## +
Fold2.Rep1: alpha=0.14076,
lambda=0.017994 ## - Fold2.Rep1:
alpha=0.14076, lambda=0.017994 ## +
Fold2.Rep1: alpha=0.96599,
lambda=4.376948 ## - Fold2.Rep1:
alpha=0.96599, lambda=4.376948 ## +

about:bl 4/

Written for

Institution
Intro to Analytics Modeling
Course
Intro to Analytics Modeling

Document information

Uploaded on
October 15, 2024
Number of pages
32
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers
$13.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
EXAMSHAVEN1

Get to know the seller

Seller avatar
EXAMSHAVEN1 Stanford University
View profile
Follow You need to be logged in order to follow users or courses
Sold
2
Member since
1 year
Number of followers
0
Documents
924
Last sold
11 months ago
A+ GRADE FOR NURSING EXAMS

Success is the sum of small efforts - repeated day in and day out. I am here to help in the precise way possible. Day in day out I will be updating you \\\'all with the latest exams not only in nursing but also in other areas. Don\\\'t forget to check out my store and recommend it to a friend. I will be uploading LATEST TESTBANKS TOO.

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions