Re: [R] lmer: random factor nested in a fixed factor
hi folks, I believe that the construction y ~ A + (A|B) (where A is a categorical variable for a fixed effect and B is a categorical variable for a random effect) will generate random effects for all of the fixed effect coefficients. That is, in addition fitted a systematic fixed effect coefficient for intercept and relevant added effects of levels of A, it will fit corresponding random coefficients for each level of B, including random intercepts, and relevant added random effects of A, given B (i.e. for each separate B). Thus if you think that each family has, in addition to a different overall mean, also has a different response to levels of A (and you have the replication to estimate them), then you should include (A|B) and see if it is better than simply (1|B). Hank On Oct 6, 2008, at 11:02 AM, Christian Ritz wrote: Dear Agnes, I think your model specification should look like this: YourModel1 - lmerlmer(y ~ poptype*matingtype + (1|poptype:pop) + (1| poptype:fam), data = ...) The 1 in front of | refers to models that are random intercepts models as opposed to general random coefficients models in which case 1 would need to be replaced by a variable that is quantitative. So, the (poptype|/pop/fam) construction is definitely not relevant to your problem, unless poptype is a quantitative variable... The combined factor poptype:pop corresponds to the factor pop, but taking the nesting structure into account. Similar for the construction poptype:fam. From the summary output of the lmer() fit you should be able to check whether or not the correct number of groups are used for these random factors. Kind regards Christian __ R-help@r-project.org 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. Dr. Hank Stevens, Associate Professor 338 Pearson Hall Botany Department Miami University Oxford, OH 45056 Office: (513) 529-4206 Lab: (513) 529-4262 FAX: (513) 529-4243 http://www.cas.muohio.edu/~stevenmh/ http://www.cas.muohio.edu/ecology http://www.muohio.edu/botany/ If the stars should appear one night in a thousand years, how would men believe and adore. -Ralph Waldo Emerson, writer and philosopher (1803-1882) __ R-help@r-project.org 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] Using the mcmcsamp function
mcmcsamp does not yet operate on non-normal distributions. Hank On Sep 27, 2008, at 9:06 AM, Parry Clarke wrote: Hello, I'm building a couple of mixed models using the lmer function. The actual modelling is going well, but doing some reading on the use of crossed random effects and the comparison of models with and without random effects it is clear that I need to generate some Markov Chain Monte Carlo samples. However, I'm struggling because everyone time I go to generate a sample I get the following error: 'Error in .local(object, n, verbose, ...) : Update not yet written' Can anyone tell me what this means and how I can resolve it, I'm using R. 2.7.2 and updated 'lme4' yesterday The code I use is as follows: model-lmer(FemApp~MaleWith+(1|MaleID)+(1| FemID),poisson,data=Compliance) mcmp-mcmcsamp(model3, n= 1000) Thanks in advance Parry __ R-help@r-project.org 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. Dr. Hank Stevens, Associate Professor 338 Pearson Hall Botany Department Miami University Oxford, OH 45056 Office: (513) 529-4206 Lab: (513) 529-4262 FAX: (513) 529-4243 http://www.cas.muohio.edu/~stevenmh/ http://www.cas.muohio.edu/ecology http://www.muohio.edu/botany/ If the stars should appear one night in a thousand years, how would men believe and adore. -Ralph Waldo Emerson, writer and philosopher (1803-1882) __ R-help@r-project.org 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] R + Linux
I typically use a Mac (I love it) with Aquamacs, LaTeX, and R, and recently started using Linux Ubuntu as well. Ubuntu is the only distribution I have ever tried, and I really like it. I like it so much that I would have made my switch complete, but cannot find replacement for the PDF cut and paste functionality of the Mac. Ubuntu has amazing built in upgrade GUI's and other bells and whistles that a Mac user like me has come to depend on. Hank On Jun 6, 2008, at 3:18 PM, Douglas Bates wrote: On Fri, Jun 6, 2008 at 1:13 PM, steven wilson [EMAIL PROTECTED] wrote: Dear all; I'm planning to install Linux on my computer to run R (I'm bored of W..XP). However, I haven't used Linux before and I would appreciate, if possible, suggestions/comments about what could be the best option install, say Fedora, Ubuntu or OpenSuse which to my impression are the most popular ones (at least on the R-help lists). The computer is a PC desktop with 4GB RAM and Intel Quad-Core Xeon processor and will be used only to run R. Ah yes, we haven't had a good flame war for a long time. Let's start discussing the relative merits of various Linux distributions. That should heat things up a bit. I can only speak about Ubuntu. I have used it exclusively for several years now and find it to be superb. In my opinion it is easy to install and maintain and has very good support for R (take a bow, Dirk). __ R-help@r-project.org 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. Dr. Hank Stevens, Associate Professor 338 Pearson Hall Botany Department Miami University Oxford, OH 45056 Office: (513) 529-4206 Lab: (513) 529-4262 FAX: (513) 529-4243 http://www.cas.muohio.edu/~stevenmh/ http://www.cas.muohio.edu/ecology http://www.muohio.edu/botany/ If the stars should appear one night in a thousand years, how would men believe and adore. -Ralph Waldo Emerson, writer and philosopher (1803-1882) __ R-help@r-project.org 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] Constructing groupedData objects in nlme - a little problem
HI Toby, I think that the problem is that you have not specified using Rail and travel in the model statement, but rather are still using x1 and x2. It also does not realize that you want x1 to be a factor. Try x1=factor(c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6)) x2=c(55,53,54,26,37,32,78,91,85,92,100,96,49,51,50,80,85,83) eg1=data.frame(x1,x2); colnames(eg1)=c(Rail,travel); eg1gd=groupedData(travel~1|Rail,data=eg1) print(eg1gd) x11(); print(plot(eg1gd)) femodel=lm(x2~x1-1,data=eg1gd) femodel=lm(travel~Rail-1,data=eg1gd) summary(femodel) Cheers, Hank On Jun 4, 2008, at 10:01 AM, Toby Marthews wrote: Dear R-help, I am trying to create groupedData objects using the nlme library. I'm missing something basic, I know: Here is the first example in ch.1 of Pinheiro Bates (2000): library(nlme) x2=Rail$travel;x1=Rail$Rail;eg1=data.frame(x1,x2);eg1gd=Rail print(eg1gd) x11();print(plot(eg1gd)) femodel=lm(x2~x1-1,data=eg1gd) print(femodel$coefficients) Result: x12 x15 x11 x16 x13 x14 31.7 50.0 54.0 82.7 84.7 96.0 ...which works fine. This uses a built-in groupedData object called Rail that is part of the nlme library. I am trying to 'recreate' this groupedData object. Here's what I've done: x1=c(1,1,1,2,2,2,3,3,3,4,4,4,5,5,5,6,6,6); x2=c(55,53,54,26,37,32,78,91,85,92,100,96,49,51,50,80,85,83) eg1=data.frame(x1,x2); colnames(eg1)=c(Rail,travel); eg1gd=groupedData(travel~1|Rail,data=eg1) print(eg1gd) x11(); print(plot(eg1gd)) femodel=lm(x2~x1-1,data=eg1gd) print(femodel$coefficients) Result: x1 16.49817 ...but, as you can see, the coefficients I get at the end this time are completely different and I don't know why. Somehow, I am not creating the structure properly even though the formula and data values are all correct. Can anyone help? I've looked at the ?groupedData man page, but it has no solution to this. Thanks very much for any advice, Toby Pinheiro JC Bates DM (2000). Mixed-Effects Models in S and S-PLUS (1st ed.). Springer, New York. __ R-help@r-project.org 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. Dr. Hank Stevens, Associate Professor 338 Pearson Hall Botany Department Miami University Oxford, OH 45056 Office: (513) 529-4206 Lab: (513) 529-4262 FAX: (513) 529-4243 http://www.cas.muohio.edu/~stevenmh/ http://www.cas.muohio.edu/ecology http://www.muohio.edu/botany/ If the stars should appear one night in a thousand years, how would men believe and adore. -Ralph Waldo Emerson, writer and philosopher (1803-1882) __ R-help@r-project.org 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] Constructing groupedData objects in nlme - a little problem
Hi Dieter, I never really used groupedData objects at all. I can imagine that if you become even more immersed in nlme and lattice, groupedData could reduce your typing, and sometimes simplify your life, but it was not a hurdle I chose willingly. Hank On Jun 4, 2008, at 1:15 PM, Dieter Menne wrote: Toby Marthews Toby.Marthews at lsce.ipsl.fr writes: Dear R-help, I am trying to create groupedData objects using the nlme library. I'm missing something basic, I know: Here is the first example in ch.1 of Pinheiro Bates (2000): ... ...but, as you can see, the coefficients I get at the end this time are completely different and I don't know why. Somehow, I am not creating the structure properly even though the formula and data values are all correct. Hank is right. On the other hand your well-defined query points to a problem using groupedData. I do a lot of my work with nlme and love it, but I admit that I only started to understand it after I totally stopped using groupedData. Which makes reading Pinheiro/Bates sometimes difficult, because many examples give the impression that these must be done with groupedData. Everything can be done by explicitly saying what should be analyzed in lme and friends, there is no need to rely on groupedData. Note that in lme4 that partially re-designs nlme, there is no such thing as groupedData. Dieter __ R-help@r-project.org 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. Dr. Hank Stevens, Associate Professor 338 Pearson Hall Botany Department Miami University Oxford, OH 45056 Office: (513) 529-4206 Lab: (513) 529-4262 FAX: (513) 529-4243 http://www.cas.muohio.edu/~stevenmh/ http://www.cas.muohio.edu/ecology http://www.muohio.edu/botany/ If the stars should appear one night in a thousand years, how would men believe and adore. -Ralph Waldo Emerson, writer and philosopher (1803-1882) __ R-help@r-project.org 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] Table of basic descriptive statistics like SPSS
Hi Udo, See the Hmisc and Design libraries by Frank Harrell, and some associated PDF docs by Alzola and Harrell describing data management and display. Hank On Mar 17, 2008, at 2:05 PM, [EMAIL PROTECTED] wrote: Dear list readers, I want to: 1. Get a table of basic descriptive statistics for my variables with the variable names one below the other like SPSS descriptive statistics: Varname N Min Max Mean SD x x xx x xxx x x xx x 2. Delete some variables from a data frame or exclude variables from beeing analyzed. 3. Create a text file / redirect the terminal output to a file (it is supposed to be easy, but I could not find a solution)? 4. Create a latex/dvi file 5. Create a PDF file (can that be done within R?) This code took me some ours (I am new to R). What do you think about my solution? Are there easier ones? Comments welcome! Sorry if my questions look very basic and I hope they are understandable. #here is my code setwd(c:\\temp) #set working directory library(psych) library(xtable) library(tools) #Create example data frame with many variables df - as.data.frame(matrix( rnorm(1000), ncol=100)) df - describe(df) #describe from lib psych #How Can I create a text file with the output of describe? #The save as function from the GUI saves #only last part of the output to a text file (the first part is cut) #delete some variables. Or can I exclude variables from #beeing analyzed by describe to reduce the numer of cols? df$kurtosis - df$skew - df$se - NULL x.df - xtable(df) #Create an xtable object print(x.df, tabular.environment = longtable, , floating = FALSE, file=c:\\temp\\descript.tex) #create latex file # produce dvi file in working directory (from tools) texi2dvi(c:\\temp\\descript.tex) #the lines below have to be added #Problem: these lines have to be added manually to the latex #before calling texi2dvi: #\documentclass{article} #\usepackage{longtable} # Latex code #\end{document #Can I prodcuce a PDF file within R? Thanks a lot in advance! Udo __ R-help@r-project.org 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. Dr. Hank Stevens, Associate Professor 338 Pearson Hall Botany Department Miami University Oxford, OH 45056 Office: (513) 529-4206 Lab: (513) 529-4262 FAX: (513) 529-4243 http://www.cas.muohio.edu/~stevenmh/ http://www.cas.muohio.edu/ecology http://www.muohio.edu/botany/ If the stars should appear one night in a thousand years, how would men believe and adore. -Ralph Waldo Emerson, writer and philosopher (1803-1882) __ R-help@r-project.org 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.