STAT 360: Computational Statistics and Data Analysis

Load R Libraries, Import and Attach Relevant Data, and Specify Seed

library(rmarkdown); library(knitr); library(readxl)
set.seed(37)

EXERCISE 01

Part (a)

mentalCov <- matrix(c(.165, .031, .055, .038, .031, .205, 0.089, 0.040, .055, 0.089, .165, .053, .038, 0.040, .053, .172), nrow = 4, ncol = 4)
rownames(mentalCov)<- c("Comfortable", "Benefits", "Anonymity", "Discussed")
colnames(mentalCov)<- c("Comfortable", "Benefits", "Anonymity", "Discussed")
mentalCov
##             Comfortable Benefits Anonymity Discussed
## Comfortable       0.165    0.031     0.055     0.038
## Benefits          0.031    0.205     0.089     0.040
## Anonymity         0.055    0.089     0.165     0.053
## Discussed         0.038    0.040     0.053     0.172
R <- solve(sqrt(diag(diag(mentalCov)))) %*% mentalCov %*%
  t(solve(sqrt(diag(diag(mentalCov)))))
rownames(R)<- c("Comfortable", "Benefits", "Anonymity", "Discussed")
colnames(R)<- c("Comfortable", "Benefits", "Anonymity", "Discussed")
R
##             Comfortable  Benefits Anonymity Discussed
## Comfortable   1.0000000 0.1685554 0.3333333 0.2255680
## Benefits      0.1685554 1.0000000 0.4839173 0.2130192
## Anonymity     0.3333333 0.4839173 1.0000000 0.3146079
## Discussed     0.2255680 0.2130192 0.3146079 1.0000000

Part (b)

Rpredictors <- R[2:4, 2:4]
eigenvalues <- eigen(Rpredictors)$values
joliffe <- sum(eigenvalues > .7)
library(psych)
## Warning: package 'psych' was built under R version 4.0.5
rotatedPredictors <- pca(Rpredictors, joliffe, rotate = "varimax")$loadings[]
rotatedPredictors
##                 RC1        RC2
## Benefits  0.8917286 0.02004494
## Anonymity 0.8036748 0.27631981
## Discussed 0.1461694 0.97938309

Part (c)

We only have one response variable, which is "Comfortable", so it wouldn't make sense to do dimensionality reduction. We can't reduce one dimension to less than one dimension.

Part (d)

library(knitr)
include_graphics("C:/Users/Sarah Chock/OneDrive - University of St. Thomas/Senior Year/STAT 360 Comp Stat and Data Analysis/Structural Equation Models/PS13 Q1.png")

EXERCISE 02

Part (a)

Measured Variables: 6, Housing, Threats, Assaults, Fights, Anxiety, Depression
Latent Variables: 2, Violence and Psychological Distress

Part (b)

Error and Disturbance terms only go on dependent variables, so those with arrows pointing towards them. Error is for measured variables and disturbance is for latent.
Error: 5, they should go on Threats, Assaults, Fights, Depression, Anxiety
Disturbance: 1, Psychological Distress

Part (c)

There are 8 independent variables, which include Housing and Violence and then the 5 error terms and 1 disturbance term.

Part (d)

There are 6 dependent variables, with 5 measured and 1 latent. The measured dependent variables are Threats, Assaults, Fights, Depression, and Anxiety. The latent dependent variable is Psychological Distress.

Part (e)

Variances go on independent variables. Since we found 8 total independent variables, there should be 8 variances.

Part (f)

The variance arrows are loopy, only one-sided arrows instead of two-sided.
include_graphics("C:/Users/Sarah Chock/OneDrive - University of St. Thomas/Senior Year/STAT 360 Comp Stat and Data Analysis/Structural Equation Models/PS13 Q2.png")