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/
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%