R Under development (unstable) (2024-04-29 r86495 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > # TODO: Add comment > # > # Author: iovleff > #----------------------------------------------------------------------- > library(MixAll) Loading required package: rtkore Loading required package: Rcpp Attaching package: 'rtkore' The following object is masked from 'package:Rcpp': LdFlags > data(iris) > > gamma_model <- clusterGamma( iris[1:4], nbCluster = 3, models = c("gamma_pk_ajk_bjk") + , strategy = clusterFastStrategy()) > > data<-gamma_model@component@data > nbCluster <- gamma_model@nbCluster > prop <- gamma_model@pk > shape <- gamma_model@component@shape > scale <- gamma_model@component@scale > > nbSample <- nrow(data) > nbVariable <- ncol(data) > > f <-vector(length=nbSample) > lnComp <- vector(length=nbCluster) > > for (i in 1:nbSample) + { + for (k in 1:nbCluster) + { lnComp[k] = log(prop[k]) + sum(dgamma(data[i,], shape=shape[k,], scale=scale[k,],log=TRUE)); } + lmax <- max(lnComp) + + for (k in 1:nbCluster) + { lnComp[k] = lnComp[k] -lmax;} + + f[i] = log(sum(exp(lnComp))) + lmax; + } > if (abs(sum(f) - gamma_model@lnLikelihood) < 1.e-15) + { print ("clusterGammaLikelihood failed") + } else{ print ("clusterGammaLikelihood successful") } [1] "clusterGammaLikelihood successful" > > proc.time() user system elapsed 0.73 0.10 0.82