[R] regression on data subsets in datafile
Gabor Grothendieck
ggrothendieck at gmail.com
Mon Sep 12 13:26:33 CEST 2011
On Mon, Sep 12, 2011 at 3:42 AM, marcel <marcelcurlin at gmail.com> wrote:
> I have data of the form
>
> tC <- textConnection("
> Subject Date parameter1
> bob 3/2/99 10
> bob 4/2/99 10
> bob 5/5/99 10
> bob 6/27/99 NA
> bob 8/35/01 10
> bob 3/2/02 10
> steve 1/2/99 4
> steve 2/2/00 7
> steve 3/2/01 10
> steve 4/2/02 NA
> steve 5/2/03 16
> kevin 6/5/04 24
> ")
> data <- read.table(header=TRUE, tC)
> close.connection(tC)
> rm(tC)
>
> I am trying to calculate rate of change of parameter1 in units/day for each
> person. I think I need something like:
Try this:
data$Date <- as.Date(data$Date, "%m/%d/%y")
fm <- lm(parameter1 ~ Subject / Date - 1, data)
coef(fm)
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list