On Tue, Apr 3, 2012 at 9:58 AM, Joachim Audenaert <joachim.audena...@pcsierteelt.be> wrote: > Hello all, > > I would like to get parameter estimates for different models. For one of > them I give the code in example. I am estimating the parameters (i,j and > k) with the nls function, which sees the error distribution as normal, I > would however like to do the same as nls with the assumption that the > errors are poisson distributed. > > Is there a way to do this with R? Are there packages designed for this? I > tried with the gnm package, but don't understand how to transform my > equation to a generalised equation. Is there an option for nls to choose > family = poisson? > > Lower in the mail the code with the model and visualisations I use to > check my results. I also copied the test dataset from my txt file. > > I am using R 2.15 and Rstudio to visualise it. > > > plot(FR~N0) > x <- > nls(FR~(exp(i+j*N0)/(1+exp(i+j*N0)))*(k*N0/(k+N0)),start=list(i=0.02,j=0.002,k=6)) > summary(x) > hatx <- predict(x) > lines(spline(N0,hatx)) >
Just minimize the negative log likelihood from first principles. Define the mean function and then define the negative log likelihood in terms of that: Mean <- function(p) { i <- p[1]; j <- p[2]; k <- p[3]; exp(i+j*N0)/(1+exp(i+j*N0))*(k*N0/(k+N0)) } ll <- function(p) - sum(dpois(FR, Mean(p), log = TRUE)) out <- optim(c(1, 1, 1), ll); out plot(FR ~ N0, pch = 20) lines(Mean(out$par) ~ N0) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com ______________________________________________ R-help@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.