https://github.com/cran/flexmix
Raw File
Tip revision: 0e4ff321a1e17d4a2b03adb63568b6e881ae2114 authored by Bettina Gruen on 20 March 2012, 00:00:00 UTC
version 2.3-7
Tip revision: 0e4ff32
FLXMCmvpois.R
#
#  Copyright (C) 2004-2011 Friedrich Leisch and Bettina Gruen
#  $Id: flxmcmvpois.R 4666 2011-02-23 15:52:35Z gruen $
#

FLXMCmvpois <- function(formula=.~.)
{
  z <- new("FLXMC", weighted=TRUE, formula=formula,
                dist="mvpois", name="model-based Poisson clustering")
  
  require("stats")
  z@preproc.y <- function(x){
    x <- as.matrix(x)
    storage.mode(x) <- "integer"
    x
  }

  z@defineComponent <- expression({
    logLik <- function(x, y){
      colSums(dpois(t(y), lambda, log=TRUE))
    }

    predict <- function(x, ...){
      matrix(lambda, nrow = nrow(x), ncol=length(lambda),
             byrow=TRUE)
    }
    
    new("FLXcomponent", parameters=list(lambda=lambda), df=df,
        logLik=logLik, predict=predict)
  })
  z@fit <- function(x, y, w){
    with(list(lambda = colSums(w*y)/sum(w), df = ncol(y)),
         eval(z@defineComponent))
  }
  z 
}

back to top