if (FALSE) {
#----------------------------
# Linear model
dat <- data.frame(x1 = c(3, 2, 4, 9, 5, 3, 6, 4, 5, 6, 3, 5),
x2 = c(1, 4, 3, 1, 2, 4, 3, 5, 1, 7, 8, 7),
x3 = c(0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1),
y = c(0, 1, 0, 2, 0, 1, 0, 0, 1, 2, 1, 0))
# Dominance analysis
dominance.manual(cor(dat[, c("y", "x1", "x2", "x3")]))
# Equivalent results using the dominance() function
mod <- lm(y ~ x1 + x2 + x3, data = dat)
dominance(mod)
# Outcome 'x3' predicted by 'y', 'x1', and 'x2'
dominance.manual(cor(dat[, c("y", "x1", "x2", "x3")]), out = "x3")
#----------------------------
# Structural equation modeling
library(lavaan)
#.............
# Latent variables
# Model specification
model <- '# Measurement model
ind60 =~ x1 + x2 + x3
dem60 =~ y1 + y2 + y3 + y4
dem65 =~ y5 + y6 + y7 + y8
# regressions
ind60 ~ dem60 + dem65'
# Model estimation
fit <- sem(model, data = PoliticalDemocracy)
# Model-implied correlation matrix of the latent variables
fit.cor <- lavInspect(fit, what = "cor.lv")
# Dominance analysis
dominance.manual(fit.cor)
#.............
# Latent and manifest variables
# Model specification, convert manifest to latent variable
model <- '# Measurement model
ind60 =~ x1 + x2 + x3
dem60 =~ y1 + y2 + y3 + y4
# Manifest as latent variable
ly5 =~ 1*y5
y5 ~~ 0*y5
# Regressions
ind60 ~ dem60 + ly5'
# Model estimation
fit <- sem(model, data = PoliticalDemocracy)
# Model-implied correlation matrix of the latent variables
fit.cor <- lavInspect(fit, what = "cor.lv")
# Dominance analysis
dominance.manual(fit.cor)
#----------------------------
# Multilevel modeling
# Model specification
model <- 'level: 1
fw =~ y1 + y2 + y3
# Manifest as latent variables
lx1 =~ 1*x1
lx2 =~ 1*x2
lx3 =~ 1*x3
x1 ~~ 0*x1
x2 ~~ 0*x2
x3 ~~ 0*x3
# Regression
fw ~ lx1 + lx2 + lx3
level: 2
fb =~ y1 + y2 + y3
# Manifest as latent variables
lw1 =~ 1*w1
lw2 =~ 1*w2
# Regression
fb ~ lw1 + lw2'
# Model estimation
fit <- sem(model, data = Demo.twolevel, cluster = "cluster")
# Model-implied correlation matrix of the latent variables
fit.cor <- lavInspect(fit, what = "cor.lv")
# Dominance analysis Within
dominance.manual(fit.cor$within)
# Dominance analysis Between
dominance.manual(fit.cor$cluster)
#----------------------------
# Mplus
#
# In Mplus, the model-impied correlation matrix of the latent variables
# can be requested by OUTPUT: TECH4 and imported into R by using the
# MplusAuomtation package, for example:
library(MplusAutomation)
# Read Mplus output
output <- readModels()
# Extract model-implied correlation matrix of the latent variables
fit.cor <- output$tech4$latCorEst
}
Run the code above in your browser using DataLab