Skip to content
Prev 354916 / 398498 Next

How to calculate standard error of estimate (S) for my non-linear regression model?

You may not be a statistician, but you should at least learn about the 
calculations you are making. You cannot expect to convince others that 
your calculations are right just because "Peter on the internet said they 
were right".

To give you a gentle push in this direction, I have reproduced the 
calculations on that reference web page using R, so you can get a head 
start on understanding how to perform them on your data. (Hint: about all 
you should need to do is give your dta.nls to predict and use your 
column names instead of X and Y.) Once you have convinced yourself that
the pre-defined functions are doing what you expect, then you can omit the 
do-it-yourself option with confidence in the results.

Please note that no use of attach is included here... that usually ends in 
unhappiness at some point, so prefer to use the data argument instead.

###
dta <- data.frame( X=c(1,2,3,4,5), Y=c(1,2,1.3,3.75,2.25) )
nrow( dta )
# linear regression
y.lm <- lm( Y~X, data=dta )
# compute predictions from original data
## Be aware that you can also "predict" using a nonlinear regression fit
## Also be aware that you can compute estimates using different data if you
## specify the "newdata" argument... see the help for predict.lm
## ?predict.lm
dta$Yprime <- predict( y.lm )
# ?with
dta$YlessYprime <- with( dta, Y - Yprime )
dta$YlessYprime2 <- with( dta, YlessYprime^2 )

# confirm sums
# ?sum
sum( dta$X )
sum( dta$Y )
sum( dta$Yprime )
sum( dta$YlessYprime )
sum( dta$YlessYprime2 )

# standard error of the estimate for population data
sigma.est <- sqrt( sum( dta$YlessYprime2 ) / nrow( dta ) )
sigma.est
# sd function assumes sample standard deviation, can correct the result if 
# you want
# ?sd
# ?all.equal
all.equal( sigma.est, sd( dta$YlessYprime ) * sqrt( ( nrow( dta ) - 1 ) / 
nrow( dta ) ) )

# alternate formulation
SSY <- sum( ( dta$Y - mean( dta$Y ) )^2 )
rho <- with( dta, cor( Y, X ) )
all.equal( sigma.est, sqrt( (1-rho^2)*SSY/nrow(dta) ) )

# when working with a sample...
s.est <- sqrt( sum( dta$YlessYprime2 ) / ( nrow( dta ) - 2 ) )
s.est

####
[1] 5
[1] 15
[1] 10.3
[1] 10.3
[1] 2.220446e-16
[1] 2.79075
[1] 0.7470944
/ nrow( dta ) ) )
[1] TRUE
[1] TRUE
[1] 0.9644947

        
On Sat, 26 Sep 2015, Michael Eisenring wrote:

            
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                       Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k