差异分析和加权序列数据:我在哪里可以找到我的组变量?

Discrepancy analysis and weighted sequence data: where do I find my group variable?

我正在尝试差异分析。由于我的序列数据量很大,我将权重与 WeightedCluster 包一起使用。一切顺利,直到我到达实际的 dissassoc() 部分。我似乎无法找到我的组变量。

我已经尝试密切关注 WeightedCluster 手册和 Studer 等人 2011 年的文章中的示例。这篇 post 很有用并且帮助我前进 How to use discrepancy analysis with TraMineR and aggregated sequence data?,但我不能弄清楚如何从那里找到 dissassoc() 参数中的那些单独的组变量。假设我正在使用相同的示例数据(尽管我的原始数据没有采样权重),但我只能使用聚合数据:

## Aggregate example data
mvad.agg <- wcAggregateCases(mvad[, c(10:12, 17:86)], weights=mvad$weight)
mvad.agg

## Define sequence object 
mvad.agg.seq <- seqdef(mvad[mvad.agg$aggIndex, 17:86], alphabet=mvad.alphabet,
                       states=mvad.scodes, labels=mvad.labels,
                       weights=mvad.agg$aggWeights)

## Computing OM dissimilarities
mvad.agg.dist <- seqdist(mvad.agg.seq, method="OM", indel=1.5, sm="CONSTANT")

## Discrepancy analysis
dissassoc (mvad.agg.dist, group = mvad$gcse5eq, weights = mvad.agg$aggWeights, weight.permutation = "replicate")

所以在最后一步,我无法弄清楚如何 link 到组变量。我尝试使用不同的选项来定义组(例如,mvad.agg$gcse5eqmvad$gcse5eq)以及 disaggregating/aggregating 和 weighting/unweighting 数据的许多变体,但我要么得到 "Object gcse5eq not found" 或 "Error in diss[!is.na(group), !is.na(group)] : incorrect number of dimensions"

我是 SO 的新手,所以希望我的示例清晰且有用。希望有人能帮忙!

首先,您需要在提供给 wcAggregateCases 的 table 中包含您的协变量。 (这里 gcse5eqmvad 的第 12 列,已经属于 mvad[, c(10:12, 17:86)]。)

然后,您必须提供与 wcAggregateCases 选择的个案对应的协变量值作为 group 变量。你可以通过 $aggIndex 来做到这一点。我在下面举例说明:

library(TraMineR) 
library(WeightedCluster) 
## Load example data and assign labels
data(mvad)
mvad.alphabet <- c("employment", "FE", "HE", "joblessness", "school", "training")
mvad.labels <- c("Employment", "Further Education", "Higher Education", 
                 "Joblessness", "School", "Training")
mvad.scodes <- c("EM", "FE", "HE", "JL", "SC", "TR")
## Aggregate example data
mvad.agg <- wcAggregateCases(mvad[, c(10:12, 17:86)], weights=mvad$weight)
## Define the sequence object 
mvad.agg.seq <- seqdef(mvad[mvad.agg$aggIndex, 17:86], alphabet=mvad.alphabet,
                       states=mvad.scodes, labels=mvad.labels,
                       weights=mvad.agg$aggWeights)
## Computing OM dissimilarities
mvad.agg.dist <- seqdist(mvad.agg.seq, method="OM", indel=1.5, sm="CONSTANT")
## Discrepancy analysis
dissassoc (mvad.agg.dist, group = mvad$gcse5eq[mvad.agg$aggIndex], 
           weights = mvad.agg$aggWeights, 
           weight.permutation = "random-sampling")

请注意,我在这里使用 weight.permutation = "random-sampling" 因为我们有非整数权重。