å帰åæ - ç·å½¢åå帰åæ
ä»åã¯ããã¼ã¿è§£æã®åºæ¬ã§ããç·å½¢åå帰åæã®å¾©ç¿ããã¦ã¿ã
lmé¢æ°
Rã«ã¯ãç·å½¢å帰åæãè¡ãé¢æ°ã¨ãã¦ãlmãç¨æããã¦ãã
lm(formula, data, weights, subset, na.action)
- formula : ã¢ãã«ã®å½¢å¼
- data : ãã¼ã¿ã»ãã
- weights : 説æå¤æ°ã«éã¿ãã¤ããå ´åã«æå®ãã
- na.action : æ¬ æå¤ã®æ±ããæå®
ãã¼ã¿ã®ç¨æ
ä»åã¯ãUCIãã·ã³ã©ã¼ãã³ã°•ã¬ãã¸ããªã«ããAuto MPG Data Setã®ä¸ã®èªåè»ã®ææ°éã¨ééã®äºã¤ã®å¤æ°ã使ãã
ats <- read.table("auto-mpg.data", header=T) ats <- ats[, c("displacement", "weight")] head(ats)
displacement weight 1 307 3504 2 350 3693 3 318 3436 4 304 3433 5 302 3449 6 429 4341
ç¸é¢ä¿æ°ã確èª
cor(ats$displacement, ats$weight)
[1] 0.9328241
ç¸é¢ä¿æ°ã確èªããã¨ã0.9ãè¶ ãã¦ããã®ã§ãããªãå¼·ãç¸é¢é¢ä¿ããããã¨ãåãã
å帰åæã®çµæã®è¦ç´
summary(ats.lm)
Call: lm(formula = ats$weight ~ ats$displacement) Residuals: Min 1Q Median 3Q Max -1866.13 -175.35 -44.68 181.79 1042.20 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 1505.0187 32.3062 46.59 <2e-16 *** ats$displacement 7.5761 0.1471 51.52 <2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 305.5 on 396 degrees of freedom Multiple R-squared: 0.8702, Adjusted R-squared: 0.8698 F-statistic: 2654 on 1 and 396 DF, p-value: < 2.2e-16
Residuals
- æ®å·®ã®ååä½æ°ã
- lmé¢æ°ã§æ±ããã¢ãã«ã«ããå¤ã¨å®ãã¼ã¿ã®å¤ã®å·®ã®äºã§ãæ®å·®ã®æå°å¤ã第ï¼ååä½æ°ãä¸å¤®å¤ã第ï¼ååä½æ°ãæ大å¤ãåºåããã
Coefficients
- æ¨å®ãããå帰ä¿æ°ã
- Interceptã®è¡ã«ãå®æ°é ããã®ä¸ã«ãã¢ãã«ã§æå®ãã説æå¤æ°ã®ä¿æ°ããããããã§ã¯ats.s$displacementã«ãªã£ã¦ããã
- åè¡ã¯ãä¿æ°ã®æ¨æ¸¬å¤ããã®æ¨æºèª¤å·®ãtå¤ãpå¤ã®é ã«ä¸¦ã¹ããã¦ããã
- ä¿æ°ã®æ¨ªã«ãããtå¤ãpå¤ã¯ãä¿æ°ãå帰ã¢ãã«ã«å½¹ç«ã£ã¦ãããã©ããã«é¢ããçµ±è¨éã§ãpå¤ãå°ããã»ã©ããã®ä¿æ°ãå½¹ç«ã£ã¦ããäºã示ãã
- ä¸çªå³ã«ãããã¢ã¹ã¿ãªã¹ã¯ã¯ãå½¹ã«ç«ã£ã¦ã度ã表ãã¦ããã3ã¤ãæ大ã
- 追è¨: ä¿æ°ããã®å帰ã¢ãã«ã«å½¹ç«ã£ã¦ãããã©ããã§ãå®éã®ãã¼ã¿ã¸ã®å½ã¦ã¯ã¾ãã«å½¹ç«ã£ã¦ãããã©ããã¯å¥ã§ãã
Multiple R-squaredãAdjusted R-squared
- 決å®ä¿æ°ã¨èªç±åº¦èª¿æ´æ¸ã¿æ±ºå®ä¿æ°
- æ±ããå帰ã¢ãã«ãã©ã®ç¨åº¦ãã¼ã¿ã«ãã£ãããã¦ããããè©ä¾¡ããææ¨ã§ããããã1ã«è¿ã¥ãã»ã©å帰ã¢ãã«ããã¼ã¿ã«è¯ããã£ãããã¦ãããã¨ã«ãªãã
- 調æ´ãããçç±ã¯ã決å®ä¿æ°ãããã®å®ç¾©ä¸èª¬æå¤æ°ãå¤ããªãã°å®éãã大ãããªã£ã¦ãã¾ãå¾åããããã
æ£å¸å³+å帰ç´ç·ã®æç»
ç·å½¢åå帰åæã®å ´åãæ£å¸å³ã«å帰ç´ç·ãå¼ããã¨ã§ããã¼ã¿ã®å¾åãæ¦è¦³ãããã¨ãåºæ¥ã
plot(ats) abline(ats.lm,col="red")
å帰診æå³
å帰åæã§ã¯æ®å·®ãè¦è¦çã«åæãããããã
plotã«ãlmã®çµæãå
¥ããã¨ãå帰診æå³ã¨ããå³ãåºåãããã¨ãåºæ¥ãã
ä»åã®ãã¼ã¿ã¯ãæ®å·®ã®å½±é¿ã大ããäºãåãã
par(mfrow=c(2,2)) plot(ats.lm)
å·¦ä¸ããããæ®å·®ã¨ãã£ããå¤ã®ãããããããæ®å·®ã®æ£è¦Q-Qãããããããæ®å·®ã®å¹³æ¹æ ¹ãããããããæ®å·®ã¨å½±é¿åããããã
- æ®å·®ã¨ãã£ããå¤ã®ãããã
- æ®å·®ã¨ãã£ããå¤ã®æ£å¸å³ã§ãå³ããæ®å·®ã®å ¨ä½åãè¦ãäºãåºæ¥ã
- æ£è¦Q-Qãããã
- ãã¼ã¿ã®æ£è¦æ§ãèå¯ããããã®å³
- ãã¼ã¿ãæ£è¦åå¸ã«å¾ãå ´åãç¹ãç´ç·ä¸ã§ä¸¦ã¶
- å帰åæã§ã¯ãæ®å·®ãæ¨æºæ£è¦åå¸ã«å¾ãã¨ä»®å®ãã¦ããããããã®å³ãç´ç·ã«è¿ãã»ã©è¯ããã¨ã«ãªã
- æ®å·®ã®å¹³æ¹æ ¹ãããã
- æ¨æºåããæ®å·®ã®çµ¶å¯¾å¤ã®å¹³æ¹æ ¹ã縦軸ã«ããäºæ¸¬å¤ã横軸ã¨ããæ£å¸å³
- ãã®å³ãæ®å·®ã®å¤åç¶æ³ãèå¯ãããã¨ãç®ç
- æ®å·®ã¨å½±é¿åãããã
- 横軸ããæ¢åå¤ã縦軸ãæ¨æºåããæ®å·®ã§ãç¹ç·ã§ã¯ãã¯ã®è·é¢0.5ã示ãã¦ãã
- æ¢åå¤ã大ããã»ã©å½ã¦ã¯ã¾ããè¯ããã¯ãã¯ã®è·é¢ã0.5以ä¸ã§å½±é¿åã大ããã1以ä¸ã ã¨ç¹ç°ã«å¤§ããã¨è¨ããã
ä¿¡é ¼åºéã¨äºæ¸¬åºé
ats.clim <- predict(ats.lm, interval="confidence") ats.plim <- predict(ats.lm, interval="prediction")
- ã°ã©ãæç»
matplot(ats$displacement,cbind(ats.clim, ats.plim[,-1]), lty=c(1,2,2,3,3), type="l", ylab="predicted weight", xlab="displacement")
åèæ¸ç±
- å¤æ¬¡å ãã¼ã¿è§£ææ³ (Rã§å¦ã¶ãã¼ã¿ãµã¤ã¨ã³ã¹ 2)
- Rã«ãããã¼ã¿ãµã¤ã¨ã³ã¹ - ãã¼ã¿è§£æã®åºç¤ããææ°ææ³ã¾ã§