library(rmarkdown); library(knitr)
library(dplyr)
library(psych); library(corrplot); library(GPArotation)
library(lavaan); library(semPlot); library(moments)
HUNGERDATA <- read.csv("https://www.dropbox.com/s/znpumq7o1fghlfb/?dl=1")
attach(HUNGERDATA)
set.seed(37)
Use cbind() along with cor() to compute the correlation matrix, R1, for the interaction between VOLUNTEERS, BOXES, and MEALSPERVOL
r <- cor(cbind(VOLUNTEERS, BOXES, MEALSPERVOL))
corrplot(r, method = "number")
Explain what the correlation matrix above means in terms of the presence or absence of multicollinearity
BOXES and VOLUNTEERS have a correlation greater than 0.9 which could imply multicollinearity between the two variables.
Compute the eigenvalues of the correlation matrix above
(ev <- eigen(r)$values)
## [1] 2.10754899 0.86161349 0.03083751
Use the eigenvalues above to compute the condition indices for the interaction between VOLUNTEERS, BOXES, and MEALPERVOL
multiColl <- F
seriousMultiColl <- F
for (value in ev) {
multiColl <- sqrt(max(ev)/value) > 15 || multiColl
seriousMultiColl <- sqrt(max(ev)/value) > 30 || seriousMultiColl
}
multiColl #Is there multicollinearty?
## [1] FALSE
seriousMultiColl #Is there severe mukticollinearity?
## [1] FALSE
Explain what the condition indices above mean in terms of the presence or absence of multicollinearity
The indices above do not suggest multicollinearity.
Explain if the conclusion above supports your earlier conclusion regarding the presence of absence of multicollinearity
It does not support my earlier conclusion.
Compute the (missing value) correlation matrix, R2, for the interaction between VOLUNTEERS, BOXES, MEALSPERVOL, and KIDSFED
r <- cor(cbind(VOLUNTEERS, BOXES, MEALSPERVOL, KIDSFED), use = "pairwise.complete.obs")
corrplot(r, method = "number")
Explain what the correlation matrix above means in terms of the presence or absence of singularity
There seems to be a singulatiry between BOXES and KIDSFED
Compute the eigenvalues of the correlation matrix above
(ev <- eigen(r)$values)
## [1] 2.9984164194 0.9673883611 0.0345186971 -0.0003234776
Explain what the eigenvalues above mean in terms of the presence or absence of singularity
The negative eigenvalue suggests a singularity between the two variables.
Compute the variance-covariance matrix, S1, for the interaction between VOLUNTEERS and MEALSPERVOL
(varcov <- cov(cbind(VOLUNTEERS, MEALSPERVOL)))
## VOLUNTEERS MEALSPERVOL
## VOLUNTEERS 1560.023 -1650.909
## MEALSPERVOL -1650.909 8030.970
Use sum() and diag() to compute the trace of the variance-covariance matrix above
sum(diag(varcov))
## [1] 9590.992
Compute the (missing value) variance-covariance matrix, S2, for the interaction between BOXES and KIDSFED
(varcovmiss <- cov(cbind(BOXES, KIDSFED), use = "complete.obs"))
## BOXES KIDSFED
## BOXES 2255.278 1270.042
## KIDSFED 1270.042 716.000
Explain how to find the first (top left) element in the product of the two variance-covariance matrices above
Take the first row of the first varcovar matrix above and multiply each of the two elements with the two elements in the first column of the second varcovar matrix and then add the two resulting products together to get the top left element in the matrix product.
Use algebra to compute the first (top left) element in the product of the two variance-covariance matrices above
(varcov[1,1]*varcovmiss[1,1] + varcov[1,2]*varcovmiss[2,1])
## [1] 1421561
Use %*% to compute the full product, P, of the two variance-covariance matrices above
(varcovprod <- varcov %*% varcovmiss)
## BOXES KIDSFED
## VOLUNTEERS 1421561 799243
## MEALSPERVOL 6476408 3653451
Explain how to find the transpose of the product matrix, P, above
Reflect all elements of the matrix across the diagonal of the matrix. (Or take each row (0 through n) and make it a column in the same order)
Use t() to compute the transpose of the product matrix, P
t(varcovprod)
## VOLUNTEERS MEALSPERVOL
## BOXES 1421561 6476408
## KIDSFED 799243 3653451
Use det() to compute the determinant of the product matrix, P
det(varcovprod)
## [1] 17381236703
Use solve() to compute the inverse of the product matrix, P
solve(varcovprod)
## VOLUNTEERS MEALSPERVOL
## BOXES 0.0002101951 -4.598309e-05
## KIDSFED -0.0003726091 8.178712e-05