User Tools

Site Tools


sequential_regression

Differences

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

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
sequential_regression [2018/11/09 07:45]
hkimscil [Seq.]
sequential_regression [2019/10/18 07:03] (current)
hkimscil [r]
Line 94: Line 94:
 https://​ww2.coastal.edu/​kingw/​statistics/​R-tutorials/​multregr.html https://​ww2.coastal.edu/​kingw/​statistics/​R-tutorials/​multregr.html
  
 +====== r ======
 +<​code>​
 +datavar <- read.csv("​http://​commres.net/​wiki/​_media/​regression01-bankaccount.csv"​)
 +datavar ​
 +m1 <- lm(bankaccount~income+famnum,​ data=datavar)
 +summary(m1)
 +library(ppcor)
 +spcor(datavar)
 +pcor(datavar)
 +
 +</​code>​
 +<​code>​
 +> datavar <- read.csv("​http://​commres.net/​wiki/​_media/​regression01-bankaccount.csv"​)
 +> datavar ​
 +   ​bankaccount income famnum
 +1            6    220      5
 +2            5    190      6
 +3            7    260      3
 +4            7    200      4
 +5            8    330      2
 +6           ​10 ​   490      4
 +7            8    210      3
 +8           ​11 ​   380      2
 +9            9    320      1
 +10           ​9 ​   270      3
 +> m1 <- lm(bankaccount~income+famnum,​ data=datavar)
 +> summary(m1)
 +
 +Call:
 +lm(formula = bankaccount ~ income + famnum, data = datavar)
 +
 +Residuals:
 +    Min      1Q  Median ​     3Q     ​Max ​
 +-1.2173 -0.5779 -0.1515 ​ 0.6642 ​ 1.1906 ​
 +
 +Coefficients:​
 +             ​Estimate Std. Error t value Pr(>​|t|) ​  
 +(Intercept) ​ 6.399103 ​  ​1.516539 ​  ​4.220 ​ 0.00394 **
 +income ​      ​0.011841 ​  ​0.003561 ​  ​3.325 ​ 0.01268 * 
 +famnum ​     -0.544727 ​  ​0.226364 ​ -2.406 ​ 0.04702 * 
 +---
 +Signif. codes: ​ 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +Residual standard error: 0.9301 on 7 degrees of freedom
 +Multiple R-squared: ​ 0.7981,​ Adjusted R-squared: ​ 0.7404 ​
 +F-statistic:​ 13.84 on 2 and 7 DF,  p-value: 0.003696
 +
 +> library(ppcor)
 +> spcor(datavar)
 +$estimate
 +            bankaccount ​   income ​    ​famnum
 +bankaccount ​  ​1.0000000 0.5646726 -0.4086619
 +income ​       0.7171965 1.0000000 ​ 0.2078919
 +famnum ​      ​-0.6166940 0.2470028 ​ 1.0000000
 +
 +$p.value
 +            bankaccount ​  ​income ​   famnum
 +bankaccount ​ 0.00000000 0.113182 0.2748117
 +income ​      ​0.02964029 0.000000 0.5914441
 +famnum ​      ​0.07691195 0.521696 0.0000000
 +
 +$statistic
 +            bankaccount ​   income ​    ​famnum
 +bankaccount ​   0.000000 1.8101977 -1.1846548
 +income ​        ​2.722920 0.0000000 ​ 0.5623159
 +famnum ​       -2.072679 0.6744045 ​ 0.0000000
 +
 +$n
 +[1] 10
 +
 +$gp
 +[1] 1
 +
 +$method
 +[1] "​pearson"​
 +
 +> pcor(datavar)
 +$estimate
 +            bankaccount ​   income ​    ​famnum
 +bankaccount ​  ​1.0000000 0.7825112 -0.6728560
 +income ​       0.7825112 1.0000000 ​ 0.3422911
 +famnum ​      ​-0.6728560 0.3422911 ​ 1.0000000
 +
 +$p.value
 +            bankaccount ​    ​income ​    ​famnum
 +bankaccount ​ 0.00000000 0.01267595 0.04702022
 +income ​      ​0.01267595 0.00000000 0.36723388
 +famnum ​      ​0.04702022 0.36723388 0.00000000
 +
 +$statistic
 +            bankaccount ​   income ​    ​famnum
 +bankaccount ​   0.000000 3.3251023 -2.4064253
 +income ​        ​3.325102 0.0000000 ​ 0.9638389
 +famnum ​       -2.406425 0.9638389 ​ 0.0000000
 +
 +$n
 +[1] 10
 +
 +$gp
 +[1] 1
 +
 +$method
 +[1] "​pearson"​
 +
 +## zero-order correlation
 +> cor(datavar)
 +            bankaccount ​    ​income ​    ​famnum
 +bankaccount ​  ​1.0000000 ​ 0.7944312 -0.6922935
 +income ​       0.7944312 ​ 1.0000000 -0.3999614
 +famnum ​      ​-0.6922935 -0.3999614 ​ 1.0000000
 +
 +
 +</​code>​
 +semipartial (part): spcor()
 +
 +|           | bankaccount ​ | income ​   | famnum ​ |
 +| bankaccount ​ | 1.0000000 ​ | <fc #​ff0000>​0.5646726</​fc> ​ | <fc #​ff0000>​-0.4086619</​fc> ​ |
 +| income ​  | 0.7171965 ​ | 1.0000000 ​ | 0.2078919 ​ |
 +| famnum ​     | -0.6166940 ​ | 0.2470028 ​ | 1.0000000 ​ |
 +
 +
 +
 +|            | bankaccount ​ | income ​ | famnum ​   | 
 +| bankaccount ​ | 1.0000000 ​ | <fc #​ff0000>​0.7825112</​fc> ​ | <fc #​ff0000>​-0.6728560</​fc> ​   | 
 +| income ​ | 0.7825112 ​ | 1.0000000 ​ | 0.3422911 ​   | 
 +| famnum ​ | -0.6728560 ​ | 0.3422911 ​ | 1.0000000 ​   | 
 +
 +
 +|  | bankaccount ​ | income ​ | famnum ​  ​| ​
 +| bankaccount ​ | 1.0000000 ​ | 0.7944312 ​ | -0.6922935 ​ | 
 +| income ​ | 0.7944312 ​ | 1.0000000 ​ | -0.3999614 ​  ​| ​
 +| famnum ​ | -0.6922935 ​ | -0.3999614 ​  | 1.0000000 ​   | 
 +
 +<​code>​
 +pcor.test(datavar$bankaccount,​ datavar$income,​ datavar$famnum)
 +pcor.test(datavar$bankaccount,​ datavar$famnum,​ datavar$income)
 +
 +spcor.test(datavar$bankaccount,​ datavar$income,​ datavar$famnum)
 +spcor.test(datavar$bankaccount,​ datavar$famnum,​ datavar$income)
 +</​code>​
 +. . . 
 +<​code>​
 +> pcor.test(datavar$bankaccount,​ datavar$income,​ datavar$famnum)
 +   ​estimate ​   p.value statistic ​ n gp  Method
 +1 0.7825112 0.01267595 ​ 3.325102 10  1 pearson
 +> pcor.test(datavar$bankaccount,​ datavar$famnum,​ datavar$income)
 +   ​estimate ​   p.value statistic ​ n gp  Method
 +1 -0.672856 0.04702022 -2.406425 10  1 pearson
 +>
 +> spcor.test(datavar$bankaccount,​ datavar$income,​ datavar$famnum)
 +   ​estimate ​ p.value statistic ​ n gp  Method
 +1 0.5646726 0.113182 ​ 1.810198 10  1 pearson
 +> spcor.test(datavar$bankaccount,​ datavar$famnum,​ datavar$income)
 +    estimate ​  ​p.value statistic ​ n gp  Method
 +1 -0.4086619 0.2748117 -1.184655 10  1 pearson
 +
 +
 + 
 +</​code>​
sequential_regression.1541718909.txt.gz · Last modified: 2018/11/09 07:45 by hkimscil