Re: [R] Reformat a data frame
You want to reshape from wide into long format: see help(reshape). For your example this should look something like df2 - reshape(df1, varying=list(c(resist,thick,temp)), direction=long, v.names=c(Value), timevar=Param, idvar=ID, times=c(resist,thick,temp)) will give you roughly what you want - maybe not in the exact order as listed below for df2, but you can sort' then. You are merging all value for three variables in the wide format, into one variable (Value) in the long format... Try it, I did not test the above, but have done similar things before along those lines. Michael Jerosch-Herold Thorsten Muehge [EMAIL PROTECTED] 11/07/06 1:10 AM Hello Experts, how do I reformat a data frame in the way described below: df1: ID desc resist thick temp 1 4711 100 5 20 2 4712 101 4 21 3 4711 99 3 19 4 4712 98 7 22 TO df2: id desc Param Value 1 4711 resist 100 1 4711 Thick 5 1 4711 temp 20 2 4712 resist 101 2 4712 Thick 4 2 4712 temp 21 3 4711 resist 99 3 4711 thick 4 3 4711 temp 19 4 4712 resist 98 4 4712 thick 7 4 4712 temp 22 Thanks a lot for your help. With best regards Thorsten [[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] Tinn-R functionality for Mac?
Dear readers: I like very much how one can hightlight R-code sections in Tinn-R and send them to R for execution. Is there an editor for the Mac that similarly allows you to highlight code and send it to the R-console? Thank you in advance for recommendations! Michael Jerosch-Herold __ 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] bullseye or polar display of circular data
I have data for several rings of a left heart chamber, and which I would like to display in concentric rings, with color-encoding of the values. Each ring corresponds to one slice through the heart, and the rings correspond to positions from the base to the apex of the heart as you move from the outermost ring to the innermost one. The data have a circular pattern. These types of displays are referred to as bullseye displays in the nuclear medicine literature. Does any reader of these messages know of a R function/package that offers this functionality? Also I noticed that in some contexts you can define a circular attribute for your data. Are there plot routines for such circular data? thank you! Michael Jerosch-Herold __ 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] lme convergence
It looks like in the call to lme fm1 - lme(distance ~ age, data = Orthodont, +control=lmeControl(msMaxIter=1)) you did not specify any random effects. Why not try: fm1 - lme(distance ~ age, random= ~1| groupID, data = Orthodont, +control=lmeControl(msMaxIter=1)) where groupID is some factor that can be used to stratify the data. Also, the Othodont data set is used in Pinheiro Bates book, and you may want to consult that book to see the models they use in connection with that data set. For the Orthodont data set the groupID would most likely be the subject ID (Subject variable). So a possible model would be: fm1 - lme(distance ~ age, random= ~1|Subject, data=Orthodont) summary(fm1) Linear mixed-effects model fit by REML Data: Orthodont AIC BIClogLik 455.0025 465.6563 -223.5013 Random effects: Formula: ~1 | Subject (Intercept) Residual StdDev:2.114724 1.431592 Fixed effects: distance ~ age Value Std.Error DF t-value p-value (Intercept) 16.76 0.8023952 80 20.5 0 age 0.660185 0.0616059 80 10.71626 0 Correlation: (Intr) age -0.845 Standardized Within-Group Residuals: Min Q1 Med Q3 Max -3.66453932 -0.53507984 -0.01289591 0.48742859 3.72178465 Number of Observations: 108 Number of Groups: 27 So this runs fine. As, I said this data set and its analysis is discussed extensively in Pinheiro and Bates book Michael Jerosch-Herold Spencer Graves [EMAIL PROTECTED] 06/29/06 7:08 PM Does anyone know how to obtain the 'returnObject' from an 'lme' run that fails to converge? An argument of this name is described on the 'lmeControl' help page as, a logical value indicating whether the fitted object should be returned when the maximum number of iterations is reached without convergence of the algorithm. Default is 'FALSE'. Unfortunately, I've so far been unable to get it to work, as witnessed by the following modification of an example from the '?lme' help page: library(nlme) fm1 - lme(distance ~ age, data = Orthodont, +control=lmeControl(msMaxIter=1)) Error in lme.formula(distance ~ age, data = Orthodont, control = lmeControl(msMaxIter = 1)) : iteration limit reached without convergence (9) fm1 Error: object fm1 not found fm1 - lme(distance ~ age, data = Orthodont, +control=lmeControl(msMaxIter=1, + returnObject=TRUE)) Error in lme.formula(distance ~ age, data = Orthodont, control = lmeControl(msMaxIter = 1, : iteration limit reached without convergence (9) fm1 Error: object fm1 not found I might be able to fix the problem myself, working through the 'lme' code line by line, e.g., using 'debug'. However, I'm not ready to do that just now. Best Wishes, Spencer Graves Ravi Varadhan wrote: Use try to capture error messages without breaking the loop. ?try -- Ravi Varadhan, Ph.D. Assistant Professor, The Center on Aging and Health Division of Geriatric Medicine and Gerontology Johns Hopkins University Ph: (410) 502-2619 Fax: (410) 614-9625 Email: [EMAIL PROTECTED] Webpage: http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html -- -Original Message- From: [EMAIL PROTECTED] [mailto:r-help- [EMAIL PROTECTED] On Behalf Of Pryseley Assam Sent: Wednesday, June 28, 2006 12:18 PM To: R-Users Subject: [R] lme convergence Dear R-Users, Is it possible to get the covariance matrix from an lme model that did not converge ? I am doing a simulation which entails fitting linear mixed models, using a for loop. Within each loop, i generate a new data set and analyze it using a mixed model. The loop stops When the lme function does not converge for a simulated dataset. I want to inquire if there is a method to suppress the error message from the lme function, or better still, a way of going about this issue of the loop ending once the lme function does not converge. Thanks in advance, Pryseley - [[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 __ 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 __ 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
Re: [R] AOV with repeated measures
You probably need specify the repeated measures by using an Error term in aov for repeated measures: aov(trait ~ species + strain + Error(species/strain)) Take a look at Ripley's book. Treat above with caution: I am no expert, but the answer is in that direction... Michael Jerosch-Herold I have a question on using R to analyze data with repeated measurements. I have 2 species with several strains (12) per species, each of which has been measured twice with for a given trait. No particular covariance, just two measures. Now I want to analyze the data with an ANOVA (aov) considering these repeated measures to get the MSq and SSq for the species and strain level. I would like to know how to write the ANOVA model in R. I have done the following: aov(trait ~ species + strain/replicate) Is it accurate? Thanks a lot, Christian __ 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
[R] PDF output:
I have a problem with making pdf files. I use the code below: pdf(file=resindex.pdf,width= 6, height= 7, family = Helvetica, title = MBF Data,bg=white) bwplot(... dev.off() When I run a script with the above code in it, by using source, it produces a PDF file which I can not open with Acrobat. When I copy just the lines above, from my editor, into R commander, then the output to the PDF works fine, i.e. I can open the file with Acrobat reader. What is the problem? thank you, in advance for advice! Michael Jerosch-Herold __ 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
[R] LME correlation structures: user defined
Let me modify my question about user-defined covariance structures for LME models: Can somebody tell me how I can see the code for the definition of the correlation structures that come with the NLME package. Specifically I like to see the code for the functions coef, corMatrix, and intialize for any of the pre-defined correlation structures, and use this as a template to define a new correlation structure. So how do I see e.g. the code for the method initialize for the correlation structure corExp or corARMA? thank you in advance! Michael Jerosch-Herold PS: Oh, and if somebody could still send me example code for a user defined correlation structure I would much appreciate it, as my previous requests for help have not yielded any response. __ 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
[R] lme user-defined correlation structures??
Could somebody help with the definition of new correlation structure for use with a linear mixed-effects model (package nlme). Specifically, I want to define a Toeplitz type correlation structure, but due to my inexperience with programming in R, I feel a bit overwhelmed with the task at hand. I understand that you can start with a function like corAR1 as template, but I have no idea how I would define the methods (coef, corMatrix, and initialize) in this context. An example of code for a user-defined correlation structure would be very helpful. I did a search on Google and in the R-help archives, but have not found much in terms of hints and specific examples for user defined correlation structures. Thank you in advance! Michael Jerosch-Herold __ 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
[R] user-defined correlation structure in NLME
Could somebody help with the definition of new correlation structure for use with a linear mixed-effects model (package nlme). Specifically, I want to define a Toeplitz type correlation structure, but due to my inexperience with programming in R, I feel a bit overwhelmed with the task at hand. I understand that you can start with a function like corAR1 as template, but I have no idea how I would define the methods (coef, corMatrix, and initialize) in this context. I did a search on Google and in the R-help archives, but have not found much in terms of hints and specific examples for user defined correlation structures. Thank you in advance! Michael Jerosch-Herold __ 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
[R] image() with color key?
Is there an easy way to plot a color key next to a color image (with image() in graphics package)? The color key should also include a numerical scale, so that the colors can be cross-referenced with image intensity values. I see that levelplot has a facility for color keys, but with image it seems less straightforward, i.e. generating a color key is not an option in image(). Thank you! Michael Jerosch-Herold __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] read.spss warning: unrecognized record type??
When using read.spss (library: 'foreign') I get the following warning message: Warning message: E:/R4win/mesamri.sav: Unrecognized record type 7, subtype 13 encountered in system file. I don't see anything wrong with record #7 in the database I am trying to read in, but I suspect that the warning message does not refer to a specific record, but a variable type. Is this correct? And what does subtype 13 mean? I basically have a data table with records (cases) in rows, and various variables for each record/case in the columns. Again, I suspect that I am using record in a different sense then meant by the above warning message. Based on this warning, is record type 7 discarded when the data are read in? Thank you in advance for shedding some light on this! Michael Jerosch-Herold __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] correlation structures in NLME
I am using the latest version of R on a Windows machine and get the following error when I try to initialize a correlation structure with the function corAR1 in NLME. This example is taken from the book of Pinheiro and Bates, so it should work. What is going wrong? library(nlme) data(Orthodont) cs1AR1 - corAR1(0.8, form= ~1 | Subject) cs1AR1 - initialize(cs1AR1, data = Orthodont) Error in methodsPackageMetaName(C, name) : The name of the object (e.g,. a class or generic function) to find in the meta-data must be a single string (got a character vector of length 2) In addition: Warning message: the condition has length 1 and only the first element will be used in: if (!is.na(match(Class, .BasicClasses))) return(newBasic(Class, Thank you! Michael Jerosch-Herold __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
[R] circular structures in NLME
I have a problem where I am looking at a circular structure and I want to examine the spatial correlation pattern in the random effects portion of the model. I am looking at 8 sectors of a circular patch, and plan to use the corExp class. The sector number is the position variable, but for the calculation of the distance between two sectors I need to take into account the fact that the sectors are arranged in a circular pattern. I have read through some of the NLME documentation, it is not clear to me how I can specify the distance function appropriately. Any help/suggestions would be much appreciated. Michael Jerosch-Herold __ [EMAIL PROTECTED] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html