suppressWarnings({library(githubinstall)library(evaluate)library(haven)library(tidyverse) devtools::install_local("/Users/jihoonchoi/Documents/GitHub/konfound", force =TRUE)library(konfound) })
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
── R CMD build ─────────────────────────────────────────────────────────────────
* checking for file ‘/private/var/folders/gl/9nbm4d7s0zv_7r1wcdpj_kv80000gn/T/RtmpbNatIP/file22802a21dc0b/konfound/DESCRIPTION’ ... OK
* preparing ‘konfound’:
* checking DESCRIPTION meta-information ... OK
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
NB: this package now depends on R (>= 3.5.0)
WARNING: Added dependency on R >= 3.5.0 because serialized objects in
serialize/load version 3 cannot be read in older versions of R.
File(s) containing such objects:
‘konfound/data/binary_dummy_data.rda’
* building ‘konfound_1.0.2.tar.gz’
Sensitivity analysis as described in Frank,
Maroulis, Duong, and Kelcey (2013) and in
Frank (2000).
For more information visit http://konfound-it.com.
Model 1
auto =read_dta("auto.dta")m1 <-lm(mpg ~ weight + displacement + gear_ratio, data = auto)summary(m1)
Call:
lm(formula = mpg ~ weight + displacement + gear_ratio, data = auto)
Residuals:
Min 1Q Median 3Q Max
-6.8220 -2.0305 -0.5961 1.0858 13.6341
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 37.564106 6.564394 5.722 2.40e-07 ***
weight -0.006534 0.001176 -5.556 4.67e-07 ***
displacement 0.007686 0.011578 0.664 0.509
gear_ratio 0.645258 1.598012 0.404 0.688
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 3.477 on 70 degrees of freedom
Multiple R-squared: 0.6537, Adjusted R-squared: 0.6389
F-statistic: 44.05 on 3 and 70 DF, p-value: 4.161e-16
konfound(m1, weight, to_return ="table")
Dependent variable is mpg
For interpretation, check out to_return = 'print'.
X represents weight, Y represents mpg, v represents each covariate.
First table is based on unconditional correlations, second table is based on
partial correlations.
For interpretation, check out to_return = 'print'.
X represents gear_ratio, Y represents mpg, v represents each covariate.
First table is based on unconditional correlations, second table is based on
partial correlations.
lifeexp =read_dta("lifeexp.dta")m2 <-lm(mpg ~ wt + hp + gear, data = mtcars)summary(m2)
Call:
lm(formula = mpg ~ wt + hp + gear, data = mtcars)
Residuals:
Min 1Q Median 3Q Max
-3.3712 -1.9017 -0.3444 0.9883 6.0655
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 32.013657 4.632264 6.911 1.64e-07 ***
wt -3.197811 0.846546 -3.777 0.000761 ***
hp -0.036786 0.009891 -3.719 0.000888 ***
gear 1.019981 0.851408 1.198 0.240963
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 2.574 on 28 degrees of freedom
Multiple R-squared: 0.8352, Adjusted R-squared: 0.8176
F-statistic: 47.31 on 3 and 28 DF, p-value: 4.334e-11
konfound(m2, wt, to_return ="table")
Dependent variable is mpg
For interpretation, check out to_return = 'print'.
X represents wt, Y represents mpg, v represents each covariate.
First table is based on unconditional correlations, second table is based on
partial correlations.
$Main_Output
# A tibble: 4 × 6
term estimate std.error statistic p.value itcv
<chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) 32.0 4.63 6.91 0 NA
2 wt -3.20 0.847 -3.78 0.001 0.096
3 hp -0.037 0.01 -3.72 0.001 0.511
4 gear 1.02 0.851 1.20 0.241 0.28
$Unconditional_Impact
# A tibble: 2 × 4
term `Cor(vX)` `Cor(vY)` Impact
<chr> <dbl> <dbl> <dbl>
1 hp 0.659 -0.776 -0.511
2 gear -0.583 0.480 -0.280
$Partial_Impact
# A tibble: 2 × 4
term `Partial Cor(vX)` `Partial Cor(vY)` Partial_Impact
<chr> <dbl> <dbl> <dbl>
1 gear -0.670 0.612 -0.410
2 hp 0.726 -0.823 -0.598
konfound(m2, hp, to_return ="table")
Dependent variable is mpg
For interpretation, check out to_return = 'print'.
X represents hp, Y represents mpg, v represents each covariate.
First table is based on unconditional correlations, second table is based on
partial correlations.
For interpretation, check out to_return = 'print'.
X represents gear, Y represents mpg, v represents each covariate.
First table is based on unconditional correlations, second table is based on
partial correlations.
$Main_Output
# A tibble: 4 × 6
term estimate std.error statistic p.value itcv
<chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) 32.0 4.63 6.91 0 NA
2 wt -3.20 0.847 -3.78 0.001 0.506
3 hp -0.037 0.01 -3.72 0.001 0.098
4 gear 1.02 0.851 1.20 0.241 0.032
$Unconditional_Impact
# A tibble: 2 × 4
term `Cor(vX)` `Cor(vY)` Impact
<chr> <dbl> <dbl> <dbl>
1 wt -0.583 -0.868 0.506
2 hp -0.126 -0.776 0.0976
$Partial_Impact
# A tibble: 2 × 4
term `Partial Cor(vX)` `Partial Cor(vY)` Partial_Impact
<chr> <dbl> <dbl> <dbl>
1 wt -0.670 -0.751 0.504
2 hp 0.423 -0.547 -0.231
Model 3
data(longley)# Fit a linear regression modelm3 <-lm(Employed ~ GNP + Unemployed + Population, data = longley)summary(m3)
Call:
lm(formula = Employed ~ GNP + Unemployed + Population, data = longley)
Residuals:
Min 1Q Median 3Q Max
-0.86541 -0.28638 -0.00244 0.23951 1.09949
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 66.157747 23.855700 2.773 0.0169 *
GNP 0.047616 0.017014 2.799 0.0161 *
Unemployed -0.003854 0.003315 -1.162 0.2677
Population -0.153892 0.266420 -0.578 0.5742
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 0.5387 on 12 degrees of freedom
Multiple R-squared: 0.9812, Adjusted R-squared: 0.9765
F-statistic: 208.5 on 3 and 12 DF, p-value: 1.293e-10
konfound(m3, GNP, to_return ="table")
Dependent variable is Employed
For interpretation, check out to_return = 'print'.
X represents GNP, Y represents Employed, v represents each covariate.
First table is based on unconditional correlations, second table is based on
partial correlations.
$Main_Output
# A tibble: 4 × 6
term estimate std.error statistic p.value itcv
<chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) 66.2 23.9 2.77 0.017 NA
2 GNP 0.048 0.017 2.80 0.016 0.003
3 Unemployed -0.004 0.003 -1.16 0.268 0.304
4 Population -0.154 0.266 -0.578 0.574 0.952
$Unconditional_Impact
# A tibble: 2 × 4
term `Cor(vX)` `Cor(vY)` Impact
<chr> <dbl> <dbl> <dbl>
1 Unemployed 0.604 0.502 0.304
2 Population 0.991 0.960 0.952
$Partial_Impact
# A tibble: 2 × 4
term `Partial Cor(vX)` `Partial Cor(vY)` Partial_Impact
<chr> <dbl> <dbl> <dbl>
1 Population 0.995 0.979 0.974
2 Unemployed -0.787 -0.774 0.609
konfound(m3, Unemployed, to_return ="table")
Dependent variable is Employed
For interpretation, check out to_return = 'print'.
X represents Unemployed, Y represents Employed, v represents each covariate.
First table is based on unconditional correlations, second table is based on
partial correlations.
$Main_Output
# A tibble: 4 × 6
term estimate std.error statistic p.value itcv
<chr> <dbl> <dbl> <dbl> <dbl> <dbl>
1 (Intercept) 66.2 23.9 2.77 0.017 NA
2 GNP 0.048 0.017 2.80 0.016 0.594
3 Unemployed -0.004 0.003 -1.16 0.268 0.009
4 Population -0.154 0.266 -0.578 0.574 0.659
$Unconditional_Impact
# A tibble: 2 × 4
term `Cor(vX)` `Cor(vY)` Impact
<chr> <dbl> <dbl> <dbl>
1 GNP 0.604 0.984 0.594
2 Population 0.687 0.960 0.659
$Partial_Impact
# A tibble: 2 × 4
term `Partial Cor(vX)` `Partial Cor(vY)` Partial_Impact
<chr> <dbl> <dbl> <dbl>
1 Population 0.826 -0.598 -0.494
2 GNP -0.787 0.855 -0.672
konfound(m3, Population, to_return ="table")
Dependent variable is Employed
For interpretation, check out to_return = 'print'.
X represents Population, Y represents Employed, v represents each covariate.
First table is based on unconditional correlations, second table is based on
partial correlations.
data(swiss)# Fit a linear regression modelm4 <-lm(Fertility ~ Education + Agriculture + Catholic, data = swiss)summary(m4)
Call:
lm(formula = Fertility ~ Education + Agriculture + Catholic,
data = swiss)
Residuals:
Min 1Q Median 3Q Max
-15.178 -6.548 1.379 5.822 14.840
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 86.22502 4.73472 18.211 < 2e-16 ***
Education -1.07215 0.15580 -6.881 1.91e-08 ***
Agriculture -0.20304 0.07115 -2.854 0.00662 **
Catholic 0.14520 0.03015 4.817 1.84e-05 ***
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 7.728 on 43 degrees of freedom
Multiple R-squared: 0.6423, Adjusted R-squared: 0.6173
F-statistic: 25.73 on 3 and 43 DF, p-value: 1.089e-09
konfound(m4, Education, to_return ="table")
Dependent variable is Fertility
For interpretation, check out to_return = 'print'.
X represents Education, Y represents Fertility, v represents each covariate.
First table is based on unconditional correlations, second table is based on
partial correlations.
For interpretation, check out to_return = 'print'.
Error in solve.default(cvx): system is computationally singular: reciprocal condition number = 2.19513e-17
konfound(m4, Catholic, to_return ="table")
Dependent variable is Fertility
For interpretation, check out to_return = 'print'.
X represents Catholic, Y represents Fertility, v represents each covariate.
First table is based on unconditional correlations, second table is based on
partial correlations.