[R] Problem on flexmix when trying to apply signature developed in one model to a new sample

Bettina Gruen Bettina.Gruen at jku.at
Thu Mar 3 21:11:21 CET 2011


Jon,

if I did understand you correctly the problem is that you did not 
specify the newdata argument in posterior() correctly. You need to 
specify it in way such that evaluating the formula uses the correct 
object. If you have a matrix as dependent variable, you have to use a 
list which contains an object with the name of the dependent variable 
which contains the data you want to use for determining the a-posteriori 
probabilities. The same holds for clusters().

Have a look at the following code:

library("flexmix")
library("mvtnorm")
set.seed(123)
BM <- rbind(rmvnorm(100, rep(0, 2)),
             rmvnorm(100, rep(5, 2)))
ex2 <- flexmix(BM ~ 1, k = 2, model = FLXMCmvnorm(diagonal = FALSE))
print(ex2)
plotEll(ex2, BM)

Data2 <- data.frame(var1 = BM[c(1:5, 101:105), 1],
                     var2 = BM[c(1:5, 101:105), 2])
BM2 <- list(BM = cbind(Data2$var1, Data2$var2))
ProbMCI <- posterior(ex2, BM2)

HTH,
Bettina

On 03/01/2011 05:34 PM, Jon Toledo wrote:
>
> Problem on flexmix when trying to apply signature developed in one model to a new sample.
> Dear
> R Users, R Core Team,
>
>
>
> I have a problem when trying to know the
> classification of the tested cases using two variables with the function  of flexmix:
>
>
>
> After importing the database and creating
> a matrix:
>
> BM<-cbind(Data$var1,Data$var2)
>
>
>
> I see that the best model has 2 groups and
> use:
>
>
>
> ex2
> <- flexmix(BM~1, k=2, model=FLXMCmvnorm(diagonal=FALSE))
>
> print(ex2)
>
> plotEll(ex2, BM)
>
>
>
> Then I want to test to which group one
> subset of patients belongs, so I import a smaller sample of the previous data:
>
> BM2<-data.frame (Data2$var1,Data2$var2)
>
>
>
> However when I test the results I get are
> from the complete training sample I used in ex2 and not from the new sample
> BM2.
>
>
>
> ProbMCI<-posterior(ex2, BM2)
>
>
>
> And if I do the following I get double the
> number of entered cases (I think because I entered 2 variables):
>
> BM2<-cbind (Data2$var1,Data2$var2)
>
> p<-posterior(ex2)[BMMCI,]
>
> max.col(p)
>
>
>
> (The same with clusters(ex2)[BM2])
>
>
>
> In the future I would like to test the
> result of this mixture also in new samples.
>
>
>
> Thank you in advance 		 	   		
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>    


-- 
-------------------------------------------------------------------
Bettina Grün
Institut für Angewandte Statistik / IFAS
Johannes Kepler Universität Linz
Altenbergerstraße 69
4040 Linz, Austria

Tel: +43 732 2468-5889
Fax: +43 732 2468-9846
E-Mail: Bettina.Gruen at jku.at
www.ifas.jku.at



More information about the R-help mailing list