From 175ac10904d0f31c3ffeeeed507c8914f13d0b15 Mon Sep 17 00:00:00 2001 From: leshe4ka46 Date: Sat, 13 Dec 2025 19:41:40 +0300 Subject: linr, logr --- R_LinR/main.r | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) (limited to 'R_LinR/main.r') diff --git a/R_LinR/main.r b/R_LinR/main.r index d7b5856..3bb98fb 100755 --- a/R_LinR/main.r +++ b/R_LinR/main.r @@ -5,7 +5,7 @@ df <- subset(df, sex == "F") df <- subset(df, select = -c(zcta, sex)) df <- subset(df, 8 < meaneducation & meaneducation < 18) df <- subset(df, 10000 < meanhouseholdincome & meanhouseholdincome < 200000) -df <- subset(df, 10000 < meanhouseholdincome & meanhouseholdincome < 200000) +df <- subset(df, 0 < meanemployment & meanemployment < 3) df <- subset(df, 20 < meanage & meanage < 60) df$log_income <- log10(df$meanhouseholdincome) @@ -15,12 +15,46 @@ names(df) <- c("X", "age", "education", "employment", "income", "log_income") library(ggplot2) -ggplot(df, aes(x = age, y = log_income)) + - geom_point(alpha = 0.2) + - labs(x = "age", y = "income", title = "log_income(age)") +# b model <- lm(log_income ~ age, df) +# a +ggplot(df, aes(x = age, y = log_income)) + + geom_point(alpha = 0.2) + + geom_abline( + intercept = coef(model)[1], + slope = coef(model)[2], + color = "red", + size = 1 + ) + + labs(x = "age", y = "income", title = "log_income(age)") + +# bcde print(model) summary(model) + +model_2 <- lm(log_income ~ education, df) +print(model_2) +summary(model_2) + +ggplot(df, aes(x = education, y = log_income)) + + geom_point(alpha = 0.2) + + geom_abline( + intercept = coef(model_2)[1], + slope = coef(model_2)[2], + color = "red", + size = 1 + ) + + labs(x = "education", y = "income", title = "log_income(education)") + + +model_3 <- lm(log_income ~ education + age + employment, df) +print(model_3) +summary(model_3) + +ggplot(df) + + geom_point(aes(x = log_income, y = fitted(model_3)), alpha = 0.2) + + geom_line(aes(x = log_income, y = log_income), col = "red") + + labs(x = "actual", y = "predicted") -- cgit v1.2.3