[R] Variance explained in mixed models
Hi, I realise this has come up before in various reincarnations but I couldnt find the answer... I wish to quote the percentage variance explained by each of three components in my mixed model, one random effect and two fixed effects. lmer(response~x1+x2+(1|random), data=data) Using lmer I can get the variance explained by the random effect but not the fixed effects obviously. I was using a suggestion by someone that you can compare the variance components of the model with with both fixed terms included, with another model that has one of the fixed terms removed. When I did this the Variance + residual variance did not add up to the same figure each time. #first model with both fixed terms Variance StdDev (Intercept) 1.074666 1.036661 Residual1.136264 1.065957 #second model with one term ommitted Variance StdDev (Intercept) 1.113713 1.055326 Residual1.154527 1.074489 #third model with the other term ommitted Variance StdDev (Intercept) 1.069478 1.034156 Residual1.145590 1.070322 Actually the second model with only one fixed effect is saying that the percentage variance explained is higher than the one with both fixed effects which is impossible right? Any better ideas? Thanks in advance, Simon. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 http://www.uec.ac.uk/biology/research/phd-students/simon_pickett.shtml __ R-help@stat.math.ethz.ch 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.
[R] percentage explained by fixed effects in random model
Hi, I realise this has come up before in various reincarnations but I couldnt find the answer... I wish to quote the percentage variance explained by each of three components in my mixed model. If I didnt have a random effect I would just use r squared. I can work out the percentage explained by the random effect using summary() but this doesnt give variance for the fixed effects. Linear mixed-effects model fit by REML Formula: yell ~ carot.code + weight16 + (1 | fosterbrood) Data: colour AIC BIClogLik MLdeviance REMLdeviance 1555.455 1576.282 -772.7276 1536.585 1545.455 Random effects: Groups NameVariance Std.Dev. fosterbrood (Intercept) 1.0747 1.0367 Residual1.1363 1.0660 # of obs: 476, groups: fosterbrood, 61 Fixed effects: Estimate Std. Error DF t value Pr(|t|) (Intercept) -3.187028 1.011828 473 -3.1498 0.001737 ** carot.code1 0.201951 0.098442 473 2.0515 0.040771 * weight16 0.168861 0.054273 473 3.1114 0.001975 ** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Correlation of Fixed Effects: (Intr) crt.c1 carot.code1 0.035 weight16-0.989 -0.084 I was thinking of (cheating by) taking the residuals from a regression with the random effect (fosterbrood) as a fixed effect, then correlating these with my two x variables? Any better ideas? Thanks in advance, Simon. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch 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.
[R] graph dimensions default
Hi, I would like to (if possible) set the default width and height for graphs at the start of each session and have each new graphic device overwrite the previous one. I only know how to do this using windows(width=,height=...) which opens up a new plotting device every time, so I end up with lots of graphs all over the place until I get the one I want! Thanks in advance, Simon Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 http://www.uec.ac.uk/biology/research/phd-students/simon_pickett.shtml __ R-help@stat.math.ethz.ch 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.
Re: [R] graph dimensions default
Yes, Thankyou, that does the trick nicely. I thought that kind of thing could be specified using par() but I guess not. Thanks again. On Tue, 14 Aug 2007, Simon Pickett wrote: Hi, I would like to (if possible) set the default width and height for graphs at the start of each session and have each new graphic device overwrite the previous one. Hmm. It is graphics devices that have dimensions, and plots that overwrite other plots on a device, so your intentions are pretty unclear. (If you resize a device window the plot dimensions change so they are not intrinsic to the plot.) If you want the default behaviour to be like normal but with, say, a wider onscreen device window you can have (on Windows, which you didn't say) mywindows - function(...) windows(width=10, height=6, ...) options(device=mywindows) in your ~/.Rprofile . Otherwise, please try again to tell us what you do want. I only know how to do this using windows(width=,height=...) which opens up a new plotting device every time, so I end up with lots of graphs all over the place until I get the one I want! Thanks in advance, Simon Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 http://www.uec.ac.uk/biology/research/phd-students/simon_pickett.shtml __ R-help@stat.math.ethz.ch 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. -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 http://www.uec.ac.uk/biology/research/phd-students/simon_pickett.shtml __ R-help@stat.math.ethz.ch 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.
[R] how to be clever with princomp?
Hi all, I have been using princomp() recently, its very useful indeed, but I have a question about how to specify the rows of data you want it to choose. I have a set of variables relating to bird characteristics and I have been using princomp to produce PC scores from these. However since I have multiple duplicate entries per individual (each bird had a varying number of chicks), I only want princomp to treat each individual bird as the sample and not include all the duplicates. Then I want to replicate the pc scores for all the duplicated rows for that individual. Any idea how to do this? Up to now I have been using princomp to only select the entries which are not duplicated which is easy, but the difficult bit is the programming to duplicate the pc scores across the entries for each individual. (I developed something that worked but it takes about 5 minutes to run!) Thanks for all your help, very much appreciated, Simon. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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.
[R] general question about plotting multiple regression results
Hi all, I have been bumbling around with r for years now and still havent come up with a solution for plotting reliable graphs of relationships from a linear regression. Here is an example illustrating my problem 1.I do a linear regression as follows summary(lm(n.day13~n.day1+ffemale.yell+fmale.yell+fmale.chroma,data=surv)) which gives some nice sig. results Coefficients: Estimate Std. Error t value Pr(|t|) (Intercept) -0.739170.43742 -1.690 0.093069 . n.day11.004600.05369 18.711 2e-16 *** ffemale.yell 0.224190.06251 3.586 0.000449 *** fmale.yell0.258740.06925 3.736 0.000262 *** fmale.chroma 0.235250.11633 2.022 0.044868 * 2. I want to plot the effect of ffemale.yell, fmale.yell and fmale.chroma on my response variable. So, I either plot the raw values (which is fine when there is a very strong relationship) but what if I want to plot the effects from the model? In this case I would usually plot the fitted values values against the raw values of x... Is this the right approach? fit-fitted(lm(n.day13~n.day1+ffemale.yell+fmale.yell+fmale.chroma,data=fsurv1)) plot(fit~ffemale.yell) #make a dummy variable across the range of x x-seq(from=min(fsurv1$ffemale.yell),to=max(fsurv1$ffemale.yell), length=100) #get the coefficients and draw the line co-coef(lm(fit~ffemale.yell,data=fsurv1)) y-(co[2]*x)+co[1] lines(x,y, lwd=2) This often does the trick but for some reason, especially when my model has many terms in it or when one of the independent variables is only significant when the other independent variables are in the equation, it gives me strange lines. Please can someone show me the light? Thanks in advance, Simon. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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.
[R] legend with density and fill
Hi, I am trying to make a legend with four symbols as follows 1.white box 2.black box 3.clear box (same as background) 4.clear box with shading lines but the shading lines arent showing... here is my code. par(bg=lightyellow) barplot(c(seq(1,6,1))) legend(8.5,0.3, bty=o, legend=c(young,old,male,female), col=black,cex=1.5, fill=c(white,dark grey,0,0),density=c(NA,NA,0,100),angle=45) any suggestions much appreciated, Thanks, Simon. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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.
[R] link function
Hi everyone, I have a model which yields a qqnorm plot (residuals~fitted values) of a sigmoidal shape. I have been reading about link functions and leafing through Crawley, but I'm still not sure how to solve this. Perhaps family=quasi(power= is the best route? Any suggestions much appreciated. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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.
[R] str() to extract components
Hi, I have been dabbling with str() to extract values from outputs such as lmer etc and have found it very helpful sometimes. but only seem to manage to extract the values when the output is one simple table, any more complicated and I'm stumped :-( take this example of the extracted coeficients from a lmer analysis... using str(coef(lmer(resp3~b$age+b$size+b$pcfat+(1|sex), data=b))) yields Formal class 'lmer.coef' [package Matrix] with 3 slots ..@ .Data :List of 1 .. ..$ :`data.frame': 2 obs. of 4 variables: .. .. ..$ (Intercept): num [1:2] 1.07 1.13 .. .. ..$ b$age : num [1:2] 0.00702 0.00702 .. .. ..$ b$size : num [1:2] 0.0343 0.0343 .. .. ..$ b$pcfat: num [1:2] 0.0451 0.0451 ..@ varFac: list() ..@ stdErr: num(0) how do I get inside the first table to get the value 1.07 for instance? Any help much appreciated. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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.
[R] arrows and points for error bars
Hello everyone, I have successfully made an error bar graph using the points() command with the arrows() command to maually add on the standard errors. However, one slightly annoying feature of using this method is that the points dont line up exactly with the arrows (if you look carefully the points are never perfectly in the centre of the arrow), even when you move the arrows around in an attempt to correct this. Secondly I cant seem to force the points to appear on top of the arrows i.e. with the arrows behind the points. Uing ADD=TRUE to either command wont work. Does anyone have any solutions to this problem, or maybe even a different way of making error plots? Sorry if this seems a bit pedantic, but it would be great if I could resolve this problem and so enable me to use R for publication standard graphs... Thanks everyone :-) Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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.
Re: [R] arrows and points for error bars
Hi there, I did what Peter Dalgaard very kindly suggested and saved it as a pdf and viewed it using adobe, which as if by magic resolves the problem. It must have been a pixel issue with the r graphics device. Sorry to have wasted your time, thanks for your help, always appreciated. Simon. It would be very helpful to have a reproducible example, including the OS and graphics device used. For example, this may only happen with certain values of 'pch' -- e.g. some graphics devices (pdf is one) plot circles using completely different code from squares. And we frequently see reports of problems with R graphics where the bug is in the viewer software or the including application (Word being notorious for mis-rendering WMF files). On Fri, 20 Oct 2006, Peter Dalgaard wrote: Simon Pickett [EMAIL PROTECTED] writes: Hello everyone, I have successfully made an error bar graph using the points() command with the arrows() command to maually add on the standard errors. However, one slightly annoying feature of using this method is that the points dont line up exactly with the arrows (if you look carefully the points are never perfectly in the centre of the arrow), even when you move the arrows around in an attempt to correct this. Is this a pixelization issue? If the line is an odd number of pixels wide and the point is an even number of pixels across, then there is just no way to line them up. It should go away with increased resolution, e.g. when plotting to pdf() and printing on a laser printer. Secondly I cant seem to force the points to appear on top of the arrows i.e. with the arrows behind the points. Uing ADD=TRUE to either command wont work. Plot the points last and use a filled symbol, or pch %in% 21:25 with bg=white. (example(points) is generally helpful in these matters) Does anyone have any solutions to this problem, or maybe even a different way of making error plots? Sorry if this seems a bit pedantic, but it would be great if I could resolve this problem and so enable me to use R for publication standard graphs... Thanks everyone :-) -- Brian D. Ripley, [EMAIL PROTECTED] Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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.
[R] help: advice on the structuring of ReML models for analysing growth curves
Hi R experts, I am interested on the effects of two dietry compunds on the growth of chicks. Rather than extracting linear growth functions for each chick and using these in an analysis I thought using ReML might provide a neater and better way of doing this. (I have read the pdf vignette(MlmSoftRev) and Fitting linear mixed models in R by Douglas Bates but I am not entirely sure that I have the right solution). Basically I fed chicks in nest boxes over a period of time and weighed them each time I fed them. I presume that chick id should be a random factor and should be nested within nest box number? (Chicks were not moved around so this should make things more simple). Also since the chicks were measured repeatedly over time I presume that this should be a random factor? Growth is not linear exactly (more quadratic), so I thought rather than put time in the fixed model I want to control for the effects of time as a random factor The resulting model is this where id=chick identity and brood=nest box model1-lmer(weight~treatment1*treatment2*brood size*sex+(id|brood)+(1|brood)+(1|age), data=H) Is this the right approach or am I barking up the wrong tree? Any suggestions much appreciated, Simon Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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.
Re: [R] help: trouble using lines()
Hi, thanks for replying. No, there arent any NA's in the original data set I think I must be mis-interpreting the use of lines()? in the example what exactly is y? lines(y,exp(tmp[1]+tmp[2])) In my case tmp[1] and tmp[2] are coeficients from the model so just one number (not a vector) and I havent specified y Thanks everyone, Simon Hi not sure but are there some NA values in your data? what length(mtf) and length(fitted(f2)) tells you? And you need not to use assignment graph1 - plot() to output a plot on screen. HTH Petr On 24 Aug 2006 at 13:43, Simon Pickett wrote: Date sent:Thu, 24 Aug 2006 13:43:18 +0100 (BST) From: Simon Pickett [EMAIL PROTECTED] To: R-help@stat.math.ethz.ch Subject: [R] help: trouble using lines() Hi R experts, I have been using ReML as follows... model-lmer(late.growth~mtf+year+treat+hatch.day+hatch.day:year+hatch. day:treat+ mtf:treat+ treat:year+ year:treat:mtf+(1|fybrood), data A) then I wanted to plot the results of the three way interaction using lines() as follows... tmp-as.vector(fixef(model)) graph1-plot(mtf,fitted(f2), xlab=list(Brood Size), ylab=list(Early growth rate), pch=16, col=darkgrey, bg=yellow) lines(y,exp(tmp[1]+tmp[2])) but no matter what I try I always get the error message Error in xy.coords(x, y) : 'x' and 'y' lengths differ Can anyone shed some light please? I am basically copying the methods of the pdf entitled Linear mixed models in R by Søren Feodor Nielsen 20003. http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-mixed-mod els.pdf#search=%22Linear%20mixed%20models%20in%20R%22 Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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. Petr Pikal [EMAIL PROTECTED] Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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.
Re: [R] REML with random slopes and random intercepts giving strange results
Hi again, Even stranger is the fact that the coefficeints (the slope) and the intercepts are not independent, in fact they are directly inversely proportional (r squared = 1). This means that that there isnt a random slope and intercept for each individual (which is what I wanted), but straight line that pivots in the middle and will change from individual to individual. Is there a problem with the way I have structured the random model or a deeper problem with lmer()? here is the code I used m2 - lmer(changewt ~ newwt+(newwt|id), data = grow) coef(m2) Any suggestions very much appreciated, Simon I don't this is because you are using REML. The BLUPs from a mixed model experience some shrinkage whereas the OLS estimates would not. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Simon Pickett Sent: Tuesday, August 15, 2006 11:34 AM To: r-help@stat.math.ethz.ch Subject: [R] REML with random slopes and random intercepts giving strange results Hi everyone, I have been using REML to derive intercepts and coeficients for each individual in a growth study. So the code is m2 - lmer(change.wt ~ newwt+(newwt|id), data = grow) Calling coef(model.lmer) gives a matrix with this information which is what I want. However, as a test I looked at each individual on its own and used a simple linear regression to obtain the same information, then I compared the results. It looks like the REML method doesnt seem to approximate the two parameters as well as using the simple linear regression on each individual separately, as judged by looking at graphs. Indeed, why do the results differ at all? Excuse my naivety if this is a silly question. Thanks to everyone for replying to my previous questions, very much appreciated. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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 Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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.
Re: [R] [SPAM] - RE: REML with random slopes and random intercepts giving strange results - Bayesian Filter detected spam
sure, thanks again. summary(m2) Linear mixed-effects model fit by REML Formula: change.wt ~ newwt + (newwt | id) Data: grow AIC BIC logLik MLdeviance REMLdeviance -6203.178 -6164.462 3107.589 -6239.374-6215.178 Random effects: Groups NameVariance Std.Dev. Corr id (Intercept) 1.0868e-02 0.1042482 newwt 4.7069e-05 0.0068606 -1.000 Residual 1.4236e-02 0.1193136 # of obs: 4688, groups: id, 485 Fixed effects: Estimate Std. Error DF t value Pr(|t|) (Intercept) 5.5692e-01 6.4189e-03 4686 86.761 2.2e-16 *** newwt -3.2382e-02 4.5962e-04 4686 -70.455 2.2e-16 *** --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Correlation of Fixed Effects: (Intr) newwt -0.954 Can you provide the summary(m2) results? -Original Message- From: Simon Pickett [mailto:[EMAIL PROTECTED] Sent: Wednesday, August 16, 2006 7:14 AM To: Doran, Harold Cc: r-help@stat.math.ethz.ch Subject: [SPAM] - RE: [R] REML with random slopes and random intercepts giving strange results - Bayesian Filter detected spam Hi again, Even stranger is the fact that the coefficeints (the slope) and the intercepts are not independent, in fact they are directly inversely proportional (r squared = 1). This means that that there isnt a random slope and intercept for each individual (which is what I wanted), but straight line that pivots in the middle and will change from individual to individual. Is there a problem with the way I have structured the random model or a deeper problem with lmer()? here is the code I used m2 - lmer(changewt ~ newwt+(newwt|id), data = grow) coef(m2) Any suggestions very much appreciated, Simon I don't this is because you are using REML. The BLUPs from a mixed model experience some shrinkage whereas the OLS estimates would not. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Simon Pickett Sent: Tuesday, August 15, 2006 11:34 AM To: r-help@stat.math.ethz.ch Subject: [R] REML with random slopes and random intercepts giving strange results Hi everyone, I have been using REML to derive intercepts and coeficients for each individual in a growth study. So the code is m2 - lmer(change.wt ~ newwt+(newwt|id), data = grow) Calling coef(model.lmer) gives a matrix with this information which is what I want. However, as a test I looked at each individual on its own and used a simple linear regression to obtain the same information, then I compared the results. It looks like the REML method doesnt seem to approximate the two parameters as well as using the simple linear regression on each individual separately, as judged by looking at graphs. Indeed, why do the results differ at all? Excuse my naivety if this is a silly question. Thanks to everyone for replying to my previous questions, very much appreciated. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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 Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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.
[R] REML with random slopes and random intercepts giving strange results
Hi everyone, I have been using REML to derive intercepts and coeficients for each individual in a growth study. So the code is m2 - lmer(change.wt ~ newwt+(newwt|id), data = grow) Calling coef(model.lmer) gives a matrix with this information which is what I want. However, as a test I looked at each individual on its own and used a simple linear regression to obtain the same information, then I compared the results. It looks like the REML method doesnt seem to approximate the two parameters as well as using the simple linear regression on each individual separately, as judged by looking at graphs. Indeed, why do the results differ at all? Excuse my naivety if this is a silly question. Thanks to everyone for replying to my previous questions, very much appreciated. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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.
[R] help: convert lmer.coef to matrix
Hi all, I am trying to coerce the coeficients from a REML using lmer() to a matrix of numbers which I can then write into excel. I have looked in the archive and read around in the (Matrix) documentation but havent found anything of use. Any suggestions much appreciated, Thankyou, S. Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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.
[R] help:coerce lmer.coef to matrix
Hi, Thanks for your response, it nearly worked! But it only wrote one coloumn of data and not the three columns I need. Using fixef(m1) doesnt give the same results as coef(m1) when you are using more than one random effect. I need the coefficients for each individual so I use coef(m1) to get this which results in an object of class lmer.coef, 3 columns by 700 rows. as.data.frame() wont work on this and I cant seem to specify that I want three columns when I tried -matrix(lmer.coef,ncol=length(lmer.coef)) Thanks very much, S Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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.
[R] help with structuring random factors using lmer()
Hi, I am an R beginner and having problems structuring my REML models. I have a model with y=weight x1=time x2=timesquared id=individual identity I need to structure the model such that in the random effects there is a constant intercept for all individuals but a separate individual slope for both x1 and x2 (a coefficient score for every individual). m1-lmer(weight~time+timesq+(1|id)+(timesq-1|id)+(time-1|id), data=dataset) coef(m1) gives me nearly what I want except there isnt an individual coefficient score for each individual for x2. Any suggestions very much appreciated. Simon Pickett [EMAIL PROTECTED] Simon Pickett PhD student Centre For Ecology and Conservation Tremough Campus University of Exeter in Cornwall TR109EZ Tel 01326371852 __ R-help@stat.math.ethz.ch 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.