【问题标题】:Multiple Correspondence Analysis on longitudinal data纵向数据的多重对应分析
【发布时间】:2017-11-22 21:45:13
【问题描述】:

我想探索一个分类变量的两种模式随着时间的推移相对于一组给定的其他分类变量的概况。我在下面粘贴了此类数据集的可重现示例。

set.seed(90114)
V1<-sample(rep(c("a", "A"), 100))
V2<-sample(rep(c("a", "A", "b", "B"), 50))
V3<-sample(rep(c("F", "M", "I"), 67), 200)
V4<-sample(rep(c("C", "R"), 100))
V5<-sample(rep(c(1970, 1980, 1990, 2000, 2010), 40))
data<-data.frame(V1, V2, V3, V4, V5)

为了探索这种模式的行为,我决定使用多重对应分析(包FactoMineR)。为了考虑随时间的变化,一种可能性是将数据集分成 5 个子样本,它们代表 V5 的不同级别,然后在每个子集上运行 MCA。分析的其余部分包括比较不同双图上的模态位置。但是,如果原始数据集太小,这种做法并非没有问题。在这种情况下,维度可能会翻转,或者更糟糕的是,活动变量的位置可能会从一个图变为另一个图。

为避免该问题,一种解决方案可能是稳定所有子集中的活动变量的位置,然后预测补充变量的坐标,允许后者随时间移动。我在某处读到,可以通过计算找到该模态的个体坐标的加权平均值来获得模态的坐标。因此,找到 1970 年模态的坐标将归结为计算该模态 1970 子集中个体坐标的加权平均值。但是,我不知道这是否是常见做法,如果是,我只是不知道如何实现这样的计算。我粘贴了其余的代码,以便您将问题可视化。

data.mca<-MCA(data[, -5], quali.sup=1, graph=F)

# Retrieve the coordinates of the first and second dimension

DIM1<-data.mca$ind$coord[, 1]
DIM2<-data.mca$ind$coord[, 2]

# Append the coordinates to the original dataframe

data1<-data.frame(data, DIM1, DIM2)

# Split the data into 5 clusters according to V5 ("year")

data1.split<-split(data1, data1$V5)
data1.split<-lapply(data1.split, function(x) x=x[, -5]) # to remove the fifth column with the years, no longer needed
seventies<-as.data.frame(data1.split[1])
eightties<-as.data.frame(data1.split[2])
# ...

a.1970<-seventies[seventies$X1970.V1=="a",]
A.1970<-seventies[seventies$X1970.V1=="A",]

# The idea, then, is to find the coordinates of the modalities "a" and "A" by computing the weighted mean of their respective indivuduals for each subset. The arithmetic mean would yield

# a.1970.DIM1<-mean(a.1970$X1970.DIM1) # 0.0818
# a.1970.DIM2<-mean(a.1970$X1970.DIM2) # 0.1104

# and so on for the other levels of V5.

提前感谢您的帮助!

【问题讨论】:

    标签: r weighted-average longitudinal correspondence-analysis


    【解决方案1】:

    我找到了解决问题的方法。我们可以简单地通过 FactoMineR 中 row.w 返回的值对坐标的平均值进行加权。考虑到 MCA 的膨胀,重心坐标的结果应该除以维度特征值的平方根。

    DIM1<-data.mca$ind$coord[, 1]
    DIM2<-data.mca$ind$coord[, 2]
    WEIGHT<-data.mca$call$row.w
    data1<-data.frame(data, WEIGHT, DIM1, DIM2)
    
    # Splitting the dataset according to values of V1
    
    v1_a<-data1[data1$V1=="a",]
    v1_A<-data1[data1$V1=="A",]
    
    # Computing the weighted average of the coordinates of Dim1 and Dim2 for the first category of V1
    
    V1_a_Dim1<-sum(v1_a$WEIGHT*v1_a$DIM1)/100 # -0.0248
    v1_a_Dim2<-sum(v1_a$WEIGHT*v1_a$DIM2)/100 # -0.0382
    
    # Account for the dilatation of the dimensions...
    
    V1_a_Dim1/sqrt(data.mca$eig[1,1])
    [1] -0.03923839
    v1_a_Dim2/sqrt(data.mca$eig[2,1])
    [1] -0.06338353
    
    # ... which is the same as the following:
    
    categories<-data.mca$quali.sup$coord[, 1:2]
    categories
    #            Dim 1       Dim 2
    # V1_a -0.03923839 -0.06338353
    # V1_A  0.03923839  0.06338353
    

    这可以根据 V5 或任何其他分类变量应用于数据的不同分区。

    【讨论】:

      猜你喜欢
      • 2014-09-12
      • 1970-01-01
      • 1970-01-01
      • 2015-12-06
      • 1970-01-01
      • 2021-12-06
      • 1970-01-01
      • 2013-02-15
      • 2021-09-20
      相关资源
      最近更新 更多