我正在尝试将增长函数拟合到数据集。我使用的数据是世界年度汽车销售量,我希望将增长函数与最大人口规模拟合为11000。去年的新车销售量约为96工厂。有关数据,请参见下文。数据集中的备忘编号以千为单位。
我首先尝试了SSlogis,但结果没有得到逻辑结果,最大值远远低于11000。我使用的代码是:
EV.ss <- nls(TotalSales ~ SSlogis(Year, phi1, phi2, phi3), data = EV_temp)
summary(EV.ss)
接下来,我尝试了自己的自定义功能。代码:
myfunction <- function(GrowthRate, time, Beta){
AsymptoticLimitOfGrowth =11000
Value = AsymptoticLimitOfGrowth / (1+exp(-GrowthRate*time-Beta))
return(Value)
}
nls(TotalSales ~ myfunction(GrowthRate, time, Beta),
data=EV_temp,
start=list(GrowthRate=0.5, time=2030, Beta=1))
但是导致错误:
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
我将如何解决这个问题?
注意:我从Application of S-shaped curves中获得了Dmitry Kucharavy和Roland De Guio的函数,请参阅第2页的方程式2。
数据:
EV_temp<-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")