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)

Homework 8 - HW8

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

Exam of 25 pages for the course Intro to Analytics Modeling at Intro to Analytics Modeling (Homework 8 - HW8)

Institution
Intro To Analytics Modeling
Course
Intro to Analytics Modeling

Content preview

10/15/24, 9:27 Homew ork 8 -
AM HW8




ISYE 6501: Homework 8
2023-03-07

Question 11.1, Part 1: Stepwise Regression
Using the crime data set uscrime.txt from Questions 8.2, 9.1, and 10.1, build a
regression model using: 1. Stepwise regression

We begin by retrieving and preparing our data as we did in previous weeks. As part of our
data preparation, we take the following steps:
• identify and remove outliers,
• replace them using a K-means imputation method, and
• scale data before and after imputation.
# Url address
url <- "http://www.statsci.org/data/general/uscrime.txt"

# Destination File location
destfile <- "C:/Users/arvin/Downloads/uscrime.txt"

# Script to download and save file
download.file(url, destfile)

# Convert file to table
cdf <- read.table("C:/Users/arvin/Downloads/uscrime.txt", header = TRUE)

# Preview the data
head(cdf)

## M So Ed Po1 Po2 LF M.F NW U1 U2 Wealth Ineq
Pop
Prob
## 1 15.1 1 9.1 5.8 5.6 95.0 30.1 0.108 3940 26.1
0.510 33 4.1
0.084602
## 2 14.3 0 11.3 10.3 9.5 101.2 10.2 0.096 5570 19.4
0.583 13 3.6
0.029599
## 3 14.2 1 8.9 4.5 4.4 96.9 21.9 0.094 3180 25.0
0.533 18 3.3
0.083401
## 4 13.6 0 12.1 14.9 14.1 99.4 8.0 0.102 6730 16.7
0.577 157 3.9
0.015801
## 5 14.1 0 12.1 10.9 10.1 98.5 3.0 0.091 5780 17.4
0.591 18 2.0
0.041399
## 6 12.1 0 11.0 11.8 11.5 96.4 4.4 0.084 6890 12.6
0.547 25 2.9
0.034201
## Time Crime
## 1 26.2011 791
## 2 25.2999 1635




about:blan 1/
k 25

,10/15/24, 9:27 Homew ork 8 -
AM HW8




## 3 578
24.3006
## 4 1969
29.9012
## 5 1234
21.2998
## 6 682
20.9995

# Outliers
cdf_out <- boxplot.stats(cdf$Crime)$out

# Indices of outliers
cdfout_ind <- which(cdf$Crime %in% c(cdf_out))

# copy df
cdf_copy <- cdf

# Replace outliers with NA prior to imputation
cdf_copy$Crime[cdfout_ind] <- NA

# Split response from predictors
cdf_x <- cdf_copy[, -16]
cdf_y <- cdf_copy[, 16]

# Scale data for Kmeans
cdf_xs <- scale(cdf_x)

# K-means to Elbow plot to determine ideal k for
imputation # later
set.seed(77)
tot_withinss <- map_dbl(2:10, function(k) {
km_mod <- kmeans(cdf_xs, centers = k, nstart =
25) km_mod$tot.withinss
})

# Elbow point appears to be k = 3
wss <- data.frame(k = 2:10, tot_withinss = tot_withinss)
ggplot(wss, aes(k, tot_withinss)) + geom_line() +
geom_point()




about:blan 2/
k 25

, 10/15/24, 9:27 Homew ork 8 -
AM HW8




about:blan 3/
k 25

Written for

Institution
Intro to Analytics Modeling
Course
Intro to Analytics Modeling

Document information

Uploaded on
October 15, 2024
Number of pages
25
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