1

How would I go about forecasting future population with a growth function in R?

I'm trying to fit a growth function to the sales of EVs in the world. One assumption I might want to make would be one such as max potential sales would be 110 million. Current vehicle sales in the world are 96,804,38 with 3,109,050 being EVs in 2017. This is for both BEV and PHEV.

The source I've used are: Logistic substitution model and technological forecasting by Dmitry Kucharavy and Roland De Guio enter image description here Application of S-shaped curves by Dmitry Kucharavy and Roland De Guio enter image description here

Data is from the iea EV outlook.

 EVAnnualWorldSales<-structure(list(Country = structure(c(21L, 21L, 21L, 21L, 21L, 
 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L), .Label = c("Australia", 
 "Brazil", "Canada", "Chile", "China", "Finland", "France", "Germany", 
 "India", "Japan", "Korea", "Mexico", "Netherlands", "New Zealand", 
 "Norway", "Others", "Portugal", "South Africa", "Sweden", "Thailand", 
 "Total", "United Kingdom", "United States"), class = "factor"), 
Year = c(2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 
2013, 2014, 2015, 2016, 2017), TotalSales = c(1.89, 2.23, 
2.69, 5.15, 7.48, 14.26, 61.33, 179.03, 381.3, 703.65, 1239.45, 
1982.04, 3109.05)), row.names = c(NA, -13L), .Names = c("Country", 
 "Year", "TotalSales"), class = "data.frame")

How would I go about forecasting EV sales through 2040?

Here is what I've tried:

myfunction <- function(GrowthRate, time, Beta){
    AsymptoticLimitOfGrowth =88000
    Value = AsymptoticLimitOfGrowth / (1+exp(-GrowthRate*time-Beta))
    return(Value)
 }
nls(TotalSales ~ myfunction(GrowthRate, time, Beta),
 data=EVAnnualWorldSales,
start=list(GrowthRate=0.5, time=2030, Beta=1))

with error:

 Error in qr(.swts * gr) : 
 dims [product 3] do not match the length of object [13]
 In addition: Warning message:
 In .swts * gr :
  longer object length is not a multiple of shorter object length

and

EV.ss <- nlsLM(TotalSales ~ SSgompertz(Year, Asym, b2, b3), data = EVAnnualWorldSales)

Error: Error in qr.qty(QR.rhs, .swts * ddot(attr(rhs, "gradient"), lin)) : NA/NaN/Inf in foreign function call (arg 5)

and

 EV.ss <- nls(TotalSales ~ SSlogis(Year, phi1, phi2, phi3), data = EVAnnualWorldSales)
 summary(EV.ss)

The last one generates an output but the limit if far below what would be expected. Therefore, not a logical result.

Would someone be able to point me in the correct direction?

user2946746
  • 115
  • 4
  • There's a danger with using nls for fitting growth, since any inference associated with it will be based on the assumption of independence, but growth is (almost by definition) dependent on earlier values. In addition any assumption of constant variance (implied by the constant weights) would not usually make sense (often not even roughly true). – Glen_b Nov 30 '18 at 04:40

2 Answers2

2

The following worked for me

y <- EVAnnualWorldSales$TotalSales/88000
x <- EVAnnualWorldSales$Year-2004

my_model <- nls(y ~ 1/(1+exp(a*x +b)),start=list(a=-0.5,b=-0.5))
plot(EVAnnualWorldSales$Year,y)
lines(EVAnnualWorldSales$Year,predict(my_model),col="red",lty=2,lwd=3)

simply by choosing the correct starting values and not working with data.frame object and scaling time to prevent under- overflow when evaluating exponential function during estimation.

Jesper for President
  • 5,049
  • 1
  • 18
  • 41
  • Thank you :) Looks great! I'm doing some cleaning up of plot etc. Will post it when I'm done. Was looking at EV adoption for fun. Doesn't look for from an oil point of view. But reinforces what I'm seeing on a fundamental level. – user2946746 Nov 29 '18 at 23:27
-1

not so easy ... I took your SCALED data enter image description here and introduced it to AUTOBOX ( a piece of forecasting software that I have helped to develop ) enter image description here and requested an automatic ARIMA model to be built which included outlier detection.

AUTOBOX automatically detected the need for a power transform (logs) and delivered the following model .enter image description here

The forecasts for the next 23 periods are here enter image description here and The Actual and Forecast graph is here enter image description here

If the forecasts exceed some upper limit that you have in mind , simply truncate the forecasts to that value.

Now AUTOBOX has an R version but if you are not interested in that version you simply need to find/use an automatic box-jenkins /ARIMA algorithm that will determine/identify an appropriate power transformation while dealing with anomalies per When (and why) should you take the log of a distribution (of numbers)?

IrishStat
  • 27,906
  • 5
  • 29
  • 55