[R] Problems with nls
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Jun 16 01:02:10 CEST 2011
On Wed, Jun 15, 2011 at 6:05 PM, Daniel Malter <daniel at umd.edu> wrote:
> There may be two issues here. The first might be that, if I understand the
> Bass model correctly, the formula you are trying to estimate is the adoption
> in a given time period. What you supply as data, however, is the cumulative
> adoption by that time period.
>
> The second issue might be that the linear algorithm may fail and that it may
> be preferable to use Newton-Raphson (the standard) as this may provide
> better values in the iterations.
>
> If you do both, i.e., you do NLS on period adoption and use Newton-Raphson,
> you get an estimate. Though, I am of course not sure whether that is
> "correct" in the sense that it is what you would expect to find.
>
>
> adoption <-
> c(167000,273000,531000,938000,2056452,3894103,5932090,7963742,9314687,10469060,11393302,11976340)
> time <- seq(from = 1,to = 12, by = 1)
>
> adoption2<-c(0,adoption[1:(length(adoption)-1)])
> S<-(adoption-adoption2)/max(adoption)
>
> ## Models
> Bass.Model <- S ~ M*((p + q)^2/p) * (exp(-(p + q) * time)/((q / p) *
> exp(-(p + q) * time) + 1)^2)
> ## Starting Parameters
> Bass.Params <- list(p = 0.1, q = 0.1, M=1)
> ## Model fitting
> Bass.Fit <- nls(formula = Bass.Model, start = Bass.Params)
> summary(Bass.Fit)
>
If your hypothesis regarding the cumulative vs. adoptions is correct
then it may be that poster wants this:
> S <- diff(adoption)
> time <- seq_along(S)
> Bass2 <- S ~ m * ((p + q)^2/p) * (exp(-(p + q) * time)/((q / p) *
+ exp(-(p + q) * time) + 1)^2)
> nls(formula = Bass2, start = c(p = 0.03, q = 0.4, m = max(S)))
Nonlinear regression model
model: S ~ m * ((p + q)^2/p) * (exp(-(p + q) * time)/((q/p) *
exp(-(p + q) * time) + 1)^2)
data: parent.frame()
p q m
8.65635536465e-03 6.52817192695e-01 1.23485254536e+07
residual sum-of-squares: 321990186229
Number of iterations to convergence: 16
Achieved convergence tolerance: 8.10600476229e-06
> # or equivalently in terms of "plinear" where S, time and Bass2 are
> # as written just above
> m <- 1 # set m to 1 since we are using .lin instead
> nls(formula = Bass2, start = c(p = 0.03, q = 0.4), alg = "plinear")
Nonlinear regression model
model: S ~ m * ((p + q)^2/p) * (exp(-(p + q) * time)/((q/p) *
exp(-(p + q) * time) + 1)^2)
data: parent.frame()
p q .lin
8.65637919209e-03 6.52816636341e-01 1.23485299874e+07
residual sum-of-squares: 321990186247
Number of iterations to convergence: 9
Achieved convergence tolerance: 5.6090474901e-06
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list