# Data input
> year<-c(1966:1984)
> adoption<-c(0.003,0.016,0.054,0.139,0.263,0.423,0.611,0.758,0.859,0.903,0.937,0.954,0.978,0.978, 0.982,0.985,0.989,0.988,0.992)
# Data output
> year
[1] 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984
> adoption
[1] 0.003 0.016 0.054 0.139 0.263 0.423 0.611 0.758 0.859 0.903 0.937 0.954 0.978 0.978 0.982 0.985
[17] 0.989 0.988 0.992
# Data plot
> plot(year, adoption)
# non-linear regression analysis
> fm<-nls(adoption~ a/(1+b*exp(c*1:19)), start=c(a=1,b=1,c=-1),trace = TRUE)
3.905671 : 1 1 -1
2.387674 : 0.9824052 0.4300442 -0.1029666
1.743185 : 0.8872618 0.8264732 -0.2623701
0.7740848 : 0.9841109 2.3123040 -0.2310466
0.5578214 : 0.9271411 7.5149746 -0.5270324
0.0922908 : 1.0001338 17.1134435 -0.4350728
0.06874582 : 0.9606817 40.3886060 -0.6606493
0.01653944 : 0.9826601 75.9510223 -0.7160221
0.003486703 : 0.9806949 110.6878625 -0.7509771
0.001959816 : 0.9804580 123.8500769 -0.7565368
0.001949770 : 0.9806034 123.8048205 -0.7553703
0.001949752 : 0.9806268 123.6621025 -0.7551686
0.001949752 : 0.9806279 123.6609492 -0.7551648
# Summary
> summary(fm)
Formula: adoption ~ a/(1 + b * exp(c * 1:19))
Parameters:
Estimate Std. Error t value Pr(>|t|)
a 0.98063 0.00384 255.401 < 2e-16 ***
b 123.66095 13.56739 9.115 9.82e-08 ***
c -0.75516 0.01742 -43.347 < 2e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.01104 on 16 degrees of freedom
Number of iterations to convergence: 12
Achieved convergence tolerance: 7.08e-06
# make plots larger
> plot(year,adoption,cex=2)
# add lines
> lines(year,adoption,cex=2)
# add fitting curve, add legend
> lines(年度,fitted(fm),col=2,lty=2,lwd=2)
> legend(1975,0.5,c("data","theoretical"), col=1:2,lty=1:2,lwd=2)
# non-linear regression analysis with other format
> fm1<-nls(adoption~SSlogis(1:19, Asym, xmid, scal ),list( Asym = 1, xmid = 0, scal = 1 ),trace = TRUE)
0.001949752 : 0.9806279 6.3794602 1.3242145
# comparison of two analysis
> data.frame(fitted(fm),fitted(fm1))
fitted.fm. fitted.fm1.
1 0.01658921 0.01658922
2 0.03464022 0.03464024
3 0.07088854 0.07088857
4 0.13947542 0.13947545
5 0.25576569 0.25576573
6 0.42053977 0.42053979
7 0.60313972 0.60313972
8 0.75775773 0.75775771
9 0.86154829 0.86154827
10 0.92081868 0.92081866
11 0.95158253 0.95158252
12 0.96676078 0.96676077
13 0.97406204 0.97406204
14 0.97753137 0.97753137
15 0.97917027 0.97917028
16 0.97994235 0.97994235
17 0.98030559 0.98030560
18 0.98047639 0.98047639
19 0.98055667 0.98055667