r:linear_regression
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
r:linear_regression [2018/06/15 08:53] – [e.g. 3] hkimscil | r:linear_regression [2019/06/13 10:15] (current) – hkimscil | ||
---|---|---|---|
Line 51: | Line 51: | ||
Does the model fit the data well? | Does the model fit the data well? | ||
* **Plot the residuals** and check the regression diagnostics. | * **Plot the residuals** and check the regression diagnostics. | ||
+ | * see [[https:// | ||
Does the data satisfy the assumptions behind linear regression? | Does the data satisfy the assumptions behind linear regression? | ||
* Check whether the diagnostics confirm that a linear model is reasonable for your data. | * Check whether the diagnostics confirm that a linear model is reasonable for your data. | ||
Line 146: | Line 147: | ||
</ | </ | ||
+ | <WRAP info> | ||
+ | What about beta coefficient? | ||
+ | |||
+ | < | ||
+ | |||
+ | < | ||
+ | EngineSize | ||
+ | -0.7100032 | ||
+ | > cor(MPG.city, | ||
+ | [1] -0.7100032 | ||
+ | > | ||
+ | </ | ||
====== Multiple Regression ====== | ====== Multiple Regression ====== | ||
+ | regression output table | ||
| anova(m) | | anova(m) | ||
| coefficients(m) = coef(m) | | coefficients(m) = coef(m) | ||
Line 184: | Line 198: | ||
F-statistic: | F-statistic: | ||
</ | </ | ||
- | Questions: | + | <WRAP box help>Questions: |
* What is R< | * What is R< | ||
* How many cars are involved in this test? (cf. df = 90) | * How many cars are involved in this test? (cf. df = 90) | ||
+ | * df + # of variables involved (3) = 93 | ||
+ | * check ' | ||
* If I eliminate the R< | * If I eliminate the R< | ||
+ | </ | ||
+ | <WRAP box info>The last question: | ||
+ | * If I eliminate the R< | ||
+ | * to answer the question, use the regression output table: | ||
+ | |||
+ | R< | ||
+ | = | ||
+ | |||
+ | < | ||
+ | Analysis of Variance Table | ||
+ | |||
+ | Response: Cars93$MPG.city | ||
+ | Df Sum Sq Mean Sq F value Pr(> | ||
+ | Cars93$EngineSize | ||
+ | Cars93$Price | ||
+ | Residuals | ||
+ | --- | ||
+ | Signif. codes: | ||
+ | |||
+ | > sstotal = 1465+131+1310 | ||
+ | > ssreg <- 1465+131 | ||
+ | > ssreg/ | ||
+ | [1] 0.54921 | ||
+ | > | ||
+ | > # or | ||
+ | > 1-(deviance(lm.model)/ | ||
+ | [1] 0.54932 | ||
+ | </ | ||
+ | |||
+ | |||
+ | </ | ||
Regression formula: | Regression formula: | ||
* $\hat{Y} = -2.99 * EngineSize + -0.15 * Price + 33.35$ | * $\hat{Y} = -2.99 * EngineSize + -0.15 * Price + 33.35$ | ||
* $\hat{Y} = \widehat{\text{MPG.city}}$ | * $\hat{Y} = \widehat{\text{MPG.city}}$ | ||
+ | |||
+ | <WRAP box info>in the meantime, | ||
+ | < | ||
+ | Cars93$EngineSize | ||
+ | | ||
+ | > cor(MPG.city, | ||
+ | [1] -0.7100032 | ||
+ | > cor(EngineSize, | ||
+ | [1] 0.5974254 | ||
+ | > cor(MPG.city, | ||
+ | [1] -0.5945622 | ||
+ | > | ||
+ | </ | ||
+ | Or . . . . | ||
+ | < | ||
+ | > temp | ||
+ | . . . . | ||
+ | |||
+ | > cor(temp) | ||
+ | | ||
+ | MPG.city | ||
+ | EngineSize -0.7100032 | ||
+ | Price -0.5945622 | ||
+ | > | ||
+ | </ | ||
+ | Beta coefficients are not equal to correlations among variables. | ||
+ | </ | ||
< | < |
r/linear_regression.1529020393.txt.gz · Last modified: 2018/06/15 08:53 by hkimscil