【问题标题】:Id class membership in R poLCAR poLCA 中的 Id 类成员资格
【发布时间】:2019-11-08 12:42:20
【问题描述】:

我在 R 中运行一个潜在的类分析,一切运行良好,我得到了我的最终类模型。现在我需要查看班级成员资格,所以我使用了以下代码:

  round(lca.raq2 $posterior[1:3413,],2)

问题是 R 从我的原始文件中消除了案例(可能是模型的问题案例?)所以我无法确定哪些概率对应于原始数据库中的每个案例。

有没有在 $posterior 命令中包含我的 id_variable??

我尝试将 ID 与 poLCA 生成的数据集合并,但它没有合并并给我这个错误:

合并(lca.raq,homdata$idnumber) as.data.frame.default(x) 中的错误: 无法将“poLCA”类强制转换为 data.frame

欢迎提出任何建议 - 我确实需要能够识别每个类中的具体案例,以便对这些类进行进一步分析。

【问题讨论】:

  • 从文档看来,na 值已被删除。如果为空值,您的数据集可能包含缺失值。在这种情况下,homdata[complete.cases(homdata),] 将是估计期间使用的数据。

标签: r


【解决方案1】:

您可以从 lca.raq2$y 获取行名。就像@Oliver 所说,NA 值被取出,所以你只剩下你的值的一个子集。您可以查看以下示例以了解如何获取 id 或观察名称。我建议以您的 id 命名输入数据的行。

library(poLCA)
set.seed(123)
data(values)
#introduce some random NAs
# here it set the rownames of the matrix to be id
# in your case it might be homdata$idnumber
rownames(values) = paste("row",1:nrow(values),sep="")
for(i in 1:ncol(values)){
 values[sample(1:nrow(values),10),i]<-NA
 }
 f <- cbind(A,B,C,D)~1
M1 <- poLCA(f,values,nclass=2)

POST = round(M1$posterior,2)
rownames(POST) = rownames(M1$y)

# we can check that the rownames of posterior values are indeed those complete values in original data
table(rownames(values)[complete.cases(values)] == rownames(POST))
TRUE 
 183 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-01-24
    • 1970-01-01
    • 2021-11-27
    • 1970-01-01
    • 2011-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多