r:multiple_regression
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| r:multiple_regression [2020/12/01 14:54] – [Multiple Regression] hkimscil | r:multiple_regression [2023/10/19 08:23] (current) – hkimscil | ||
|---|---|---|---|
| Line 104: | Line 104: | ||
| * unemployment rate (UNEM) = 9%, 12%, 3% | * unemployment rate (UNEM) = 9%, 12%, 3% | ||
| * spring high school graduating class (HGRAD) = 100000, 98000, 78000 | * spring high school graduating class (HGRAD) = 100000, 98000, 78000 | ||
| - | * a per capita income (INC) of $30,000, $2800, $36000 | + | * a per capita income (INC) of \$30000, \$28000, \$36000 |
| * 일 때, enrollment는 어떻게 predict할 수 있을까? | * 일 때, enrollment는 어떻게 predict할 수 있을까? | ||
| Line 111: | Line 111: | ||
| 여기에 위의 정보를 대입해 보면 된다. | 여기에 위의 정보를 대입해 보면 된다. | ||
| + | < | ||
| new.data <- data.frame(UNEM=c(9, | new.data <- data.frame(UNEM=c(9, | ||
| predict(three.predictor.model, | predict(three.predictor.model, | ||
| + | </ | ||
| < | < | ||
| Line 129: | Line 131: | ||
| \end{align*} | \end{align*} | ||
| - | [[:sequential_regression# | + | beta coefficient 살펴보기 |
| + | see [[:beta coefficients]] | ||
| + | < | ||
| + | # install.packages(' | ||
| + | # library(lm.beta) | ||
| + | lm.beta(three.predictor.model) | ||
| + | </ | ||
| + | < | ||
| + | > # install.packages(' | ||
| + | > # library(lm.beta) | ||
| + | > lm.beta(three.predictor.model) | ||
| + | |||
| + | Call: | ||
| + | lm(formula = ROLL ~ UNEM + HGRAD + INC, data = datavar) | ||
| + | |||
| + | Standardized Coefficients:: | ||
| + | (Intercept) | ||
| + | 0.0000000 | ||
| + | |||
| + | > | ||
| + | </ | ||
| + | by hand | ||
| + | < | ||
| + | # coefficient * (sd(x)/ | ||
| + | # | ||
| + | attach(datavar) | ||
| + | sd.roll <- sd(ROLL) | ||
| + | sd.unem <- sd(UNEM) | ||
| + | sd.hgrad <- sd(HGRAD) | ||
| + | sd.inc <- sd(INC) | ||
| + | |||
| + | b.unem <- three.predictor.model$coefficients[2] | ||
| + | b.hgrad <- three.predictor.model$coefficients[3] | ||
| + | b.inc <- three.predictor.model$coefficients[4] | ||
| + | |||
| + | ## or | ||
| + | b.unem <- 4.501e+02 | ||
| + | b.hgrad <- 4.065e-01 | ||
| + | b.inc <- 4.275e+00 | ||
| + | |||
| + | |||
| + | b.unem * (sd.unem / sd.roll) | ||
| + | b.hgrad * (sd.hgrad / sd.roll) | ||
| + | b.inc * (sd.inc / sd.roll) | ||
| + | |||
| + | lm.beta(three.predictor.model) | ||
| + | |||
| + | </ | ||
| + | output of the above | ||
| + | < | ||
| + | > sd.roll <- sd(ROLL) | ||
| + | > sd.unem <- sd(UNEM) | ||
| + | > sd.hgrad <- sd(HGRAD) | ||
| + | > sd.inc <- sd(INC) | ||
| + | > | ||
| + | > b.unem <- three.predictor.model$coefficients[2] | ||
| + | > b.hgrad <- three.predictor.model$coefficients[3] | ||
| + | > b.inc <- three.predictor.model$coefficients[4] | ||
| + | > | ||
| + | > ## or | ||
| + | > b.unem <- 4.501e+02 | ||
| + | > b.hgrad <- 4.065e-01 | ||
| + | > b.inc <- 4.275e+00 | ||
| + | > | ||
| + | > | ||
| + | > b.unem * (sd.unem / sd.roll) | ||
| + | [1] 0.1554 | ||
| + | > b.hgrad * (sd.hgrad / sd.roll) | ||
| + | [1] 0.3656 | ||
| + | > b.inc * (sd.inc / sd.roll) | ||
| + | [1] 0.6062 | ||
| + | > | ||
| + | > lm.beta(three.predictor.model) | ||
| + | |||
| + | Call: | ||
| + | lm(formula = ROLL ~ UNEM + HGRAD + INC, data = datavar) | ||
| + | |||
| + | Standardized Coefficients:: | ||
| + | (Intercept) | ||
| + | | ||
| + | |||
| + | > | ||
| + | </ | ||
| + | |||
| + | see also [[: | ||
| + | see also [[: | ||
| + | |||
| + | < | ||
| + | > fit <- three.predictor.model | ||
| + | > step <- stepAIC(fit, | ||
| + | Start: | ||
| + | ROLL ~ UNEM + HGRAD + INC | ||
| + | |||
| + | Df Sum of Sq RSS AIC | ||
| + | < | ||
| + | - UNEM | ||
| + | - HGRAD 1 12852039 24089352 401 | ||
| + | - INC 1 33568255 44805568 419 | ||
| + | > | ||
| + | |||
| + | </ | ||
| ====== Housing ====== | ====== Housing ====== | ||
| {{housing.txt}} | {{housing.txt}} | ||
| Line 137: | Line 239: | ||
| ====== etc ====== | ====== etc ====== | ||
| + | {{: | ||
| < | < | ||
| + | marketing <- read.csv(" | ||
| + | </ | ||
| + | |||
| + | < | ||
| + | # install.packages(" | ||
| library(tidyverse) | library(tidyverse) | ||
| data(" | data(" | ||
| Line 145: | Line 253: | ||
| * Note that to list all the independent (explanatory) variables, you could use '' | * Note that to list all the independent (explanatory) variables, you could use '' | ||
| * You could also use '' | * You could also use '' | ||
| + | |||
| | | ||
| < | < | ||
| Line 371: | Line 480: | ||
| | interest | | interest | ||
| | unemp | 1 (b) | 22394 (2) | 22394 | 4.497690299 | | unemp | 1 (b) | 22394 (2) | 22394 | 4.497690299 | ||
| - | | res | 21 (c) | 104559 (3) | 4979 | | | + | | res | 21 %%(%%c%%)%% | 104559 (3) | 4979 | | |
| | total | 23 | 1021416 (4) | | | total | 23 | 1021416 (4) | | ||
| - | | interst | + | | interest |
| (4) = (1) + (2) + (3) | (4) = (1) + (2) + (3) | ||
r/multiple_regression.1606802044.txt.gz · Last modified: by hkimscil
