[R-sig-eco] Manually calculate residuals

Johannes Radinger JRadinger at gmx.at
Wed Nov 23 16:10:15 CET 2011


now just another question popped up:

How do I have to handle the case when
variables are transformed?

the regression function is as follows:

log(y) ~ log(x1)+ log(x2) + sqrt(x3)

Is that way correct?:

#original data not transformed yet
df <- data.frame(y=runif(10), x1=1:10, x2=11:20, x3=1:10) 

# parameter estimates for from lm with transformed data
Intercept <- 0.5
b1 <- 0.6
b2 <- 0.7
b3 <- 0.8

df$yTheo <- Intercept + b1*log(x$x1) + b2*log(x$x2) + b3*sqrt(x$x3)

#how about the transformed y? this way?
df$resid <- df$y - exp(df$yTheo)
#or this way
df$resid <- log(df$y) - df$yTheo


Are the manually calculated residuals to those which are usually produced with resid(lm())? Or are there any standardizations of residuals etc.


/Johannes



-------- Original-Nachricht --------
> Datum: Wed, 23 Nov 2011 14:52:51 +0100
> Von: Rainer M Krug <r.m.krug at gmail.com>
> An: Johannes Radinger <JRadinger at gmx.at>
> CC: r-sig-ecology at r-project.org
> Betreff: Re: [R-sig-eco] Manually calculate residuals

> On Wed, Nov 23, 2011 at 2:45 PM, Johannes Radinger <JRadinger at gmx.at>
> wrote:
> 
> > Hello,
> >
> > I have a dataset like:
> >
> > dataframe(y,x1,x2,x3)
> >
> > and I know a given (external) regression with its
> > parameter estimates like:
> >
> > y = Intercept + b1*x1 + b2*x2 + b3*x3
> >
> > Now I'd like to manually calculate the residuals
> > of my "new" data based on the given (external) regression.
> >
> > Is there any built in function of R for doing that
> > (not resid()) or do I have to manually calculate fitted values
> > and then residuals for each dataset?
> >
> >
> Well - that is not to difficult:
> 
> 
> 
> x <- data.frame(y=runif(10), x1=1:10, x2=11:20, x3=1:10)
> Intercept <- 0.5
> b1 <- 0.6
> b2 <- 0.7
> b3 <- 0.8
> x$yTheo <- Intercept + b1*x$x1 + b2*x$x2 + b3*x$x3
> x$resid <- x$y - x$yTheo
> x
> 
> 
> The values are obviously useless examples.
> 
> Cheers,
> 
> Rainer
> 
> best regards,
> > Johannes
> > --
> >
> > _______________________________________________
> > R-sig-ecology mailing list
> > R-sig-ecology at r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-sig-ecology
> >
> 
> 
> 
> -- 
> Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation
> Biology,
> UCT), Dipl. Phys. (Germany)
> 
> Centre of Excellence for Invasion Biology
> Stellenbosch University
> South Africa
> 
> Tel :       +33 - (0)9 53 10 27 44
> Cell:       +33 - (0)6 85 62 59 98
> Fax (F):       +33 - (0)9 58 10 27 44
> 
> Fax (D):    +49 - (0)3 21 21 25 22 44
> 
> email:      Rainer at krugs.de
> 
> Skype:      RMkrug

--



More information about the R-sig-ecology mailing list