Re: [R] Reading fixed column format
I know you would prefer a 100% R solution but using the unix cut command (a Windows version is available in tools.zip at: http://www.murdoch-sutherland.com/Rtools/ ) is really easy. Maybe if you preprocessed it with that you could then use read.fwf. For example, look how easy it was to cut this file down to half extracting columns 2-3 and 6-8: C:\bintype a.dat 123456789 123456789 123456789 C:\bincut -c2-3,6-8 a.dat 23678 23678 23678 On 9/13/06, Anupam Tyagi [EMAIL PROTECTED] wrote: Barry Rowlingson B.Rowlingson at lancaster.ac.uk writes: None of these seem to read non-coniguous variables from columns; or may be I am missing something. read.fwf is not meant for large files according to a post in the archives. Thanks for the pointers. I have read the R data input and output. Anupam. First up, how 'large' is your 'large ASCII file'? How many rows and columns? There are 356,112 records, 326 variables, fixed record length of 1283 positions. Zipped file is 42MB. There are no field (variable) separaters (delimiters). Secondly, what are 'non-contiguous' variables? Variables that are not in adjoining positions in the file: reading them from the file would require skipping columns while reading. For example, below are the start positions of the first three variables I would like to read. StartingColumn VariableNameFieldLength 1 STATE 2 24 INTVID 3 30 PSU 10 Perhaps if you posted the first few lines and columns of the file then we might get an idea of how to read it in. Because a record (row) of the file is 1283 columns, I would not like to post it here. Thank you for your response. Anupam. __ 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@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] Reading fixed column format
Gabor Grothendieck ggrothendieck at gmail.com writes: C:\bincut -c2-3,6-8 a.dat 23678 23678 23678 Thanks. I think this will work. How do I redirect the output to a file on windows? Is there simple way to convert the cut command to a script on windows, because the entire command may not fit on one line? Anupam. __ 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] Reading fixed column format
Barry Rowlingson B.Rowlingson at lancaster.ac.uk writes: None of these seem to read non-coniguous variables from columns; or may be I am missing something. read.fwf is not meant for large files according to a post in the archives. Thanks for the pointers. I have read the R data input and output. Anupam. First up, how 'large' is your 'large ASCII file'? How many rows and columns? There are 356,112 records, and 326 variables. It has a fixed record length of 1283 positions, therefore cut -b can not be used. Secondly, what are 'non-contiguous' variables? When I do not want to read all columns. For example, I would like to read the following: StartingColumn VariableNameFieldLength 1 STATE 2 24 INTVID 3 27 DISPCODE 3 30 PSU 10 Sometimes I would also like to format the data after it has been read. For example, the ASCII file has price in columns 100 to 105 written as 005999. I want to read this and format it as 59.99 (omitting leading zeros in the price). Perhaps if you posted the first few lines and columns of the file then we might get an idea of how to read it in. I have not even downloaded the data onto my computer yet, because I am not sure I can read it in. The zipped file is 67MB. Using similar data a few years ago, I recall the unzipped file to be about 350--400 MB. I had used MySQL then, but it took some doing to get it in, and there were things that did not seem to work as I wanted them to---I could not figure out how to label the variables. I usually do not have to work with a dataframe of more than 10-30 MB at a time. It would be good to have a facility in R which defines the meta-data: labelling and structure of the dataset: positions of variables, their names, their lables, their levels (e.g. for ordered choice or group variables: yes, sometimes, no type responses). This can be saved as a seperate object and passed to a function that gets the named varibales from the ASCII file (names of variables to get can be given as arguments or as, attaches the meta data and creates a dataframe with all the meta-data attached. The meta-data of the dataframe could include notes at dataframe and variable level, and other information. This information is passed on to the plotting functions and used when formatting the output of statistical procedures. I agree with with Michael Kobovy that this is a very helpful list, and people do not owe less than what one paid for the software :) Anupam. __ 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] Of fixed column format (and more fixed mindsets)
Message: 107 Date: Tue, 12 Sep 2006 05:25:09 -0400 From: Michael Kubovy [EMAIL PROTECTED] Subject: Re: [R] Reading fixed column format To: Anupam Tyagi [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Message-ID: [EMAIL PROTECTED] Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Sep 12, 2006, at 2:47 AM, Anupam Tyagi wrote: Jason Barnhart jasoncbarnhart at msn.com writes: These posts may be helpful. http://tolstoy.newcastle.edu.au/R/help/05/06/5776.html https://stat.ethz.ch/pipermail/r-help/2002-May/021145.html Using scan directly may also work for you rather than read.fwf. Also, there are posts regarding using other tools such a 'perl' or 'cut' to prepocess the data before reading with R. Searching the archives with those keywords should help. I new user should not have to learn perl,cut, awk, etc simply to be able to use R. Does not make sense to me. Hi Anupam, You'll get much better help here if you're not ill-tempered. This is a group of extraordinarily helpful volunteers who owe you less than you paid for the product. Please consider saving your data in a way that will make it easier to read into R. No program can read every dataset. _ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400Charlottesville, VA 22904-4400 Parcels:Room 102Gilmer Hall McCormick RoadCharlottesville, VA 22903 Office:B011+1-434-982-4729 Lab:B019+1-434-982-4751 Fax:+1-434-982-4766 WWW:http://www.people.virginia.edu/~mk9y/ Also, if a user is new to R, it always helps if he or she uses a spreadsheet or another program/ set of scripts to first preprocess the data before reading them in R. These preprocessing might include simple steps such as naming and renaming columns, selecting which columns one needs in the dataset, etc. Then, once one is more familiar working with R, these can be accomplished within R relatively easily. /Arin Basu __ 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] Gnuplot epslatex format also in R?
Prof Brian Ripley ripley at stats.ox.ac.uk writes: R has an xfig driver, and AFAIK you can do this from xfig. Is there an xfig port for Windows, without cygwin? If so, I will be thankful for a pointer to the where it can be downloaded from. I have been looking for it for some time. Anupam. __ 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] Transformation of a data frame
Dear R-helpers, Apologies in advance for this (probably) simple question. I've searched the R Archive and can't seem to find a solution to my problem. I have a data frame of vegetation quadrat data with the following format: Q S C 1 A 5 1 B 10 1 C 50 1 D 10 2 A 20 2 E 10 2 C 40 3 D 5 3 F 1 3 G 5 3 B 75 Where Q is the sample (vegetation quadrats), S is the species and C is the percentage cover of each species within the sample. I wish to transform this into a community data matrix for analysis within the vegan package, which needs the following data frame format: Q A B C D E F G 1 5 10 50 10 0 0 0 2 20 0 40 0 10 0 0 3 0 75 0 5 0 1 75 I can't manage to do this transformation so your help would be much appreciated. Thanks very much in advance. All the best, Des __ 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] Power analysis for repeated measures ANCOVA
Dear All, I wonder if anyone has written a code for power analysis with repeated measures ANCOVA? I am aware of the following reference: Frison L and Pocock SJ: Repeated Measures in Clinical Trials: analysis using mean summary statistics and its implications for design in Statistics in Medicine, 1992, 11:1685-1704. Statistics in Medicine It will probably be fairly easy to code this up or even work on this from scratch, but it would be good if people have already done this and can share their code. Thanks. Steve. [[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] functions and strings
Hi If string - xyz f - function(x){1 + sin(cos(x)) + exp(x^2)} How do I manipulate string and f() to give the string 1 + sin(cos(xyz)) + exp(xyz^2) ? -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ 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] Transformation of a data frame
one approach is to use reshape(), e.g., # suppose that 'dat' is your data.frame, then res - reshape(dat, direction = wide, idvar = Q, timevar = S) res[is.na(res)] - 0 res I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Des Callaghan [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Tuesday, September 12, 2006 8:43 AM Subject: [R] Transformation of a data frame Dear R-helpers, Apologies in advance for this (probably) simple question. I've searched the R Archive and can't seem to find a solution to my problem. I have a data frame of vegetation quadrat data with the following format: Q S C 1 A 5 1 B 10 1 C 50 1 D 10 2 A 20 2 E 10 2 C 40 3 D 5 3 F 1 3 G 5 3 B 75 Where Q is the sample (vegetation quadrats), S is the species and C is the percentage cover of each species within the sample. I wish to transform this into a community data matrix for analysis within the vegan package, which needs the following data frame format: Q A B C D E F G 1 5 10 50 10 0 0 0 2 20 0 40 0 10 0 0 3 0 75 0 5 0 1 75 I can't manage to do this transformation so your help would be much appreciated. Thanks very much in advance. All the best, Des __ 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. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ 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] functions and strings
Robin Hankin wrote: Hi If string - xyz f - function(x){1 + sin(cos(x)) + exp(x^2)} How do I manipulate string and f() to give the string 1 + sin(cos(xyz)) + exp(xyz^2) ? Hi, Here what i'll do : f - function(x){ sprintf(1 + sin(cos(%s)) + exp(%s^2), x, x) } Cheers, Romai -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ 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@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] functions and strings
one approach could be the following strng - gsub(x, xyz, deparse(body(f))[2]) sub('^[[:space:]]+', '', strng) I hope it helps. Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Robin Hankin [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, September 13, 2006 9:10 AM Subject: [R] functions and strings Hi If string - xyz f - function(x){1 + sin(cos(x)) + exp(x^2)} How do I manipulate string and f() to give the string 1 + sin(cos(xyz)) + exp(xyz^2) ? -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ 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. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ 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] functions and strings
Hi Dmitris thanks for this but it's not quite right: f - function(x){sin(x)+exp(x)} strng - gsub(x, xyz, deparse(body(f))[2]) sub('^[[:space:]]+', '', strng) [1] sin(xyz) + exyzp(xyz) and I would want sin(xyz) + exp(xyz) On 13 Sep 2006, at 08:45, Dimitris Rizopoulos wrote: strng - gsub(x, xyz, deparse(body(f))[2]) sub('^[[:space:]]+', '', strng) -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ 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] wireplot margins and additional z-axis
Dear Deepayan, sorry for not being clear - but my problem has nothing to do with the aspect. If I create the eps the following way library(lattice) plot.vol- wireframe(volcano, aspect = c(1,1.5), scales=list(arrows=F),zlab=list(Z-axis,rot=90)) postscript(example_plot_3.eps, width = 14.0/2.54, height = 19.0/2.54, horizontal = FALSE, onefile = FALSE,paper=special) trellis.par.set(axis.line,list(alpha=1,col=1,lty=1,lwd=1)) print(plot.vol) dev.off() The plot is still not in the left bottom corner of the file. There is a lot of space below the outer box line. If I include this eps in latex it will also include this space and if I put for example the figure caption below it I have this huge gap between actual graph and caption. And for comparison, if I create with xyplot an eps like postscript(example_plot_4.eps, width = 14.0/2.54, height = 19.0/2.54, horizontal = FALSE, onefile = FALSE,paper=special) Depth - equal.count(quakes$depth, number=8, overlap=.1) plot.depth-xyplot(lat ~ long | Depth, data = quakes) update(trellis.last.object(), strip = strip.custom(strip.names = TRUE, strip.levels = TRUE), par.strip.text = list(cex = 0.75), aspect = iso) print(plot.depth) dev.off() the figure is really in the left bottom corner and included in latex has not that gap between caption and actual figure. I hope this describes my problem better. Klaus On 9/12/06, Klaus Nordhausen [EMAIL PROTECTED] wrote: Dear Deepayan, thanks for your reply, the change of the aspect does however not solve my problem with the space below the graph on the .eps I attached the .eps (still with the old aspect) so that it is maybe clearer what my problem is. No, it's not clearer; this is basically the same EPS that I got, so it gives me no new information. What do you get with the new aspect? If it's not what you want, you'll have to explain what you want more clearly. Also, don't make the panel borders transparent, as it makes it difficult to understand what's going on. Deepayan Any other suggestions? Klaus Dear R experts, it would be very kind if you could help me with two wireplot problems. First, when I make a wireplot and transform it into an .eps using the postscript function the eps-file leaves always a lot of space below the plot, as if it would leave space for a legend or something like that. How can i get the plot into the bottom corner without the space below? The space is not there when I just display the plot in R on my screen (I use R.2.3.1 on Windows XP). Or in general, how can I get the margins on all sides as small as possible since I wnat to include the eps into a report and do not need the space around. The following code has the space on the eps: library(lattice) plot.vol - wireframe(volcano, aspect = 1, scales=list(arrows=F) ,zlab=list(Z-axis,rot=90)) Perhaps you want something like aspect = c(1, 1.5) instead. postscript(example_plot.eps, width = 14.0/2.54, height = 19.0/2.54, horizontal = FALSE, onefile = FALSE,paper=special) trellis.par.set(axis.line,list(alpha=1,col=1,lty=0,lwd=1)) print(plot.vol) dev.off() Secondly, is it possible to add to the wireplot a further z-axis. I found only how to choose at which veritcal line I want the tickmarks and label, but is it also possible to have it at two vertical lines? No (but it shouldn't be too hard to add that feature; I'll have to check). Deepayan -- Echte DSL-Flatrate ab 0,- Euro* http://www.gmx.net/de/go/dsl __ 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] functions and strings
yes you're right, maybe this is better f - function(x){sin(x)+exp(x)} strng - gsub((x), (xyz), deparse(body(f))[2], fixed = TRUE) sub('^[[:space:]]+', '', strng) [1] sin(xyz) + exp(xyz) Best, Dimitris Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: Robin Hankin [EMAIL PROTECTED] To: Dimitris Rizopoulos [EMAIL PROTECTED] Cc: Robin Hankin [EMAIL PROTECTED]; [EMAIL PROTECTED] Sent: Wednesday, September 13, 2006 9:54 AM Subject: Re: [R] functions and strings Hi Dmitris thanks for this but it's not quite right: f - function(x){sin(x)+exp(x)} strng - gsub(x, xyz, deparse(body(f))[2]) sub('^[[:space:]]+', '', strng) [1] sin(xyz) + exyzp(xyz) and I would want sin(xyz) + exp(xyz) On 13 Sep 2006, at 08:45, Dimitris Rizopoulos wrote: strng - gsub(x, xyz, deparse(body(f))[2]) sub('^[[:space:]]+', '', strng) -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ 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] forcing levelplot to use relative cuts (ie cuts for each panel)
Dear guRus, I'm having trouble producing a levelplot with relative cuts for each panel (my data has large differences in scales, so I want to use quantiles for each panel). My attempts to change the 'at' argument in panel.levelplot function have not met with success. Below is a toy example. xy - expand.grid(x = 1:3, y = 1:3) aaa - rbind(cbind(xy, z = 1:9, site = rep('A', 9)), cbind(xy, z = (1:9)/10, site = rep('B', 9)), cbind(xy, z = (1:9)*10, site = rep('C', 9))) aaa library(lattice) levelplot(z~x+y|site, data = aaa) # using absolute cuts # now, attempt relative cuts levelplot(z~x+y|site, data = aaa, panel = function(...) { panel.levelplot(at = quantile(z),...) }) I get the following message: Error in panel.levelplot(at = quantile(z), ...) : formal argument at matched by multiple actual arguments My idea was to determine the cut points each time the panel function is called (ie each subset of the data), but I guess this was the wrong thing to do. Can someone point out what I'm missing? Thanks in advance, MT Dr Michael Townsley Senior Research Fellow Jill Dando Institute of Crime Science University College London Second Floor, Brook House London, WC1E 7HN Phone: 020 7679 0820 Fax: 020 7679 0828 Email: [EMAIL PROTECTED] __ 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] Retrieving value computed in inner function call
Though not obvious at first the posting you pointed me too is very helpful indeed. Thanks a lot Gabor. Juan Pablo At 08:48 PM 9/12/2006 -0400, Gabor Grothendieck wrote: Check out: http://finzi.psych.upenn.edu/R/Rhelp02a/archive/83547.html On 9/12/06, Juan Pablo Lewinger [EMAIL PROTECTED] wrote: Dear R users, Consider the following example function: f = function(a,b) { g = function(x) a*x + b h = function(x) g(x)^2 + x^2 opt = optimize(h,lower = -1, upper = 1) x.min = opt$minimum h.xmin = opt$objective g.xmin = g(x.min) return(c(x.min, h.xmin, g.xmin)) } In my real problem the function that plays the role of g is costly to compute. Now, to minimize h, optimize calls h with different values of x. In particular, at the end of the optimization, h would be called with argument x.min, the minimizer of h(x). Therefore, buried somewhere, there has to be a call to g with argument x=x.min which I would like to retrieve in order to avoid the extra call to g in the line before the return. Can this be done without too much pain? I'd very much appreciate any help. Juan Pablo Lewinger Department of Preventive Medicine University of Southern California __ 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@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] functions and strings
Hi Dmitris, Thierry, I'm getting there but it's still not quite right if f() includes something like x^2: f - function(x){exp(x^2)} gsub((x), (xyz), deparse(body(f))[2], fixed = TRUE) [1] x^2 [I don't care about the spaces] also, I can't quite see how to implement Thierry's suggestion about changing the letter x into a letter that does not occur in f(), because of the following example: f - function(x){abcdefghijklmnopqrstuvwxyz(x^2)} On 13 Sep 2006, at 09:08, Dimitris Rizopoulos wrote: yes you're right, maybe this is better f - function(x){sin(x)+exp(x)} strng - gsub((x), (xyz), deparse(body(f))[2], fixed = TRUE) sub('^[[:space:]]+', '', strng) [1] sin(xyz) + exp(xyz) Best, Dimitris -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ 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] R Matlab for Particle Tracking
Dear All, A question a bit outside statistics. In my group, a lot of people use Matlab for simple simulations of stochastic processes describing convection/diffusion problems (as long as the numerics does not get too expensive and one has to resort to C or Fortran). Leaving aside the theory, it all boils down to some kind of Monte Carlo technique, picking random draws from a certain distribution at a specified time step, tracking many particles and taking averages. I cannot see why R is not suitable to do this (unless performance becomes a problem). Has anyone on the list already gained some experience in this kind of simulations using R? Is there an online collection of example codes? It goes without saying that I am not going to start any flame war with Matlab users, only I cannot see any specific reason why R could not be deployed for this sort of tasks. Kind Regards Lorenzo __ 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] formatting data to be analysed using multinomial logistic regression (nnet)
bump. would like to know the answer too. I am about using nnet--multinom to estimate a multinomial logit model, but are not sure if this function handles categorical data input. Thanks for any help. - Original Message - From: Bob Green [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Sunday, September 10, 2006 10:24 PM Subject: [R] formatting data to be analysed using multinomial logistic regression (nnet) I am looking into using the multinomial logistic regression option in the nnet library and have two questions about formatting the data. 1. Can data be analysed in the following format or does it need to be transformed into count data, such as the housing data in MASS? Id Crime paranoia hallucinate toc disorg crimhist age 1 2 1 0 1 0 1 25 2 2 0 1 1 1 1 37 3 1 1 0 1 1 0 42 4 3 0 0 0 0 1 25 5 2 1 0 1 0 0 49 2.Can a ratio variable such as $age be included into a model, such as the one below? crimepred - glm (crime ~ paranoia + hallucinate + toc + crimhist, family = poisson, data = mht ) Any assistance with the above is appreciated, regards Bob Green __ 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@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] unexpected result in glm (family=poisson) for data with an only zero response in one factor
Dear members, here is my trouble: My data consists of counts of trapped insects in different attractive traps. I usually use GLMs with a poisson error distribution to find out the differences between my traitments (and to look at other factor effects). But for some dataset where one traitment contains only zeros, GLM with poisson family fail to find any difference between this particular traitment and anyother one (even with traitment that have trapped a lot of insects). GLMs with gaussian family does not seem to have the same problem but GLMs with binomial family does. I'm not sure if it is a statistical problem or if it comes from R... in the latter case I think some solution exists (perhaps in the options of the glm() function ?). Thank you for your help. Here I figure out an exemple to past in the console: ## START ## # Take a data set of counts for two traitments, one containing only zeros A=c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) B=c(1,0,0,0,2,1,0,0,1,2,0,0,0,1,2,2,0,1,1,0,1,0,2,1,1,0,1,2,0,1,0,1,1,1,0,1,1,1,0,1) traitment=c(rep(A,40),rep(B,40)) response=c(A,B) mydata=data.frame(traitment ,response) # Make a GLM on this dataset , with family=poisson g=glm(response~traitment, data=mydata, family=poisson) anova.glm(g,test=Chisq) # There is an effect of the traitment ... summary(g) # But traitment A does not differ from traitment B ! ! ! (the pvalue is always close from 1 in such cases) # Now if you replace only one zero of the A reponse to 1, the GLM works properly: mydata[1,2]=1 g=glm(response~traitment, data=mydata, family=poisson) anova.glm(g,test=Chisq) summary(g) # END ## Antonin Ferry (PhD) Laboratoire d'Ecobiologie des Insectes Parasitoides http://www.parasitoides.univ-rennes1.fr Université de Renes1, FRANCE __ 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] functions and strings
Hello everyone I know it looks like I'm making heavy weather of this, but I don't think I communicated my problem properly. I really appreciate you guys' help here. I am writing a wrapper for a mathematical library to which I want to send character strings that it can execute, and then pass the answer back to R. Now, I want a user to be able to type _any_ function and _any_ string. For example: f - function(i){sin(i) + cos(sin(i^2))} string - tti and then I want a function do() such that do(f,string) will return sin(tti) + cos(sin(tti^2)) without worrying about whether f()'s arguments include or do not include a particular letter, and without insisting that i always appears as (i) . Although thinking about it, it's not actually that bad to require the user to use some otherwise rare sequence of letters, say XxX as an argument, and then Dmitris's first method would work. Having said that, this is not an ideal solution and it would be nicer to have some method that could detect what the argument to f() is, where it is in the body, and substitute those occurences for string. I want a method that is perfectly general; I posted my example of abcd...z(), not to be annoying and pedantic but to illustrate that a simple gsub approach wouldn't work: one has to know in advance which letters can and cannot be used, and this information isn't available. I don't have a function so named (yet ;-). best wishes rksh Hi Dmitris, Thierry, I'm getting there but it's still not quite right if f() includes something like x^2: f - function(x){exp(x^2)} gsub((x), (xyz), deparse(body(f))[2], fixed = TRUE) [1] x^2 [I don't care about the spaces] also, I can't quite see how to implement Thierry's suggestion about changing the letter x into a letter that does not occur in f(), because of the following example: f - function(x){abcdefghijklmnopqrstuvwxyz(x^2)} On 13 Sep 2006, at 09:08, Dimitris Rizopoulos wrote: yes you're right, maybe this is better f - function(x){sin(x)+exp(x)} strng - gsub((x), (xyz), deparse(body(f))[2], fixed = TRUE) sub('^[[:space:]]+', '', strng) [1] sin(xyz) + exp(xyz) Best, Dimitris -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ 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] Test internet presence
Gregor Gorjanc a écrit : If I summarize the thread there is (currently) no way to test for internet presence with a general approach. what about try(readLines(...)) ? (at least it works fine on Windows.) __ 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] functions and strings
Hi, Perhaps try this (based on 'bquote'): rewrite.expression - function(expr, to, dep) { f - function(expr) { if ( length(expr) == 1 ) if ( expr == as.name(dep) ) as.name(to) else expr else as.call(lapply(expr, f)) } f(expr) } rewrite - function(expr, to, dep='x') { rewrite.expression(substitute(expr), to, dep) } rewrite(1 + sin(cos(x)) + exp(x^2), 'xyz') 1 + sin(cos(xyz)) + exp(xyz^2) rewrite(sin(x)+exp(x), 'xyz') sin(xyz) + exp(xyz) rewrite(sin(i) + cos(sin(i^2)), 'tti', 'i') sin(tti) + cos(sin(tti^2)) ## Or, closer to your example, using the name of the argument and body ## of the function: f - function(r) 2*r/sin(r) - b rewrite.expression(body(f), 'foo', names(formals(f))) 2 * foo/sin(foo) - b Hope that helps, Rich On 9/13/06, Robin Hankin [EMAIL PROTECTED] wrote: Hello everyone I know it looks like I'm making heavy weather of this, but I don't think I communicated my problem properly. I really appreciate you guys' help here. I am writing a wrapper for a mathematical library to which I want to send character strings that it can execute, and then pass the answer back to R. Now, I want a user to be able to type _any_ function and _any_ string. For example: f - function(i){sin(i) + cos(sin(i^2))} string - tti and then I want a function do() such that do(f,string) will return sin(tti) + cos(sin(tti^2)) without worrying about whether f()'s arguments include or do not include a particular letter, and without insisting that i always appears as (i) . Although thinking about it, it's not actually that bad to require the user to use some otherwise rare sequence of letters, say XxX as an argument, and then Dmitris's first method would work. Having said that, this is not an ideal solution and it would be nicer to have some method that could detect what the argument to f() is, where it is in the body, and substitute those occurences for string. I want a method that is perfectly general; I posted my example of abcd...z(), not to be annoying and pedantic but to illustrate that a simple gsub approach wouldn't work: one has to know in advance which letters can and cannot be used, and this information isn't available. I don't have a function so named (yet ;-). best wishes rksh Hi Dmitris, Thierry, I'm getting there but it's still not quite right if f() includes something like x^2: f - function(x){exp(x^2)} gsub((x), (xyz), deparse(body(f))[2], fixed = TRUE) [1] x^2 [I don't care about the spaces] also, I can't quite see how to implement Thierry's suggestion about changing the letter x into a letter that does not occur in f(), because of the following example: f - function(x){abcdefghijklmnopqrstuvwxyz(x^2)} On 13 Sep 2006, at 09:08, Dimitris Rizopoulos wrote: yes you're right, maybe this is better f - function(x){sin(x)+exp(x)} strng - gsub((x), (xyz), deparse(body(f))[2], fixed = TRUE) sub('^[[:space:]]+', '', strng) [1] sin(xyz) + exp(xyz) Best, Dimitris -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ 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. -- Rich FitzJohn rich.fitzjohn at gmail.com __ 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] Gnuplot epslatex format also in R?
On 9/12/06, Anupam Tyagi [EMAIL PROTECTED] wrote: R has an xfig driver, and AFAIK you can do this from xfig. Is there an xfig port for Windows, without cygwin? If so, I will be thankful for a pointer to the where it can be downloaded from. I have been looking for it for some time. Anupam. WinFIG, Anupam? Its site at http://www.schmidt-web-berlin.de/WinFIG.htm Paul __ 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] R-question
Hello Colleagues, I programmed in SAS for 3 years and would like to switch to a not so costly software product. Hence I started to evaluate R, and my first test look promising. However I have some question: 1. Is it possible to query R files by SQL internally on data frames (not on a database) and how is the syntax (I have the RODBC package installed). I would like to extract year, Quarter, week, from a date column in a data frame (see attachment). After this I want to attach the column to the original data frame. How do I do this in R? Dr .Th.Mühge, PMP® Procurement Technology Center IBM Deutschland GmbH, Hechtsheimer Str.2, D-55131 Mainz Phone: xx49-(0)6131-84-2416 Mobile: xx49-(0)15117457978 e-mail: [EMAIL PROTECTED] (See attached file: Debug1.csv)__ 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] R CMD INSTALL with debugging
I've run into a problem with lazy loading on a Linux system when trying to install the Matrix package (version 0.995-16) which didn't happen with version 0.995-2. The problem is not with a x86_64 system: it's a 32 bit machine, the exact description I don't have right now (R-2.3.1). The message looks like this: Error in match.call(fmatch, fcall) : unused argument(s) (x ...) In addition: There were 12 warnings (use warnings() to see them) Error: unable to load R code in package 'Matrix' Execution halted ERROR: lazy loading failed for package 'Matrix' I even tried with the --no-lazy switch but that only gave me a message about being deprecated but otherwise the results were identical. What do I need to do to get more information about what is making that match.call message? The warnings() message is of no use once R has exited. I suspect it has something to do with warnings about NULL environments being deprecated, because I've not tracked down all instances of them, and the newer Matrix package is more particular about such things. Finding what is producing the problem with match.call might help me work out where the NULL environment messages are coming from and that would be an added bonus. TIA -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_Middle minds discuss events (:_~*~_:)Small minds discuss people (_)-(_) . Anon ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ 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] R-question
Thorsten Muehge wrote: Hello Colleagues, I programmed in SAS for 3 years and would like to switch to a not so costly software product. Hence I started to evaluate R, and my first test look promising. However I have some question: 1. Is it possible to query R files by SQL internally on data frames (not on a database) and how is the syntax (I have the RODBC package installed). I would like to extract year, Quarter, week, from a date column in a data frame (see attachment). After this I want to attach the column to the original data frame. How do I do this in R? Hi Thorsten, You may just want to convert the dates as follows, adding them to the data frame on the fly: test.df-data.frame(dates=as.POSIXlt(c(2004-05-13,2005-07-23,2006-09-13)), nums=rnorm(3)) test.df$years-format(test.df$dates,%Y) test.df$quarters-floor((as.numeric(format(test.df$dates,%m))-1)/3)+1 test.df$week-format(test.df$dates,%U) test.df Jim __ 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] functions and strings
Rich that is swet and does exactly what I want. Thank you very much. best wishes rksh On 13 Sep 2006, at 10:54, Rich FitzJohn wrote: Hi, Perhaps try this (based on 'bquote'): rewrite.expression - function(expr, to, dep) { f - function(expr) { if ( length(expr) == 1 ) if ( expr == as.name(dep) ) as.name(to) else expr else as.call(lapply(expr, f)) } f(expr) } rewrite - function(expr, to, dep='x') { rewrite.expression(substitute(expr), to, dep) } rewrite(1 + sin(cos(x)) + exp(x^2), 'xyz') 1 + sin(cos(xyz)) + exp(xyz^2) rewrite(sin(x)+exp(x), 'xyz') sin(xyz) + exp(xyz) rewrite(sin(i) + cos(sin(i^2)), 'tti', 'i') sin(tti) + cos(sin(tti^2)) ## Or, closer to your example, using the name of the argument and body ## of the function: f - function(r) 2*r/sin(r) - b rewrite.expression(body(f), 'foo', names(formals(f))) 2 * foo/sin(foo) - b Hope that helps, Rich -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ 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] Conservative ANOVA tables in lmer
On Wed, 2006-09-13 at 08:04 +1000, Andrew Robinson wrote: On Tue, September 12, 2006 7:34 am, Manuel Morales wrote: On Mon, 2006-09-11 at 11:43 -0500, Douglas Bates wrote: Having made that offer I think I will now withdraw it. Peter's example has convinced me that this is the wrong thing to do. I am encouraged by the fact that the results from mcmcsamp correspond closely to the correct theoretical results in the case that Peter described. I appreciate that some users will find it difficult to work with a MCMC sample (or to convince editors to accept results based on such a sample) but I think that these results indicate that it is better to go after the marginal distribution of the fixed effects estimates (which is what is being approximated by the MCMC sample - up to Bayesian/frequentist philosophical differences) than to use the conditional distribution and somehow try to adjust the reference distribution. Am I right that the MCMC sample can not be used, however, to evaluate the significance of parameter groups. For example, to assess the significance of a three-level factor? Are there better alternatives than simply adjusting the CI for the number of factor levels (1-alpha/levels). I wonder whether the likelihood ratio test would be suitable here? That seems to be supported. It just takes a little longer. require(lme4) data(sleepstudy) fm1 - lmer(Reaction ~ Days + (Days|Subject), sleepstudy) fm2 - lmer(Reaction ~ Days + I(Days^2) + (Days|Subject), sleepstudy) anova(fm1, fm2) So, a brief overview of the popular inferential needs and solutions would then be: 1) Test the statistical significance of one or more fixed or random effects - fit a model with and a model without the terms, and use the LRT. I believe that the LRT is anti-conservative for fixed effects, as described in Pinheiro and Bates companion book to NLME. 2) Obtain confidence intervals for one or more fixed or random effects - use mcmcsamp Did I miss anything important? - What else would people like to do? Cheers Andrew Andrew Robinson Senior Lecturer in Statistics Tel: +61-3-8344-9763 Department of Mathematics and StatisticsFax: +61-3-8344 4599 University of Melbourne, VIC 3010 Australia Email: [EMAIL PROTECTED]Website: http://www.ms.unimelb.edu.au __ 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@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] Reading fixed column format
Anupam Tyagi wrote: Barry Rowlingson B.Rowlingson at lancaster.ac.uk writes: None of these seem to read non-coniguous variables from columns; or may be I am missing something. read.fwf is not meant for large files according to a post in the archives. Thanks for the pointers. I have read the R data input and output. Anupam. First up, how 'large' is your 'large ASCII file'? How many rows and columns? There are 356,112 records, and 326 variables. It has a fixed record length of 1283 positions, therefore cut -b can not be used. Secondly, what are 'non-contiguous' variables? When I do not want to read all columns. For example, I would like to read the following: StartingColumn VariableName FieldLength 1 STATE 2 24INTVID 3 27DISPCODE 3 30PSU 10 read.fwf() can handle the skipped columns (you use negative column values; see the man page). It will break the read up into blocks, so the large size of the original file shouldn't be a problem. Duncan Murdoch Sometimes I would also like to format the data after it has been read. For example, the ASCII file has price in columns 100 to 105 written as 005999. I want to read this and format it as 59.99 (omitting leading zeros in the price). Perhaps if you posted the first few lines and columns of the file then we might get an idea of how to read it in. I have not even downloaded the data onto my computer yet, because I am not sure I can read it in. The zipped file is 67MB. Using similar data a few years ago, I recall the unzipped file to be about 350--400 MB. I had used MySQL then, but it took some doing to get it in, and there were things that did not seem to work as I wanted them to---I could not figure out how to label the variables. I usually do not have to work with a dataframe of more than 10-30 MB at a time. It would be good to have a facility in R which defines the meta-data: labelling and structure of the dataset: positions of variables, their names, their lables, their levels (e.g. for ordered choice or group variables: yes, sometimes, no type responses). This can be saved as a seperate object and passed to a function that gets the named varibales from the ASCII file (names of variables to get can be given as arguments or as, attaches the meta data and creates a dataframe with all the meta-data attached. The meta-data of the dataframe could include notes at dataframe and variable level, and other information. This information is passed on to the plotting functions and used when formatting the output of statistical procedures. I agree with with Michael Kobovy that this is a very helpful list, and people do not owe less than what one paid for the software :) Anupam. __ 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@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] Reading fixed column format
Anupam Tyagi wrote: There are 356,112 records, and 326 variables. It has a fixed record length of 1283 positions, therefore cut -b can not be used. Okay, thats 'large' enough to be awkward... It would be good to have a facility in R which defines the meta-data: labelling and structure of the dataset: positions of variables, their names, their lables, their levels (e.g. for ordered choice or group variables: yes, sometimes, no type responses). This can be saved as a seperate object and passed to a function that gets the named varibales from the ASCII file (names of variables to get can be given as arguments or as, attaches the meta data and creates a dataframe with all the meta-data attached. The meta-data of the dataframe could include notes at dataframe and variable level, and other information. This information is passed on to the plotting functions and used when formatting the output of statistical procedures. I think you need the following functions to build that kind of thing in R: * z = unz(/tmp/file.zip,data.dat) - to create a connection to a file in a zip archive - this saves you having to explicitly unzip it... * open(z) - to open the connection to the file in the zip... * readLines(z,n) - to read 'n' lines from the current position in the file... * seek(z,m*lineLength-1) - to jump to line 'm' ready to read it. Then its just 'substr' and similar string-chopping functions to build up the data from each line you want. If I had a spare day... Barry __ 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] Reading fixed column format
Barry Rowlingson wrote: If I had a spare day... Or if I'd just read Duncan's message about negative widths in read.fwf. Anyway, I've learnt about readLines() and seek() and reading zip files now, so I can read _anything_ Barry __ 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] functions and strings
Robin Hankin [EMAIL PROTECTED] writes: Rich that is swet and does exactly what I want. Thank you very much. I just wonder whatever substitute() did to get ignored like that? substitute(1 + sin(cos(x)) + exp(x^2), list(x=quote(xyz))) 1 + sin(cos(xyz)) + exp(xyz^2) best wishes rksh On 13 Sep 2006, at 10:54, Rich FitzJohn wrote: Hi, Perhaps try this (based on 'bquote'): rewrite.expression - function(expr, to, dep) { f - function(expr) { if ( length(expr) == 1 ) if ( expr == as.name(dep) ) as.name(to) else expr else as.call(lapply(expr, f)) } f(expr) } rewrite - function(expr, to, dep='x') { rewrite.expression(substitute(expr), to, dep) } rewrite(1 + sin(cos(x)) + exp(x^2), 'xyz') 1 + sin(cos(xyz)) + exp(xyz^2) rewrite(sin(x)+exp(x), 'xyz') sin(xyz) + exp(xyz) rewrite(sin(i) + cos(sin(i^2)), 'tti', 'i') sin(tti) + cos(sin(tti^2)) ## Or, closer to your example, using the name of the argument and body ## of the function: f - function(r) 2*r/sin(r) - b rewrite.expression(body(f), 'foo', names(formals(f))) 2 * foo/sin(foo) - b Hope that helps, Rich -- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743 __ 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. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ 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] unexpected result in glm (family=poisson) for data with an only zero response in one factor
Dear Antonin, It is a statistical problem: the well-known monotone likelihood. In this case ML estimate does not exist (or equals infinity) and Wald approximations (ob which SE are based) does not hold. However LRT is valid and provides reliable results. As far as I know, the only software dealing with monotone likelihood problems in loglinear models is LogXact by cytel corporation. best, vito Antonin Ferry wrote: Dear members, here is my trouble: My data consists of counts of trapped insects in different attractive traps. I usually use GLMs with a poisson error distribution to find out the differences between my traitments (and to look at other factor effects). But for some dataset where one traitment contains only zeros, GLM with poisson family fail to find any difference between this particular traitment and anyother one (even with traitment that have trapped a lot of insects). GLMs with gaussian family does not seem to have the same problem but GLMs with binomial family does. I'm not sure if it is a statistical problem or if it comes from R... in the latter case I think some solution exists (perhaps in the options of the glm() function ?). Thank you for your help. Here I figure out an exemple to past in the console: ## START ## # Take a data set of counts for two traitments, one containing only zeros A=c(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0) B=c(1,0,0,0,2,1,0,0,1,2,0,0,0,1,2,2,0,1,1,0,1,0,2,1,1,0,1,2,0,1,0,1,1,1,0,1,1,1,0,1) traitment=c(rep(A,40),rep(B,40)) response=c(A,B) mydata=data.frame(traitment ,response) # Make a GLM on this dataset , with family=poisson g=glm(response~traitment, data=mydata, family=poisson) anova.glm(g,test=Chisq) # There is an effect of the traitment ... summary(g) # But traitment A does not differ from traitment B ! ! ! (the pvalue is always close from 1 in such cases) # Now if you replace only one zero of the A reponse to 1, the GLM works properly: mydata[1,2]=1 g=glm(response~traitment, data=mydata, family=poisson) anova.glm(g,test=Chisq) summary(g) # END ## Antonin Ferry (PhD) Laboratoire d'Ecobiologie des Insectes Parasitoides http://www.parasitoides.univ-rennes1.fr Université de Renes1, FRANCE __ 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. -- Vito M.R. Muggeo Dip.to Sc Statist e Matem `Vianelli' Università di Palermo viale delle Scienze, edificio 13 90128 Palermo - ITALY tel: 091 6626240 fax: 091 485726/485612 __ 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] Transformation of a data frame
one approach is to use reshape(), e.g., # suppose that 'dat' is your data.frame, then res - reshape(dat, direction = wide, idvar = Q, timevar = S) res[is.na(res)] - 0 res You can also use the reshape package: library(reshape) datm - melt(dat, id=1:2) cast(datm, Q ~ S) See the introduction to reshape (http://www.had.co.nz/reshape/introduction.pdf) for more details and examples. Hadley __ 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] unexpected result in glm (family=poisson) for data with an only zero response in one factor
The Wald statistics that are returned as z value can be a very rough approximation. The standard error is radically different, on a logarithmic scale, between log(mu) = -20.30 [the best glm() managed in approximating -infinity] and log(mu) + log(a) = -0.29. It is actually worse than might appear; the SE=2457.38 is an approximation to infinity! The phenomenon is an extreme version, now with a poisson error model, of the Hauck-Donner effect (Modern Applied Statistics with S, 4th edn, pp.197-199) that occurs with binomial data. Use the result from the anova likelihood ratio test, where the approximations that are involved are usually much better behaved (but it would not hurt to do a simulation as a check.) There is an example of this phenomenon with a poisson error model in Subsection 8.4.2 (the same subsection number both for the 1st edn and the forthcoming 2nd edn) of Data Analysis Graphics using R, CUP, 2003 and 2006. Install and attach the DAAG package and try example(moths) John Maindonald email: [EMAIL PROTECTED] phone : +61 2 (6125)3473fax : +61 2(6125)5549 Centre for Mathematics Its Applications, Room 1194, John Dedman Mathematical Sciences Building (Building 27) Australian National University, Canberra ACT 0200. Dear members, here is my trouble: My data consists of counts of trapped insects in different attractive traps. I usually use GLMs with a poisson error distribution to find out the differences between my traitments (and to look at other factor effects). But for some dataset where one traitment contains only zeros, GLM with poisson family fail to find any difference between this particular traitment and anyother one (even with traitment that have trapped a lot of insects). GLMs with gaussian family does not seem to have the same problem but GLMs with binomial family does. I'm not sure if it is a statistical problem or if it comes from R... in the latter case I think some solution exists (perhaps in the options of the glm() function ?). Thank you for your help. Here I figure out an exemple to past in the console: ## START ## # Take a data set of counts for two traitments, one containing only zeros A=c (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0) B=c (1,0,0,0,2,1,0,0,1,2,0,0,0,1,2,2,0,1,1,0,1,0,2,1,1,0,1,2,0,1,0,1,1,1,0 ,1,1,1,0,1) traitment=c(rep(A,40),rep(B,40)) response=c(A,B) mydata=data.frame(traitment ,response) # Make a GLM on this dataset , with family=poisson g=glm(response~traitment, data=mydata, family=poisson) anova.glm(g,test=Chisq) # There is an effect of the traitment ... summary(g) # But traitment A does not differ from traitment B ! ! ! (the pvalue is always close from 1 in such cases) # Now if you replace only one zero of the A reponse to 1, the GLM works properly: mydata[1,2]=1 g=glm(response~traitment, data=mydata, family=poisson) anova.glm(g,test=Chisq) summary(g) ## ### END ## Antonin Ferry (PhD) Laboratoire d'Ecobiologie des Insectes Parasitoides http://www.parasitoides.univ-rennes1.fr Université de Renes1, FRANCE __ 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] R-question
Thorsten Muehge MUEHGE at de.ibm.com writes: 1. Is it possible to query R files by SQL internally on data frames (not on a database) and how is the syntax (I have the RODBC package installed). It is possible to do similar things conceptually in R as in SQL---at least the basic SQL queries (I have not tried others). Unlike SQL, R retains the sort order. So far as I know you can not use SQL code to query R data-frames. But you can put SQL code in a .R file and use RODBC or ODBC (I have used this) to send SQL queries to database; you can also get the results from SQL queries back to R as R objects. __ 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] unexpected result in glm (family=poisson) for data with an only zero response in one factor
PS. In part, the problem is with the use of the log link, arising because the limit of log(mu), as mu goes to 0, is minus infinity. This is not an appropriate scale on which to represent a fitted value that is zero. The estimated SE for a fitted value of zero should be 0. You will get a more sensible answer if you set family=poisson (link=sqrt) g - glm(response~traitment, data=mydata, family=poisson(link=sqrt)) summary(g) Call: glm(formula = response ~ traitment, family = poisson(link = sqrt), data = mydata) Deviance Residuals: Min 1Q Median 3Q Max -1.225e+00 -2.730e-05 -2.730e-05 2.745e-01 1.193e+00 Coefficients: Estimate Std. Error z value Pr(|z|) (Intercept) 0.193 0.0790569 0.0002441 traitmentB 0.8660061 0.11180347.746 9.5e-15 (Dispersion parameter for poisson family taken to be 1) Null deviance: 75.485 on 79 degrees of freedom Residual deviance: 33.896 on 78 degrees of freedom AIC: 89.579 Number of Fisher Scoring iterations: 14 John Maindonald email: [EMAIL PROTECTED] phone : +61 2 (6125)3473fax : +61 2(6125)5549 Centre for Mathematics Its Applications, Room 1194, John Dedman Mathematical Sciences Building (Building 27) Australian National University, Canberra ACT 0200. Dear members, here is my trouble: My data consists of counts of trapped insects in different attractive traps. I usually use GLMs with a poisson error distribution to find out the differences between my traitments (and to look at other factor effects). But for some dataset where one traitment contains only zeros, GLM with poisson family fail to find any difference between this particular traitment and anyother one (even with traitment that have trapped a lot of insects). GLMs with gaussian family does not seem to have the same problem but GLMs with binomial family does. I'm not sure if it is a statistical problem or if it comes from R... in the latter case I think some solution exists (perhaps in the options of the glm() function ?). Thank you for your help. Here I figure out an exemple to past in the console: ## START ## # Take a data set of counts for two traitments, one containing only zeros A=c (0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0) B=c (1,0,0,0,2,1,0,0,1,2,0,0,0,1,2,2,0,1,1,0,1,0,2,1,1,0,1,2,0,1,0,1,1,1,0 ,1,1,1,0,1) traitment=c(rep(A,40),rep(B,40)) response=c(A,B) mydata=data.frame(traitment ,response) # Make a GLM on this dataset , with family=poisson g=glm(response~traitment, data=mydata, family=poisson) anova.glm(g,test=Chisq) # There is an effect of the traitment ... summary(g) # But traitment A does not differ from traitment B ! ! ! (the pvalue is always close from 1 in such cases) # Now if you replace only one zero of the A reponse to 1, the GLM works properly: mydata[1,2]=1 g=glm(response~traitment, data=mydata, family=poisson) anova.glm(g,test=Chisq) summary(g) ## ### END ## Antonin Ferry (PhD) Laboratoire d'Ecobiologie des Insectes Parasitoides http://www.parasitoides.univ-rennes1.fr Université de Renes1, FRANCE __ 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] Reading fixed column format
Barry Rowlingson B.Rowlingson at lancaster.ac.uk writes: Or if I'd just read Duncan's message about negative widths in read.fwf. Anyway, I've learnt about readLines() and seek() and reading zip files now, so I can read _anything_ Thanks to everyone who answered my query. I have a lot to think about too. __ 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] wireplot margins and additional z-axis
Klaus Nordhausen: The plot is still not in the left bottom corner of the file. There is a lot of space below the outer box line. If I include this eps in latex it will also include this space and if I put for example the figure caption below it I have this huge gap between actual graph and caption. This is not a problem in LaTeX. You can put some negative vertical space between the figure and the caption. You can also put horizontal space in the figure to move the useful part of the eps file where you want it. Here is a trivial example. tmp.R: par(mfrow=c(2,2)) plot(1:10) dev.copy2eps(file=tmp.eps) tmp.tex: \documentclass{article} \usepackage{graphicx} \begin{document} \begin{figure} \includegraphics{tmp.eps} \caption{Default position.} \end{figure} \begin{figure} \hspace*{.5in} \includegraphics{tmp.eps} \vspace*{-3.8in} \caption{Controlled position.} \end{figure} \end{document} __ 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] install R on Sun Blade 2000
Hello useRs, I would like to install R 2.3.1 on a computer : Sun Blade 2000. Is there a precompiled version of R for this computer ? Thank you very much. -- David [[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.
Re: [R] wireplot margins and additional z-axis
On 9/13/2006 4:04 AM, Klaus Nordhausen wrote: Dear Deepayan, sorry for not being clear - but my problem has nothing to do with the aspect. If I create the eps the following way There is some ambiguity here. The aspect arg to wireframe controls the 3D aspect ratio. You want to control the 2D aspect ratio in the displayed plot. It is stored in the aspect.ratio member of the resulting object, and can be changed using plot.vol$aspect.ratio - 1.5 for example. You shouldn't really be fiddling around inside the object like that, but I don't know how to avoid it in this case. Duncan Murdoch library(lattice) plot.vol- wireframe(volcano, aspect = c(1,1.5), scales=list(arrows=F),zlab=list(Z-axis,rot=90)) postscript(example_plot_3.eps, width = 14.0/2.54, height = 19.0/2.54, horizontal = FALSE, onefile = FALSE,paper=special) trellis.par.set(axis.line,list(alpha=1,col=1,lty=1,lwd=1)) print(plot.vol) dev.off() The plot is still not in the left bottom corner of the file. There is a lot of space below the outer box line. If I include this eps in latex it will also include this space and if I put for example the figure caption below it I have this huge gap between actual graph and caption. And for comparison, if I create with xyplot an eps like postscript(example_plot_4.eps, width = 14.0/2.54, height = 19.0/2.54, horizontal = FALSE, onefile = FALSE,paper=special) Depth - equal.count(quakes$depth, number=8, overlap=.1) plot.depth-xyplot(lat ~ long | Depth, data = quakes) update(trellis.last.object(), strip = strip.custom(strip.names = TRUE, strip.levels = TRUE), par.strip.text = list(cex = 0.75), aspect = iso) print(plot.depth) dev.off() the figure is really in the left bottom corner and included in latex has not that gap between caption and actual figure. I hope this describes my problem better. Klaus On 9/12/06, Klaus Nordhausen [EMAIL PROTECTED] wrote: Dear Deepayan, thanks for your reply, the change of the aspect does however not solve my problem with the space below the graph on the .eps I attached the .eps (still with the old aspect) so that it is maybe clearer what my problem is. No, it's not clearer; this is basically the same EPS that I got, so it gives me no new information. What do you get with the new aspect? If it's not what you want, you'll have to explain what you want more clearly. Also, don't make the panel borders transparent, as it makes it difficult to understand what's going on. Deepayan Any other suggestions? Klaus Dear R experts, it would be very kind if you could help me with two wireplot problems. First, when I make a wireplot and transform it into an .eps using the postscript function the eps-file leaves always a lot of space below the plot, as if it would leave space for a legend or something like that. How can i get the plot into the bottom corner without the space below? The space is not there when I just display the plot in R on my screen (I use R.2.3.1 on Windows XP). Or in general, how can I get the margins on all sides as small as possible since I wnat to include the eps into a report and do not need the space around. The following code has the space on the eps: library(lattice) plot.vol - wireframe(volcano, aspect = 1, scales=list(arrows=F) ,zlab=list(Z-axis,rot=90)) Perhaps you want something like aspect = c(1, 1.5) instead. postscript(example_plot.eps, width = 14.0/2.54, height = 19.0/2.54, horizontal = FALSE, onefile = FALSE,paper=special) trellis.par.set(axis.line,list(alpha=1,col=1,lty=0,lwd=1)) print(plot.vol) dev.off() Secondly, is it possible to add to the wireplot a further z-axis. I found only how to choose at which veritcal line I want the tickmarks and label, but is it also possible to have it at two vertical lines? No (but it shouldn't be too hard to add that feature; I'll have to check). Deepayan __ 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] lattice cloud and conditional axis limits
Deepayan Sarkar skreiv: cloud(z~x*y|s,scales=list(arrows=FALSE,relation=free)) However, it does not. Any ideas how I can make it work? There's no direct support, but you can write a small panel function with more or less the desired effect: Thank you so much. It works perfectly. -- Karl Ove Hufthammer E-mail and Jabber: [EMAIL PROTECTED] __ 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] install R on Sun Blade 2000
Without knowing your OS, it is hard to say. But if this is Solaris (the most likely OS), not to my knowledge. On Wed, 13 Sep 2006, David Hajage wrote: Hello useRs, I would like to install R 2.3.1 on a computer : Sun Blade 2000. Is there a precompiled version of R for this computer ? Thank you very much. __ 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] rgl: exporting to pdf or png does not work
Daniel Franke franke.daniel at gmail.com writes: [This is a follow-up to the recent discussion on R-help] Hi all, I can reproduce both problems on gentoo (2006.0 profile), but not on OpenSuSE-10.1. Installed libraries: * Gentoo: R-2.2.1, rgl-0.67.2, OpenSuSE: R-2.3.1, rgl-0.67.2 * Gentoo: libpng-1.2.12, OpenSuSE: libpng-1.2.8 * Gentoo: Xorg-6.8.2 (mga), OpenSuSE: 6.9.0 (nvidia) * Gentoo: freeglut-2.4.0, OpenSuSE: freeglut-051110 * OpenSuse: mesa-6.4.2 Just a quick question: if you use an example with text in it, does the text show up in the output on the version that works (OpenSuSE)? Someone else reported no crash, but no text output either. Otherwise I can't help. For what it's worth, I discovered that in the Ubuntu (and I assume any Gnome) desktop, Alt-PrintScreen does screen capture on a single window, which is a good workaround for rgl.snapshot() [although it would still be nice to have rgl.postscript() working ...] Ben Bolker __ 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] printing a generated function crashes R
Dear All, the last expression in the following code snippet crashes R (version 2.3.1 on Windows XP) when run interactively: make.bad.function - function(kind) { zz - switch(kind, 1 = 1, 2 = 2) stopifnot( !is.null(zz) ) eval( bquote( function(x) { x + .(zz) })) } # bad.function - make.bad.function(5) ## error as expected bad.function - make.bad.function(1) print(bad.function(10)) ## - 11 bad.function - make.bad.function(2) print(bad.function(10)) ## - 12 bad.function## this works if the code is source()'d print(bad.function) ## oops! However, it does work (i.e. prints the body of bad.function) if run non-interactively (R --vanilla bad-function.R). Any ideas why this happens? Thanks in advance Mstislav Elagin __ 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] Reading fixed column format
On 9/13/06, Anupam Tyagi [EMAIL PROTECTED] wrote: Gabor Grothendieck ggrothendieck at gmail.com writes: C:\bincut -c2-3,6-8 a.dat 23678 23678 23678 Thanks. I think this will work. How do I redirect the output to a file on windows? Same as on UNIX cut -c2-3,6-8 a.dat a2.dat Is there simple way to convert the cut command to a script on windows, Using notepad or other text editor put it in file a.bat and then issue this command from the console a.bat Note that you could process it multiple time if you like: cut -c6-8 a.dat a2.dat cut -c2-3 a2.dat a3.dat produces the same thing but uses 2 passes and so keeps each line shorter. Be sure you do it from the tail end forward as shown above to avoid having to recalculate the positions. because the entire command may not fit on one line? Anupam. __ 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] input data format of multinom in nnet
Hi, I 'd like to use multinom to estimate a multinomial logit model of a conjoint survey with a format like: individual 1 --choice -- X1-X2-X3 1-A1.2blue12 1-0-1.4red-13 1-B3.1green---17 1-0-4.2red-14 .. 2C2.1-blue11 ... 0 means this alternative did not be chosen. choice set size is 2 for each choice. As I know at this moment, multinom deal with count data format (iris data). Anybody knows if multinom can take this format as input? Thanks. __ 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] S in cor.test(..., method=spearman)
Dear HelpeRs, I have some data: ice - structure(c(0.386, 0.374, 0.393, 0.425, 0.406, 0.344, 0.327, 0.288, 0.269, 0.256, 0.286, 0.298, 0.329, 0.318, 0.381, 0.381, 0.47, 0.443, 0.386, 0.342, 0.319, 0.307, 0.284, 0.326, 0.309, 0.359, 0.376, 0.416, 0.437, 0.548, 41, 56, 63, 68, 69, 65, 61, 47, 32, 24, 28, 26, 32, 40, 55, 63, 72, 72, 67, 60, 44, 40, 32, 27, 28, 33, 41, 52, 64, 71), .Dim = as.integer(c(30, 2))) Using cor.test(ice[,1],ice[,2],method=spearman) I get (apart from a warning message due to ties) Spearman's rank correlation rho data: ice[, 1] and ice[, 2] S = 769.4403, p-value = 1.543e-08 alternative hypothesis: true rho is not equal to 0 sample estimates: rho 0.828823 I wonder what S is. I presume it is sum((rank(ice[,1])-rank(ice[,2]))^2), but this delivers 768.5. Is it the way ranks are computed in cor.test? Thank you in advance. D. Trenkler -- Dietrich Trenkler c/o Universitaet Osnabrueck Rolandstr. 8; D-49069 Osnabrueck, Germany email: [EMAIL PROTECTED] __ 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] R-question
For your 1st question, you can write query against the tables in DB using RODBC. Being a SAS programmer, I have to say that reporting function of R is not as good as that of SAS. On 9/13/06, Thorsten Muehge [EMAIL PROTECTED] wrote: Hello Colleagues, I programmed in SAS for 3 years and would like to switch to a not so costly software product. Hence I started to evaluate R, and my first test look promising. However I have some question: 1. Is it possible to query R files by SQL internally on data frames (not on a database) and how is the syntax (I have the RODBC package installed). I would like to extract year, Quarter, week, from a date column in a data frame (see attachment). After this I want to attach the column to the original data frame. How do I do this in R? Dr .Th.Mühge, PMP(r) Procurement Technology Center IBM Deutschland GmbH, Hechtsheimer Str.2, D-55131 Mainz Phone: xx49-(0)6131-84-2416 Mobile: xx49-(0)15117457978 e-mail: [EMAIL PROTECTED] (See attached file: Debug1.csv) __ 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. -- WenSui Liu (http://spaces.msn.com/statcompute/blog) Senior Decision Support Analyst Health Policy and Clinical Effectiveness Cincinnati Children Hospital Medical Center __ 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] S in cor.test(..., method=spearman)
Dietrich Trenkler said the following on 9/13/2006 9:44 AM: Dear HelpeRs, I have some data: ice - structure(c(0.386, 0.374, 0.393, 0.425, 0.406, 0.344, 0.327, 0.288, 0.269, 0.256, 0.286, 0.298, 0.329, 0.318, 0.381, 0.381, 0.47, 0.443, 0.386, 0.342, 0.319, 0.307, 0.284, 0.326, 0.309, 0.359, 0.376, 0.416, 0.437, 0.548, 41, 56, 63, 68, 69, 65, 61, 47, 32, 24, 28, 26, 32, 40, 55, 63, 72, 72, 67, 60, 44, 40, 32, 27, 28, 33, 41, 52, 64, 71), .Dim = as.integer(c(30, 2))) Using cor.test(ice[,1],ice[,2],method=spearman) I get (apart from a warning message due to ties) Spearman's rank correlation rho data: ice[, 1] and ice[, 2] S = 769.4403, p-value = 1.543e-08 alternative hypothesis: true rho is not equal to 0 sample estimates: rho 0.828823 I wonder what S is. I presume it is sum((rank(ice[,1])-rank(ice[,2]))^2), but this delivers 768.5. Is it the way ranks are computed in cor.test? Thank you in advance. D. Trenkler Looking at the code will help. Try stats:::cor.test.default This reveals that S is determined by: x - ice[, 1] y - ice[, 2] n - nrow(ice) r - cor(rank(x), rank(y)) S - (n^3 - n) * (1 - r)/6 S ## [1] 769.4403 See ?cor.test as to definition of S. HTH, --sundar __ 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] Gnuplot epslatex format also in R?
There is a Java based implementation called jfig at: http://tams-www.informatik.uni-hamburg.de/applets/jfig/ that works on windows. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Anupam Tyagi Sent: Tuesday, September 12, 2006 5:34 AM To: r-help@stat.math.ethz.ch Subject: Re: [R] Gnuplot epslatex format also in R? Prof Brian Ripley ripley at stats.ox.ac.uk writes: R has an xfig driver, and AFAIK you can do this from xfig. Is there an xfig port for Windows, without cygwin? If so, I will be thankful for a pointer to the where it can be downloaded from. I have been looking for it for some time. Anupam. __ 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@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] R-question
Wensui Liu wrote: For your 1st question, you can write query against the tables in DB using RODBC. Being a SAS programmer, I have to say that reporting function of R is not as good as that of SAS. I beg to differ. See for example http://biostat.mc.vanderbilt.edu/StatReport Frank Harrell On 9/13/06, Thorsten Muehge [EMAIL PROTECTED] wrote: Hello Colleagues, I programmed in SAS for 3 years and would like to switch to a not so costly software product. Hence I started to evaluate R, and my first test look promising. However I have some question: 1. Is it possible to query R files by SQL internally on data frames (not on a database) and how is the syntax (I have the RODBC package installed). I would like to extract year, Quarter, week, from a date column in a data frame (see attachment). After this I want to attach the column to the original data frame. How do I do this in R? Dr .Th.Mühge, PMP(r) Procurement Technology Center IBM Deutschland GmbH, Hechtsheimer Str.2, D-55131 Mainz Phone: xx49-(0)6131-84-2416 Mobile: xx49-(0)15117457978 e-mail: [EMAIL PROTECTED] (See attached file: Debug1.csv) __ 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. -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ 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] R-question
well, Harrell, I understand sweave or R2html could be a solution. but please show me their applications in a large business setting. On the contrary, I can give you many such cases using SAS. On 9/13/06, Frank E Harrell Jr [EMAIL PROTECTED] wrote: Wensui Liu wrote: For your 1st question, you can write query against the tables in DB using RODBC. Being a SAS programmer, I have to say that reporting function of R is not as good as that of SAS. I beg to differ. See for example http://biostat.mc.vanderbilt.edu/StatReport Frank Harrell On 9/13/06, Thorsten Muehge [EMAIL PROTECTED] wrote: Hello Colleagues, I programmed in SAS for 3 years and would like to switch to a not so costly software product. Hence I started to evaluate R, and my first test look promising. However I have some question: 1. Is it possible to query R files by SQL internally on data frames (not on a database) and how is the syntax (I have the RODBC package installed). I would like to extract year, Quarter, week, from a date column in a data frame (see attachment). After this I want to attach the column to the original data frame. How do I do this in R? Dr .Th.Mühge, PMP(r) Procurement Technology Center IBM Deutschland GmbH, Hechtsheimer Str.2, D-55131 Mainz Phone: xx49-(0)6131-84-2416 Mobile: xx49-(0)15117457978 e-mail: [EMAIL PROTECTED] (See attached file: Debug1.csv) __ 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. -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University -- WenSui Liu (http://spaces.msn.com/statcompute/blog) Senior Decision Support Analyst Health Policy and Clinical Effectiveness Cincinnati Children Hospital Medical Center __ 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] printing a generated function crashes R
Mstislav Elagin [EMAIL PROTECTED] writes: Dear All, the last expression in the following code snippet crashes R (version 2.3.1 on Windows XP) when run interactively: make.bad.function - function(kind) { zz - switch(kind, 1 = 1, 2 = 2) stopifnot( !is.null(zz) ) eval( bquote( function(x) { x + .(zz) })) } # bad.function - make.bad.function(5) ## error as expected bad.function - make.bad.function(1) print(bad.function(10)) ## - 11 bad.function - make.bad.function(2) print(bad.function(10)) ## - 12 bad.function## this works if the code is source()'d print(bad.function) ## oops! However, it does work (i.e. prints the body of bad.function) if run non-interactively (R --vanilla bad-function.R). Any ideas why this happens? Well, bquote seems to be doing nasty things if passed an expression with a function inside: f - bquote(function(x) { + x + 1 + } + ) f function(x) { x + 1 } eval(f) À ÈH~ ÈH~ Program received signal SIGSEGV, Segmentation fault. I think the story is that the source attribute is getting messed up. z - eval(f) attr(z,source) function(x) {(x+1}) z ÈX~ ÈX~ ..poof.. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ 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] R-question
Wensui Liu wrote: well, Harrell, I understand sweave or R2html could be a solution. but please show me their applications in a large business setting. On the contrary, I can give you many such cases using SAS. SAS requires much more coding than R/S-Plus to produce reports that are not nearly as beautiful or informative. Please define 'large business setting'. R is being used routinely in many large businesses. Frank On 9/13/06, Frank E Harrell Jr [EMAIL PROTECTED] wrote: Wensui Liu wrote: For your 1st question, you can write query against the tables in DB using RODBC. Being a SAS programmer, I have to say that reporting function of R is not as good as that of SAS. I beg to differ. See for example http://biostat.mc.vanderbilt.edu/StatReport Frank Harrell On 9/13/06, Thorsten Muehge [EMAIL PROTECTED] wrote: Hello Colleagues, I programmed in SAS for 3 years and would like to switch to a not so costly software product. Hence I started to evaluate R, and my first test look promising. However I have some question: 1. Is it possible to query R files by SQL internally on data frames (not on a database) and how is the syntax (I have the RODBC package installed). I would like to extract year, Quarter, week, from a date column in a data frame (see attachment). After this I want to attach the column to the original data frame. How do I do this in R? Dr .Th.Mühge, PMP(r) Procurement Technology Center IBM Deutschland GmbH, Hechtsheimer Str.2, D-55131 Mainz Phone: xx49-(0)6131-84-2416 Mobile: xx49-(0)15117457978 e-mail: [EMAIL PROTECTED] (See attached file: Debug1.csv) -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ 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] Gnuplot epslatex format also in R?
Greg Snow Greg.Snow at intermountainmail.org writes: There is a Java based implementation called jfig at: http://tams-www.informatik.uni-hamburg.de/applets/jfig/ that works on windows. Hope this helps, Thanks. Is there also a port of xv? It can be useful for some graphical output. I tried Gimp on windows it did not do what I thought xv would have done fine. Anupam. __ 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] Conservative ANOVA tables in lmer
[snip] Douglas Bates wrote: Hmm - I'm not sure what confidence interval and what number of levels you mean there so I can't comment on that method. Suppose we go back to Spencer's example and consider if there is a signficant effect for the Nozzle factor. That is equivalent to the hypothesis H_0: beta_2 = beta_3 = 0 versus the general alternative. A p-value could be formulated from an MCMC sample if we assume that the marginal distribution of the parameter estimates for beta_2 and beta_3 has roughly elliptical contours and you can evaluate that by, say, examining a hexbin plot of the values in the MCMC sample. One could take the ellipses as defined by the standard errors and estimated correlation or, probably better, by the observed standard deviations and correlations in the MCMC sample. Then determine the proportion of (beta_2, beta_3) pairs in the sample that fall outside the ellipse centered at the estimates and with that eccentricity and scaling factors that passes through (0,0). That would be an empirical p-value for the test. I would recommend calculating this for a couple of samples to check on the reproducibility. Here is another thought for an empirical p-value that may be easier to compute and would require fewer assumptions: Take the proportion of MCMC samples that fall into each quadrant (++, +-, -+, --) and use the smallest of these proportions as the p-value (or the smallest out of a subset of the quadrants for a one-sided style test). Think of it this way, if the smallest proportion is greater than alpha, then any closed curve (ellipse, polygon, even concave polygons) that includes 1-alpha proportion of the points would need to include points from all 4 quadrants and therefore any convex curve would have to include (0,0) which is consistent with the null hypothesis. On the other hand if there is a quadrant that contains fewer than alpha percent of the points then there exists at least one confidence region (possibly concave) that contains 1-alpha proportion of the points and excludes (0,0) and that entire quadrant, which is consistent with the alternative that at least one of the betas differs from 0. A more conservative p-value would be to take the minimum proportion and muliply it by 4 (or 2^p for p simultaneous tests) which is the same idea as multipying by 2 for a 2 sided univariate test and assumes that the confidence regions would exclude similar proportions of points in each direction (central confidence regions rather than minimum length or other confidence regions). This seems to me that it would be over conservative in some cases (since all the proportions must sum to 1, we don't really have 4 degrees of freedom and a smaller adjustment factor may still be correct and less conservative). Some simulations would be a good idea to see if the plain minimum is to liberal and how conservative the other approach is for common situations. This is just my first thoughts on the matter, I have not tested anything, so any comments or other discussion of this idea is welcome. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 __ 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] group bunch of lines in a data.frame, an additional requirement
Thanks for pointing me out aggregate, that works fine! There is one complication though: I have mixed types (numerical and character), So the matrix is of the form: A 1.0 200 ID1 A 3.0 800 ID1 A 2.0 200 ID1 B 0.5 20 ID2 B 0.9 50 ID2 C 5.0 70 ID1 One letter always has the same ID but one ID can be shared by many letters (like ID1) I just want to keep track of the ID, and get a matrix like: A 2.0 400 ID1 B 0.7 35 ID2 C 5.0 70 ID1 Any idea on how to do that without a loop? Many thanks, Emmanuel On 9/12/06, Emmanuel Levy [EMAIL PROTECTED] wrote: Hello, I'd like to group the lines of a matrix so that: A 1.0 200 A 3.0 800 A 2.0 200 B 0.5 20 B 0.9 50 C 5.0 70 Would give: A 2.0 400 B 0.7 35 C 5.0 70 So all lines corresponding to a letter (level), become a single line where all the values of each column are averaged. I've done that with a loop but it doesn't sound right (it is very slow). I imagine there is a sort of apply shortcut but I can't figure it out. Please note that it is not exactly a matrix I'm using, the function typeof tells me it's a list, however I access to it like it was a matrix. Could someone help me with the right function to use, a help topic or a piece of code? Thanks, Emmanuel __ 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] R-question
I don't believe that doing a direct SQL query on a native R object is currently possible, others have pointed out ways to do some of the things you would want SQL for using built-in R commands. If you really want to use SQL you could transfer the data frames you want to use to database tables, then query those and return the result. You may want to look at the RSQLite and SQLiteDF packages that would help with these steps without requiring any database setup outside of R. It probably not be too much work to write a function that would take an SQL query as a string and a list of data frames as arguments, copy the data frames to SQLite tables (SQLiteDF function sql.data.frame does this), then submit the query on those data frames (using RSQLite package) and return the result. Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Thorsten Muehge Sent: Wednesday, September 13, 2006 4:18 AM To: r-help@stat.math.ethz.ch Subject: [R] R-question Hello Colleagues, I programmed in SAS for 3 years and would like to switch to a not so costly software product. Hence I started to evaluate R, and my first test look promising. However I have some question: 1. Is it possible to query R files by SQL internally on data frames (not on a database) and how is the syntax (I have the RODBC package installed). I would like to extract year, Quarter, week, from a date column in a data frame (see attachment). After this I want to attach the column to the original data frame. How do I do this in R? Dr .Th.Mühge, PMP® Procurement Technology Center IBM Deutschland GmbH, Hechtsheimer Str.2, D-55131 Mainz Phone: xx49-(0)6131-84-2416 Mobile: xx49-(0)15117457978 e-mail: [EMAIL PROTECTED] (See attached file: Debug1.csv) __ 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] Reading fixed column format
Another possibility: 1) Split the original file into smaller chunks of xx,xxx of rows. 2) Process each file using read.fwf saving the requisite variables. (If necessary, save each intermediate matrix/data.frame to disk to conserve space) 3) 'rbind' the results. Not exactly elegant but it works. - Original Message - From: Gabor Grothendieck [EMAIL PROTECTED] To: Anupam Tyagi [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Sent: Wednesday, September 13, 2006 7:21 AM Subject: Re: [R] Reading fixed column format On 9/13/06, Anupam Tyagi [EMAIL PROTECTED] wrote: Gabor Grothendieck ggrothendieck at gmail.com writes: C:\bincut -c2-3,6-8 a.dat 23678 23678 23678 Thanks. I think this will work. How do I redirect the output to a file on windows? Same as on UNIX cut -c2-3,6-8 a.dat a2.dat Is there simple way to convert the cut command to a script on windows, Using notepad or other text editor put it in file a.bat and then issue this command from the console a.bat Note that you could process it multiple time if you like: cut -c6-8 a.dat a2.dat cut -c2-3 a2.dat a3.dat produces the same thing but uses 2 passes and so keeps each line shorter. Be sure you do it from the tail end forward as shown above to avoid having to recalculate the positions. because the entire command may not fit on one line? Anupam. __ 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@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] kendall's w
Hi, I try to calculate Kendall's W coefficient and I have a bizarre error. little.app.mat-matrix(c(1,3,4,2,6,5,2,4,3,1,5,6,3,2,5,1,5,4),nrow=3,byrow=TRUE) print(kendall.w(little.app.mat[-1,])) Kendall's W for ordinal data W = 0.7753623Error in if (is.na(x$p.table)) { : argument is of length zero big.app.mat-matrix(c(1,3,4,2,6,5,2,4,3,1,5,6,3,2,5,1,5,42,3,5,3,6,7,9,9,8,7),nrow=3,byrow=TRUE) print(kendall.w(big.app.mat[-1,])) Kendall's W for ordinal data W = 0.4568966 p(X2[8]) = 0.5035488 Why is that working for the big matrix and not for the little one? Thanks, Bianca __ 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] Reading fixed column format
On 9/13/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: On 9/13/06, Anupam Tyagi [EMAIL PROTECTED] wrote: Gabor Grothendieck ggrothendieck at gmail.com writes: C:\bincut -c2-3,6-8 a.dat 23678 23678 23678 Thanks. I think this will work. How do I redirect the output to a file on windows? Same as on UNIX cut -c2-3,6-8 a.dat a2.dat Is there simple way to convert the cut command to a script on windows, Using notepad or other text editor put it in file a.bat and then issue this command from the console a.bat Note that you could process it multiple time if you like: cut -c6-8 a.dat a2.dat cut -c2-3 a2.dat a3.dat Sorry that's wrong. It should be: cut -c2-3 a.dat a1.dat cut -c6-8 a.dat a2.dat Now read in each of the files, a1.dat, a2.dat into R. produces the same thing but uses 2 passes and so keeps each line shorter. Be sure you do it from the tail end forward as shown above to avoid having to recalculate the positions. because the entire command may not fit on one line? Anupam. __ 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] reshaping a dataset
Thank you Gabor, I'll need to explore a bit the reshape package to see what benefits I get compared with the basic reshape function, but I'm glad you made me aware of it. And your solution for fixing NAs just for the columns I want is just what I wanted. Many thanks, Denis Le 06-09-13 à 00:55, Gabor Grothendieck a écrit : I missed your second question which was how to set the NAs to zero for some of the columns. Suppose we want to replace the NAs in columns ic and for sake of example suppose ic specifies columns 1 to 8: library(reshape) testm - melt(test, id = 1:6) out - cast(testm, nbpc + trip + set + tagno + depth ~ prey, sum) # fix up NAs ic - 1:8 out2 - out[,ic] out2[is.na(out2)] - 0 out[,ic] - out2 On 9/13/06, Gabor Grothendieck [EMAIL PROTECTED] wrote: If I understand this correctly we want to sum the mass over each combination of the first 6 variables and display the result with the 6th, prey, along the top and the others along the side. library(reshape) testm - melt(test, id = 1:6) cast(testm, nbpc + trip + set + tagno + depth ~ prey) Now fix up the NAs. On 9/12/06, Denis Chabot [EMAIL PROTECTED] wrote: Hi, I'm trying to move to R the last few data handling routines I was performing in SAS. I'm working on stomach content data. In the simplified example I provide below, there are variables describing the origin of each prey item (nbpc is a ship number, each ship may have been used on different trips, each trip has stations, and individual fish (tagno) can be caught at each station. For each stomach the number of lines corresponds to the number of prey items. Thus a variable identifies prey type, and others (here only one, mass) provide information on prey abundance or size or digestion level. Finally, there can be accompanying variables that are not used but that I need to keep for later analyses (e.g. depth in the example below). At some point I need to transform such a dataset into another format where each stomach occupies a single line, and there are columns for each prey item. The reshape function works really well, my program is in fact simpler than the SAS equivalent (not shown, don't want to bore you, but available on request), except that I need zeros when prey types are absent from a stomach instead of NAs, a problem for which I only have a shaky solution at the moment: 1) creation of a dummy dataset: ### nbpc - rep(c(20,34), c(110,90)) trip - c(rep(1:3, c(40, 40, 30)), rep(1:2, c(60,30))) set - c(rep(1:4, c(10, 8, 7, 15)), rep(c(10,12), c(25,15)), rep (1:3, rep(10,3)), rep(10:12, c(20, 10, 30)), rep(7:8, rep(15,2))) depth - c(rep(c(100, 150, 200, 250), c(10, 8, 7, 15)), rep(c (100,120), c(25,15)), rep(c(75, 50, 200), rep(10,3)), rep(c(200, 150, 50), c(20, 10, 30)), rep(c(100, 250), rep (15,2))) tagno - rep(round(runif(42,1,200)), c(7,3, 4,4, 2,2,3, 5,5,5, 4,6,4,3,5,3, 7,8, 4,6, 5,5, 7,3, 6,6,4,4, 4,6, 3,3,4,5,5,6,4, 5,5,5, 8,7)) prey.codes -c(187, 438, 792, 811) prey - sample(prey.codes, 200, replace=T) mass - runif(200, 0, 10) test - data.frame(nbpc, trip, set, depth, tagno, prey, mass) Because there are often multiple occurrences of the same prey in a single stomach, I need to sum them for each stomach before using reshape. Here I use summarizeBy because my understanding of the many variants of apply is not very good: test2 - summaryBy(mass~nbpc+trip+set+tagno+prey, data=test, FUN=sum, keep.names=T, id=~depth) #this messes up sorting order, I fix it k - order(test2$nbpc, test2$trip, test2$set, test2$tagno) test3 - test2[k,] result - reshape(test3, v.names=mass, idvar=c(nbpc, trip, set, tagno), timevar=prey, direction=wide) # I'm quite happy with this, although you may know of better ways of doing it. But my problem is with preys that are absent from a stomach. In later analyses, I need them to have zero abundance instead of NA. My shaky solution is: # empties - is.na(result) result[empties] - 0 # which did the job in this example, but it won't always. For instance there could have been NAs for depth, which I do not want to become zero. Is there a way to transform NAs into zeros for multiple columns of a dataframe in one step, while ignoring some columns? Or maybe there is another way to achieve this that would have put zeros where I need them (i.e. something else than reshape)? Thanking you in advance, Denis Chabot __ 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] Gnuplot epslatex format also in R?
xv has been available for windows for at least 10 years. http://download.mirror.ac.uk/sites/ftp.cis.upenn.edu/pub/xv/ __ 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] Access Rows in a Data Frame by Row Name
I have created a data frame using the read.table command. I want to be able to access the rows by the row name, or a vector of row names. I know that you can access columns by using the data.frame.name$col.name. Is there a way to access row names in a similar manner? [[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.
Re: [R] Course***Dr Frank Harrell's Regression Modeling Strategies in R/Splus course *** September 2006 near you (San Francisco, Washington DC, Atlanta)
Anyone from Chicago area interested in this course? Please email XLSolutions so they can schedule it in Chicago. We ran out of travel budget in my company :( Date: Wed, 2 Aug 2006 13:20:23 -0700From: [EMAIL PROTECTED]: [S] Course***Dr Frank Harrell's Regression Modeling Strategies in R/Splus course *** September 2006 near you (San Francisco, Washington DC, Atlanta)To: [EMAIL PROTECTED] XLSolutions Corporation (www.xlsolutions-corp.com) is very proud to announce Dr Frank Harrell's Regression Modeling Strategies in R/Splus this September 2006. http://xlsolutions-corp.com/Rstats2.htm *** San Francisco, CA / August 31st - September 1st, 2006 *** *** Atlanta, GA / September 18th - 19th, 2006 *** *** Washington, DC / September 28th - 29th, 2006 *** Please ask for group discount and reserve your seat Now - Earlybird Rates.Note that payment is due after the class! Email Sue Turner: [EMAIL PROTECTED] http://xlsolutions-corp.com/Rstats2.htm This two-day course is designed for persons interested in multivariable regression analysis of univariate responses, in developing, validating, and graphically describing multivariable predictive models. The first part of the course presents the following elements of multivariable predictive modeling for a single response variable: using regression splines to relax linearity assumptions, perils of variable selection and overfitting, where to spend degrees of freedom, shrinkage, imputation of missing data, data reduction, and interaction surfaces. Then a default overall modeling strategy will be described. This is followed by methods for graphically understanding models (e.g., using nomograms) and using re-sampling to estimate a model's likely performance on new data. Then the freely available S-Plus Design library will be overviewed. Design facilitates most of the steps of the modeling process. Next, statistical methods related to binary logistic models will be covered. Thre! e of the following case studies will be presented: an exploration of voting tendencies over U.S. counties in the 1992 presidential election, an interactive exploration of the survival status of Titanic passengers, an interactive case study in developing a survival time model, and a case study in Cox regression. In the hands-on computer lab students will develop, validate, and graphically describe multivariable regression models themselves. This short course will also survey the advantages of modeling in randomized trials. The methods covered in this course will apply to almost any regression model, including ordinary least squares, logistic regression models, and survival models. Course Outline: http://xlsolutions-corp.com/Rstats2.htm - Planning for Modeling, Covariable Adjustment. - Notation for Regression Models, Interpreting Model Parameters. - Relaxing Linearity Assumption for Continuous Predictors; Splines for Estimating Shape of Regression Function and Determining Predictor Transformations, Cubic Spline Functions, Advantages of Splines over Other Methods. - Tests of Association, Assessment of Model Fit; Regression Assumptions Modeling and Testing Interactions. - Missing Data; Strategies for Developing Imputation Algorithms , software for Fitting Models and Adjusting Variances for Multiple Imputation. - Multivariable Modeling Strategy; Pre-Specification of Predictor Complexity ,Variable Selection ,Overfitting and Limits on Number of Predictors, Shrinkage, Data Reduction. - Resampling, Validating, Describing, and Simplifying the Model; The Bootstrap, Model Validation , Graphically Describing the Fitted Model, Simplifying the Model by Approximating It. - Design library - Binary Logistic Regress! ion, Interactive Case Study: Binary Logistic Model for Survival of Titanic Passengers. - Interactive Case Study: Development of a Long-Term Survival Model for Critically Ill Patients. - Cox Proportional Hazards Model, Case Study in Cox Regression. - Case Study using Least Squares Multiple Regression: Voting Patterns in U.S. Counties. Email us for group discounts.Email Sue Turner: [EMAIL PROTECTED]: 206-686-1578Visit us: http://xlsolutions-corp.com/Rstats2.htmPlease let us know if you and your colleagues are interested in thisclass to take advantage of group discount. Register now to secure yourseat! Cheers,Elvis Miller, PhDManager Training.XLSolutions Corporation206 686 [EMAIL PROTECTED] _ Check the weather nationwide with MSN Search: Try it now! [[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.
Re: [R] group bunch of lines in a data.frame, an additional requirement
Try something like this: # Initial data frame DF V1 V2 V3 V4 1 A 1.0 200 ID1 2 A 3.0 800 ID1 3 A 2.0 200 ID1 4 B 0.5 20 ID2 5 B 0.9 50 ID2 6 C 5.0 70 ID1 # Now do the aggregation to get the means DF.1 - aggregate(DF[, 2:3], list(V1 = DF$V1), mean) DF.1 V1 V2 V3 1 A 2.0 400 2 B 0.7 35 3 C 5.0 70 # Now get the unique combinations of letters and IDs in DF DF.U - unique(DF[, c(V1, V4)]) DF.U V1 V4 1 A ID1 4 B ID2 6 C ID1 # Now merge the two data frames together, matching the letters DF.NEW - merge(DF.1, DF.U, by = V1) DF.NEW V1 V2 V3 V4 1 A 2.0 400 ID1 2 B 0.7 35 ID2 3 C 5.0 70 ID1 See ?unique and ?merge for more information. Also, for the sake of clarification, these are not matrices, but data frames. A matrix may contain only one data type, whereas data frames are specifically designed to contain multiple data types as you have here. HTH, Marc Schwartz On Wed, 2006-09-13 at 17:38 +0100, Emmanuel Levy wrote: Thanks for pointing me out aggregate, that works fine! There is one complication though: I have mixed types (numerical and character), So the matrix is of the form: A 1.0 200 ID1 A 3.0 800 ID1 A 2.0 200 ID1 B 0.5 20 ID2 B 0.9 50 ID2 C 5.0 70 ID1 One letter always has the same ID but one ID can be shared by many letters (like ID1) I just want to keep track of the ID, and get a matrix like: A 2.0 400 ID1 B 0.7 35 ID2 C 5.0 70 ID1 Any idea on how to do that without a loop? Many thanks, Emmanuel On 9/12/06, Emmanuel Levy [EMAIL PROTECTED] wrote: Hello, I'd like to group the lines of a matrix so that: A 1.0 200 A 3.0 800 A 2.0 200 B 0.5 20 B 0.9 50 C 5.0 70 Would give: A 2.0 400 B 0.7 35 C 5.0 70 So all lines corresponding to a letter (level), become a single line where all the values of each column are averaged. I've done that with a loop but it doesn't sound right (it is very slow). I imagine there is a sort of apply shortcut but I can't figure it out. Please note that it is not exactly a matrix I'm using, the function typeof tells me it's a list, however I access to it like it was a matrix. Could someone help me with the right function to use, a help topic or a piece of code? Thanks, Emmanuel __ 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] group bunch of lines in a data.frame, an additional requirement
See below. On 9/13/06, Emmanuel Levy [EMAIL PROTECTED] wrote: Thanks for pointing me out aggregate, that works fine! There is one complication though: I have mixed types (numerical and character), So the matrix is of the form: A 1.0 200 ID1 A 3.0 800 ID1 A 2.0 200 ID1 B 0.5 20 ID2 B 0.9 50 ID2 C 5.0 70 ID1 One letter always has the same ID but one ID can be shared by many letters (like ID1) I just want to keep track of the ID, and get a matrix like: A 2.0 400 ID1 B 0.7 35 ID2 C 5.0 70 ID1 Any idea on how to do that without a loop? If V4 is a function of V1 then you can aggregate by it too and it will appear but have no effect on the classification: aggregate(DF[2:3], DF[c(1,4)], mean) V1 V4 V2 V3 1 A ID1 2.0 400 2 C ID1 5.0 70 3 B ID2 0.7 35 Many thanks, Emmanuel On 9/12/06, Emmanuel Levy [EMAIL PROTECTED] wrote: Hello, I'd like to group the lines of a matrix so that: A 1.0 200 A 3.0 800 A 2.0 200 B 0.5 20 B 0.9 50 C 5.0 70 Would give: A 2.0 400 B 0.7 35 C 5.0 70 So all lines corresponding to a letter (level), become a single line where all the values of each column are averaged. I've done that with a loop but it doesn't sound right (it is very slow). I imagine there is a sort of apply shortcut but I can't figure it out. Please note that it is not exactly a matrix I'm using, the function typeof tells me it's a list, however I access to it like it was a matrix. Could someone help me with the right function to use, a help topic or a piece of code? Thanks, Emmanuel __ 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@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] kendall's w
I assume you are using the function in the concord package. This seems to happen because there is a different way of calculating the p-value depending on whether or not there are more than 7 cases. If there are 7 or less, the function doesn't work unless there are more than two rows. Here is the relevant code fragment: if (datadim[2] 7) { p.table - NA x2df - datadim[2] - 1 p.chisq - pchisq(datadim[1] * (datadim[2] - 1) * W, x2df, lower.tail = FALSE) } else { p.table - ifelse(W Wcrit01[datadim[2] - 2, datadim[1] - 2], 0.01, ifelse(W Wcrit05[datadim[2] - 2, datadim[1] - 2], 0.05, 0.05)) x2df - NA p.chisq - NA } On 13/09/06, Bianca Vieru [EMAIL PROTECTED] wrote: Hi, I try to calculate Kendall's W coefficient and I have a bizarre error. little.app.mat -matrix(c(1,3,4,2,6,5,2,4,3,1,5,6,3,2,5,1,5,4),nrow=3,byrow=TRUE) print(kendall.w(little.app.mat[-1,])) Kendall's W for ordinal data W = 0.7753623Error in if ( is.na(x$p.table)) { : argument is of length zero big.app.mat -matrix(c(1,3,4,2,6,5,2,4,3,1,5,6,3,2,5,1,5,42,3,5,3,6,7,9,9,8,7),nrow=3,byrow=TRUE) print(kendall.w(big.app.mat[-1,])) Kendall's W for ordinal data W = 0.4568966 p(X2[8]) = 0.5035488 Why is that working for the big matrix and not for the little one? Thanks, Bianca __ 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. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP [[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.
Re: [R] Access Rows in a Data Frame by Row Name
Matrix-style indexing works for both columns and rows of data frames. E.g.: x - data.frame(a=1:5, b=6:10, d=11:15) x a b d 1 1 6 11 2 2 7 12 3 3 8 13 4 4 9 14 5 5 10 15 x[2:4,c(1,3)] a d 2 2 12 3 3 13 4 4 14 Time spend reading the help document An Introduction to R will probably be well worth it. The relevant sections are 5 Arrays and matrices, and 6.3 Data frames. -- Tony Plate Michael Gormley wrote: I have created a data frame using the read.table command. I want to be able to access the rows by the row name, or a vector of row names. I know that you can access columns by using the data.frame.name$col.name. Is there a way to access row names in a similar manner? [[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-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] reformat records one to several
Hi, I am a new user of R and am still trying to figure out which statements do which functions and am looking for a jump start. I have a dataset where the data were collected as ten minute counts where the number of new individuals within a species was recorded as cohorts within 3 separate time intervals within the ten minute count persiod. Each row of data therefore follows a format like this: DateTime SampleSpecies t1 t2 t3 June 5,2006 5:20 AM AUSFAKE01 OVEN3 0 1 etc. I would like to reformat these data as if the counts recorded only individuals and not cohorts, so that the above would look as follows DateTime SampleSpecies t1 t2 t3 June 5,2006 5:20 AM AUSFAKE01 OVEN1 0 0 June 5,2006 5:20 AM AUSFAKE01 OVEN1 0 0 June 5,2006 5:20 AM AUSFAKE01 OVEN1 0 0 June 5,2006 5:20 AM AUSFAKE01 OVEN0 0 1 etc. I believe I could do this in SAS with IF, THEN and DO statements, e.g. if t10 then do i=1 to t1 output Date,Time,Sample,Species,1,0,0; if t20 then do i=1 to t2 output Date,Time,Sample,Species,0,1,0; if t30 then do i=1 to t3 output Date,Time,Sample,Species,0,0,1; end; Can anyone point me in the right direction? What is the similar statement to DO in R? Steve VW __ 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] Access Rows in a Data Frame by Row Name
The answer is yes, you can access rows of a data.frame by rowname in the same way as columns, which you could have found by merely trying it. Don't overlook the value of a little experimentation as the fastest way to an answer. -- Bert Gunter Genentech -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tony Plate Sent: Wednesday, September 13, 2006 11:02 AM To: Michael Gormley Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Access Rows in a Data Frame by Row Name Matrix-style indexing works for both columns and rows of data frames. E.g.: x - data.frame(a=1:5, b=6:10, d=11:15) x a b d 1 1 6 11 2 2 7 12 3 3 8 13 4 4 9 14 5 5 10 15 x[2:4,c(1,3)] a d 2 2 12 3 3 13 4 4 14 Time spend reading the help document An Introduction to R will probably be well worth it. The relevant sections are 5 Arrays and matrices, and 6.3 Data frames. -- Tony Plate Michael Gormley wrote: I have created a data frame using the read.table command. I want to be able to access the rows by the row name, or a vector of row names. I know that you can access columns by using the data.frame.name$col.name. Is there a way to access row names in a similar manner? [[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-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@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] Dear FE Harrell How can I get rreport ?
Mr Harrell, After reading discussion about R output and SAS output , I will like to use rreport package. I a windows XP user Sincerly - Message d'origine De : Frank E Harrell Jr [EMAIL PROTECTED] À : Wensui Liu [EMAIL PROTECTED] Cc : Thorsten Muehge [EMAIL PROTECTED]; r-help@stat.math.ethz.ch Envoyé le : Mercredi, 13 Septembre 2006, 4h49mn 01s Objet : Re: [R] R-question Wensui Liu wrote: For your 1st question, you can write query against the tables in DB using RODBC. Being a SAS programmer, I have to say that reporting function of R is not as good as that of SAS. I beg to differ. See for example http://biostat.mc.vanderbilt.edu/StatReport Frank Harrell On 9/13/06, Thorsten Muehge [EMAIL PROTECTED] wrote: Hello Colleagues, I programmed in SAS for 3 years and would like to switch to a not so costly software product. Hence I started to evaluate R, and my first test look promising. However I have some question: 1. Is it possible to query R files by SQL internally on data frames (not on a database) and how is the syntax (I have the RODBC package installed). I would like to extract year, Quarter, week, from a date column in a data frame (see attachment). After this I want to attach the column to the original data frame. How do I do this in R? Dr .Th.Mühge, PMP(r) Procurement Technology Center IBM Deutschland GmbH, Hechtsheimer Str.2, D-55131 Mainz Phone: xx49-(0)6131-84-2416 Mobile: xx49-(0)15117457978 e-mail: [EMAIL PROTECTED] (See attached file: Debug1.csv) __ 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. -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ 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. [[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] Question about optim on survival data with censored data
I have a model which is mixed exponential model, with about 40 observations. I am wandering whether i can use the optim to optimized the parameters? Thank you very much. __ 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] Conservative ANOVA tables in lmer
On Wed, Sep 13, 2006 at 07:04:17AM -0400, Manuel Morales wrote: On Wed, 2006-09-13 at 08:04 +1000, Andrew Robinson wrote: On Tue, September 12, 2006 7:34 am, Manuel Morales wrote: On Mon, 2006-09-11 at 11:43 -0500, Douglas Bates wrote: Having made that offer I think I will now withdraw it. Peter's example has convinced me that this is the wrong thing to do. I am encouraged by the fact that the results from mcmcsamp correspond closely to the correct theoretical results in the case that Peter described. I appreciate that some users will find it difficult to work with a MCMC sample (or to convince editors to accept results based on such a sample) but I think that these results indicate that it is better to go after the marginal distribution of the fixed effects estimates (which is what is being approximated by the MCMC sample - up to Bayesian/frequentist philosophical differences) than to use the conditional distribution and somehow try to adjust the reference distribution. Am I right that the MCMC sample can not be used, however, to evaluate the significance of parameter groups. For example, to assess the significance of a three-level factor? Are there better alternatives than simply adjusting the CI for the number of factor levels (1-alpha/levels). I wonder whether the likelihood ratio test would be suitable here? That seems to be supported. It just takes a little longer. require(lme4) data(sleepstudy) fm1 - lmer(Reaction ~ Days + (Days|Subject), sleepstudy) fm2 - lmer(Reaction ~ Days + I(Days^2) + (Days|Subject), sleepstudy) anova(fm1, fm2) So, a brief overview of the popular inferential needs and solutions would then be: 1) Test the statistical significance of one or more fixed or random effects - fit a model with and a model without the terms, and use the LRT. I believe that the LRT is anti-conservative for fixed effects, as described in Pinheiro and Bates companion book to NLME. Yes, you are right. I had forgotten that. Back to square one :). Bert Gunter also kindly pointed this out to me. Cherse Andrew 2) Obtain confidence intervals for one or more fixed or random effects - use mcmcsamp Did I miss anything important? - What else would people like to do? Cheers Andrew Andrew Robinson Senior Lecturer in Statistics Tel: +61-3-8344-9763 Department of Mathematics and StatisticsFax: +61-3-8344 4599 University of Melbourne, VIC 3010 Australia Email: [EMAIL PROTECTED]Website: http://www.ms.unimelb.edu.au __ 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. -- Andrew Robinson Department of Mathematics and StatisticsTel: +61-3-8344-9763 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 Email: [EMAIL PROTECTED] http://www.ms.unimelb.edu.au __ 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] About truncated distribution
Inspired by the responses, I tried to do this analytically. The idea is that truncated mean and standard deviation could be expressed as integral forms. So if given truncated mean, sd and truncated point (mut, sdt, thre), an optim( ) function could be writen to get the parameters. But the problem is, pdf is needed in advance to shape the normal curve. So I think it is possible to do this in an iterative optimization, given assummed initial sigma and mu, if the optimization meets requirements, then the sigma and mu could be considered as the real numbers. I tried to do these by : f - function(x,sigma,mu) (1/(sigma*sqrt(2*pi)))*exp(-(x-mu)^2/(2*sigma^2)) pdf.fun - function(x) x*f(x); sd.fun - function(x) x^2*f(x); #-- define a few functions solve.fun - function(sigma,mu,thre,mut,sdt) { (mut-integrate(pdf.fun,thre,upper=Inf)$value/integrate(f,thre,upper=Inf)$value)^2 +(sdt - integrate(sd.fun,thre,upper=Inf)$value/integrate(f,thre,upper=Inf)$value-(integrate(pdf.fun,thre,upper=Inf)$value/integrate(f,thre,upper=Inf)$value)^2)^2 } I wish this solve.fun ( ) could be minimized and then gives minimum = 5 for( i in 1:100) { mu - 200;sigma - 20; thre - 160; mut - 230; sdt - 15; sol.tem - optimize(solve.fun, lower =0.1,upper =100,tol=0.001); if (sol.tem$minimum= 5) return(sol.tem) } I know my codes is just awkward, and not really working. But I expect some advice and suggestion about the methods. Am I going in a wrong way since I have been working on it for a long time. Thanks a lot! Jen -Original Message- From:Ritwik Sinha , [EMAIL PROTECTED] Sent: 2006-09-12, 17:20:04 To: CC:jennystadt; r-help@stat.math.ethz.ch Subject: Re: [R] About truncated distribution However, if you know the point(s) of truncation then you should be able to work your way back. Look for the mean and variance of a truncated normal, it will involve mu, sigma and c (point of truncation). You will need to solve for mu and sigma from two equation. For example look at the wikipedia page on normal distribution, it has the mean of a truncated normal distribution. Many standard statistics books should have the rest of the information. On 9/12/06, Berton Gunter [EMAIL PROTECTED] wrote: But my question is a bit different. What I know is the mean and sd after truncation. If I assume the distribution is normal, how I am gonna develope the original distribution using this two parameters? You can't, as they are plainly not sufficient (you need to know the amount of truncation also). If you have only the mean and sd and neither the actual data nor the truncation point you're through. -- Bert Gunter Genentech Could anybody give me some advice? Thanks in advance! Jen [[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-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. -- Ritwik Sinha Graduate Student Epidemiology and Biostatistics Case Western Reserve University http://darwin.cwru.edu/~rsinha [[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] recursive methods for concatenating sets of files
Hello, I would like to read sets of files within a folder, perhaps using recursive methods. Right now, I rename the files before import. It would be even better to do this without renaming files, without providing explicit filenames, perhaps by importing files based on chronology, and translating each filename into a header? Please excuse my ignorance, and help cure my clunky programming (below) with more elegant code. Thanks, Warren data0 -read.delim(t.txt, quote=, as.is=TRUE) data1 -read.delim(t (1).txt, quote=, as.is=TRUE) data2 -read.delim(t (2).txt, quote=, as.is=TRUE) data3 -read.delim(t (3).txt, quote=, as.is=TRUE) data4 -read.delim(t (4).txt, quote=, as.is=TRUE) data5 -read.delim(t (5).txt, quote=, as.is=TRUE) data6 -read.delim(t (6).txt, quote=, as.is=TRUE) data7 -read.delim(t (7).txt, quote=, as.is=TRUE) data8 -read.delim(t (8).txt, quote=, as.is=TRUE) data9 -read.delim(t (9).txt, quote=, as.is=TRUE) data10 -read.delim(t (10).txt, quote=, as.is=TRUE) data11 -read.delim(t (11).txt, quote=, as.is=TRUE) data12 -read.delim(t (12).txt, quote=, as.is=TRUE) data13 -read.delim(t (13).txt, quote=, as.is=TRUE) data14 -read.delim(t (14).txt, quote=, as.is=TRUE) data15 -read.delim(t (15).txt, quote=, as.is=TRUE) data16 -read.delim(t (16).txt, quote=, as.is=TRUE) data17 -read.delim(t (17).txt, quote=, as.is=TRUE) data18 -read.delim(t (18).txt, quote=, as.is=TRUE) data19 -read.delim(t (19).txt, quote=, as.is=TRUE) data20 -read.delim(t (20).txt, quote=, as.is=TRUE) data21 -read.delim(t (21).txt, quote=, as.is=TRUE) data22 -read.delim(t (22).txt, quote=, as.is=TRUE) data23 -read.delim(t (23).txt, quote=, as.is=TRUE) data24 -read.delim(t (24).txt, quote=, as.is=TRUE) data25 -read.delim(t (25).txt, quote=, as.is=TRUE) data26 -read.delim(t (26).txt, quote=, as.is=TRUE) data27 -read.delim(t (27).txt, quote=, as.is=TRUE) data28 -read.delim(t (28).txt, quote=, as.is=TRUE) data29 -read.delim(t (29).txt, quote=, as.is=TRUE) data30 -read.delim(t (30).txt, quote=, as.is=TRUE) data31 -read.delim(t (31).txt, quote=, as.is=TRUE) data32 -read.delim(t (32).txt, quote=, as.is=TRUE) data33 -read.delim(t (33).txt, quote=, as.is=TRUE) data34 -read.delim(t (34).txt, quote=, as.is=TRUE) data35 -read.delim(t (35).txt, quote=, as.is=TRUE) data36 -read.delim(t (36).txt, quote=, as.is=TRUE) data37 -read.delim(t (37).txt, quote=, as.is=TRUE) data38 -read.delim(t (38).txt, quote=, as.is=TRUE) data39 -read.delim(t (39).txt, quote=, as.is=TRUE) data40 -read.delim(t (40).txt, quote=, as.is=TRUE) data41 -read.delim(t (41).txt, quote=, as.is=TRUE) data42 -read.delim(t (42).txt, quote=, as.is=TRUE) data43 -read.delim(t (43).txt, quote=, as.is=TRUE) data44 -read.delim(t (44).txt, quote=, as.is=TRUE) data45 -read.delim(t (45).txt, quote=, as.is=TRUE) data46 -read.delim(t (46).txt, quote=, as.is=TRUE) data47 -read.delim(t (47).txt, quote=, as.is=TRUE) data48 -read.delim(t (48).txt, quote=, as.is=TRUE) data49 -read.delim(t (49).txt, quote=, as.is=TRUE) data50 -read.delim(t (50).txt, quote=, as.is=TRUE) data51 -read.delim(t (51).txt, quote=, as.is=TRUE) data52 -read.delim(t (52).txt, quote=, as.is=TRUE) data53 -read.delim(t (53).txt, quote=, as.is=TRUE) data54 -read.delim(t (54).txt, quote=, as.is=TRUE) data55 -read.delim(t (55).txt, quote=, as.is=TRUE) data56 -read.delim(t (56).txt, quote=, as.is=TRUE) data57 -read.delim(t (57).txt, quote=, as.is=TRUE) data58 -read.delim(t (58).txt, quote=, as.is=TRUE) data59 -read.delim(t (59).txt, quote=, as.is=TRUE) data60 -read.delim(t (60).txt, quote=, as.is=TRUE) data61 -read.delim(t (61).txt, quote=, as.is=TRUE) data62 -read.delim(t (62).txt, quote=, as.is=TRUE) data63 -read.delim(t (63).txt, quote=, as.is=TRUE) data64 -read.delim(t (64).txt, quote=, as.is=TRUE) data65 -read.delim(t (65).txt, quote=, as.is=TRUE) data66 -read.delim(t (66).txt, quote=, as.is=TRUE) data67 -read.delim(t (67).txt, quote=, as.is=TRUE) data68 -read.delim(t (68).txt, quote=, as.is=TRUE) data69 -read.delim(t (69).txt, quote=, as.is=TRUE) data70 -read.delim(t (70).txt, quote=, as.is=TRUE) data71 -read.delim(t (71).txt, quote=, as.is=TRUE) data72 -read.delim(t (72).txt, quote=, as.is=TRUE) data73 -read.delim(t (73).txt, quote=, as.is=TRUE) data74 -read.delim(t (74).txt, quote=, as.is=TRUE) data75 -read.delim(t (75).txt, quote=, as.is=TRUE) dataALL -cbind(data0,data1,data2,data3,data4,data5,data6,data7,data8,data9,data10,data11,data12,data13,data14,data15,data16,data17,data18,data19,data20,data21,data22,data23,data24,data25,data26,data27,data28,data29,data20,data31,data32,data33,data34,data35,data36,data37,data38,data39,data40,data41,data42,data43,data44,data45,data46,data47,data48,data49,data50,data51,data52,data53,data54,data55,data56,data57,data58,data59,data60,data61,data62,data63,data64,data65,data66,data67,data68,data69,data70,data71,data72,data73,data74,data75) write.table(dataALL,0905p528.txt, quote=FALSE) -- [EMAIL PROTECTED]
[R] an error message with 't.test' with R under Unix
Hi list,Could you please help me to explain the following error messages with 't.test' in R Unix 2.1.1? I don't see it in R under Windows (R 2.3.0) or Unix (R2.3.1). Is it really due to the different R versions?Thanks,...TaoUnix session: (R.2.1.1) R.version _ platform x86_64-unknown-linux-gnuarch x86_64 os linux-gnu system x86_64, linux-gnu status major2 minor1.1 year 2005month06 day 20 language Rt.test(extra ~ group, data = sleep)Welch Two Sample t-testdata: extra by group t = -1.8608, df = 17.776, p-value = 0.0794alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -3.3654832 0.2054832 sample estimates:mean in group 1 mean in group 2! 0.752.33 t.test((1:6)~rep(1:2,each=3))Error in terms.formula(formula[-3]) : invalid model formula in ExtractVars t.test(2^(1:6)~rep(1:2,each=3))Error in terms.formula(formula[-3]) : invalid power in formula t.test(2^extra ~ group, data = sleep)Error in terms.formula(formula[-3]) : invalid power in formulaUnix session: (R 2.3.1) R.version _ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 3.1 year 2006 month 06day 01svn rev38247 language R version.string Version 2.3.1 (2006-06-01) t.test(1:6~rep(1:2,each=! 3))Welch Two Sample t-testdata: 1:6 by rep(1:2, each = 3) t = -3.6742, df = 4, p-value = 0.02131alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -5.266958 -0.733042 sample estimates:mean in group 1 mean in group 2 2 5 Windows session:=== R.version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 3.0 year 2006 month 04day 24svn rev37909 language R version.string Version 2.3.0 (2006-04-24) help(t.test) t.test(extra ~ group, data = sleep)Welch Two Sample t-testdata: extra by group t = -1.8608, df = 17.7! 76, p-value = 0.0794alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -3.3654832 0.2054832 sample estimates:mean in group 1 mean in group 20.752.33 t.test(2^extra ~ group, data = sleep)Welch Two Sample t-testdata: 2^extra by group t = -1.6362, df = 10.718, p-value = 0.1308alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -18.641557 2.773344 sample estimates:mean in group 1 mean in group 23.448644 11.382751 t.test(1:6~rep(1:2,each=3))Welch Two Sample t-testdata: 1:6 by rep(1:2, each = 3) t = -3.6742, df = 4, p-value = 0.02131alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -5.266958 -0.733042 sample estimates:mean in group 1 mean in group 2 2 5 _ Use Messenger to talk to your IM friends, even those on Yahoo! 685ee3e858fe [[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.
Re: [R] inserting columns in the middle of a dataframe
Dear R users: Is there a built-in and simple way to insert new columns after other columns in a dataframe? I.e. currently I have: V1 V2 V3 V4 [1,] [2,] Etc. But I want V1 V5 V2 V3 V4 [1,] [2,] Etc. Can this be done in one line? Jon Minton [[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.
Re: [R] recursive methods for concatenating sets of files
Try this: setwd(d:/perf/windows) # wherever your data is results - list() for (i in list.files(pattern=t.*txt$)){ # need the 'pattern' of the names results[[i]] - read.delim(i, quote='', as.is=TRUE) } dataALL - do.call('cbind', results) write.table(dataALL,0905p528.txt, quote=FALSE) On 9/13/06, Warren [EMAIL PROTECTED] wrote: Hello, I would like to read sets of files within a folder, perhaps using recursive methods. Right now, I rename the files before import. It would be even better to do this without renaming files, without providing explicit filenames, perhaps by importing files based on chronology, and translating each filename into a header? Please excuse my ignorance, and help cure my clunky programming (below) with more elegant code. Thanks, Warren data0 -read.delim(t.txt, quote=, as.is=TRUE) data1 -read.delim(t (1).txt, quote=, as.is=TRUE) data2 -read.delim(t (2).txt, quote=, as.is=TRUE) data3 -read.delim(t (3).txt, quote=, as.is=TRUE) data4 -read.delim(t (4).txt, quote=, as.is=TRUE) data5 -read.delim(t (5).txt, quote=, as.is=TRUE) data6 -read.delim(t (6).txt, quote=, as.is=TRUE) data7 -read.delim(t (7).txt, quote=, as.is=TRUE) data8 -read.delim(t (8).txt, quote=, as.is=TRUE) data9 -read.delim(t (9).txt, quote=, as.is=TRUE) data10 -read.delim(t (10).txt, quote=, as.is=TRUE) data11 -read.delim(t (11).txt, quote=, as.is=TRUE) data12 -read.delim(t (12).txt, quote=, as.is=TRUE) data13 -read.delim(t (13).txt, quote=, as.is=TRUE) data14 -read.delim(t (14).txt, quote=, as.is=TRUE) data15 -read.delim(t (15).txt, quote=, as.is=TRUE) data16 -read.delim(t (16).txt, quote=, as.is=TRUE) data17 -read.delim(t (17).txt, quote=, as.is=TRUE) data18 -read.delim(t (18).txt, quote=, as.is=TRUE) data19 -read.delim(t (19).txt, quote=, as.is=TRUE) data20 -read.delim(t (20).txt, quote=, as.is=TRUE) data21 -read.delim(t (21).txt, quote=, as.is=TRUE) data22 -read.delim(t (22).txt, quote=, as.is=TRUE) data23 -read.delim(t (23).txt, quote=, as.is=TRUE) data24 -read.delim(t (24).txt, quote=, as.is=TRUE) data25 -read.delim(t (25).txt, quote=, as.is=TRUE) data26 -read.delim(t (26).txt, quote=, as.is=TRUE) data27 -read.delim(t (27).txt, quote=, as.is=TRUE) data28 -read.delim(t (28).txt, quote=, as.is=TRUE) data29 -read.delim(t (29).txt, quote=, as.is=TRUE) data30 -read.delim(t (30).txt, quote=, as.is=TRUE) data31 -read.delim(t (31).txt, quote=, as.is=TRUE) data32 -read.delim(t (32).txt, quote=, as.is=TRUE) data33 -read.delim(t (33).txt, quote=, as.is=TRUE) data34 -read.delim(t (34).txt, quote=, as.is=TRUE) data35 -read.delim(t (35).txt, quote=, as.is=TRUE) data36 -read.delim(t (36).txt, quote=, as.is=TRUE) data37 -read.delim(t (37).txt, quote=, as.is=TRUE) data38 -read.delim(t (38).txt, quote=, as.is=TRUE) data39 -read.delim(t (39).txt, quote=, as.is=TRUE) data40 -read.delim(t (40).txt, quote=, as.is=TRUE) data41 -read.delim(t (41).txt, quote=, as.is=TRUE) data42 -read.delim(t (42).txt, quote=, as.is=TRUE) data43 -read.delim(t (43).txt, quote=, as.is=TRUE) data44 -read.delim(t (44).txt, quote=, as.is=TRUE) data45 -read.delim(t (45).txt, quote=, as.is=TRUE) data46 -read.delim(t (46).txt, quote=, as.is=TRUE) data47 -read.delim(t (47).txt, quote=, as.is=TRUE) data48 -read.delim(t (48).txt, quote=, as.is=TRUE) data49 -read.delim(t (49).txt, quote=, as.is=TRUE) data50 -read.delim(t (50).txt, quote=, as.is=TRUE) data51 -read.delim(t (51).txt, quote=, as.is=TRUE) data52 -read.delim(t (52).txt, quote=, as.is=TRUE) data53 -read.delim(t (53).txt, quote=, as.is=TRUE) data54 -read.delim(t (54).txt, quote=, as.is=TRUE) data55 -read.delim(t (55).txt, quote=, as.is=TRUE) data56 -read.delim(t (56).txt, quote=, as.is=TRUE) data57 -read.delim(t (57).txt, quote=, as.is=TRUE) data58 -read.delim(t (58).txt, quote=, as.is=TRUE) data59 -read.delim(t (59).txt, quote=, as.is=TRUE) data60 -read.delim(t (60).txt, quote=, as.is=TRUE) data61 -read.delim(t (61).txt, quote=, as.is=TRUE) data62 -read.delim(t (62).txt, quote=, as.is=TRUE) data63 -read.delim(t (63).txt, quote=, as.is=TRUE) data64 -read.delim(t (64).txt, quote=, as.is=TRUE) data65 -read.delim(t (65).txt, quote=, as.is=TRUE) data66 -read.delim(t (66).txt, quote=, as.is=TRUE) data67 -read.delim(t (67).txt, quote=, as.is=TRUE) data68 -read.delim(t (68).txt, quote=, as.is=TRUE) data69 -read.delim(t (69).txt, quote=, as.is=TRUE) data70 -read.delim(t (70).txt, quote=, as.is=TRUE) data71 -read.delim(t (71).txt, quote=, as.is=TRUE) data72 -read.delim(t (72).txt, quote=, as.is=TRUE) data73 -read.delim(t (73).txt, quote=, as.is=TRUE) data74 -read.delim(t (74).txt, quote=, as.is=TRUE) data75 -read.delim(t (75).txt, quote=, as.is=TRUE) dataALL
Re: [R] recursive methods for concatenating sets of files
On Wed, 13 Sep 2006 13:53:45 -0700, Warren [EMAIL PROTECTED] wrote: Hello, I would like to read sets of files within a folder, perhaps using recursive methods. Maybe this: fv - list.files() lf - sapply(fv, read.delim, quote=, as.is=TRUE) xx - do.call(cbind, lf) You can find more info in the respective help pages. -- Seb __ 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] an error message with 't.test' with R under Unix
Tao Shi [EMAIL PROTECTED] writes: Hi list,Could you please help me to explain the following error messages with 't.test' in R Unix 2.1.1? This is completely unreadable! However, yes, there was at some point a bug where the LHS of model formulas was checked more rigorously than need be, using the same rules that apply to the RHS. This fact can be found in a recent NEWS file. I don't see it in R under Windows (R 2.3.0) or Unix (R2.3.1). Is it really due to the different R versions?Thanks,...TaoUnix session: (R.2.1.1) R.version _ platform x86_64-unknown-linux-gnuarch x86_64 os linux-gnu system x86_64, linux-gnu status major2 minor1.1 year 2005month06 day 20 language Rt.test(extra ~ group, data = sleep)Welch Two Sample t-testdata: extra by group t = -1.8608, df = 17.776, p-value = 0.0794alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -3.3654832 0.2054832 sample estimates:mean in group 1 mean in group 2! 0.752.33 t.test((1:6)~rep(1:2,each=3))Error in terms.formula(formula[-3]) : invalid model formula in ExtractVars t.test(2^(1:6)~rep(1:2,each=3))Error in terms.formula(formula[-3]) : invalid power in formula t.test(2^extra ~ group, data = sleep)Error in terms.formula(formula[-3]) : invalid power in formulaUnix session: (R 2.3.1) R.version _ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 3.1 year 2006 month 06day 01svn rev38247 language R version.string Version 2.3.1 (2006-06-01) t.test(1:6~rep(1:2,each =! 3))Welch Two Sample t-testdata: 1:6 by rep(1:2, each = 3) t = -3.6742, df = 4, p-value = 0.02131alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -5.266958 -0.733042 sample estimates:mean in group 1 mean in group 2 2 5 Windows session:=== R.version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 3.0 year 2006 month 04 day24svn rev37909 language R version.string Version 2.3.0 (2006-04-24) help(t.test) t.test(extra ~ group, data = sleep)Welch Two Sample t-testdata: extra by group t = -1.8608, df = 17. 7! 76, p-value = 0.0794alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -3.3654832 0.2054832 sample estimates:mean in group 1 mean in group 20.752.33 t.test(2^extra ~ group, data = sleep)Welch Two Sample t-testdata: 2^extra by group t = -1.6362, df = 10.718, p-value = 0.1308alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -18.641557 2.773344 sample estimates:mean in group 1 mean in group 23.448644 11.382751 t.test(1:6~rep(1:2,each=3)) Welch Two Sample t-testdata: 1:6 by rep(1:2, each = 3) t = -3.6742, df = 4, p-value = 0.02131alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -5.266958 -0.733042 sample estimates:mean in group 1 mean in group 2 2 5 _ Use Messenger to talk to your IM friends, even those on Yahoo! 685ee3e858fe [[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. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
Re: [R] inserting columns in the middle of a dataframe
Is there a built-in and simple way to insert new columns in a dataframe? You do this by collecting the columns in the new order you desire, and making a new frame. oldframe - data.frame(matrix(0:14,ncol=3)) newcol - data.frame(20:24) names(newcol) - newcol newframe - data.frame(c(oldframe[1],newcol, oldframe[2:3])) __ 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] reformat records one to several
Try this: n - 10 # create some sample data x - data.frame(date=1:n, t1=sample(0:3, n, TRUE), t2=sample(0:3, n, TRUE), t3=sample(0:3, n, TRUE)) x # print data result - lapply(c('t1','t2','t3'), function(i){ xsub - x[rep(1:nrow(x), x[[i]]),] xsub$t1 - xsub$t2 - xsub$t3 - 0 xsub[[i]] - 1 xsub }) do.call('rbind', result) # result On 9/13/06, Steven Van Wilgenburg [EMAIL PROTECTED] wrote: Hi, I am a new user of R and am still trying to figure out which statements do which functions and am looking for a jump start. I have a dataset where the data were collected as ten minute counts where the number of new individuals within a species was recorded as cohorts within 3 separate time intervals within the ten minute count persiod. Each row of data therefore follows a format like this: DateTime SampleSpecies t1 t2 t3 June 5,2006 5:20 AM AUSFAKE01 OVEN3 0 1 etc. I would like to reformat these data as if the counts recorded only individuals and not cohorts, so that the above would look as follows DateTime SampleSpecies t1 t2 t3 June 5,2006 5:20 AM AUSFAKE01 OVEN1 0 0 June 5,2006 5:20 AM AUSFAKE01 OVEN1 0 0 June 5,2006 5:20 AM AUSFAKE01 OVEN1 0 0 June 5,2006 5:20 AM AUSFAKE01 OVEN0 0 1 etc. I believe I could do this in SAS with IF, THEN and DO statements, e.g. if t10 then do i=1 to t1 output Date,Time,Sample,Species,1,0,0; if t20 then do i=1 to t2 output Date,Time,Sample,Species,0,1,0; if t30 then do i=1 to t3 output Date,Time,Sample,Species,0,0,1; end; Can anyone point me in the right direction? What is the similar statement to DO in R? Steve VW __ 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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ 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] inserting columns in the middle of a dataframe
Another way is to use attach(dataframe) x1 - rep(1,10) x2 - rep(2,10) x3 - rep(3,10) x4 - rep(4,10) x5 - rep(5,10) dat - data.frame(x1,x2,x3,x4) rm(x1,x2,x3,x4) attach(dat) dat2 - data.frame(x1,x5,x2,x3,x4) detach(dat) On 13/09/06, Timothy Bates [EMAIL PROTECTED] wrote: Is there a built-in and simple way to insert new columns in a dataframe? You do this by collecting the columns in the new order you desire, and making a new frame. oldframe - data.frame(matrix(0:14,ncol=3)) newcol - data.frame(20:24) names(newcol) - newcol newframe - data.frame(c(oldframe[1],newcol, oldframe[2:3])) __ 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. -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP -- = David Barron Said Business School University of Oxford Park End Street Oxford OX1 1HP [[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.
Re: [R] wireplot margins and additional z-axis
On 9/13/06, Duncan Murdoch [EMAIL PROTECTED] wrote: On 9/13/2006 4:04 AM, Klaus Nordhausen wrote: Dear Deepayan, sorry for not being clear - but my problem has nothing to do with the aspect. If I create the eps the following way There is some ambiguity here. The aspect arg to wireframe controls the 3D aspect ratio. You want to control the 2D aspect ratio in the displayed plot. It is stored in the aspect.ratio member of the resulting object, and can be changed using plot.vol$aspect.ratio - 1.5 for example. You shouldn't really be fiddling around inside the object like that, but I don't know how to avoid it in this case. update(plot.vol, aspect = fill) seems to work, but I don't know if that should be considered a bug or a feature. I wonder what S-PLUS does (I no longer have access to a copy). Deepayan Duncan Murdoch library(lattice) plot.vol- wireframe(volcano, aspect = c(1,1.5), scales=list(arrows=F),zlab=list(Z-axis,rot=90)) postscript(example_plot_3.eps, width = 14.0/2.54, height = 19.0/2.54, horizontal = FALSE, onefile = FALSE,paper=special) trellis.par.set(axis.line,list(alpha=1,col=1,lty=1,lwd=1)) print(plot.vol) dev.off() The plot is still not in the left bottom corner of the file. There is a lot of space below the outer box line. If I include this eps in latex it will also include this space and if I put for example the figure caption below it I have this huge gap between actual graph and caption. And for comparison, if I create with xyplot an eps like postscript(example_plot_4.eps, width = 14.0/2.54, height = 19.0/2.54, horizontal = FALSE, onefile = FALSE,paper=special) Depth - equal.count(quakes$depth, number=8, overlap=.1) plot.depth-xyplot(lat ~ long | Depth, data = quakes) update(trellis.last.object(), strip = strip.custom(strip.names = TRUE, strip.levels = TRUE), par.strip.text = list(cex = 0.75), aspect = iso) print(plot.depth) dev.off() the figure is really in the left bottom corner and included in latex has not that gap between caption and actual figure. I hope this describes my problem better. Klaus On 9/12/06, Klaus Nordhausen [EMAIL PROTECTED] wrote: Dear Deepayan, thanks for your reply, the change of the aspect does however not solve my problem with the space below the graph on the .eps I attached the .eps (still with the old aspect) so that it is maybe clearer what my problem is. No, it's not clearer; this is basically the same EPS that I got, so it gives me no new information. What do you get with the new aspect? If it's not what you want, you'll have to explain what you want more clearly. Also, don't make the panel borders transparent, as it makes it difficult to understand what's going on. Deepayan Any other suggestions? Klaus Dear R experts, it would be very kind if you could help me with two wireplot problems. First, when I make a wireplot and transform it into an .eps using the postscript function the eps-file leaves always a lot of space below the plot, as if it would leave space for a legend or something like that. How can i get the plot into the bottom corner without the space below? The space is not there when I just display the plot in R on my screen (I use R.2.3.1 on Windows XP). Or in general, how can I get the margins on all sides as small as possible since I wnat to include the eps into a report and do not need the space around. The following code has the space on the eps: library(lattice) plot.vol - wireframe(volcano, aspect = 1, scales=list(arrows=F) ,zlab=list(Z-axis,rot=90)) Perhaps you want something like aspect = c(1, 1.5) instead. postscript(example_plot.eps, width = 14.0/2.54, height = 19.0/2.54, horizontal = FALSE, onefile = FALSE,paper=special) trellis.par.set(axis.line,list(alpha=1,col=1,lty=0,lwd=1)) print(plot.vol) dev.off() Secondly, is it possible to add to the wireplot a further z-axis. I found only how to choose at which veritcal line I want the tickmarks and label, but is it also possible to have it at two vertical lines? No (but it shouldn't be too hard to add that feature; I'll have to check). Deepayan -- http://www.stat.wisc.edu/~deepayan/ __ 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] inserting columns in the middle of a dataframe
See ?append -Christos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jon Minton Sent: Wednesday, September 13, 2006 5:14 PM To: r-help@stat.math.ethz.ch Cc: 'Jon Minton' Subject: Re: [R] inserting columns in the middle of a dataframe Dear R users: Is there a built-in and simple way to insert new columns after other columns in a dataframe? I.e. currently I have: V1 V2 V3 V4 [1,] [2,] Etc. But I want V1 V5 V2 V3 V4 [1,] [2,] Etc. Can this be done in one line? Jon Minton [[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-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] an error message with 't.test' with R under Unix
Hi Peter, Thank you for the reply! Really sorry for the formating (forgot to change to plain text). Here is basically what I'm talking about: R.version _ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major2 minor1.1 year 2005 month06 day 20 language R t.test(1:6~rep(1:2,each=3)) Error in terms.formula(formula[-3]) : invalid model formula in ExtractVars Again, I don't see the error in R under Windows (R 2.3.0) or Unix (R2.3.1). Is this the bug you were talking about? ...Tao To: [EMAIL PROTECTED] CC: r-help@stat.math.ethz.ch Subject: Re: [R] an error message with 't.test' with R under Unix From: [EMAIL PROTECTED] Date: Wed, 13 Sep 2006 23:52:04 +0200 Tao Shi [EMAIL PROTECTED] writes: Hi list,Could you please help me to explain the following error messages with 't.test' in R Unix 2.1.1? This is completely unreadable! However, yes, there was at some point a bug where the LHS of model formulas was checked more rigorously than need be, using the same rules that apply to the RHS. This fact can be found in a recent NEWS file. I don't see it in R under Windows (R 2.3.0) or Unix (R2.3.1). Is it really due to the different R versions?Thanks,...TaoUnix session: (R.2.1.1) R.version _ platform x86_64-unknown-linux-gnuarch x86_64 os linux-gnu system x86_64, linux-gnu status major2 minor1.1 year 2005month06 day 20 language Rt.test(extra ~ group, data = sleep)Welch Two Sample t-testdata: extra by group t = -1.8608, df = 17.776, p-value = 0.0794alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -3.3654832 0.2054832 sample estimates:mean in group 1 mean in group 2 ! 0.752.33 t.test((1:6)~rep(1:2,each=3))Error in terms.formula(formula[-3]) : invalid model formula in ExtractVars t.test(2^(1:6)~rep(1:2,each=3))Error in terms.formula(formula[-3]) : invalid power in formula t.test(2^extra ~ group, data = sleep)Error in terms.formula(formula[-3]) : invalid power in formulaUnix session: (R 2.3.1) R.version _ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 3.1 year 2006 month 06 day01svn rev38247 language R version.string Version 2.3.1 (2006-06-01) t.test(1:6~rep(1:2,each =! 3))Welch Two Sample t-testdata: 1:6 by rep(1:2, each = 3) t = -3.6742, df = 4, p-value = 0.02131alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -5.266958 -0.733042 sample estimates:mean in group 1 mean in group 2 2 5 Windows session:=== R.version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 3.0 year 2006 month 04day24svn rev 37909 language R version.string Version 2.3.0 (2006-04-24) help(t.test) t.test(extra ~ group, data = sleep)Welch Two Sample t-testdata: extra by group t = -1.8608, df = 17. 7! 76, p-value = 0.0794alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -3.3654832 0.2054832 sample estimates:mean in group 1 mean in group 20.752.33 t.test(2^extra ~ group, data = sleep)Welch Two Sample t-testdata: 2^extra by group t = -1.6362, df = 10.718, p-value = 0.1308alternative hypothesis: true difference in means is not equal to 0 95 percent confidence interval: -18.641557 2.773344 sample
Re: [R] inserting columns in the middle of a dataframe
Thanks, but isn't that only for elements in vectors? I think I've found the following method to work: e.g. for df - data.frame(v1,v2,v3,v4) use: df - data.frame(df[1:2],v5,df[-c(1:2)]) I *believe* this is the one-line solution I was looking for. Can anyone see why this wouldn't work? Jon -Original Message- From: Christos Hatzis [mailto:[EMAIL PROTECTED] Sent: 13 September 2006 23:22 To: 'Jon Minton'; r-help@stat.math.ethz.ch Subject: RE: [R] inserting columns in the middle of a dataframe See ?append -Christos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jon Minton Sent: Wednesday, September 13, 2006 5:14 PM To: r-help@stat.math.ethz.ch Cc: 'Jon Minton' Subject: Re: [R] inserting columns in the middle of a dataframe Dear R users: Is there a built-in and simple way to insert new columns after other columns in a dataframe? I.e. currently I have: V1 V2 V3 V4 [1,] [2,] Etc. But I want V1 V5 V2 V3 V4 [1,] [2,] Etc. Can this be done in one line? Jon Minton [[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-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] Reading fixed column format
How about using python/perl/ruby, designed precisely for this type of routine data munging, to pipe the processed output into an R dataframe? msci - read.table(pipe(python steve/python/msci.py), header=T, as.is=T) Iteratively, you could deliver the python output in chunks, something like: msci - read.table(pipe(python steve/python/msci.py 1 50), header=T, as.is=T) msci - rbind(msci, read.table(pipe(python steve/python/msci.py 51 100), header=T, as.is=T)) etc. Steve Miller -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jason Barnhart Sent: Wednesday, September 13, 2006 11:52 AM To: Gabor Grothendieck; Anupam Tyagi Cc: r-help@stat.math.ethz.ch Subject: Re: [R] Reading fixed column format Another possibility: 1) Split the original file into smaller chunks of xx,xxx of rows. 2) Process each file using read.fwf saving the requisite variables. (If necessary, save each intermediate matrix/data.frame to disk to conserve space) 3) 'rbind' the results. Not exactly elegant but it works. - Original Message - From: Gabor Grothendieck [EMAIL PROTECTED] To: Anupam Tyagi [EMAIL PROTECTED] Cc: r-help@stat.math.ethz.ch Sent: Wednesday, September 13, 2006 7:21 AM Subject: Re: [R] Reading fixed column format On 9/13/06, Anupam Tyagi [EMAIL PROTECTED] wrote: Gabor Grothendieck ggrothendieck at gmail.com writes: C:\bincut -c2-3,6-8 a.dat 23678 23678 23678 Thanks. I think this will work. How do I redirect the output to a file on windows? Same as on UNIX cut -c2-3,6-8 a.dat a2.dat Is there simple way to convert the cut command to a script on windows, Using notepad or other text editor put it in file a.bat and then issue this command from the console a.bat Note that you could process it multiple time if you like: cut -c6-8 a.dat a2.dat cut -c2-3 a2.dat a3.dat produces the same thing but uses 2 passes and so keeps each line shorter. Be sure you do it from the tail end forward as shown above to avoid having to recalculate the positions. because the entire command may not fit on one line? Anupam. __ 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@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. [[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.
Re: [R] forcing levelplot to use relative cuts (ie cuts for each panel)
On 9/13/06, Mike Townsley [EMAIL PROTECTED] wrote: Dear guRus, I'm having trouble producing a levelplot with relative cuts for each panel (my data has large differences in scales, so I want to use quantiles for each panel). My attempts to change the 'at' argument in panel.levelplot function have not met with success. Below is a toy example. xy - expand.grid(x = 1:3, y = 1:3) aaa - rbind(cbind(xy, z = 1:9, site = rep('A', 9)), cbind(xy, z = (1:9)/10, site = rep('B', 9)), cbind(xy, z = (1:9)*10, site = rep('C', 9))) aaa library(lattice) levelplot(z~x+y|site, data = aaa) # using absolute cuts # now, attempt relative cuts levelplot(z~x+y|site, data = aaa, panel = function(...) { panel.levelplot(at = quantile(z),...) }) I get the following message: Error in panel.levelplot(at = quantile(z), ...) : formal argument at matched by multiple actual arguments My idea was to determine the cut points each time the panel function is called (ie each subset of the data), but I guess this was the wrong thing to do. Can someone point out what I'm missing? Mostly that you have to catch the arguments you want to use/replace, e.g. levelplot(z~x+y|site, data = aaa, panel = function(..., z, at) { panel.levelplot(..., z = z, at = quantile(z)) }) This won't actually give you want, you will need: levelplot(z~x+y|site, data = aaa, panel = function(..., z, subscripts, at) { panel.levelplot(..., z = z, subscripts = subscripts, at = quantile(z[subscripts])) }) ?panel.levelplot should explain why. Deepayan __ 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] inserting columns in the middle of a dataframe
Sorry, I guess I did not explain at all how append could work in a one-liner: data.frame(df, v5)[append(1:4,5,2)] Your method is fine as well. The above might be more flexible if you need a more general solution, e.g. if you wanted to make it a function. -Christos -Original Message- From: Jon Minton [mailto:[EMAIL PROTECTED] Sent: Wednesday, September 13, 2006 6:43 PM To: [EMAIL PROTECTED]; r-help@stat.math.ethz.ch Cc: 'Jon Minton' Subject: RE: [R] inserting columns in the middle of a dataframe Thanks, but isn't that only for elements in vectors? I think I've found the following method to work: e.g. for df - data.frame(v1,v2,v3,v4) use: df - data.frame(df[1:2],v5,df[-c(1:2)]) I *believe* this is the one-line solution I was looking for. Can anyone see why this wouldn't work? Jon -Original Message- From: Christos Hatzis [mailto:[EMAIL PROTECTED] Sent: 13 September 2006 23:22 To: 'Jon Minton'; r-help@stat.math.ethz.ch Subject: RE: [R] inserting columns in the middle of a dataframe See ?append -Christos -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Jon Minton Sent: Wednesday, September 13, 2006 5:14 PM To: r-help@stat.math.ethz.ch Cc: 'Jon Minton' Subject: Re: [R] inserting columns in the middle of a dataframe Dear R users: Is there a built-in and simple way to insert new columns after other columns in a dataframe? I.e. currently I have: V1 V2 V3 V4 [1,] [2,] Etc. But I want V1 V5 V2 V3 V4 [1,] [2,] Etc. Can this be done in one line? Jon Minton [[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-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] lme for time series prediction
Could anyone give me a simple example how to use lme() for t time series prediction/modeling ? I understand the concept of longitudinal data and have read the book by Pinheiro but still have a difficult time for the (simpler) case of no grouped data. I am dealing with the case of predicting a scalar from another multivariate time series. Thanks ! Mark __ 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 for time series prediction
Hello Mark, it's quite possible that someone can do this. However, you should try to help us as much as possible by providing commented, minimal, self-contained, reproducible code. What are you trying to do? In what way is it not working? Etc. Cheers Andrew On Wed, Sep 13, 2006 at 10:32:11PM -0400, Markus Loecher wrote: Could anyone give me a simple example how to use lme() for t time series prediction/modeling ? I understand the concept of longitudinal data and have read the book by Pinheiro but still have a difficult time for the (simpler) case of no grouped data. I am dealing with the case of predicting a scalar from another multivariate time series. Thanks ! Mark __ 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. -- Andrew Robinson Department of Mathematics and StatisticsTel: +61-3-8344-9763 University of Melbourne, VIC 3010 Australia Fax: +61-3-8344-4599 Email: [EMAIL PROTECTED] http://www.ms.unimelb.edu.au __ 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] building R-2.3.1 on Solaris 10
Sun has modified the standard gcc to provide better support for Sun's thread. They used it to build OpenSolaris and it is available under the standard GPL license, ie, it is free. I could build R-2.2.1 with the standard gcc, but I needed to use the gcc from Sun to build 2.3.x. I am not entirely happy with R-2.3.0 because some of the demo(graphics) had their titles clipped, but I want to see how it works in practice. It did pass make check, but I didn't invoke the more strenuous dev checks. /greg __ 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] Access Rows in a Data Frame by Row Name
I hope this helps. x - data.frame(a=1:5, b=6:10, d=11:15) x a b d 1 1 6 11 2 2 7 12 3 3 8 13 4 4 9 14 5 5 10 15 # access row with name a. This does not work. x$a [1] 1 2 3 4 5 # access column with name d x$d [1] 11 12 13 14 15 x$row.names NULL attributes(x) $names [1] a b d $row.names [1] 1 2 3 4 5 $class [1] data.frame x$row.names() Error: attempt to apply non-function row.names(x) [1] 1 2 3 4 5 # access first row by index x[1,] a b d 1 1 6 11 # access first row by name x[1,] a b d 1 1 6 11 # access second row by name x[2,] a b d 2 2 7 12 # change row names to alphabets. row.names(x) - c(a,b,c,d,e) row.names(x) [1] a b c d e # access second row by old name. Does not work because of name change. Why this does not give error: 2 row name does not exist? x[2,] a b d NA NA NA NA # access third row by name. x[c,] a b d c 3 8 13 __ 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] inserting columns in the middle of a dataframe
I think it should be possible to create the column at the end and then use order on the columns names and indexes to only change the order of column indexes, rather than having to do operations on the data itself (which will be very time consuming if the dataset is large). Perhaps people with better R skills can suggest how to code this. Anupam. __ 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] Dear FE Harrell How can I get rreport ?
justin bem justin_bem at yahoo.fr writes: Mr Harrell, After reading discussion about R output and SAS output , I will like to use rreport package. I a windows XP user Sincerly See: http://biostat.mc.vanderbilt.edu/twiki/bin/view/Main/Rreport Anupam. __ 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] Adding predicted values as a new variable in a data frame
I am running a regression: ols.reg1 - lm(y ~ x1 + x2 + x3 + x4) on a data.frame and then generating fitted values: y.hat - ols.reg1$fitted.values Then I would like to add these fitted values to the data.frame as a new variable. The problem is that when the values are predicted the resulting output has too few rows. for some reason certian observations do not get predicted values. So this shrinks the column down and I then cannot combine the output into the original data.frame. If someone could please help I would apreciate it. Stata automatically adds a new column to the data set when you find the fitted values. So having to fight with R just to do something I used to routimely do has made me think of turning back to the dark side. I hope I have just missed something trival in all the help files I have been looking through. Thanks, -- Robi Ragan Graduate Student Department of Economics Department of Political Science The University of Georgia __ 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.