aboutsummaryrefslogtreecommitdiff
path: root/R_LinR/main.r
diff options
context:
space:
mode:
authorleshe4ka46 <alex9102naid1@ya.ru>2025-12-13 19:41:40 +0300
committerleshe4ka46 <alex9102naid1@ya.ru>2025-12-13 19:41:40 +0300
commit175ac10904d0f31c3ffeeeed507c8914f13d0b15 (patch)
tree671c68a03354c5084470c5cfcfd4fe87aae2aff8 /R_LinR/main.r
parent72b4edeadeafc9c54b3db9b0961a45da3d07b77c (diff)
linr, logr
Diffstat (limited to 'R_LinR/main.r')
-rwxr-xr-xR_LinR/main.r42
1 files changed, 38 insertions, 4 deletions
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")