0

我目前正试图通过高斯混合模型来推测缺失的数据。 我的参考文献是从这里: http://mlg.eng.cam.ac.uk/zoubin/papers/nips93.pdf潜在变量与高斯混合模型来推算缺失的数据

我目前专注于具有2高斯分量的双变量数据集。 这是定义的权重为每个高斯分量代码:

myData = faithful[,1:2]; # the data matrix 
for (i in (1:N)) { 
     prob1 = pi1*dmvnorm(na.exclude(myData[,1:2]),m1,Sigma1); # probabilities of sample points under model 1 
     prob2 = pi2*dmvnorm(na.exclude(myData[,1:2]),m2,Sigma2); # same for model 2 
     Z<-rbinom(no,1,prob1/(prob1 + prob2)) # Z is latent variable as to assign each data point to the particular component 

     pi1<-rbeta(1,sum(Z)+1/2,no-sum(Z)+1/2) 
     if (pi1>1/2) { 
      pi1<-1-pi1 
      Z<-1-Z 
     } 
     } 

这是我的代码来定义缺失值:

> whichMissXY<-myData[ which(is.na(myData$waiting)),1:2] 
> whichMissXY 
    eruptions waiting 
11  1.833  NA 
12  3.917  NA 
13  4.200  NA 
14  1.750  NA 
15  4.700  NA 
16  2.167  NA 
17  1.750  NA 
18  4.800  NA 
19  1.600  NA 
20  4.250  NA 

我的约束是,如何推诿中的丢失数据“等待“基于特定组件的变量。 此代码是我第一次尝试使用条件平均插补计算丢失的数据。我知道,这肯定是错误的。结果不会落在特定组件上并产生异常值。

miss.B2 <- which(is.na(myData$waiting)) 
for (i in miss.B2) { 
    myData[i, "waiting"] <- m1[2] + ((rho * sqrt(Sigma1[2,2]/Sigma1[1,1])) * (myData[i, "eruptions"] - m1[1]) + rnorm(1,0,Sigma1[2,2])) 
    #print(miss.B[i,]) 
    } 

我将不胜感激,如果有人可以提供有关如何提高归集技术,可以通过高斯混合模型潜伏/隐藏变量工作的任何建议。 谢谢您提前

+0

这完全取决于你承担你的混合模型的协方差结构。但一般过程是每个迭代有两个EM步骤 –

回答

0

This是一种协方差结构的解决方案。

devtools::install_github("alexwhitworth/emclustr") 
library(emclustr) 
data(faithful) 
set.seed(23414L) 
ff <- apply(faithful, 2, function(j) { 
    na_idx <- sample.int(length(j), 50, replace=F) 
    j[na_idx] <- NA 
    return(j) 
}) 
ff2 <- em_clust_mvn_miss(ff, nclust=2) 

# hmm... seems I don't return the imputed values. 
# note to self to update the code  
plot(faithful, col= ff2$mix_est) 

enter image description here

和参数输出

$it 
[1] 27 

$clust_prop 
[1] 0.3955708 0.6044292 

$clust_params 
$clust_params[[1]] 
$clust_params[[1]]$mu 
[1] 2.146797 54.833431 

$clust_params[[1]]$sigma 
[1] 13.41944 


$clust_params[[2]] 
$clust_params[[2]]$mu 
[1] 4.317408 80.398192 

$clust_params[[2]]$sigma 
[1] 13.71741 
+0

尊敬的@Alex W,谢谢,我在等待您的更新:) – Jas

+0

@Jas什么更新 - 我的回购?这对我来说并不是重中之重。我不打算尽快解决它。 –