[R] Fitting data to a sigmoidal curve
Rubén Roa-Ureta
rroa at udec.cl
Wed Nov 12 21:21:22 CET 2008
Greg Snow wrote:
> Sarah,
>
> Doing:
>
>
>> RSiteSearch('gompertz', restrict='functions')
>>
>
> At the command prompt gives several promising results.
>
> Hope this helps,
>
> --
> Gregory (Greg) L. Snow Ph.D.
>
>
And you can also do:
nobs <- length(data$salam.size.observed)
fn<-function(p){
salam.size.model <-
salam.size.inf*exp(-G1*exp(-G2*data$age.observed)); # Gompertz model
squdiff <-
(salam.size.model-data$salam.size.observed)^2; #vector of squared
differences
sigmasqu <- sum(squdiff)/nobs; # nuisance sigma parameter
profiled out
minloglik <- (nobs/2)*log(sigmasqu); #profile likelihood
as approx. to true likelihood
}
(salam.size.likfit <- nlm(fn,p=c(init. val. 4 salam.size.inf, init. val.
4 G1, init. val 4 G2), hessian=TRUE))
where data is a dataframe with observed sizes and ages.
Invert Hessian to obtain measures of precision.
Note also that if you know the size at birth then you can
re-parameterize, put size at birth instead of asymptotic size
(salam.size.inf), and reduce model complexity to two parameters (but of
course the Gompertz formula changes).
If the Gompertz model is not flexible enough, note that it is a
particular case of another more flexible, and more complex model,
Schnute's, which I have found often provides a better explanation of
growth data (as measured by the AIC), especially if you have sizes of
very young individuals.
HTH
Rubén
More information about the R-help
mailing list