Set up data:
dd <- data.frame(x=c(1981,1990,2000:2013),
y = c(3.262897,2.570096,7.098903,5.428424,6.056302,5.593942,
10.869635,12.425793,5.601889,6.498187,6.967503,5.358961,3.519295,
7.137202,19.121631,6.479928))
The problem is that exponentiating any number larger than about 709 gives a number greater than the maximum value storable as a double-precision floating-point value (approx. 1e308), and hence leads to a numeric overflow. You can easily remedy this by shifting your x
variable:
lm(y~exp(x),data=dd) ## error
lm(y~exp(x-1981),data=dd) ## fine
However, you can plot the fitted value for this model more easily as follows:
library(ggplot2); theme_set(theme_bw())
ggplot(dd,aes(x,y))+geom_point()+
geom_smooth(method="glm",
method.args=list(family=gaussian(link="log")))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…