$ontext Non-Linear Least Squares Regression example Erwin Kalvelagen, may 2008 Reference: http://www.statsci.org/data/general/chloride.html Transport of Sulfite Ions from Blood Cells -------------------------------------------------------------------------------- Description The data related to the transport of sulfite ions from blood cells suspended in a salt solution. The chloride concentration (%) was measured over a period of about 8 minutes as a continuous curve generated from electrical potentials. The data given here were digitized from the curve at 10 second intervals. The theory of ion transport suggested that the concentration asymptote exponentially, i.e., Chloride = q1 {1 - q2 exp(- q3 Time)} -------------------------------------------------------------------------------- Variable Description -------------------------------------------------------------------------------- Time Elapsed time in minutes Chloride Chloride concentration (%) -------------------------------------------------------------------------------- Source Sredni, J. (1970). Problems of Design, Estimation and Lack of Fit in Model Building. PhD Thesis, University of Wisconsin-Madison. Bates, D. M., and Watts, D. G. (1988). Nonlinear Regression Analysis and Its Applications. Wiley, New York. The data were originally collected by W. H. Dennis and P. Wood at the University of Wisconsin. The data were obtained electronically from the web site Data sets from "Nonlinear Regression Analysis" maintained by Douglas Bates Analysis > chloride <- read.table("chloride.txt",header=T) > attach(chloride) > plot(Time,Chloride) > out <- nls(Chloride~cbind(1,exp(-b*Time)),start=list(b=0.1),algorithm="plinear") > summary(out) Formula: Chloride ~ cbind(1, exp( - b * Time)) Parameters: Value Std. Error t value b 0.158523 0.010444 15.1784 39.094900 0.974427 40.1209 -32.387600 0.561816 -57.6481 Residual standard error: 0.191962 on 51 degrees of freedom Correlation of Parameter Estimates: b -0.994 0.911 -0.950 > lines(Time,fitted(out),col=2) $offtext set i /i1*i54/; table data(i,*) Time Chloride i1 2.45 17.3 i2 2.55 17.6 i3 2.65 17.9 i4 2.75 18.3 i5 2.85 18.5 i6 2.95 18.9 i7 3.05 19 i8 3.15 19.3 i9 3.25 19.8 i10 3.35 19.9 i11 3.45 20.2 i12 3.55 20.5 i13 3.65 20.6 i14 3.75 21.1 i15 3.85 21.5 i16 3.95 21.9 i17 4.05 22 i18 4.15 22.3 i19 4.25 22.6 i20 4.35 22.8 i21 4.45 23 i22 4.55 23.2 i23 4.65 23.4 i24 4.75 23.7 i25 4.85 24 i26 4.95 24.2 i27 5.05 24.5 i28 5.15 25 i29 5.25 25.4 i30 5.35 25.5 i31 5.45 25.9 i32 5.55 25.9 i33 5.65 26.3 i34 5.75 26.2 i35 5.85 26.5 i36 5.95 26.5 i37 6.05 26.6 i38 6.15 27 i39 6.25 27 i40 6.35 27 i41 6.45 27 i42 6.55 27.3 i43 6.65 27.8 i44 6.75 28.1 i45 6.85 28.1 i46 6.95 28.1 i47 7.05 28.4 i48 7.15 28.6 i49 7.25 29 i50 7.35 29.2 i51 7.45 29.3 i52 7.55 29.4 i53 7.65 29.4 i54 7.75 29.4 ; parameters Time(i) 'Elapsed time in minutes' Chloride(i) 'Chloride concentration (%)' ; Time(i) = data(i,'Time'); Chloride(i) = data(i,'Chloride'); variables a1 'parameter to be estimated' a2 'parameter to be estimated' a3 'parameter to be estimated' sse 'sum of squared errors' ; equation fit(i) 'equation to fit' sumsq 'dummy objective' ; sumsq.. sse =n= 0; fit(i).. Chloride(i) =e= a1+a2*exp(-a3*Time(i)); a3.l=1; option nlp=nls; models m /sumsq,fit/; solve m minimizing sse using nlp;