diff options
| author | leshe4ka46 <alex9102naid1@ya.ru> | 2025-12-13 19:41:40 +0300 |
|---|---|---|
| committer | leshe4ka46 <alex9102naid1@ya.ru> | 2025-12-13 19:41:40 +0300 |
| commit | 175ac10904d0f31c3ffeeeed507c8914f13d0b15 (patch) | |
| tree | 671c68a03354c5084470c5cfcfd4fe87aae2aff8 /R_LogR/main.r | |
| parent | 72b4edeadeafc9c54b3db9b0961a45da3d07b77c (diff) | |
linr, logr
Diffstat (limited to 'R_LogR/main.r')
| -rwxr-xr-x | R_LogR/main.r | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/R_LogR/main.r b/R_LogR/main.r new file mode 100755 index 0000000..748b0f4 --- /dev/null +++ b/R_LogR/main.r @@ -0,0 +1,41 @@ +#!/usr/bin/env Rscript + +# https://www.r-bloggers.com/2015/09/how-to-perform-a-logistic-regression-in-r/ + +data <- read.csv("survey.csv") + + +str(data) +head(data) + +data$price20 <- ifelse(data$Price == 20, 1, 0) +data$price30 <- ifelse(data$Price == 30, 1, 0) +head(data) + +model <- glm( + MYDEPV ~ Income + Age + price20 + price30, + family = binomial(link = "logit"), + data = data +) +summary(model) + +coef(model) + +plot(data$Income, data$MYDEPV) + + +test_dat <- data.frame(Income = seq(20, 100, 1), Age = 20, price20 = 1, price30 = 0) +pred <- predict(model, newdata = test_dat, type = "response") + +lines(test_dat$Income, pred, col = "blue", lwd = 2) + + +new_data3 <- data.frame( + Income = c(58), + Age = c(25), + price20 = c(1), + price30 = c(0) +) + +predicted <- predict(model, newdata = new_data3) +print(1 / (1 + exp(-predicted))) |
