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什麼更新 - 我的回購?這對我來說並不是重中之重。我不打算儘快解決它。 –