Skip to content

Instantly share code, notes, and snippets.

@pdparker
Last active May 28, 2016 21:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdparker/53502f6ffc61dd2d155388d488e0b136 to your computer and use it in GitHub Desktop.
Save pdparker/53502f6ffc61dd2d155388d488e0b136 to your computer and use it in GitHub Desktop.
Get loadings and residuals to give a particular Omega reliability
findValues <- function(reliability, n=6, n.total=100){
require(MASS)
f = function(L,reliability, n){-reliability+(L*n)^2/((L*n)^2 + (1- L^2)*n)}
#Base loadings residuals on that
L <- uniroot(f,interval = c(0,1), reliability=reliability, n = n)$root
R <- 1-L^2
out<- sprintf("The sum of the loadings must equal: %f and the residual: %f\n
For a Tau equaivilent model - \nEach loading should be: %f and each residual: %f",
L*n, R*n, L, R)
lamba <- matrix(rep(L,n))
tau <- diag(rep(R,n))
m <- lamba %*% t(lamba) + tau
data <- mvrnorm(n = n.total,rep(0,n), m,empirical = TRUE)
cat(out)
return(invisible(list(data=data, loading = L, residual = R, implied.covar = m, n.items = n, n.sample = n.total)))
}
test <- findValues(reliability = .95, n.total = 1000)
psych::omega(test$data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment