--drop table 성적 create table 성적 ( 통계 int , 결석 int , 수학 int ); insert 성적 values (85, 3, 65) , (74, 7, 50) , (76, 5, 55) , (90, 1, 65) , (85, 3, 55) , (87, 3, 70) , (94, 1, 65) , (98, 2, 70) , (81, 4, 55) , (91, 2, 70) , (76, 3, 50) , (74, 4, 55);
> # SQL Server 2008 연동한 R코드: 다중회귀분석 > library("TSodbc") > con <-odbcConnect(dsn = "sql2008") > options(TSconnection = con) > #만약 데이터가 많다면 select * from 성적 tablesample(1 percent)와 같이 샘플링을 한다. > result = try(dbGetQuery(con, paste("SELECT 통계, 수학, 결석 FROM 성적"))) > model = lm(통계 ~ 수학 + 결석, result) > summary(model) Call: lm(formula = 통계 ~ 수학 + 결석, data = result) Residuals: Min 1Q Median 3Q Max -5.348 -2.274 -1.276 2.954 5.673 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 53.6832 14.1808 3.786 0.00431 ** 수학 0.6073 0.1984 3.062 0.01353 * 결석 -1.9346 0.9144 -2.116 0.06348 . --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 3.721 on 9 degrees of freedom Multiple R-squared: 0.8289, Adjusted R-squared: 0.7909 F-statistic: 21.8 on 2 and 9 DF, p-value: 0.0003544 > anova(model) #자유도, 제곱합, 제곱평균 F값, Analysis of Variance Table Response: 통계 Df Sum Sq Mean Sq F value Pr(>F) 수학 1 541.69 541.69 39.1297 0.0001487 *** 결석 1 61.97 61.97 4.4762 0.0634803 . Residuals 9 124.59 13.84 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 > dbDisconnect(con) [1] TRUE > options(TSconnection = NULL) > odbcCloseAll() >
> summary(model) Call: lm(formula = 통계 ~ 수학 + 결석, data = result) Residuals: Min 1Q Median 3Q Max -5.348 -2.274 -1.276 2.954 5.673 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 53.6832 14.1808 3.786 0.00431 ** 수학 0.6073 0.1984 3.062 0.01353 * 결석 -1.9346 0.9144 -2.116 0.06348 . --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 3.721 on 9 degrees of freedom Multiple R-squared: 0.8289, Adjusted R-squared: 0.7909 F-statistic: 21.8 on 2 and 9 DF, p-value: 0.0003544
> anova(model) #자유도, 제곱합, 제곱평균 F값, Analysis of Variance Table Response: 통계 Df Sum Sq Mean Sq F value Pr(>F) 수학 1 541.69 541.69 39.1297 0.0001487 *** 결석 1 61.97 61.97 4.4762 0.0634803 . Residuals 9 124.59 13.84 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
요인 | 제곱합 | 자유도 | 제곱평균 | F비 |
회귀 | 603.66 | 11 | 301.83 | 21.802950 |
잔차 | 124.59 | 9 | 13.84 | |
계 | 728.25 | 11 |