Mixed Models providing a correlation structure.

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Mixed Models providing a correlation structure.

Marcio
Hi folks,
I was wondering how to run a mixed models approach to analyze a linear regression with a user-defined covariance structure.

I have my model
y = xa +zb +e and
b ~ N (0, C*sigma_square). (and a is a fixed effects)

I would like to provide R the C (variance-covariance) matrix

I can easily provide an example, but at this point I am first trying to know what is the best package the allows an unstructured covariance matrix.

I was trying the function lme in the package nlme but I didn't have success in the defining the option "correlation"

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Mixed Models providing a correlation structure.

Simon Blomberg-4
You need to look at the corSymm correlation class for nlme models.

Essentially, in your lme call, you need to do
correlation=corSymm(mat[lower.tri(mat)], fixed=TRUE)

Where mat is your (symmetric) variance-covariance matrix. Remember to
make sure that the rows and columns of mat are in the same order as in
your data frame.

Cheers,

Simon.

On 06/07/12 11:43, Marcio wrote:

> Hi folks,
> I was wondering how to run a mixed models approach to analyze a linear
> regression with a user-defined covariance structure.
>
> I have my model
> y = xa +zb +e and
> b ~ N (0, C*sigma_square). (and a is a fixed effects)
>
> I would like to provide R the C (variance-covariance) matrix
>
> I can easily provide an example, but at this point I am first trying to know
> what is the best package the allows an unstructured covariance matrix.
>
> I was trying the function lme in the package nlme but I didn't have success
> in the defining the option "correlation"
>
> Thanks
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Mixed-Models-providing-a-correlation-structure-tp4635569.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Simon Blomberg, BSc (Hons), PhD, MAppStat, AStat.
Lecturer and Consultant Statistician
School of Biological Sciences
The University of Queensland
St. Lucia Queensland 4072
Australia
T: +61 7 3365 2506
email: S.Blomberg1_at_uq.edu.au
http://www.uq.edu.au/~uqsblomb/

Policies:
1.  I will NOT analyse your data for you.
2.  Your deadline is your problem.

Statistics is the grammar of science - Karl Pearson.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Mixed Models providing a correlation structure.

Simon Blomberg-4
In reply to this post by Marcio
Aah. From your model description, you are more interested in the
covariance structure of the random effects, rather than the residuals.
You will then need to use the pdSymm class in the specification of the
random effects. See Pinheiro and Bates pp 157-166.

Cheers,

Simon.

On 06/07/12 11:43, Marcio wrote:

> Hi folks,
> I was wondering how to run a mixed models approach to analyze a linear
> regression with a user-defined covariance structure.
>
> I have my model
> y = xa +zb +e and
> b ~ N (0, C*sigma_square). (and a is a fixed effects)
>
> I would like to provide R the C (variance-covariance) matrix
>
> I can easily provide an example, but at this point I am first trying to know
> what is the best package the allows an unstructured covariance matrix.
>
> I was trying the function lme in the package nlme but I didn't have success
> in the defining the option "correlation"
>
> Thanks
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Mixed-Models-providing-a-correlation-structure-tp4635569.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

--
Simon Blomberg, BSc (Hons), PhD, MAppStat, AStat.
Lecturer and Consultant Statistician
School of Biological Sciences
The University of Queensland
St. Lucia Queensland 4072
Australia
T: +61 7 3365 2506
email: S.Blomberg1_at_uq.edu.au
http://www.uq.edu.au/~uqsblomb/

Policies:
1.  I will NOT analyse your data for you.
2.  Your deadline is your problem.

Statistics is the grammar of science - Karl Pearson.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: Mixed Models providing a correlation structure.

Marcio
Dear Simon,
Thanks for the quick reply.
Unfortunately I don't have access to Pinheiro and Bates. I tried googling the pdSymm and lme but I still cannot get the syntax right.

In my model, I only have 1 random factor with repetitions (groups) (e.g. 2 records per each level)
I am pasting bellow a very small example (2 records and 2 levels) which demonstrates the error I am having.
The syntax of lme is obviously wrong, and any help would be appreciated:

Thanks

> #Example
> CovM <- matrix(c(1,0.5,0.5,1),2)
> CovM
     [,1] [,2]
[1,]  1.0  0.5
[2,]  0.5  1.0
> DATA <- data.frame(Y = c(rnorm(4)), Random = c(1,1,2,2))
> DATA
            Y              Random
1  0.24037680      1
2  0.03477704      1
3 -1.83389279      2
4 -0.84793117      2
> lme(Y~Random, data = DATA, random = list(Random = pdSymm (CovM[lower.tri(CovM)],~Random)))
Error in `Names<-.pdMat`(`*tmp*`, value = c("(Intercept)", "Random")) :
  Length of names should be 1
Reply | Threaded
Open this post in threaded view
|

Re: Mixed Models providing a correlation structure.

Kevin Wright-5
Why did you use the 'lower.tri' syntax?

Does this work for you?

lme(Y~Random, data = DATA,
random = list(Random = pdSymm(CovM,~Random)))

Kevin

On Wed, Jul 11, 2012 at 9:27 AM, Marcio <[hidden email]> wrote:

> Dear Simon,
> Thanks for the quick reply.
> Unfortunately I don't have access to Pinheiro and Bates. I tried googling
> the pdSymm and lme but I still cannot get the syntax right.
>
> In my model, I only have 1 random factor with repetitions (groups) (e.g. 2
> records per each level)
> I am pasting bellow a very small example (2 records and 2 levels) which
> demonstrates the error I am having.
> The syntax of lme is obviously wrong, and any help would be appreciated:
>
> Thanks
>
>> #Example
>> CovM <- matrix(c(1,0.5,0.5,1),2)
>> CovM
>      [,1] [,2]
> [1,]  1.0  0.5
> [2,]  0.5  1.0
>> DATA <- data.frame(Y = c(rnorm(4)), Random = c(1,1,2,2))
>> DATA
>             Y              Random
> 1  0.24037680      1
> 2  0.03477704      1
> 3 -1.83389279      2
> 4 -0.84793117      2
>> lme(Y~Random, data = DATA, random = list(Random = pdSymm
>> (CovM[lower.tri(CovM)],~Random)))
> Error in `Names<-.pdMat`(`*tmp*`, value = c("(Intercept)", "Random")) :
>   Length of names should be 1
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Mixed-Models-providing-a-correlation-structure-tp4635569p4636141.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



--
Kevin Wright

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.