[R] Question on partial effect
Gavin Simpson
gavin.simpson at ucl.ac.uk
Tue Jul 11 19:47:17 CEST 2006
On Wed, 2006-07-12 at 00:51 +0800, Guo Wei-Wei wrote:
> Thank you, Gavin. I think that might be what I need. But I'm a little
> bit wandering what's the scale of resid(mod). Is it
> scale(dist)/scale(speed), for example kilometer / (kilometer per
> hour)? or something else?
>
> Thank you very much!
> Wei-Wei
The scale of dist - they are just the differences between observed dist
and fitted dist (based on speed).
mod <- lm(dist ~ speed, data = cars)
resid(mod)
1 2 3 4 5
3.849460 11.849460 -5.947766 12.052234 2.119825
6 7 8 9 10
-7.812584 -3.744993 4.255007 12.255007 -8.677401
....
# visualise the residuals
plot(resid(mod) ~ dist, data = cars)
abline(h = 0, col = "grey")
## length of blue line represents the residual
lines(cars$dist, resid(mod), type = "h", col = "blue")
So you see that for the 1st residual it is 3.849 ft (the distances are
measured in feet, see ?cars)
Does this help?
G
>
>
> 2006/7/12, Gavin Simpson <gavin.simpson at ucl.ac.uk>:
> > On Tue, 2006-07-11 at 23:51 +0800, Guo Wei-Wei wrote:
> > > Dear all,
> > >
> > > I don't know what's my question is called. I have a performance
> > > variable A, such as sales. And I have another variable B, let's say
> > > establish time of firm. I want to create the third variable that is
> > > sales without the effect of establish time. Maybe it can be called
> > > partial effect problem. I'm not sure.
> > >
> > > Does anyone have any suggestion? Thank you in advance!
> > >
> > > All the best,
> > > Wei-Wei
> >
> > Do you mean?
> >
> > ## dummy data
> > A <- rnorm(100)
> > B <- rnorm(100)
> > C <- resid(lm(A ~ B))
> >
> > C now contains the residual variation in A after fitting B.
> >
> > e.g. with some real data
> > ?cars
> > data(cars) # not sure this is needed now, I forget
> > mod <- lm(dist ~ speed, data = cars)
> > summary(mod)
> > partial <- resid(mod)
> >
> > ## check
> > mod2 <- lm(dist ~ partial, data = cars)
> > summary(mod2)
> > ## from the two R^2 form mod1 and mod2 - partial contains dist minus
> > ## the effects of speed
> > > 0.6511 + 0.3489
> > [1] 1
> >
> > HTH
> >
> > G
> > --
> > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> > Gavin Simpson [t] +44 (0)20 7679 0522
> > ECRC & ENSIS, UCL Geography, [f] +44 (0)20 7679 0565
> > Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
> > Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/cv/
> > London, UK. WC1E 6BT. [w] http://www.ucl.ac.uk/~ucfagls/
> > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
> >
> >
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
--
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Gavin Simpson [t] +44 (0)20 7679 0522
ECRC & ENSIS, UCL Geography, [f] +44 (0)20 7679 0565
Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk
Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/cv/
London, UK. WC1E 6BT. [w] http://www.ucl.ac.uk/~ucfagls/
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
More information about the R-help
mailing list