User Tools

Site Tools


partial_and_semipartial_correlation

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revisionBoth sides next revision
partial_and_semipartial_correlation [2019/05/23 10:27] – [regression gpa against sat] hkimscilpartial_and_semipartial_correlation [2019/05/26 22:54] – [Semipartial cor] hkimscil
Line 331: Line 331:
 > </code> > </code>
  
 +<code>> tests <- read.csv("http://commres.net/wiki/_media/r/tests_cor.csv")
 +> colnames(tests) <- c("ser", "sat", "clep", "gpa")
 +> tests <- subset(tests, select=c("sat", "clep", "gpa"))
 +> attach(tests)
 +> cors <- cor(tests)
 +> round(cors,3)
 +       sat  clep   gpa
 +sat  1.000 0.875 0.718
 +clep 0.875 1.000 0.876
 +gpa  0.718 0.876 1.000
 +> lm.sat.clep <- lm(sat ~ clep, data = tests)
 +> summary(lm.sat.clep)
 +
 +Call:
 +lm(formula = sat ~ clep, data = tests)
 +
 +Residuals:
 +     Min       1Q   Median       3Q      Max 
 +-101.860  -19.292    1.136   28.306   54.132 
 +
 +Coefficients:
 +            Estimate Std. Error t value Pr(>|t|)    
 +(Intercept)  -19.421    114.638  -0.169  0.86967    
 +clep          17.665      3.464   5.100  0.00093 ***
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +Residual standard error: 48.2 on 8 degrees of freedom
 +Multiple R-squared:  0.7648, Adjusted R-squared:  0.7353 
 +F-statistic: 26.01 on 1 and 8 DF,  p-value: 0.0009303
 +
 +> res.lm.sat.clep <- lm.sat.clep$residuals
 +
 +> install.packages("ppcor")
 +WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:
 +
 +https://cran.rstudio.com/bin/windows/Rtools/
 +Installing package into ‘C:/Users/Hyo/Documents/R/win-library/3.6’
 +(as ‘lib’ is unspecified)
 +trying URL 'https://cran.rstudio.com/bin/windows/contrib/3.6/ppcor_1.1.zip'
 +Content type 'application/zip' length 30230 bytes (29 KB)
 +downloaded 29 KB
 +
 +package ‘ppcor’ successfully unpacked and MD5 sums checked
 +
 +The downloaded binary packages are in
 + C:\Users\Hyo\AppData\Local\Temp\Rtmp61tIED\downloaded_packages
 +> library(ppcor)
 +Loading required package: MASS
 +> spcor.gpa.sat.clep <- lm(gpa ~ res.lm.sat.clep)
 +> summary(spcor.gpa.sat.clep)
 +
 +Call:
 +lm(formula = gpa ~ res.lm.sat.clep)
 +
 +Residuals:
 +    Min      1Q  Median      3Q     Max 
 +-0.3756 -0.2694 -0.0092  0.2514  0.4686 
 +
 +Coefficients:
 +                  Estimate Std. Error t value Pr(>|t|)    
 +(Intercept)      3.1600000  0.1069377  29.550 1.86e-09 ***
 +res.lm.sat.clep -0.0007015  0.0024806  -0.283    0.785    
 +---
 +Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
 +
 +Residual standard error: 0.3382 on 8 degrees of freedom
 +Multiple R-squared:  0.009898, Adjusted R-squared:  -0.1139 
 +F-statistic: 0.07997 on 1 and 8 DF,  p-value: 0.7845
 +
 +</code>
 ====== 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.txt · Last modified: 2023/05/31 08:56 by hkimscil

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki