From d.rizopoulos at erasmusmc.nl  Tue Apr 20 08:57:30 2010
From: d.rizopoulos at erasmusmc.nl (Dimitris Rizopoulos)
Date: Tue, 20 Apr 2010 08:57:30 +0200
Subject: [Rd] Derivative of model formula
Message-ID: <4BCD505A.9030407@erasmusmc.nl>

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



[Rd] Derivative of model formula
Dimitris Rizopoulos