User Tools

Site Tools


c:ms:2023:schedule:w11.lecture.note

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
c:ms:2023:schedule:w11.lecture.note [2023/05/22 11:57] hkimscilc:ms:2023:schedule:w11.lecture.note [2023/05/24 08:37] (current) hkimscil
Line 1: Line 1:
 +====== 하나의 독립변인이 갖는 고유의 영향력 혹은 설명력 파악하기 ======
 +[[:multiple regression]] 참조
 +[[:partial and semipartial correlation]] 참조
 <code> <code>
 datavar <- read.csv("http://commres.net/wiki/_media/regression01-bankaccount.csv" datavar <- read.csv("http://commres.net/wiki/_media/regression01-bankaccount.csv"
Line 6: Line 9:
 attach(datavar) attach(datavar)
  
 +library(ggplot2) # ggplot 사용을 위해서 
 +# install.packages("ggplot2")
  
 lm.y.x1 <- lm(y~x1, data=datavar) lm.y.x1 <- lm(y~x1, data=datavar)
Line 14: Line 19:
 intercept.y intercept.y
 slope.x slope.x
-ggplot(data=datavar, aes(income,bankaccount)) ++ggplot(data=datavar, aes(x1,y)) +
   geom_point(color="blue", size=1.5, pch=2) +   geom_point(color="blue", size=1.5, pch=2) +
-  geom_hline(aes(yintercept=mean(bankaccount)),size=1.5, color="red") ++  geom_hline(aes(yintercept=mean(y)), size=1.5, color="red") +
   geom_abline(intercept=intercept.y, slope=slope.x, size=1.5, color="darkgreen")   geom_abline(intercept=intercept.y, slope=slope.x, size=1.5, color="darkgreen")
  
Line 41: Line 46:
 intercept.y intercept.y
 slope.x slope.x
-ggplot(data=datavar, aes(famnum,bankaccount)) ++ggplot(data=datavar, aes(x2,y)) +
   geom_point(color="blue", size=1.5, pch=2) +   geom_point(color="blue", size=1.5, pch=2) +
-  geom_hline(aes(yintercept=mean(bankaccount)),size=1.5, color="red") ++  geom_hline(aes(yintercept=mean(y)),size=1.5, color="red") +
   geom_abline(intercept=intercept.y, slope=slope.x, size=1.5, color="darkgreen")   geom_abline(intercept=intercept.y, slope=slope.x, size=1.5, color="darkgreen")
  
Line 51: Line 56:
  
 ################################## ##################################
-res.y.minus.x2 <- resid(lm.y.x2) # y - x2 +res.lm.y.x2 <- resid(lm.y.x2) # y - x2 
  
 # x2를 제외하기 위한 계산 # x2를 제외하기 위한 계산
 lm.x1.x2 <- lm(x1~x2, data=datavar) lm.x1.x2 <- lm(x1~x2, data=datavar)
-res.x1.minus.x2 <- resid(lm.x1.x2) # x1 - x2+res.lm.x1.x2 <- resid(lm.x1.x2) # x1 - x2
  
-lm(res.y.minus.x2~res.x1.minus.x2) +lm(res.lm.y.x2~res.lm.x1.x2) 
-summary(lm(res.y.minus.x2 ~ res.x1.minus.x2)) # x2를 y, x1에서 모두 제외한 분석+summary(lm(res.lm.y.x2~res.lm.x1.x2)) # x2를 y, x1에서 모두 제외한 분석
 # or  # or 
-cor(res.y.minus.x2, res.x1.minus.x2) +cor(res.lm.y.x2, res.lm.x1.x2) 
-cor(res.y.minus.x2, res.x1.minus.x2)^2 +# cor제곱 값은 x2의 설명력을 제어 혹은 제외한 후에 보는  
-summary(lm(res.y.minus.x2~res.x1.minus.x2))$r.squared+# y와 x1간의 r 제곱값이다  
 +cor(res.lm.y.x2, res.lm.x1.x2)^2 
 +summary(lm(res.lm.y.x2~res.lm.x1.x2))$r.squared
  
-################## +############################ 
-install.packages("ppcor")+# http://commres.net/wiki/partial_and_semipartial_correlation 문서 확인할 것 
 +install.packages("ppcor")
 library(ppcor) library(ppcor)
 pcor(datavar) pcor(datavar)
  
-+datavar # data 확인 
-x1 +pcor.test(y, x1, x2) # x2제어 하고, y와 x1과의 correlation값을 묻는 펑션
-x2 +
-datavar +
-pcor.test(y, x1, x2)+
 summary(lm(res.y.minus.x2~res.x1.minus.x2)) summary(lm(res.y.minus.x2~res.x1.minus.x2))
-r.sq <- (summary(lm(res.y.minus.x2~res.x1.minus.x2)))$r.squared+r.sq <- (summary(lm(res.lm.y.x2~res.lm.x1.x2)))$r.squared
 r.sq  r.sq 
 sqrt(r.sq) sqrt(r.sq)
Line 82: Line 87:
 # 알아낼 수 있다.  # 알아낼 수 있다. 
 sp.y.x1 <- spcor.test(y, x1, x2) sp.y.x1 <- spcor.test(y, x1, x2)
-sp.y.x1 
 sp.y.x2 <- spcor.test(y, x2, x1) sp.y.x2 <- spcor.test(y, x2, x1)
 +
 b <- sp.y.x1$estimate^2 b <- sp.y.x1$estimate^2
 c <- sp.y.x2$estimate^2 c <- sp.y.x2$estimate^2
Line 95: Line 100:
 common.area common.area
  
-# b + common.area should be r.squared from lm(y~x1,data=datavar)+# common.area가 맞는지 확인  
 +# b + common.area는 lm(y~x1,data=datavar)에서의 r.square 값이어야 한다
 summary(lm.y.x1)$r.squared summary(lm.y.x1)$r.squared
 b + common.area b + common.area
Line 102: Line 108:
 summary(lm.y.x2)$r.squared summary(lm.y.x2)$r.squared
 c + common.area c + common.area
 +</code>
  
 +====== 기울기 b에 대한 통계학적인 테스트 ======
 +[[:multiple regression]]에서 앞 쪽에 기울기에 대한 테스트 부분
 +regression 문서에서 [[:regression#eg_3_simple_regressionadjusted_r_squared_slope_test]] 부분
  
 +<code>
 ################################################ ################################################
 # standard error of coefficient의 의미  # standard error of coefficient의 의미 
c/ms/2023/schedule/w11.lecture.note.1684724256.txt.gz · Last modified: 2023/05/22 11:57 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki