issues with nls in R -
i'm trying solve two-component decay model in r using nls function, running errors. equation is:
where t time, ctot c1+c2, , p1 , p2 known proportions of ctot.
my data (dd) is:
> head(dd,n=15) t ctot 1 0.00 6.62 2 0.33 6.45 3 0.50 6.38 4 0.67 6.44 5 0.83 6.38 6 1.00 6.39 7 1.17 6.35 8 1.33 6.33 9 1.50 6.33 10 1.67 6.28 11 1.83 6.17 12 2.00 6.11 13 2.17 6.07 14 2.33 5.89 15 2.50 5.86
using nls have tried:
p1 <- 0.3 p2 <- 0.7 z <- nls(ctot~(p1*c1*(exp(-k1*t)))+(p2*c2*(exp(-k2*t))), data=dd, start=list(c1=6, c2=0.1, k1=0.01, k2=0.01))
however getting:
z <- nls(ctot~(p1*c1*(exp(-k1*t)))+(p2*c2*(exp(-k2*t))), data=dd, start=list(c1=6, c2=0.1, k1=0.01, k2=0.01)) error in numericderiv(form[[3l]], names(ind), env) : missing value or infinity produced when evaluating model
i grateful if has suggestions!
the data seems limited , incomplete since head. if make data testing methods ... , leave out confusing p1 , p2:
t=seq(0, 20, by=.3) ctot = 3 * exp( -1 * t) + 4 * exp(-5*t) # following hte example on gnm::gnm's page: saved.fits <- list(); library(gnm) (i in 1:10) { saved.fits[[i]] <- suppresswarnings( gnm(ctot ~ exp(1 + t, inst = 1) + exp(1 + t, inst = 2), verbose=false))} plot(ctot~t) lines(saved.fits[[3]]$fitted~t) lines(saved.fits[[3]]$fitted~t,col="red")
i wasn't familiar gnm package , ended reading first few sections , worked 2 component data fitting example in vignette: https://cran.r-project.org/web/packages/gnm/vignettes/gnmoverview.pdf . of fits expected, find local maximum in likelihood not global max:
> saved.fits[[1]]$coefficients (intercept) exp(. + t, inst = 1).(intercept) 1.479909e-12 1.098612e+00 exp(1 + ., inst = 1).t exp(. + t, inst = 2).(intercept) -1.000000e+00 1.386294e+00 exp(1 + ., inst = 2).t -5.000000e+00 attr(,"eliminated") [1] 0 > exp( saved.fits[[1]]$coefficients[4] ) exp(. + t, inst = 2).(intercept) 4 > exp( saved.fits[[1]]$coefficients[2] ) exp(. + t, inst = 1).(intercept) 3
Comments
Post a Comment