partial_and_semipartial_correlation
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
partial_and_semipartial_correlation [2024/10/15 15:51] – [e.g. Using ppcor.test with 4 var] hkimscil | partial_and_semipartial_correlation [2024/10/17 10:28] (current) – [e.g. Using ppcor.test with 4 var] hkimscil | ||
---|---|---|---|
Line 422: | Line 422: | ||
library(faux) | library(faux) | ||
- | set.seed(1011) | + | set.seed(101) |
scholar <- rnorm_multi(n = 50, | scholar <- rnorm_multi(n = 50, | ||
- | mu = c(3.12, 3.3, 540, 650), | + | mu = c(3.12, 3.3, 540, 650), |
- | | + | |
- | | + | |
- | | + | |
- | | + | |
attach(scholar) | attach(scholar) | ||
Line 441: | Line 441: | ||
# install.packages(" | # install.packages(" | ||
library(ppcor) | library(ppcor) | ||
+ | |||
+ | reg.g.sh <- lm(GREV ~ SATV + HSGPA) | ||
+ | res.g.sh <- resid(reg.g.sh) | ||
+ | |||
+ | reg.g.fh <- lm(GREV ~ FGPA + HSGPA) | ||
+ | res.g.fh <- resid(reg.g.fh) | ||
+ | |||
+ | reg.g.sf <- lm(GREV ~ SATV + FGPA) | ||
+ | res.g.sf <- resid(reg.g.sf) | ||
reg.f.sh <- lm(FGPA ~ SATV + HSGPA) | reg.f.sh <- lm(FGPA ~ SATV + HSGPA) | ||
Line 460: | Line 469: | ||
summary(reg.2) | summary(reg.2) | ||
summary(reg.3) | summary(reg.3) | ||
+ | |||
+ | reg.1a <- lm(res.g.sh~res.f) | ||
+ | reg.2a <- lm(res.g.fh~res.s) | ||
+ | reg.3a <- lm(res.g.sf~res.h) | ||
+ | |||
+ | reg.1$coefficient[2] | ||
+ | reg.2$coefficient[2] | ||
+ | reg.3$coefficient[2] | ||
+ | |||
+ | reg.1a$coefficient[2] | ||
+ | reg.2a$coefficient[2] | ||
+ | reg.3a$coefficient[2] | ||
spr.y.f <- spcor.test(GREV, | spr.y.f <- spcor.test(GREV, | ||
spr.y.s <- spcor.test(GREV, | spr.y.s <- spcor.test(GREV, | ||
spr.y.h <- spcor.test(GREV, | spr.y.h <- spcor.test(GREV, | ||
+ | |||
+ | spr.y.f$estimate | ||
+ | spr.y.s$estimate | ||
+ | spr.y.h$estimate | ||
spr.y.f$estimate^2 | spr.y.f$estimate^2 | ||
Line 472: | Line 497: | ||
summary(reg.2)$r.square | summary(reg.2)$r.square | ||
summary(reg.3)$r.square | summary(reg.3)$r.square | ||
+ | |||
+ | ca <- summary(reg.1)$r.square + | ||
+ | summary(reg.2)$r.square + | ||
+ | summary(reg.3)$r.square | ||
+ | # so common explanation area should be | ||
+ | summary(reg.all)$r.square - carm(list=ls()) | ||
+ | |||
+ | library(ggplot2) | ||
+ | library(dplyr) | ||
+ | library(tidyr) | ||
+ | library(faux) | ||
+ | |||
+ | set.seed(101) | ||
+ | scholar <- rnorm_multi(n = 50, | ||
+ | mu = c(3.12, 3.3, 540, 650), | ||
+ | sd = c(.25, .34, 12, 13), | ||
+ | r = c(0.15, 0.44, 0.47, 0.55, 0.45, 0.88), | ||
+ | | ||
+ | | ||
+ | attach(scholar) | ||
+ | |||
+ | # library(psych) | ||
+ | describe(scholar) # provides descrptive information about each variable | ||
+ | |||
+ | corrs <- cor(scholar) # find the correlations and set them into an object called ' | ||
+ | corrs # print corrs | ||
+ | |||
+ | pairs(scholar) | ||
+ | |||
+ | # install.packages(" | ||
+ | library(ppcor) | ||
+ | |||
+ | reg.f.sh <- lm(FGPA ~ SATV + HSGPA) | ||
+ | res.f <- resid(reg.f.sh) | ||
+ | |||
+ | reg.s.fh <- lm(SATV ~ FGPA + HSGPA) | ||
+ | res.s <- resid(reg.s.fh) | ||
+ | |||
+ | reg.h.sf <- lm(HSGPA ~ FGPA + SATV) | ||
+ | res.h <- resid(reg.h.sf) | ||
+ | |||
+ | reg.all <- lm(GREV ~ HSGPA + FGPA + SATV) | ||
+ | reg.1 <- lm(GREV ~ res.f) | ||
+ | reg.2 <- lm(GREV ~ res.s) | ||
+ | reg.3 <- lm(GREV ~ res.h) | ||
+ | |||
+ | summary(reg.all) | ||
+ | summary(reg.1) | ||
+ | summary(reg.2) | ||
+ | summary(reg.3) | ||
+ | |||
+ | reg.1$coefficient[2] | ||
+ | reg.2$coefficient[2] | ||
+ | reg.3$coefficient[2] | ||
+ | |||
+ | spr.y.f <- spcor.test(GREV, | ||
+ | spr.y.s <- spcor.test(GREV, | ||
+ | spr.y.h <- spcor.test(GREV, | ||
+ | |||
+ | spr.y.f$estimate | ||
+ | spr.y.s$estimate | ||
+ | spr.y.h$estimate | ||
+ | |||
+ | spr.y.f$estimate^2 | ||
+ | spr.y.s$estimate^2 | ||
+ | spr.y.h$estimate^2 | ||
+ | |||
+ | summary(reg.1)$r.square | ||
+ | summary(reg.2)$r.square | ||
+ | summary(reg.3)$r.square | ||
+ | |||
+ | ca <- summary(reg.1)$r.square + | ||
+ | summary(reg.2)$r.square + | ||
+ | summary(reg.3)$r.square | ||
+ | # so common explanation area should be | ||
+ | summary(reg.all)$r.square - ca | ||
</ | </ | ||
< | < | ||
+ | > | ||
> rm(list=ls()) | > rm(list=ls()) | ||
> | > | ||
Line 482: | Line 584: | ||
> library(faux) | > library(faux) | ||
> | > | ||
- | > set.seed(1011) | + | > set.seed(101) |
> scholar <- rnorm_multi(n = 50, | > scholar <- rnorm_multi(n = 50, | ||
- | + mu = c(3.12, 3.3, 540, 650), | + | + mu = c(3.12, 3.3, 540, 650), |
- | + sd = c(.25, .34, 12, 13), | + | + sd = c(.25, .34, 12, 13), |
- | + r = c(0.21, 0.24, 0.5, 0.24, 0.6, 0.48), | + | + r = c(0.15, 0.44, 0.47, 0.55, 0.45, 0.88), |
- | + varnames = c(" | + | + varnames = c(" |
- | + empirical = FALSE) | + | + empirical = FALSE) |
> attach(scholar) | > attach(scholar) | ||
The following objects are masked from scholar (pos = 3): | The following objects are masked from scholar (pos = 3): | ||
Line 494: | Line 596: | ||
FGPA, GREV, HSGPA, SATV | FGPA, GREV, HSGPA, SATV | ||
+ | > | ||
> # library(psych) | > # library(psych) | ||
> describe(scholar) # provides descrptive information about each variable | > describe(scholar) # provides descrptive information about each variable | ||
vars n | vars n | ||
- | HSGPA 1 50 | + | HSGPA 1 50 |
- | FGPA 2 50 3.27 0.40 3.27 3.25 0.42 2.50 4.24 1.74 0.43 | + | FGPA 2 50 3.34 0.35 3.32 3.33 0.33 2.50 4.19 1.68 0.27 |
- | SATV 3 50 539.52 10.92 539.54 539.51 11.69 511.15 565.69 54.54 -0.05 | + | SATV 3 50 541.28 11.43 538.45 540.50 10.85 523.74 567.97 44.24 |
- | GREV 4 50 648.41 12.96 649.14 648.14 13.47 622.89 682.17 59.28 0.19 | + | GREV 4 50 651.72 11.90 649.70 651.29 10.55 629.89 678.33 48.45 0.35 |
kurtosis | kurtosis | ||
- | HSGPA -0.22 0.04 | + | HSGPA 1.21 0.03 |
- | FGPA -0.18 0.06 | + | FGPA -0.01 0.05 |
- | SATV -0.25 1.54 | + | SATV -0.60 1.62 |
- | GREV -0.33 1.83 | + | GREV -0.54 1.68 |
> | > | ||
> corrs <- cor(scholar) # find the correlations and set them into an object called ' | > corrs <- cor(scholar) # find the correlations and set them into an object called ' | ||
> corrs # print corrs | > corrs # print corrs | ||
| | ||
- | HSGPA 1.0000 0.3965 0.2047 0.6175 | + | HSGPA 1.0000 0.3404 0.4627 0.5406 |
- | FGPA 0.3965 1.0000 0.2894 0.7300 | + | FGPA 0.3404 1.0000 0.5266 0.5096 |
- | SATV 0.2047 0.2894 1.0000 0.3461 | + | SATV 0.4627 0.5266 1.0000 0.8802 |
- | GREV 0.6175 0.7300 0.3461 1.0000 | + | GREV 0.5406 0.5096 0.8802 1.0000 |
> | > | ||
> pairs(scholar) | > pairs(scholar) | ||
Line 541: | Line 644: | ||
Residuals: | Residuals: | ||
Min 1Q Median | Min 1Q Median | ||
- | -15.939 -4.001 0.451 4.301 16.377 | + | -13.541 -3.441 0.148 4.823 7.796 |
Coefficients: | Coefficients: | ||
Estimate Std. Error t value Pr(> | Estimate Std. Error t value Pr(> | ||
- | (Intercept) | + | (Intercept) |
- | HSGPA 16.971 4.160 4.08 | + | HSGPA 8.3214 3.8050 2.19 |
- | FGPA | + | FGPA |
- | SATV | + | SATV 0.8143 0.0867 9.40 2.8e-12 *** |
--- | --- | ||
Signif. codes: | Signif. codes: | ||
- | Residual standard error: | + | Residual standard error: |
- | Multiple R-squared: | + | Multiple R-squared: |
- | F-statistic: | + | F-statistic: |
> summary(reg.1) | > summary(reg.1) | ||
Line 562: | Line 665: | ||
Residuals: | Residuals: | ||
- | | + | |
- | -24.346 -5.405 -0.617 | + | -21.76 -8.65 -2.08 |
Coefficients: | Coefficients: | ||
Estimate Std. Error t value Pr(> | Estimate Std. Error t value Pr(> | ||
- | (Intercept) | + | (Intercept) |
- | res.f 17.68 | + | res.f 1.40 |
--- | --- | ||
Signif. codes: | Signif. codes: | ||
- | Residual standard error: | + | Residual standard error: |
- | Multiple R-squared: | + | Multiple R-squared: |
- | F-statistic: | + | F-statistic: |
> summary(reg.2) | > summary(reg.2) | ||
Line 583: | Line 686: | ||
Residuals: | Residuals: | ||
| | ||
- | -24.71 -10.49 1.15 | + | -22.54 |
Coefficients: | Coefficients: | ||
Estimate Std. Error t value Pr(> | Estimate Std. Error t value Pr(> | ||
- | (Intercept) | + | (Intercept) |
- | res.s 0.131 0.179 0.73 | + | res.s 0.814 0.148 |
--- | --- | ||
Signif. codes: | Signif. codes: | ||
- | Residual standard error: | + | Residual standard error: |
- | Multiple R-squared: | + | Multiple R-squared: |
- | F-statistic: | + | F-statistic: |
> summary(reg.3) | > summary(reg.3) | ||
Line 602: | Line 705: | ||
Residuals: | Residuals: | ||
- | | + | Min |
- | -24.918 -7.537 0.222 | + | -22.71 -9.32 -1.30 |
Coefficients: | Coefficients: | ||
Estimate Std. Error t value Pr(> | Estimate Std. Error t value Pr(> | ||
- | (Intercept) | + | (Intercept) |
- | res.h 16.97 | + | res.h 8.32 |
--- | --- | ||
Signif. codes: | Signif. codes: | ||
- | Residual standard error: | + | Residual standard error: |
- | Multiple R-squared: | + | Multiple R-squared: |
- | F-statistic: | + | F-statistic: |
+ | > | ||
+ | > reg.1$coefficient[2] | ||
+ | res.f | ||
+ | 1.399 | ||
+ | > reg.2$coefficient[2] | ||
+ | | ||
+ | 0.8143 | ||
+ | > reg.3$coefficient[2] | ||
+ | res.h | ||
+ | 8.321 | ||
> | > | ||
> spr.y.f <- spcor.test(GREV, | > spr.y.f <- spcor.test(GREV, | ||
> spr.y.s <- spcor.test(GREV, | > spr.y.s <- spcor.test(GREV, | ||
> spr.y.h <- spcor.test(GREV, | > spr.y.h <- spcor.test(GREV, | ||
+ | > | ||
+ | > spr.y.f$estimate | ||
+ | [1] 0.03519 | ||
+ | > spr.y.s$estimate | ||
+ | [1] 0.6217 | ||
+ | > spr.y.h$estimate | ||
+ | [1] 0.1447 | ||
> | > | ||
> spr.y.f$estimate^2 | > spr.y.f$estimate^2 | ||
- | [1] 0.24 | + | [1] 0.001238 |
> spr.y.s$estimate^2 | > spr.y.s$estimate^2 | ||
- | [1] 0.01098 | + | [1] 0.3865 |
> spr.y.h$estimate^2 | > spr.y.h$estimate^2 | ||
- | [1] 0.1188 | + | [1] 0.02094 |
> | > | ||
> summary(reg.1)$r.square | > summary(reg.1)$r.square | ||
- | [1] 0.24 | + | [1] 0.001238 |
> summary(reg.2)$r.square | > summary(reg.2)$r.square | ||
- | [1] 0.01098 | + | [1] 0.3865 |
> summary(reg.3)$r.square | > summary(reg.3)$r.square | ||
- | [1] 0.1188 | + | [1] 0.02094 |
+ | > | ||
+ | > ca <- summary(reg.1)$r.square + | ||
+ | + | ||
+ | + | ||
+ | > # so common explanation area should be | ||
+ | > summary(reg.all)$r.square - ca | ||
+ | [1] 0.39 | ||
> | > | ||
</ | </ | ||
- | {{:pasted:20241015-152559.png}} | + | {{:pasted:20241016-080226.png}} |
multiple regression 분석을 보면 독립변인의 coefficient 값은 각각 | multiple regression 분석을 보면 독립변인의 coefficient 값은 각각 | ||
- | * HSGPA 16.971 | + | * HSGPA 8.3214 |
- | * FGPA | + | * FGPA |
- | * SATV | + | * SATV 0.8143 |
이 기울기에 대해서 t-test를 각각 하여 HSGPA와 FGPA의 설명력이 significant 한지를 확인하였다. 그리고 이 때의 R< | 이 기울기에 대해서 t-test를 각각 하여 HSGPA와 FGPA의 설명력이 significant 한지를 확인하였다. 그리고 이 때의 R< | ||
- | * 0.672 (67.2%) | + | * 0.799 이었다. |
- | 그런데 이 coefficient값은 독립변인 각각의 고유의 설명력을 가지고 (spcor.test(GREV, | + | 그런데 이 coefficient값은 독립변인 각각의 고유의 설명력을 가지고 (spcor.test(GREV, |
- | * <WRAP box> | + | |
- | < | + | |
- | > reg.1$coefficient[2] | + | |
- | res.f | + | |
- | 17.68 | + | |
- | > reg.2$coefficient[2] | + | |
- | res.s | + | |
- | 0.1305 | + | |
- | > reg.3$coefficient[2] | + | |
- | res.h | + | |
- | 16.97 | + | |
- | > | + | |
- | </ | + | |
- | </ | + | |
- | + | ||
- | correlation값 | + | |
- | <WRAP box> | + | |
- | Coefficients: | + | |
- | Estimate Std. Error t value Pr(> | + | |
- | (Intercept) | + | |
- | HSGPA | + | |
- | FGPA 17.679 | + | |
- | SATV | + | |
- | --- | + | |
- | Signif. codes: | + | |
- | + | ||
- | Residual standard error: 7.66 on 46 degrees of freedom | + | |
- | Multiple R-squared: | + | |
- | F-statistic: | + | |
- | </ | + | |
- | + | ||
- | 위의 결과를 보면 | + | |
+ | 또한 세 독립변인이 공통적으로 설명하는 부분은 | ||
+ | * 0.39 | ||
+ | 임을 알 수 있다. | ||
====== e.g., 독립변인 들이 서로 독립적일 때의 각각의 설명력 ====== | ====== e.g., 독립변인 들이 서로 독립적일 때의 각각의 설명력 ====== | ||
In this example, the two IVs are orthogonal to each other (not correlated with each other). Hence, regress res.y.x2 against x1 would not result in any problem. | In this example, the two IVs are orthogonal to each other (not correlated with each other). Hence, regress res.y.x2 against x1 would not result in any problem. |
partial_and_semipartial_correlation.1728975076.txt.gz · Last modified: 2024/10/15 15:51 by hkimscil