# [R] Repeated measures

Sean Davis sdavis2 at mail.nih.gov
Thu Oct 7 14:19:31 CEST 2004

```Dan,

Thanks for the reply.  To be a bit more specific, the "time" variable
continuous and the measurement is a real value at random intervals.  I
would, ultimately, like to define a state for each measured point
through time.  In my specific case right now, the state could be
described as a binomial random variable with unknown p and measure is a
continuous predictor.  I don't have a function for
autocorrelation--this would have to be estimated from the data.  In
R-speak, the data would be something like:

x <- runif(1000,max=50000000)
y <- c(rnorm(150,0),rnorm(350,b),rnorm(10,a),rnorm(490,0)) # just as an
example--region lengths and positions vary

For my current specific case, I would like to find the region where the
mean is a=b!=0 (the perturbed state) as compared to the other region
where mean is 0 (the unperturbed state).

In a more general case, I would like to find all regions and states
where a!=b!=0 and have state(a) be distinct from state(b), if it is
"justifiably" different.

Thanks,

Sean

On Oct 7, 2004, at 7:35 AM, Dan Bebber wrote:

> Hi Sean,
>
> I'm not sure I quite understand your question. Am I right in thinking
> that:
> state = a binomial dependent variable
> measure = a continuous predictor
>
> If so, perhaps you could try using glmmPQL (Generalized Linear Mixed
> Models
> fitted by Penalized Quasi-Likelihood) in library MASS.
> The model would include random intercepts for each individual, have
> binomial
> errors, and some kind of continuous autoregressive error structure (I
> expect), and would look something like
>
> results<-glmmPQL(fixed=state~measure,random=~1|individual,
> family=binomial,
> correlation=corCar1(args...),data=your.data)
>
> If I've got the wrong end of the stick, my apologies.
>
> Dan Bebber
>
> Department of Plant Sciences
> University of Oxford
> Oxford OX1 3RB
> UK
> Tel. 01865 275000
>
>
> ------------------------------
>
> Message: 11
> Date: Wed, 6 Oct 2004 08:07:38 -0400
> From: Sean Davis <sdavis2 at mail.nih.gov>
> Subject: [R] Repeated measures
> To: r-help <r-help at stat.math.ethz.ch>
> Message-ID: <5125203F-1790-11D9-97DA-000A95D7BA10 at mail.nih.gov>
> Content-Type: text/plain; charset=US-ASCII; format=flowed
>
> I have a data set in which I have 5000 repeated measures on 6 subjects
> over time (varying intervals, but measurements for all individuals are
> at the same times).  There are two states, a "resting" state (the
> majority of the time), and a perturbed state.  I have a continuous
> measurement at each time point for each of the individuals.  I would
> like to determine the "state" for each individual at each time point.
> It looks to me like I should be able to do this with the "hidden"
> command from the "repeated" package
> (http://popgen0146uns50.unimaas.nl/~jlindsey/rcode.html), but I have
> found it a bit confusing to get started.  The distributions in the two
> states are approximately normal with differences in centrality and
> possibly variance (but I can start by assuming similar variances).
>
> Thanks,
> Sean

```