Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write R-code that reads from the downloaded file, and create and use your model that helps to answer the question you stated above. (e.g logistic

Write R-code that reads from the downloaded file, and create and use your model that helps to answer the question you stated above. (e.g logistic regression, or multiple linear regression, etc. ). You will also have to use training/test data set and cross validation for your analysis. Also, do an error analysis of the goodness of your model and comment on that.

I am using the dataset "mtcars". I am trying to determine the relationship that "disp", "hp", and "wt" have on the "mpg"

the formula i used for the model was fit <- lm(mpg~disp+wt+hp, data=mtcars)

I really need writing the code for the training/test data set and cross validation and error analysis.

basically all I have so far is:

>print(mtcars)

>fit <- lm(mpg~disp+wt+hp, data=mtcars)

>summary(fit)

> sample <- sample.int(n=nrow(mtcars), size=floor(.50*nrow(mtcars)), replace = F)

> train <- mtcars[sample, ]

> test <- mtcars[-sample, ]

> score = list()

> LOOCV_function=function(x,label){

+ for(i in 1:nrow(x)){

+ traiing = x[-i,]

+ model =

+ validation = x[i,]

+ pred=predict(model, validation[,setdiff(names(validation),label)])

+ score[[i]] = rmse(pred, validation[[label]])

+ }

+ return(unlist(score))

+ }

>

> library(caret)

Loading required package: lattice

Loading required package: ggplot2

> data(mtcars)

> set.seed(42)

>model <- train(mpg~disp+hp+wt, mtcars,

+ method = "lm",

+ trControl = trainControl(

+ method = "cv", number = 10,

+ verboseIter = TRUE

+ printdat

+ )

but i dont think its right

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Experts Guide To Database 2

Authors: Bruce L. Larson

1st Edition

0070232679, 978-0070232679

More Books

Students also viewed these Databases questions