我正在尝试提供一个lavaan.mi对象(使用semTools 0.5-2中的runMI()对多个推算数据进行建模的扫描电镜)。到semPaths() (semPlot 1.1.2)。执行此操作将返回错误:
Error in (function (classes, fdef, mtable) :
unable to find an inherited method for function ‘semPlotModel_S4’ for signature ‘"lavaan.mi"’这在GitHub上被标记为一个“问题”,但如果能有一个建议的解决方法,我会很感激。下面是一个示例:
# Libraries
library(mice)
library(semTools)
library(lavaan)
library(semPlot)
# Create DF
HSMiss <- HolzingerSwineford1939[,paste("x", 1:9, sep="")]
randomMiss <- rbinom(prod(dim(HSMiss)), 1, 0.1)
randomMiss <- matrix(as.logical(randomMiss), nrow=nrow(HSMiss))
HSMiss[randomMiss] <- NA
# Specify model
HS.model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
# Fit the model
model_fit <- runMI(HS.model,
data=HSMiss,
m = 5,
miPackage="mice",
fun="sem")
# Attempt to create SEM plot
semPaths(model_fit)发布于 2019-12-17 01:08:54
因此,我使用的“解决方案”是简单地将MI模型中的参数估计值替换为从“lavaan”对象创建的“semPlotModel”对象:
# Libraries
library(mice)
library(semTools)
library(lavaan)
library(semPlot)
# Create DF
HSMiss <- HolzingerSwineford1939[,paste("x", 1:9, sep="")]
randomMiss <- rbinom(prod(dim(HSMiss)), 1, 0.1)
randomMiss <- matrix(as.logical(randomMiss), nrow=nrow(HSMiss))
HSMiss[randomMiss] <- NA
# Specify model
HS.model <- ' visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9 '
# Create a 'dummy' object, with the same model structure as we'll use in the MI method
model_fit <- sem(HS.model, data=HSMiss)
# Create a dummy semplot object
SEMPLOT <- semPlot::semPlotModel(model_fit)
# Fit the actual model
model_fit <- runMI(HS.model,
data=HSMiss,
m = 5,
miPackage="mice",
fun="sem")
# Extract the direct results from the SEM with MI data
desired_output <- data.frame(standardizedsolution(model_fit))
# Subsitute the desired parameter estimates for the desired ones, in the semplot object
SEMPLOT@Pars$std <- desired_output$est.std
# Create SEM plot
semPaths(SEMPLOT)https://stackoverflow.com/questions/59304910
复制相似问题