lets us create a model on mtcars dataset

data(“mtcars”)

View(mtcars) str(mtcars)

let us create a variable- miles_per_gallon and cylinder

miles_per_gallon <- mtcars\(mpg cylinder <- mtcars\)cyl

#let us use simple regression

model1 <- lm(miles_per_gallon~cylinder) model1

Given the sample used if car can run hypothetically with no cylinder, it would give 37.885 miles_per_gallon of gasoline it uses. with each cylinder more in the car, its milege will decrease 2.876 miles_per_gallon

a car with 8 cylinder will have a predict milege of ..?..

we are creating a predictive model1

criteria : a car having 8 cylinder

to check : the milege/performance of car having 8 cylinder

predict(model1, newdata = data.frame(cylinder=8)) therefore, a car with 8 cylinder will have predicted milege of 14.87826 miles_per_gallon

a car with 6 cylinder will have a predict milege of ..?..

we are creating a predictive model1

criteria : a car having 6 cylinder

to check : the milege/performance of car having 6 cylinder

predict(model1, newdata = data.frame(cylinder=6)) therefore, a car with 8 cylinder will have predicted milege of 20.62984 miles_per_gallon

a car with cylinder will have a predict milege of ..?..

we are creating a predictive model1

criteria : a car having 4 cylinder

to check : the milege/performance of car having 4 cylinder

predict(model1, newdata = data.frame(cylinder=4)) therefore, a car with 8 cylinder will have predicted milege of 26.38142 miles_per_gallon

let us create some visuals

plot <- plot(cylinder,miles_per_gallon,type = “p”,main = “gas consumption as explaind by number of cylinder”,sub = ” general information”,xlab = “# of cylinder”,ylab = “miles(us) per gallon”,col=“firebrick”) # create a model using multiple regression model variable to be used mpg,cyl,am

abline(model1) # let us create model2 using above three vriables am <- mtcars$am am model2 <- lm(miles_per_gallon~cylinder+am) model2 In this model, along with the number of cylinders, we include the variable am(0 if the car has automatic transmission, 1 if this is manual) 1-if the car is automatic and the number of cylinder is zero, the hypothetical milege of it would be 34.522 miles_per_gallon 2-if evry thing else remains constant, per each cylinder more than the cars has, it will decrease by 2.501 miles_per_gallon 3-if every thing else remains constant, if the car is manual, its milege will increase by 2.567 miles_per_gallon