[Rd] Derivative of model formula
Dimitris Rizopoulos
d.rizopoulos at erasmusmc.nl
Tue Apr 20 08:57:30 CEST 2010
Dear All,
I'd like to ask fro any pointers to code in any package out there that
can (even partially) handle the following situation: say we have the
linear model
# toy data
y <- rnorm(100)
time <- runif(100, 0, 5)
treat <- gl(2, 50, labels = c("placebo", "active"))
sex <- gl(2, 1, 100, labels = c("male", "female"))
bmi <- runif(100, 20, 35)
# linear model fit
lmFit <- lm(y ~ (time + I(time^2) + I(time^3))*sex + bmi*treat)
Now, I'd like to compute the derivative of the linear predictor with
respect to 'time'. I thought of the following procedure:
step 1: create a new formula that is the derivative of the original
formula wrt 'time'.
step 2: feed this to model.matrix().
step 3: multiple with the corresponding estimated coefficients.
Is this a reasonable way to attack this problem or is there another more
optimal solution -- I'd like to obtain a solution as generalizable as
possible.
Thanks in advance.
Best,
Dimitris
--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
More information about the R-devel
mailing list