Skip to content

Instantly share code, notes, and snippets.

@cigrainger
Created March 21, 2014 07:32
Show Gist options
  • Select an option

  • Save cigrainger/9681359 to your computer and use it in GitHub Desktop.

Select an option

Save cigrainger/9681359 to your computer and use it in GitHub Desktop.
sales <- # (this is where we need data, but it's easy to find)
cumsales <- cumsum(sales)
time <- seq_along(sales)
tdelt <- (1:100)/length(time)
Bass <- sales ~ m * (((p+q)^2/p)*exp(-(p+q)*time))/(1+(q/p)*exp(-(p+q)*time))^2)
Bass.nls <- nls(formula = Bass, start=c(p=0.03,q=0.04,m=max(S)))
Bcoef <- coef(Bass.nls)
m <- Bcoef[1]
p <- Bcoef[2]
q <- Bcoef[3]
ngete <- exp(-(p+q) * tdelt)
Bpdf <- m*((p+q)^2/p)*ngete/(1+(q/p)*ngete)^2
plot(tdelt, Bpdf, xlab = "Year from base",ylab = "Sales per year", type='l')
points(time, sales)
Bcdf <- m*(1-ngete)/(1+(q/p)*ngete)
plot(tdelt, Bcdf, xlab = "Year from base",ylab = "Cumulative sales", type='l')
points(t79, cusales)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment