Приложение А
Листинг 1 – Код программы
#laba 6
#task 1 library(DAAG)
df <- DAAG::cps2[c(1:1000), c(2,3,10)]
#task 2
library(psych)
pairs.panels(df)
#task 3 library(ggplot2)
ggplot(df,aes(x=educ, y=re78))+ geom_point()
#task 4
summary(lm(df$age ~ df$educ)) summary(lm(df$educ ~ df$re78)) summary(lm(df$re78 ~ df$age))
# task 5
newdf = data.frame(df$re78)
prediction = predict(lm(df$educ ~ df$re78), newdata = newdf) plot(df$re78, df$educ, xlab = "Годы обучения", ylab = "Возраст"
)
lines(newdf$df.re78, prediction, col = "red")
# task 6
lm <- lm(df$educ ~ poly(df$re78, 1)) points_to_predict <- data.frame(re78 = df$re78) prediction <- predict(lm, newdata = points_to_predict)
plot(df$re78, df$educ, xlab="Годы обучения", ylab="Возраст") lines(points_to_predict$re78, prediction, col = "red")
# task 7
pol_many <- lm(df$re78 ~ polym(df$re78, df$educ, degree = 2, raw = T), data = df)
ggplot(df, aes(x=re78, y=educ, color=age))+ geom_point()+
geom_smooth()+ theme_classic()
# task 8 library(stargazer)
stargazer(pol_many, out = 'regres.html')
11