Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mismatch in sign of partial and semi partial correlations #44

Closed
aravindhebbali opened this issue Oct 23, 2017 · 0 comments

Comments

Projects
None yet
1 participant
@aravindhebbali
Copy link
Member

commented Oct 23, 2017

Mismatch in the sign of partial and semi partial correlation in ols_correlations().

library(tidyverse)
library(olsrr)
library(ppcor)

# read data
fire <- read_csv("firedata.csv")

lm2 <- lm(damage ~ fighters + severe, data=fire)
ols_regress(lm2)
##                             Model Summary                             
## ---------------------------------------------------------------------
## R                       0.908       RMSE                   20958.007 
## R-Squared               0.824       Coef. Var                 17.899 
## Adj. R-Squared          0.824       MSE                439238058.090 
## Pred R-Squared          0.823       MAE                    16952.542 
## ---------------------------------------------------------------------
##  RMSE: Root Mean Square Error 
##  MSE: Mean Square Error 
##  MAE: Mean Absolute Error 
## 
##                                       ANOVA                                       
## ---------------------------------------------------------------------------------
##                         Sum of                                                   
##                        Squares         DF      Mean Square       F          Sig. 
## ---------------------------------------------------------------------------------
## Regression        2.050264e+12          2     1.025132e+12    2333.887    0.0000 
## Residual      437920343915.371        997    439238058.090                       
## Total             2.488184e+12        999                                        
## ---------------------------------------------------------------------------------
## 
##                                          Parameter Estimates                                          
## -----------------------------------------------------------------------------------------------------
##       model          Beta    Std. Error    Std. Beta       t        Sig          lower         upper 
## -----------------------------------------------------------------------------------------------------
## (Intercept)     55253.771      1669.994                  33.086    0.000     51976.665     58530.877 
##    fighters    -12711.639       552.040       -0.922    -23.027    0.000    -13794.932    -11628.345 
##      severe     29951.971       695.578        1.725     43.061    0.000     28587.007     31316.935 
## -----------------------------------------------------------------------------------------------------

pcor.test(fire$damage,fire$fighters,fire[,c("severe")])
##     estimate     p.value statistic    n gp  Method
## 1 -0.5892224 2.01807e-94 -23.02667 1000  1 pearson

spcor.test(fire$damage,fire$fighters,fire[,c("severe")])
##     estimate      p.value statistic    n gp  Method
## 1 -0.3059425 4.330228e-23 -10.14676 1000  1 pearson

pcor.test(fire$damage,fire$severe,fire[,c("fighters")])
##    estimate      p.value statistic    n gp  Method
## 1 0.8064269 1.03021e-229  43.06058 1000  1 pearson

spcor.test(fire$damage,fire$severe,fire[,c("fighters")])
##    estimate      p.value statistic    n gp  Method
## 1 0.5721218 6.390856e-88  22.02586 1000  1 pearson

ols_correlations(lm2)
##                Correlations                
## ------------------------------------------
## Variable    Zero Order    Partial    Part  
## ------------------------------------------
## fighters         0.705      0.589    0.306 
## severe           0.855      0.806    0.572 
## ------------------------------------------

@aravindhebbali aravindhebbali added the bug label Oct 23, 2017

@aravindhebbali aravindhebbali self-assigned this Oct 23, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.