##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
Set-up
# 1
df.Regression = read.csv("C:/Purdue/Regression/psy631_data.csv")
df.hw2 <- data.frame(df.Regression$totimp90, df.Regression$wviq90, df.Regression$consc90)
colnames(df.hw2) <- c("tot.Imp", "wv.Iq", "consc")
# 2
## No missing values?
# 3
tot.Mu <- mean(df.hw2$tot.Imp)
wv.Mu <- mean(df.hw2$wv.Iq)
consc.Mu <- mean(df.hw2$consc)
df.Cent <- data.frame(df.hw2$tot.Imp - tot.Mu, df.hw2$wv.Iq - wv.Mu, df.hw2$consc - consc.Mu)
colnames(df.Cent) <- c("cent.Imp", "cent.Iq", "cent.Consc")Problems
Number 1
# 1
regress.Imp.Iq <- lm(df.hw2$tot.Imp ~ df.Cent$cent.Iq)
(summary.Imp.Iq <- summary(regress.Imp.Iq))##
## Call:
## lm(formula = df.hw2$tot.Imp ~ df.Cent$cent.Iq)
##
## Residuals:
## Min 1Q Median 3Q Max
## -10.8053 -4.6311 -0.4211 4.8665 12.0075
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.61451 0.66964 0.918 0.362
## df.Cent$cent.Iq -0.19478 0.04609 -4.226 7.26e-05 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.603 on 68 degrees of freedom
## Multiple R-squared: 0.208, Adjusted R-squared: 0.1963
## F-statistic: 17.86 on 1 and 68 DF, p-value: 7.261e-05
## Analysis of Variance Table
##
## Response: df.hw2$tot.Imp
## Df Sum Sq Mean Sq F value Pr(>F)
## df.Cent$cent.Iq 1 560.51 560.51 17.856 7.261e-05 ***
## Residuals 68 2134.50 31.39
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Number 2
# 2
regress.Imp.Consc <- lm(df.hw2$tot.Imp ~ df.Cent$cent.Consc)
(summary.Imp.Consc <- summary(regress.Imp.Consc))##
## Call:
## lm(formula = df.hw2$tot.Imp ~ df.Cent$cent.Consc)
##
## Residuals:
## Min 1Q Median 3Q Max
## -10.354 -4.283 -2.036 4.917 13.549
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.6145 0.6782 0.906 0.368114
## df.Cent$cent.Consc -2.8291 0.7141 -3.962 0.000181 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.675 on 68 degrees of freedom
## Multiple R-squared: 0.1875, Adjusted R-squared: 0.1756
## F-statistic: 15.69 on 1 and 68 DF, p-value: 0.000181
## Analysis of Variance Table
##
## Response: df.hw2$tot.Imp
## Df Sum Sq Mean Sq F value Pr(>F)
## df.Cent$cent.Consc 1 505.35 505.35 15.694 0.000181 ***
## Residuals 68 2189.65 32.20
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Number 3 Set-Up
# 3
regress.Imp.both <- lm(df.hw2$tot.Imp ~ df.Cent$cent.Iq + df.Cent$cent.Consc)
(summary.Imp.both <- summary(regress.Imp.both))##
## Call:
## lm(formula = df.hw2$tot.Imp ~ df.Cent$cent.Iq + df.Cent$cent.Consc)
##
## Residuals:
## Min 1Q Median 3Q Max
## -10.7186 -3.9085 -0.9699 3.9025 12.5366
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.61451 0.61472 1.000 0.321068
## df.Cent$cent.Iq -0.17015 0.04283 -3.972 0.000176 ***
## df.Cent$cent.Consc -2.42472 0.65522 -3.701 0.000436 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 5.143 on 67 degrees of freedom
## Multiple R-squared: 0.3424, Adjusted R-squared: 0.3228
## F-statistic: 17.44 on 2 and 67 DF, p-value: 7.977e-07
## Analysis of Variance Table
##
## Response: df.hw2$tot.Imp
## Df Sum Sq Mean Sq F value Pr(>F)
## df.Cent$cent.Iq 1 560.51 560.51 21.190 1.909e-05 ***
## df.Cent$cent.Consc 1 362.25 362.25 13.695 0.0004364 ***
## Residuals 67 1772.25 26.45
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
3a
The betas to the regression in number three are smaller than their respective counterparts for the models which only include one predictor value at a time.
3b
The difference in R squared between regression 3 and regression 1 is 0.1344147, which corresponds to the amount of additional variance explained by regression 3.
3c
The difference in R squared between regression 3 and regression 2 is 0.1548797, which corresponds to the amount of additional variance explained by regression 3.
## 1 2 3 4 5 6
## -0.2007733 -6.1466242 4.4265993 5.0130737 -2.2351824 8.6739414
## 7 8 9 10 11 12
## -7.6814185 10.2992236 1.9438710 -8.8874891 -10.8052710 5.9844364
## 13 14 15 16 17 18
## -2.6686607 -9.7833753 -6.7587335 4.4156804 3.8374324 -4.0620507
## 19 20 21 22 23 24
## 0.1323401 -4.6320408 -6.1331649 5.2436167 -3.9661543 -2.9591929
## 25 26 27 28 29 30
## -4.7592670 12.0075387 5.4422502 -2.2119909 -5.0620985 5.2075079
## 31 32 33 34 35 36
## 1.9020021 6.0655819 1.8242954 -8.4667346 10.1492248 4.3400083
## 37 38 39 40 41 42
## 2.8609803 -4.2981149 8.3249139 5.2148137 -5.1869266 5.2032527
## 43 44 45 46 47 48
## 8.3399835 0.3185473 3.3398962 5.5280506 3.1342491 -5.3447673
## 49 50 51 52 53 54
## -1.9529373 3.6919664 -5.1888924 -3.3103216 -1.0979813 7.1765530
## 55 56 57 58 59 60
## -1.0162650 -4.6283835 -6.2102322 -4.7354414 2.1950720 -2.7929442
## 61 62 63 64 65 66
## -4.2383943 -2.4049059 5.5466268 -0.6413580 4.4167392 -8.0482481
## 67 68 69 70
## 6.4462391 0.2162761 -6.6416417 -3.7048056
## 1 2 3 4 5 6
## -0.2911598 -4.0539357 4.7257692 6.3883548 -5.4217627 2.9147297
## 7 8 9 10 11 12
## -3.9996517 10.2599472 5.5436751 -1.6794572 -3.8431274 2.4188950
## 13 14 15 16 17 18
## -5.4965373 -7.1372049 -10.2220548 4.9809960 -2.7828549 -3.5478452
## 19 20 21 22 23 24
## 2.9636267 -9.7249552 -3.3539217 1.8111481 -5.5125462 -3.4294737
## 25 26 27 28 29 30
## -2.5026530 6.4219145 4.3673774 -5.1835357 -5.0502649 2.8925984
## 31 32 33 34 35 36
## 8.3309212 2.7256714 7.4027342 -3.9441496 8.7570963 6.1048458
## 37 38 39 40 41 42
## 4.3490769 -10.3543250 3.8568489 5.1138319 -4.4268328 8.3623904
## 43 44 45 46 47 48
## 13.5491232 6.9422446 7.8518860 7.7750026 4.3764573 -2.4729660
## 49 50 51 52 53 54
## -3.4684766 6.0922486 -6.8480999 -2.4682651 -1.2606685 5.5790509
## 55 56 57 58 59 60
## -5.4226246 -6.2364809 -6.6294030 -4.4266094 3.7651313 -4.3595936
## 61 62 63 64 65 66
## -4.7289325 -2.3930722 -3.0725527 -1.0807862 5.3822065 -3.0030338
## 67 68 69 70
## 2.8701023 -8.7722023 -3.3802839 -2.8936018
## 1 2 3 4 5 6
## 4.953724516 -1.299436073 5.294025335 1.337948490 -1.831089586 4.081770183
## 7 8 9 10 11 12
## 1.720760305 2.550310069 2.465181650 0.721060131 2.954324168 3.550010243
## 13 14 15 16 17 18
## -3.149781868 -2.447977945 -1.256818650 -1.001646250 4.145589890 1.401768197
## 19 20 21 22 23 24
## 7.505980660 3.847800066 -5.595813738 0.402174450 -1.214307655 -5.170384500
## 25 26 27 28 29 30
## -2.788278765 -7.190880704 -1.618428181 -5.723346724 0.146895622 3.826491355
## 31 32 33 34 35 36
## 0.040458492 5.379153753 5.825678848 5.719348145 7.080657850 1.678249309
## 37 38 39 40 41 42
## 2.252520245 8.718448667 -3.766563800 -0.767676133 -0.831495840 4.528295278
## 43 44 45 46 47 48
## 1.422970481 0.210608902 -0.002052503 6.995529431 4.485784282 -0.618834435
## 49 50 51 52 53 54
## 0.444685446 -0.214713908 -2.128879410 -1.575917186 -4.085662335 1.189106792
## 55 56 57 58 59 60
## -0.448577598 -4.532293857 -7.573798946 -4.489782861 1.508098900 2.848099893
## 61 62 63 64 65 66
## -1.107976952 0.146895622 4.847500240 -3.511391399 5.060055218 2.911813172
## 67 68 69 70
## -2.171390406 0.444791873 -0.278533615 -3.234910287
## 1 2 3 4 5 6
## -2.0774316 -4.3022386 2.5991966 5.3887440 -2.7808163 4.3580079
## 7 8 9 10 11 12
## -6.3251126 9.4625323 2.9453120 -5.3628138 -8.3451905 2.9793757
## 13 14 15 16 17 18
## -2.4799369 -7.1800042 -7.6838602 5.3779416 -0.9318772 -4.1397566
## 19 20 21 22 23 24
## -1.3749013 -8.5192259 -2.1349619 3.6333880 -3.9599009 -0.7498665
## 25 26 27 28 29 30
## -2.2051515 12.5365754 5.8526241 -1.0079279 -4.8588228 2.7050789
## 31 32 33 34 35 36
## 5.3281663 2.4000469 2.3869122 -8.3821217 6.7299677 4.7649342
## 37 38 39 40 41 42
## 2.9064135 -10.7186102 7.9617504 5.7483266 -4.2000376 5.1154711
## 43 44 45 46 47 48
## 10.5784138 3.7693392 5.8346804 3.9469258 2.1150874 -3.4018705
## 49 50 51 52 53 54
## -2.6317860 5.2307427 -4.8524019 -1.9685677 0.8057357 6.1428393
## 55 56 57 58 59 60
## -2.7496327 -3.2519260 -2.9609389 -2.4276038 2.5953701 -4.5117600
## 61 62 63 64 65 66
## -3.7541370 -2.2016302 -0.5089278 0.8828663 3.0180848 -6.5195476
## 67 68 69 70
## 5.8513496 -4.1634649 -4.6494893 -1.6779496
##
## Call:
## lm(formula = cent.Iq ~ cent.Consc, data = df.Cent)
##
## Coefficients:
## (Intercept) cent.Consc
## 5.302e-15 2.377e+00
## 1 2 3 4 5 6
## -10.4981931 -1.4593141 -12.4981931 -5.8748657 15.5212464 8.4823674
## 7 8 9 10 11 12
## -13.6670899 -4.6865294 -15.2709778 -21.6476504 -26.4593141 3.2940311
## 13 14 15 16 17 18
## 17.7290222 -0.2515383 14.9173585 2.3329101 10.8784795 -3.4787536
## 19 20 21 22 23 24
## -25.4981931 7.0862553 7.1640133 10.7095827 9.1251343 15.7484617
## 25 26 27 28 29 30
## 1.7484617 35.9367980 8.7290222 24.5406859 1.1251343 -1.1020810
## 31 32 33 34 35 36
## -17.6476504 -1.9137447 -29.4787536 -26.0826415 -11.9137447 -7.8748657
## 37 38 39 40 41 42
## -8.4787536 -2.1409600 24.1251343 3.7290222 1.3329101 -19.0826415
## 43 44 45 46 47 48
## -17.4593141 -18.6476504 -11.8554262 -22.4981931 -13.2904173 -5.4593141
## 49 50 51 52 53 54
## 4.9173585 -5.0632020 11.7290222 2.9367980 12.1445738 3.3134706
## 55 56 57 58 59 60
## 15.7095827 17.5406859 21.5601254 11.7484617 -6.8748657 -0.8943052
## 61 62 63 64 65 66
## 5.7290222 1.1251343 15.0668158 11.5406859 -13.8943052 -20.6670899
## 67 68 69 70
## 17.5212464 27.0862553 -7.4593141 7.1445738
##
## Call:
## lm(formula = cent.Consc ~ cent.Iq, data = df.Cent)
##
## Coefficients:
## (Intercept) cent.Iq
## -3.128e-16 1.016e-02
## 1 2 3 4 5 6
## -0.773968068 0.760658232 -0.753654166 0.154933273 -0.225029371 -1.779969573
## 7 8 9 10 11 12
## 0.559365265 -0.345066727 0.413012501 1.453640306 1.014582014 -1.239341768
## 13 14 15 16 17 18
## 0.077833109 1.073677662 -0.381539086 0.396854044 -1.966950143 -0.032047297
## 19 20 21 22 23 24
## -0.621613799 -1.603145956 1.648931768 -0.664087663 0.002579003 0.911166442
## 25 26 27 28 29 30
## 1.053363760 0.218184367 0.169245670 0.496577498 0.083834614 -1.032047297
## 31 32 33 34 35 36
## 1.413012501 -1.511733394 0.232033437 0.034895916 -1.410163881 0.175247175
## 37 38 39 40 41 42
## 0.018737460 -2.647929207 -0.149775266 0.220030427 0.407010996 -0.036202743
## 43 44 45 46 47 48
## 0.923169452 1.423169452 1.028894411 -0.652084653 -0.420320832 0.801286037
## 49 50 51 52 53 54
## -0.279969573 0.634619370 0.138774816 0.553363760 0.785127580 -0.426322338
## 55 56 57 58 59 60
## -0.714872420 0.567676157 1.340067783 0.951794247 0.165090224 -0.708870914
## 61 62 63 64 65 66
## 0.199716524 0.083834614 -2.497420997 0.628617865 -0.576830548 0.630463924
## 67 68 69 70
## -0.245343274 -1.806284981 0.821599939 0.835912337
## [1] 0.5851451
## [1] -0.3935476
## [1] -0.3666261
## [1] -0.4366059
## [1] -0.4119603
## [1] 0.8109286
Partials
It says that the function doesn’t exist and I couldn’t figure out what package it came from. Maybe I didn’t look hard enough but I couldn’t find it in the lab either.
##partial corrrelations
par.cor(df.Cent$cent.Iq, y= df.hw2$tot.Imp, p.xy= df.Cent$Consc, sig=T)
par.cor(df.Cent$Consc, y=df.hw2$tot.Imp, p.xy=df.Cent$cent.Iq, sig=T)
##semi-partial correlations
par.cor(df.Cent$cent.Iq, y=df.hw2$tot.Imp, p.x=df.Cent$Consc, sig=T)
par.cor(df.Cent$Consc, y=df.hw2$tot.Imp, p.x=df.Cent$cent.Iq, sig=T).## Error: <text>:7:69: unexpected symbol
## 6: par.cor(df.Cent$cent.Iq, y=df.hw2$tot.Imp, p.x=df.Cent$Consc, sig=T)
## 7: par.cor(df.Cent$Consc, y=df.hw2$tot.Imp, p.x=df.Cent$cent.Iq, sig=T).
## ^