Access over 20 million homework & study documents

Hw6 Final

Content type
User Generated
Subject
R
Type
Homework
Rating
Showing Page:
1/6

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/6

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/6

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 6 pages?
Access Now
Unformatted Attachment Preview
Homework 6 Admin 3/12/2022 Problem 1 The file CommunityCrime.csv is a dataset containing 319 observations on 123 variables. The observations are communities within the United States. The data combines socioeconomic data from the 1990 US Census, law enforcement data from the 1990 US LEMAS survey, and crime data from the 1995 FBI Uniform Crime Reporting program. A detailed description of all variables is available at Link. We seek to predict the variable ViolentCrimesPerPop, the total number of violent crimes per 100,000 people. Note: when asked to perform cross-validation to select a tuning parameter, be sure to conduct this cross-validation on the training data only, then see how well your crossvalidated tuning parameter does on the test data. crime = read_csv("CommunityCrime.csv",show_col_types = FALSE) # Dimensions dim(crime) ## [1] 319 123 a) Test Train Split Set a seed of 1 and split the data into a 90% training set, and a 10% test set. set.seed(1) train = sample(1:nrow(crime), .9*nrow(crime),replace=F) crime.train = crime[train,] crime.test = crime[-train,] VC.test=crime.test$ViolentCrimesPerPop b) Linear Regression Model Fit a linear model using least squares on the training set. Report the test error obtained. lin.fit = lm(ViolentCrimesPerPop ~ ., data = crime.train) lin.pred = predict(lin.fit, newdata = crime.test) lin.error = mean((lin.pred - VC.test)^2) lin.error ## [1] 0.03439512 Final Best Linear Regression model # Using Step() on lin.fit gives the better reg ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
I was struggling with this subject, and this helped me a ton!

Studypool
4.7
Trustpilot
4.5
Sitejabber
4.4