CODE 6 : MTCAR DATA
1.cars_data <- mtcars
mean : a regression model with more than 1 independent variable
and we need to create a dataset by use the data of mtcars
2.cars_data$log_mpg <- log(cars_data$mpg)
cars_data$log_hp <- log(cars_data$hp)
model1 <- lm(log_mg ~ log_hp ~ data= cars_data)
summary(model1)
mean : to satisfy the regression assumption, transform the mpg and hp
by take log because the skewness of mpg and hp is positive
and finally made summary in model 1
3.cor(car_data)
mean : The relationship between the data in the car_data.
4.cor(car_data$hp, car_data$am)
mean : The relationship between the data hp with information that is relevant am or not .
5.hist(cars_data$am)
mean : made a histogram of car data as am
SECTION 2 :
1.library(psych)
describe(cars_data$am)
mean : call package psych to describe cars_data$am
2. model 2 <- lm(log_mg ~ log_hp + am, data =cars_data)
summary(model 2)
anova( model 1, model 2)
mean : to check if the model 2 is statistically better than model 1
ไม่มีความคิดเห็น:
แสดงความคิดเห็น