0

주어진 다른 범주 형 변수와 관련하여 시간 경과에 따른 범주 형 변수의 두 가지 양상을 탐구하고 싶습니다. 아래에 이러한 데이터 세트의 재현 가능한 예를 붙여 넣습니다. 종단 데이터에 대한 다중 대응 분석

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)를 사용하기로 결정했다. 시간이 경과함에 따라 변이를 설명하기 위해 하나의 가능성은 데이터 집합을 V5의 다른 수준을 나타내는 5 개의 하위 샘플로 분할 한 다음 각 하위 집합에서 MCA를 실행하는 것입니다. 분석의 나머지 부분은 다른 biplots에 걸쳐 양식의 위치를 ​​비교하는 것으로 구성됩니다. 그러나 원래의 데이터 세트가 너무 작 으면 이러한 관행에 문제가없는 것은 아닙니다. 이 경우 치수가 뒤집어 지거나 더 나빠질 수 있으므로 활성 변수의 위치가 한 플롯에서 다른 플롯으로 변경 될 수 있습니다.

문제를 피하려면 모든 하위 집합에서 활성 변수의 위치를 ​​안정화하고 이후에 보조 변수의 좌표를 예측하여 후자가 시간 경과에 따라 움직 이도록 할 수 있습니다. 나는이 양식이있는 개인의 좌표의 가중 평균을 계산함으로써 양식의 좌표를 얻을 수있는 곳을 읽습니다. 따라서 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. 

도움을 주셔서 감사합니다.

답변

0

내 문제에 대한 해결책을 찾았습니다. 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 또는 다른 범주 형 변수에 따라 데이터의 다른 파티션에 적용될 수 있습니다.

관련 문제