An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-sig-mixed-models/attachments/20111207/044c856f/attachment.pl>
MIXED MODEL WITH REPEATED MEASURES
5 messages · Erin Ryan, ONKELINX, Thierry, Ben Bolker
Dear Erin,
Your model seems reasonable. As soon as you add the random effect, then the repeated measures are taken into account. However, I would specify the correlation structure more explicit like corAR1(form = ~Years) which is equal to corAR1(form = ~Years|Subject) in your case.
Furthermore I would suggest that you center the continuous variables so that zero is at least near to your data. You'll get intercepts that are much more easy to interpret and it might help the computation.
Best regards,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
Thierry.Onkelinx at inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
-----Oorspronkelijk bericht-----
Van: r-sig-mixed-models-bounces at r-project.org [mailto:r-sig-mixed-models-bounces at r-project.org] Namens Erin Ryan
Verzonden: donderdag 8 december 2011 4:17
Aan: R-SIG-Mixed-Models at r-project.org
Onderwerp: [R-sig-ME] MIXED MODEL WITH REPEATED MEASURES
I am trying to specify a mixed model for my research, but I can't quite get it to work. I've spent several weeks looking thru various online sources to no avail. I can't find an example of someone trying to do precisely what I'm trying to do. I'm hoping some smart member of this mailing list may be able to help.
First off, full disclosure: (1) I'm an engineer by trade, so the problem may be related to my ignorance of statistics, and/or (2) I'm fairly new to R, so the problem may be related to my ignorance of R syntax. Here is the basic structure of my data (in longitudinal form):
FixedVar1 FixedVar2 RandomVar1 RandomVar2 ...
DepVar
Subject1
1996 AF A 0.002 800 2.1
1997 AF A 0.002 760 2.1
1998 AF A 0.003 760 2.1
1999 AF A 0.005 760 2.1
2001 AF A NA 900 2.1
2002 AF A 0.004 880 2.1
2003 AF A 0.005 870 2.1
2004 AF A 0.006 870 2.1
2005 AF A 0.006 900 2.1
Subject2
2001 NA S 0.000 350 18.0
2002 NA S 0.000 350 18.0
2003 NA S 0.136 380 18.0
2005 NA S 0.146 390 18.0
2006 NA S 0.146 510 18.0
2007 NA S 0.161 510 18.0
2009 NA S 0.161 NA 18.0
2010 NA S 0.161 350 18.0
...
The rows below each subject are repeated measures (in years), with the specific pattern of repeated measurements unique to each subject. The data contains fixed effects and random effects, and there is clearly correlation in the random effects within each subject. The DepVar column represents the dependent variable which is a constant for each subject. All the data is empirical, but I wish to create a predictive model. Specifically, I wish to predict the value for DepVar for new subjects.
So I understand enough about statistics to know that I must employ a mixed model. I further understand that I must specify a covariance matrix structure. Given the relatively high degree of correlation in consecutive years, an AR(1) structure seems like a good starting point. I have been trying to build the model in SPSS, but without success, so I've recently turned to R. My first attempt was as follows--
ModelFit <- lme(fixed = DepVar ~FixedVar1+FixedVar2, random =
~RandomVar1+RandomVar2 | Subject, na.action = na.omit, data = dataset, corr = corAR1())
I assume this can't be the right specification since it neglects the repeated measure aspect of the data, so I instead decided to employ the
corCAR1 structure, i.e.--
ModelFit <- lme(fixed = DepVar ~FixedVar1+FixedVar2, random =
~RandomVar1+RandomVar2 | Subject, na.action = na.omit, data = dataset, corr = corCAR1(0.5, form = ~ Years | Subject))
Now perhaps neither correlation structure is the right one (probably a different discussion for another day), but the problem I'm experiencing seems to occur regardless of the structure I specify. In both cases, I get the following error--
Error in solve.default(estimates[dimE[1] - (p:1), dimE[2] - (p:1), drop =
FALSE]) :
system is computationally singular: reciprocal condition number =
5.42597e-022
Anybody know what is going wrong here? This error appears to be related to the fact that the DepVar is constant for each subject, because when I select a different dependent variable that is different for each repeated measure w/in the subject, I do not get this error.
Sorry for the long post. Hope this makes sense.
Erin
_______________________________________________
R-sig-mixed-models at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
Erin Ryan <erin at ...> writes:
I am trying to specify a mixed model for my research, but I can't quite get it to work. I've spent several weeks looking thru various online sources to no avail. I can't find an example of someone trying to do precisely what I'm trying to do. I'm hoping some smart member of this mailing list may be able to help. First off, full disclosure: (1) I'm an engineer by trade, so the problem may be related to my ignorance of statistics, and/or (2) I'm fairly new to R, so the problem may be related to my ignorance of R syntax. Here is the basic structure of my data (in longitudinal form):
[snip]
The rows below each subject are repeated measures (in years), with the specific pattern of repeated measurements unique to each subject. The data contains fixed effects and random effects, and there is clearly correlation in the random effects within each subject. The DepVar column represents the dependent variable which is a constant for each subject. All the data is empirical, but I wish to create a predictive model. Specifically, I wish to predict the value for DepVar for new subjects. So I understand enough about statistics to know that I must employ a mixed model. I further understand that I must specify a covariance matrix structure. Given the relatively high degree of correlation in consecutive years, an AR(1) structure seems like a good starting point. I have been trying to build the model in SPSS, but without success, so I've recently turned to R. My first attempt was as follows-- ModelFit <- lme(fixed = DepVar ~FixedVar1+FixedVar2, random = ~RandomVar1+RandomVar2 | Subject, na.action = na.omit, data = dataset, corr = corAR1()) I assume this can't be the right specification since it neglects the repeated measure aspect of the data, so I instead decided to employ the corCAR1 structure, i.e.-- ModelFit <- lme(fixed = DepVar ~FixedVar1+FixedVar2, random = ~RandomVar1+RandomVar2 | Subject, na.action = na.omit, data = dataset, corr = corCAR1(0.5, form = ~ Years | Subject)) Now perhaps neither correlation structure is the right one (probably a different discussion for another day), but the problem I'm experiencing seems to occur regardless of the structure I specify. In both cases, I get the following error-- Error in solve.default(estimates[dimE[1] - (p:1), dimE[2] - (p:1), drop = FALSE]) : system is computationally singular: reciprocal condition number = 5.42597e-022 Anybody know what is going wrong here? This error appears to be related to the fact that the DepVar is constant for each subject, because when I select a different dependent variable that is different for each repeated measure w/in the subject, I do not get this error.
I think you're right that DepVar is fixed per individual. Technical details aside, I'm having trouble seeing how you're going to estimate the effects of predictor variables that vary within subject when you've only got one response per subject. Furthermore, I think what you're terming "RandomVar1" and "RandomVar2" are probably *not* random variables, but rather are variables that vary within subject. For this response variable, I would suggest averaging the values of RandomVar1 and RandomVar2 per subject and collapsing the data set to a simple linear model on subjects -- and get rid of the correlation model at the same time. For response variables that do vary within subject, I would suggest ModelFit <- lme(fixed = DepVar ~FixedVar1+FixedVar2+ RandomVar1 + RandomVar2, random = 1 | Subject, na.action = na.omit, data = dataset, corr = corAR())
1 day later
Thanks, Thierry. Both helpful suggestions, except I still can't get past
singularity error. Can a mixed model not handle a fixed dependent variable?
-----Original Message-----
From: ONKELINX, Thierry [mailto:Thierry.ONKELINX at inbo.be]
Sent: Thursday, December 08, 2011 11:04 AM
To: Erin Ryan; R-SIG-Mixed-Models at r-project.org
Subject: RE: [R-sig-ME] MIXED MODEL WITH REPEATED MEASURES
Dear Erin,
Your model seems reasonable. As soon as you add the random effect, then the
repeated measures are taken into account. However, I would specify the
correlation structure more explicit like corAR1(form = ~Years) which is
equal to corAR1(form = ~Years|Subject) in your case.
Furthermore I would suggest that you center the continuous variables so that
zero is at least near to your data. You'll get intercepts that are much more
easy to interpret and it might help the computation.
Best regards,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium
Thierry.Onkelinx at inbo.be
www.inbo.be
To call in the statistician after the experiment is done may be no more than
asking him to perform a post-mortem examination: he may be able to say what
the experiment died of.
~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data.
~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey
-----Oorspronkelijk bericht-----
Van: r-sig-mixed-models-bounces at r-project.org
[mailto:r-sig-mixed-models-bounces at r-project.org] Namens Erin Ryan
Verzonden: donderdag 8 december 2011 4:17
Aan: R-SIG-Mixed-Models at r-project.org
Onderwerp: [R-sig-ME] MIXED MODEL WITH REPEATED MEASURES
I am trying to specify a mixed model for my research, but I can't quite get
it to work. I've spent several weeks looking thru various online sources to
no avail. I can't find an example of someone trying to do precisely what I'm
trying to do. I'm hoping some smart member of this mailing list may be able
to help.
First off, full disclosure: (1) I'm an engineer by trade, so the problem may
be related to my ignorance of statistics, and/or (2) I'm fairly new to R, so
the problem may be related to my ignorance of R syntax. Here is the basic
structure of my data (in longitudinal form):
FixedVar1 FixedVar2 RandomVar1 RandomVar2 ...
DepVar
Subject1
1996 AF A 0.002 800 2.1
1997 AF A 0.002 760 2.1
1998 AF A 0.003 760 2.1
1999 AF A 0.005 760 2.1
2001 AF A NA 900 2.1
2002 AF A 0.004 880 2.1
2003 AF A 0.005 870 2.1
2004 AF A 0.006 870 2.1
2005 AF A 0.006 900 2.1
Subject2
2001 NA S 0.000 350 18.0
2002 NA S 0.000 350 18.0
2003 NA S 0.136 380 18.0
2005 NA S 0.146 390 18.0
2006 NA S 0.146 510 18.0
2007 NA S 0.161 510 18.0
2009 NA S 0.161 NA 18.0
2010 NA S 0.161 350 18.0
...
The rows below each subject are repeated measures (in years), with the
specific pattern of repeated measurements unique to each subject. The data
contains fixed effects and random effects, and there is clearly correlation
in the random effects within each subject. The DepVar column represents the
dependent variable which is a constant for each subject. All the data is
empirical, but I wish to create a predictive model. Specifically, I wish to
predict the value for DepVar for new subjects.
So I understand enough about statistics to know that I must employ a mixed
model. I further understand that I must specify a covariance matrix
structure. Given the relatively high degree of correlation in consecutive
years, an AR(1) structure seems like a good starting point. I have been
trying to build the model in SPSS, but without success, so I've recently
turned to R. My first attempt was as follows--
ModelFit <- lme(fixed = DepVar ~FixedVar1+FixedVar2, random =
~RandomVar1+RandomVar2 | Subject, na.action = na.omit, data = dataset, corr
= corAR1())
I assume this can't be the right specification since it neglects the
repeated measure aspect of the data, so I instead decided to employ the
corCAR1 structure, i.e.--
ModelFit <- lme(fixed = DepVar ~FixedVar1+FixedVar2, random =
~RandomVar1+RandomVar2 | Subject, na.action = na.omit, data = dataset, corr
= corCAR1(0.5, form = ~ Years | Subject))
Now perhaps neither correlation structure is the right one (probably a
different discussion for another day), but the problem I'm experiencing
seems to occur regardless of the structure I specify. In both cases, I get
the following error--
Error in solve.default(estimates[dimE[1] - (p:1), dimE[2] - (p:1), drop =
FALSE]) :
system is computationally singular: reciprocal condition number =
5.42597e-022
Anybody know what is going wrong here? This error appears to be related to
the fact that the DepVar is constant for each subject, because when I select
a different dependent variable that is different for each repeated measure
w/in the subject, I do not get this error.
Sorry for the long post. Hope this makes sense.
Erin
_______________________________________________
R-sig-mixed-models at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models
Good suggestions; however, there is inherent value in the temporal progression of the repeated measures, so I need to capture that in some way. For similar reasons, averaging the values of the independent variables is problematic, as they progress over time to a final, actual value, which presumably should be weighted more heavily. In other words, truth is known on the final repeated measure, but I wish to make accurate predictions much earlier than the final repeated measure. As for your first concern, I actually have other dependent variables - I have just omitted them for simplicity. I ran your version of the model and unfortunately I obtained the same singularity error. Thanks, Erin -----Original Message----- From: r-sig-mixed-models-bounces at r-project.org [mailto:r-sig-mixed-models-bounces at r-project.org] On Behalf Of Ben Bolker Sent: Thursday, December 08, 2011 5:01 PM To: r-sig-mixed-models at r-project.org Subject: Re: [R-sig-ME] MIXED MODEL WITH REPEATED MEASURES Erin Ryan <erin at ...> writes:
I am trying to specify a mixed model for my research, but I can't quite get it to work. I've spent several weeks looking thru various online sources to no avail. I can't find an example of someone trying to do precisely what I'm trying to do. I'm hoping some smart member of this mailing list may be able to help. First off, full disclosure: (1) I'm an engineer by trade, so the problem may be related to my ignorance of statistics, and/or (2) I'm fairly new to R, so the problem may be related to my ignorance of R syntax. Here is the basic structure of my data (in longitudinal form):
[snip]
The rows below each subject are repeated measures (in years), with the specific pattern of repeated measurements unique to each subject. The data contains fixed effects and random effects, and there is clearly correlation in the random effects within each subject. The DepVar column represents the dependent variable which is a constant for each subject. All the data is empirical, but I wish to create a predictive model. Specifically, I wish to predict the value for DepVar for new
subjects.
So I understand enough about statistics to know that I must employ a mixed model. I further understand that I must specify a covariance matrix structure. Given the relatively high degree of correlation in consecutive years, an AR(1) structure seems like a good starting point. I have been trying to build the model in SPSS, but without success, so I've recently turned to R. My first attempt was as follows-- ModelFit <- lme(fixed = DepVar ~FixedVar1+FixedVar2, random = ~RandomVar1+RandomVar2 | Subject, na.action = na.omit, data = dataset, corr = corAR1()) I assume this can't be the right specification since it neglects the repeated measure aspect of the data, so I instead decided to employ the corCAR1 structure, i.e.-- ModelFit <- lme(fixed = DepVar ~FixedVar1+FixedVar2, random = ~RandomVar1+RandomVar2 | Subject, na.action = na.omit, data = dataset, corr = corCAR1(0.5, form = ~ Years | Subject)) Now perhaps neither correlation structure is the right one (probably a different discussion for another day), but the problem I'm experiencing seems to occur regardless of the structure I specify. In both cases, I get the following error-- Error in solve.default(estimates[dimE[1] - (p:1), dimE[2] - (p:1), drop = FALSE]) : system is computationally singular: reciprocal condition number = 5.42597e-022 Anybody know what is going wrong here? This error appears to be related to the fact that the DepVar is constant for each subject, because when I select a different dependent variable that is different for each repeated measure w/in the subject, I do not get this error.
I think you're right that DepVar is fixed per individual. Technical details aside, I'm having trouble seeing how you're going to estimate the effects of predictor variables that vary within subject when you've only got one response per subject. Furthermore, I think what you're terming "RandomVar1" and "RandomVar2" are probably *not* random variables, but rather are variables that vary within subject. For this response variable, I would suggest averaging the values of RandomVar1 and RandomVar2 per subject and collapsing the data set to a simple linear model on subjects -- and get rid of the correlation model at the same time. For response variables that do vary within subject, I would suggest ModelFit <- lme(fixed = DepVar ~FixedVar1+FixedVar2+ RandomVar1 + RandomVar2, random = 1 | Subject, na.action = na.omit, data = dataset, corr = corAR()) _______________________________________________ R-sig-mixed-models at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models