Re: [R] What is the most cost effective hardware for R?
Thank you all for the help. We have decided against using for example Amazon cloud for basicly paperwork issues. We have money available now for buying kit, this may not be available for buying services, and may not be available next year, or the next. We shall certainly consider it as a fall back at times of high load. We are looking at the Dell poweredge M915. It has 64 cores and we are getting it with 256 GB memory, and it really not that expensive. I am surprised what power you can get these days for not very much money. Thanks again. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dotchart showing mean and median by group
hi all I have another question reated to the dotchart: is it possible by means of par() to set a logaritmic scale? If yes, how ? and if not, any alternative solution? thanks -- View this message in context: http://r.789695.n4.nabble.com/Dotchart-showing-mean-and-median-by-group-tp4619597p4622618.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] reception of (Vegan) envfit analysis by manuscript reviewers
On Wed, 2012-05-09 at 15:51 -0600, Matt Bakker wrote: I'm getting lots of grief from reviewers about figures generated with the envfit function in the Vegan package. Has anyone else struggled to effectively explain this analysis? If so, can you share any helpful tips? The most recent comment I've gotten back: What this shows is which NMDS axis separates the communities, not the relationship between the edaphic factor and the Bray-Curtis distance. Without further context for that quote and your manuscript to see how you are using the method it is difficult to say whether you are doing something silly or the reviewer is bone-headed. I've had similar comments from reviewers about my use of the ordisurf() function. In each case it was the reviewers' failure to understand the methods applied that was the cause of the confusion. As you provide little or no context I'll explain what envfit() does etc. The idea goes back a long way (!) and is in my 1995 edition of Jongman et al Data Analysis in Community and Landscape Ecology (Cambridge University Press) though most likely was in 1987 version too. See Section 5.4 of the Ordination chapter by Ter Braak in that book. The idea is to find the direction (in the k-dimensional ordination space) that has maximal correlation with an external variable. Essentially, we have: E(z_j) = b_0 + b_1x_1 + b_2x_2 where E(z_j) is the expectation (or mean, or fitted values) of the jth external (environmental) variable, x_1 and x_2 are the axis scores in ordination dimensions 1 and 2, and b_y are unknown regression coefficients. This generalises to more than 2 dimensions or axes. The biplot arrow drawn goes from (0,0) to (b_1, b_2). You can see that the aim is to model or predict the values of the jth environmental variable (z_j) as a linear combination of the axis or site scores of the samples in the ordination space. Exactly the same idea underlies the ordisurf() function except that we use a GAM and for the right hand side of the equation multivariate splines are used which allow a non-linear surface instead of a plane. When applied to nMDS, if the nMDS provides a reasonable approximation to the original dissimilarities, then envfit() will estimate and show the strengths of the correlation and direction of maximal correlation between the nMDS configuration and the jth enviromental variable. This technique can be used to indicate if one or more environmental variables are associated with differences between sites/samples as represented in the nMDS ordination. The big caveat is the implication that the correlation or relationship between z_j and the ordination space is linear. ordisurf() allows you to relax this assumption as we fit a potentially non-linear surface to the ordination space instead of the plane that envfit() effectively produces (though we show only the direction of change with the arrow). So without seeing your manuscript or more context (and I'm not promising to read it or comment more if you provide it) I would suggest that, *if* you have applied nMDS and used envfit() correctly the combined analysis *does* reflect the *linear* relationship between the edaphic factor and the Bray-Curtis distance, assuming of course that the nMDS has low stress (i.e fits the original dissimilarities well). In future, you should consider posting similar questions (ecological/environmental) to the R-SIG-Ecology list instead of the main R-Help list. I know Jari (lead developer of vegan and author of envfit() ) has stopped regularly reading the main R-Help list and you will get far more eyes familiar with these techniques on the R-SIG-Ecology list. I have taken the liberty of cc'ing this to the R-Sig-Ecology list so others can comment. HTH G Thanks for any suggestions! Matt __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fwd: Finding local maxima on a loess surface
On May 10, 2012, at 12:10 AM, Diego Rojas wrote: -- Forwarded message -- From: Diego Rojas diroj...@gmail.com Date: Wed, May 9, 2012 at 3:05 PM Subject: Re: [R] Finding local maxima on a loess surface To: David Winsemius dwinsem...@comcast.net Thanks again, would you please try to ilustrate further your point with this example code. How would you find the coordinates for the maxima on the surface. Consider that in the surface I'm dealing with there are at least 35 maxima. require(MASS) topo.lo - loess(z ~ x * y, topo, degree = 1, span = 0.25, normalize = FALSE) topo.mar - list(x = seq(0, 6.5, 0.1), y = seq(0, 6.5, 0.1)) new.dat - expand.grid(topo.mar) topo.pred - predict(topo.lo, new.dat) ## draw the contour map based on loess predictions library(rgl) persp3d(topo.mar$x, topo.mar$y, topo.pred, shade=0.5, col=blue) hasmax - function(mtx, x, y) if( (mtx[x,y] mtx[x,y-1]) (mtx[x,y] mtx[x,y+1]) (mtx[x,y] mtx[x-1,y]) (mtx[x,y] mtx[x+1,y]) ) {return(TRUE ) } else {return(FALSE)} for(x in 3:(dim(topo.pred)[1] -4)) { for(y in 3:(dim(topo.pred)[2]-4) ) { if( hasmax(topo.pred, x , y) ){print(c(x,y))} }} # [1] 40 7 Note: that topo.pred has a border of two and three row/columns of NA's that made this very annoying to debug. A proper function would probably need to pre-qualify the index ranges. I tried a sign change approach but generalizing to 2d created conceptual difficulties I could not resolve, so I just checked in both directions for the local point being greater than its neighbors. You obviously could do something other than printing coordinates at a maximum -- David. Thanks fot your help On Sat, May 5, 2012 at 9:34 AM, David Winsemius dwinsem...@comcast.net wrote: On May 4, 2012, at 3:00 PM, Diego Rojas wrote: Thanks, I know about it but i wat to find several local maxima, so in other words I need a way to identify the places in the surface where both slopes are equal to 0 and the second derivative is negative. There is no way that I know that will produce a mathematical function that would support symbolic manipulations of that sort for the results obtainable from a loess-object. I was expecting that you would be approaching this numerically and doing evaluations on a grid. Testing for equality to 0 is not a good practice if following that route. Sign reversal would be a more sensible criterion. ( And you _would_ be using predict.loess(). ) Still no data example or code offered, so not pursuing further efforts at illustration. On Fri, May 4, 2012 at 9:28 AM, David Winsemius dwinsem...@comcast.net wrote: On May 3, 2012, at 6:09 PM, Diego Rojas wrote: If a run a LOESS model and then produce a smoothed surface: Is there any way to determine the coordinates of the local maxima on the surface? ?predict# it has a loess method. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dotchart showing mean and median by group
On May 10, 2012, at 2:24 AM, maxbre wrote: hi all I have another question reated to the dotchart: is it possible by means of par() to set a logaritmic scale? If yes, how ? and if not, any alternative solution? Looking at the dotchart code it appears to me that the log parameter to plot.window is hard-coded at , i.e both scales are linear. Testing with the xlog parameter to par does fail. You can always define a new dochart2 on the basis of that code. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dotchart showing mean and median by group
On May 10, 2012, at 5:03 AM, David Winsemius wrote: On May 10, 2012, at 2:24 AM, maxbre wrote: hi all I have another question reated to the dotchart: is it possible by means of par() to set a logaritmic scale? If yes, how ? and if not, any alternative solution? Looking at the dotchart code it appears to me that the log parameter to plot.window is hard-coded at , i.e both scales are linear. Testing with the xlog parameter to par does fail. You can always define a new dochart2 on the basis of that code. Another alternative would be lattice (a simple mod to one of its examples shows it works): dotplot(variety ~ yield | site, data = barley, groups = year, key = simpleKey(levels(barley$year), space = right), scales=list(x=list(log=TRUE)), xlab = Barley Yield (bushels/acre) , aspect=0.5, layout = c(1,6), ylab=NULL) -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] There must be a better way to do this
On 05/10/2012 02:17 AM, David Perlman wrote: Thanks, that is very helpful. I agree that my example plot was a bit cluttered, but this is what I actually wanted: http://brainimaging.waisman.wisc.edu/~perlman/data/MNPT1T2_h_unp_raw.pdf I just needed to get example code out quickly. You get better help when you have a self-contained demo of the question. :) I have replaced my old horrible code with the nice concise segments code. Thanks! That's a rather nice way of illustrating what happened. I can see the trends in the bumpcharts on the bottom. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] bigmemory
Hi all, I have a question about using bigmemory package. Here is my code: x=read.big.matrix(acc3.dat,backingfile=acc3.bin,descriptorfile=acc3.desc,type=double) Error in filebacked.big.matrix(nrow = nrow, ncol = ncol, type = type, : A big.matrix must have at least one row and one column And here is the example code: x - read.big.matrix(airline.csv, header=TRUE, + backingfile=airline.bin, + descriptorfile=airline.desc, + type=integer) So, what was wrong? Any suggestions please? Thank you very much. ya __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [R-sig-eco] reception of (Vegan) envfit analysis by manuscript reviewers
On 10/05/2012, at 11:45 AM, Gavin Simpson wrote: On Wed, 2012-05-09 at 15:51 -0600, Matt Bakker wrote: I'm getting lots of grief from reviewers about figures generated with the envfit function in the Vegan package. Has anyone else struggled to effectively explain this analysis? If so, can you share any helpful tips? The most recent comment I've gotten back: What this shows is which NMDS axis separates the communities, not the relationship between the edaphic factor and the Bray-Curtis distance. Without further context for that quote and your manuscript to see how you are using the method it is difficult to say whether you are doing something silly or the reviewer is bone-headed. I've had similar comments from reviewers about my use of the ordisurf() function. In each case it was the reviewers' failure to understand the methods applied that was the cause of the confusion. As you provide little or no context I'll explain what envfit() does etc. The idea goes back a long way (!) and is in my 1995 edition of Jongman et al Data Analysis in Community and Landscape Ecology (Cambridge University Press) though most likely was in 1987 version too. See Section 5.4 of the Ordination chapter by Ter Braak in that book. The idea is to find the direction (in the k-dimensional ordination space) that has maximal correlation with an external variable. Hello, The method was indeed in the first edition of ter Braak's book. However, the idea is much older. The vegan implementation was based on an unpublished report from the Bell Labs from 1970s (or earlier). In this Bell Labs memorandum the method was specifically suggested for NMDS. Vegan uses different algorithm, but the method is the same. The early history in vegan can be traced in ORDNEWS correspondence from 2001 or so, but it is so old that I cannot find that message via this computer any longer. Then about Bray-Curtis. The referee may be correct when writing that the fitted vectors are not directly related to Bray-Curtis. You fit the vectors to the NMDS ordination, and that is a non-linear mapping from Bray-Curtis to the metric ordination space. There are two points here: non-linearity and stress. Because of these, it is not strictly about B-C. Of course, the referee is wrong when writing about NMDS axes: the fitted vector has nothing to do with axes (unless you rotate your axis parallel to the fitted vector which you can do). The NMDS is based on Bray-Curtis, but it is not the same, and the vector fitting is based on NMDS. So why not write that is about NMDS? Why to insist on Bray-Curtis which is only in the background? Cheers, Jari Oksanen -- Jari Oksanen, Dept Biology, Univ Oulu, 90014 Finland __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] bigmemory
Hi all, In addition, I am planning to do a multiple imputation with MICE package using the data read by bigmemory package. So usually, the multiple imputation code is like this: imp=mice(data.frame,m=50,seed=1234,print=F) the data.frame is required. How can I change the big.matrix class generated by bigmemory package to a data.frame? Thank you very much. ya __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] stop calculation in a function
Hi dear R-users, I have a question about a function I'm trying to improve. How can I stop the function calculation at the last numeric value of my data? The problem is that the end of my data contains missing values (NAs). And the aim of my function is to compare the first numeric value with the next one (till the end). For the moment, It works well when my data doesn't contains any NAs at the end of my file. I think that the problem is, as I have NAs at the end of my data, R tries to compare my last numeric value with the next numeric value wich doesn't exists, and so tries to modify the length of my data (the error message is that the output has not the same length as the input). Could somebody tell me what I should modify or add in my function in order to fix this problem? Here's the function. Thanks for your advises! out2NA - function(x,seuil){ st1 = NULL # Temporal variable memorysing the last correct numeric value# temp - st1[1] - x[1] ind_temp - 1 # Max time gap between two comparisons # ecart_temps - 10 tps - time(x) for (i in 2:length(x)){ if((!is.na(x[i]))){ if((tps[i]-tps[ind_temp] ecart_temps) (abs(x[i]-temp) seuil)){ #(abs(x[i+1]-x[i])1)){ st1[i] - NA } else { temp - st1[i] - x[i] ind_temp - i } } } return(st1) } dat1 - myts[,2] myts[,2] - apply(dat1,2,function(x) out2NA(x,2)) -- View this message in context: http://r.789695.n4.nabble.com/stop-calculation-in-a-function-tp4622964.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Interweaving of two datasets
it doesn't work. Find attached what I need explained in xls. Thank you very very much! http://r.789695.n4.nabble.com/file/n4622912/interweaving_of_2_datasets.xls interweaving_of_2_datasets.xls -- View this message in context: http://r.789695.n4.nabble.com/Interweaving-of-two-datasets-tp4608505p4622912.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Classification of Cluster-Correlated data
Dear R-Help, I'm dealing with a supervized binary classification issue. My dataset is composed of 1500 individuals, living in 600 households. I have approximately 4000 variables to classify my subjects as infected/uninfected. I was wondering how would it be possible to account for the hierarchical nature of my data in a data mining classification method, such as CART, MARS or other methods, as it is done for instance in mixed-effects models ? I suppose that the hierarchical structure of the data cannot be ignored, because the risk of a individual to be infected is higher is there is already an infected individual in his household. Thank you Yohann Mansiaux [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] outlier identify in qqplot
Sorry, but I need the same and i don't understand your help. So, after fitting my lm model, how can i identify my data? I was trying the following, but it doesn't work. /identify(qnorm(c(0.25, 0.75)),quantile(rstandard(mymodel)[!is.na(rstandard(mymodel))], c(0.25, 0.75)),row.names(mydata)) warning: no point within 0.25 inches/ /In identify.default(qnorm(c(0.25, 0.75)), quantile(rstandard(lmt2t)[!is.na(rstandard(lmt2t))], : more 'labels' than points/ Thanks in advance, show u...@host.com -- View this message in context: http://r.789695.n4.nabble.com/outlier-identify-in-qqplot-tp4076587p4623088.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] stop calculation in a function
Well, if i goes from 2 to length(x) and you try to access x[i+1], of course odd things will happen. Why not construct the loop to (length(x)-1) instead, so that x[i+1] is defined. Sarah On Thu, May 10, 2012 at 5:14 AM, jeff6868 geoffrey_kl...@etu.u-bourgogne.fr wrote: Hi dear R-users, I have a question about a function I'm trying to improve. How can I stop the function calculation at the last numeric value of my data? The problem is that the end of my data contains missing values (NAs). And the aim of my function is to compare the first numeric value with the next one (till the end). For the moment, It works well when my data doesn't contains any NAs at the end of my file. I think that the problem is, as I have NAs at the end of my data, R tries to compare my last numeric value with the next numeric value wich doesn't exists, and so tries to modify the length of my data (the error message is that the output has not the same length as the input). Could somebody tell me what I should modify or add in my function in order to fix this problem? Here's the function. Thanks for your advises! out2NA - function(x,seuil){ st1 = NULL # Temporal variable memorysing the last correct numeric value# temp - st1[1] - x[1] ind_temp - 1 # Max time gap between two comparisons # ecart_temps - 10 tps - time(x) for (i in 2:length(x)){ if((!is.na(x[i]))){ if((tps[i]-tps[ind_temp] ecart_temps) (abs(x[i]-temp) seuil)){ #(abs(x[i+1]-x[i])1)){ st1[i] - NA } else { temp - st1[i] - x[i] ind_temp - i } } } return(st1) } dat1 - myts[,2] myts[,2] - apply(dat1,2,function(x) out2NA(x,2)) -- -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] outlier identify in qqplot
Reproducible example? https://github.com/hadley/devtools/wiki/Reproducibility Michael On Thu, May 10, 2012 at 6:31 AM, agent dunham crossp...@hotmail.com wrote: Sorry, but I need the same and i don't understand your help. So, after fitting my lm model, how can i identify my data? I was trying the following, but it doesn't work. /identify(qnorm(c(0.25, 0.75)),quantile(rstandard(mymodel)[!is.na(rstandard(mymodel))], c(0.25, 0.75)),row.names(mydata)) warning: no point within 0.25 inches/ /In identify.default(qnorm(c(0.25, 0.75)), quantile(rstandard(lmt2t)[!is.na(rstandard(lmt2t))], : more 'labels' than points/ Thanks in advance, show u...@host.com -- View this message in context: http://r.789695.n4.nabble.com/outlier-identify-in-qqplot-tp4076587p4623088.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Modifying R package code
Hi, I was trying to change some code in an existing package. I downloaded the source package (say 'package_xx') from CRAN, and changed the R code provided in the /package_xx/R/xx.R. I then saved the changes and did the R CMD INSTALL -l /path to modified package/. Do I need to do something else before the changes will be effective? thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Axes value format
On 08/05/2012, David Winsemius dwinsem...@comcast.net wrote: On May 8, 2012, at 2:23 PM, Vihan Pandey wrote: On 8 May 2012 19:47, John Kane jrkrid...@inbox.com wrote: Quite likely, but we need to know what you are doing and what graphics package you are using. PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Frightfully sorry about that. I'm using R on a Mac, and its a simple plot using plot() which is taking values from a CSV file, let me illustrate for one dataset : See if this is helpful. Untested, since you still do not have a reproducible example for us to work with. x - c(12345, 1234567, 123) paste( round( x/c(1, 1000, 100)[findInterval(x, c(1,1000,100)) ], 2), c(,K,M)[findInterval(x, c(1,1000,100)) ] ) [1] 12.35 K 1.23 M 123 Thanks, xaxt, yaxt in plot() did the job. Sorry for not posting a reproducible example I just needed a quick fix which I was sure would be a simple option in plot() or elsewhere. Thanks and Cheers! - vihan -- David. == #!/usr/bin/Rscript out_file = foobar.pdf pdf(out_file, height=8.5, width=11) my_values - read.csv(foo.csv,head=TRUE,sep=,) plot(my_values$num_sims, my_values$exec_time, xlab=Number of Simulations, ylab=Execution Time(in milliseconds), col=red, main=Execution Time for Simulations) lines(my_values$num_sims,my_values$exec_time,col=red) my_values2 - read.csv(bar.csv,head=TRUE,sep=,) lines(my_values2$num_sims,my_values2$exec_time,col=blue) points(my_values2$num_sims,my_values2$exec_time,col=blue) legend(topright, lty=c(1,1), c(foo,bar), col=c(red,blue) ); dev.off() print(paste(Plot was saved in:, getwd())) == foo.csv and bar.csv have values like: num_sims,exec_time 100,44556 200,89112 300,133668 etc. Please let me know if you require any additional information. Cheers! - vihan John Kane Kingston ON Canada -Original Message- From: vihanpan...@gmail.com Sent: Tue, 8 May 2012 19:29:45 +0200 To: r-help@r-project.org Subject: [R] Axes value format Hi all, I have some graphs where the values on the X and Y axes are by default in exponent form like 2e+05 or 1.0e+07. Is it possible to make them in a more readable form like 10M for 1.0e+07 or 200K for 2e+05? Thanks and Regards, - vihan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with SQLDF - Error in sqliteExecStatement(con, statement, bind.data) : RS-DBI driver: (error in statement: no such table:
Thanks Gabor, Jim, POSIXct is working fine :) Regards, Shivam On Thu, May 10, 2012 at 5:22 AM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Wed, May 9, 2012 at 7:24 PM, Shivam shivamsi...@gmail.com wrote: Ohh ... Thanks Gabor. I have a few related queries then, kindly have a look: 1. Does it only hinder the sqldf package or are there other issues with using POSIXlt in a dataframe? Am asking because I have a few dataframes with columns of class(POSIXlt ). 2. I have columns containing 'date+timestamp', something like '2011-01-03 09:07:07' which are of class POSIXlt. I need to perform some arithmetic operations on these columns. Which class would be most appropriate for such kind of data? Its not just sqldf. You will have other problems too if you put POSIXlt objects in data frames too. See R News 4/1. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com -- *Victoria Concordia Crescit* [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] additional axis, different scale
Dear list, I am looking for a possibility to present results in a more graphical way by adding an axis. But I have trouble relating my data to the added axis. Imagine the following example: a - c(10, 20, 30, 40) b - c(50, 250, 500, 600) ba - b/a par(las=1, mar=c(5,5,.5,5)) plot(a,b, type=b, pch=22, cex=2, col=4, lwd=2, ylim=c(0,650), xlim=c(0,45)) axis(4, at=c(seq(0,600,length=6)), lab=c(seq(0,25,length=6)), col.axis=2 ) lines(a,ba, type=b, pch=21, cex=2, col=2, lwd=2, lty=1) I want the red line to relate its values to the x-axis (a) and axis 4 (on the right) and not as usual to the x-axis (a) and the y-axis (b). This would show the tendency of the red line much clearer which now can't be seen because of the very different scaling. E.g. I want R to know that I am trying to plot the first point of the red line P1(50/5) using the x-axis and the right axis, not the y-axis on the left ect. I would like to solve this without using a factor solution like: bb -600/25 * ba lines(a,bb, type=b, pch=21, cex=2, col=3, lwd=2, lty=1) For any kind of help I would be grateful ! -- View this message in context: http://r.789695.n4.nabble.com/additional-axis-different-scale-tp4623210.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Axes value format
On 08/05/2012, John Kane jrkrid...@inbox.com wrote: Actually I meant a working example and some data (See ?dput for a handy way to supply data) It is also a good idea to include the information from sessionInfo() I think David W has a good approach. Otherwise you might just want to write the axis yourself. = x - c(100, 200, 300) y - c( 44556, 89112, 133668) nms - c(1M, 2M, 3M) plot(x,y, xaxt=n) axis(1, x, labels=nms) Sorry for not posting a working example and some data, I just wanted a quick fix and didn't know people would work so much for my query few mailing lists do so :-) Thanks though, your xaxt option did the trick. I will learn from this and read up on dput and sessioninfo() Thanks and Cheers! - vihan John Kane Kingston ON Canada -Original Message- From: vihanpan...@gmail.com Sent: Tue, 8 May 2012 20:23:21 +0200 To: jrkrid...@inbox.com Subject: Re: [R] Axes value format On 8 May 2012 19:47, John Kane jrkrid...@inbox.com wrote: Quite likely, but we need to know what you are doing and what graphics package you are using. PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Frightfully sorry about that. I'm using R on a Mac, and its a simple plot using plot() which is taking values from a CSV file, let me illustrate for one dataset : == #!/usr/bin/Rscript out_file = foobar.pdf pdf(out_file, height=8.5, width=11) my_values - read.csv(foo.csv,head=TRUE,sep=,) plot(my_values$num_sims, my_values$exec_time, xlab=Number of Simulations, ylab=Execution Time(in milliseconds), col=red, main=Execution Time for Simulations) lines(my_values$num_sims,my_values$exec_time,col=red) my_values2 - read.csv(bar.csv,head=TRUE,sep=,) lines(my_values2$num_sims,my_values2$exec_time,col=blue) points(my_values2$num_sims,my_values2$exec_time,col=blue) legend(topright, lty=c(1,1), c(foo,bar), col=c(red,blue) ); dev.off() print(paste(Plot was saved in:, getwd())) == foo.csv and bar.csv have values like: num_sims,exec_time 100,44556 200,89112 300,133668 etc. Please let me know if you require any additional information. Cheers! - vihan John Kane Kingston ON Canada -Original Message- From: vihanpan...@gmail.com Sent: Tue, 8 May 2012 19:29:45 +0200 To: r-help@r-project.org Subject: [R] Axes value format Hi all, I have some graphs where the values on the X and Y axes are by default in exponent form like 2e+05 or 1.0e+07. Is it possible to make them in a more readable form like 10M for 1.0e+07 or 200K for 2e+05? Thanks and Regards, - vihan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! GET FREE SMILEYS FOR YOUR IM EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Axes value format
On 08/05/2012, arun smartpink...@yahoo.com wrote: Hi Vihan, The link below might be helpful. (http://stackoverflow.com/questions/3415097/controlling-number-formatting-at-axis-of-r-plots) Thanks, the xaxt parameter in plot() solved the problem. Thanks and Cheers! - vihan A.K. - Original Message - From: Vihan Pandey vihanpan...@gmail.com To: r-help r-help@r-project.org Cc: Sent: Tuesday, May 8, 2012 1:29 PM Subject: [R] Axes value format Hi all, I have some graphs where the values on the X and Y axes are by default in exponent form like 2e+05 or 1.0e+07. Is it possible to make them in a more readable form like 10M for 1.0e+07 or 200K for 2e+05? Thanks and Regards, - vihan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] stop calculation in a function
On 10-05-2012, at 12:59, Sarah Goslee wrote: Well, if i goes from 2 to length(x) and you try to access x[i+1], of course odd things will happen. Why not construct the loop to (length(x)-1) instead, so that x[i+1] is defined. The reference to x[i+1] in a commented line so I don't think this is the cause. The reason for the behaviour can be seen when indenting the code for the for loop part properly: for (i in 2:length(x)){ if((!is.na(x[i]))){ if((tps[i]-tps[ind_temp] ecart_temps) (abs(x[i]-temp) seuil)){ #(abs(x[i+1]-x[i])1)) st1[i] - NA } else { temp - st1[i] - x[i] ind_temp - i } } } return(st1) When is.na(x[i]) == TRUE then the st1 entry for that value of i is skipped. So when x has trailing NA's st1 will be shorter. It's better to declare st1 initially of the correct length st1 - numeric(length(x)) which could also speed things up when x is very long (because st1 has to be increased every time i increases). Berend Sarah On Thu, May 10, 2012 at 5:14 AM, jeff6868 geoffrey_kl...@etu.u-bourgogne.fr wrote: Hi dear R-users, I have a question about a function I'm trying to improve. How can I stop the function calculation at the last numeric value of my data? The problem is that the end of my data contains missing values (NAs). And the aim of my function is to compare the first numeric value with the next one (till the end). For the moment, It works well when my data doesn't contains any NAs at the end of my file. I think that the problem is, as I have NAs at the end of my data, R tries to compare my last numeric value with the next numeric value wich doesn't exists, and so tries to modify the length of my data (the error message is that the output has not the same length as the input). Could somebody tell me what I should modify or add in my function in order to fix this problem? Here's the function. Thanks for your advises! out2NA - function(x,seuil){ st1 = NULL # Temporal variable memorysing the last correct numeric value# temp - st1[1] - x[1] ind_temp - 1 # Max time gap between two comparisons # ecart_temps - 10 tps - time(x) for (i in 2:length(x)){ if((!is.na(x[i]))){ if((tps[i]-tps[ind_temp] ecart_temps) (abs(x[i]-temp) seuil)){ #(abs(x[i+1]-x[i])1)){ st1[i] - NA } else { temp - st1[i] - x[i] ind_temp - i } } } return(st1) } dat1 - myts[,2] myts[,2] - apply(dat1,2,function(x) out2NA(x,2)) -- -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] stop calculation in a function
Thank you for your reply sarah. Well actually I don't try to access x[i+1]. The line where you saw it starts with #. It was just try I wanted to keep (sorry I should have removed it before posting). But I ask him to access to the next value if conditions in the loop are not verified (restart the comparison from the next value). It works well as long as I have numeric values in my data. But if my data ends with NAs, I have this problem. That's why I'm trying to ask him to stop the calculation in the loop at the last numeric value to avoid this error (don't know if it's the best way to solve it, but it's the main idea I think). Have you got any other idea about this? Thanks a lot! -- View this message in context: http://r.789695.n4.nabble.com/stop-calculation-in-a-function-tp4622964p4623259.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] additional axis, different scale
On 05/10/2012 09:37 PM, pannigh wrote: Dear list, I am looking for a possibility to present results in a more graphical way by adding an axis. But I have trouble relating my data to the added axis. Imagine the following example: a- c(10, 20, 30, 40) b- c(50, 250, 500, 600) ba- b/a par(las=1, mar=c(5,5,.5,5)) plot(a,b, type=b, pch=22, cex=2, col=4, lwd=2, ylim=c(0,650), xlim=c(0,45)) axis(4, at=c(seq(0,600,length=6)), lab=c(seq(0,25,length=6)), col.axis=2 ) lines(a,ba, type=b, pch=21, cex=2, col=2, lwd=2, lty=1) I want the red line to relate its values to the x-axis (a) and axis 4 (on the right) and not as usual to the x-axis (a) and the y-axis (b). This would show the tendency of the red line much clearer which now can't be seen because of the very different scaling. E.g. I want R to know that I am trying to plot the first point of the red line P1(50/5) using the x-axis and the right axis, not the y-axis on the left ect. I would like to solve this without using a factor solution like: bb-600/25 * ba lines(a,bb, type=b, pch=21, cex=2, col=3, lwd=2, lty=1) Hi pannigh, Have a look at twoord.plot (plotrix) Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] additional axis, different scale
I don't think there is any other way. On the other hand, most gurus suggest that a dual scales on a graph are not a good thing. What about using a two panel graph? Quick rejigging of your code : = a - c(10, 20, 30, 40) b - c(50, 250, 500, 600) ba - b/a op - par(las=1, mar=c(5,5,.5,5), mfrow=c(2, 1)) plot(a,b, type=b, pch=22, cex=2, col=4, lwd=2, ylim=c(0,650), xlim=c(0,45)) plot (a,ba, type=b, pch=21, cex=2, col=2, lwd=2, lty=1) par(op) == John Kane Kingston ON Canada -Original Message- From: pann...@gwdg.de Sent: Thu, 10 May 2012 04:37:37 -0700 (PDT) To: r-help@r-project.org Subject: [R] additional axis, different scale Dear list, I am looking for a possibility to present results in a more graphical way by adding an axis. But I have trouble relating my data to the added axis. Imagine the following example: a - c(10, 20, 30, 40) b - c(50, 250, 500, 600) ba - b/a par(las=1, mar=c(5,5,.5,5)) plot(a,b, type=b, pch=22, cex=2, col=4, lwd=2, ylim=c(0,650), xlim=c(0,45)) axis(4, at=c(seq(0,600,length=6)), lab=c(seq(0,25,length=6)), col.axis=2 ) lines(a,ba, type=b, pch=21, cex=2, col=2, lwd=2, lty=1) I want the red line to relate its values to the x-axis (a) and axis 4 (on the right) and not as usual to the x-axis (a) and the y-axis (b). This would show the tendency of the red line much clearer which now can't be seen because of the very different scaling. E.g. I want R to know that I am trying to plot the first point of the red line P1(50/5) using the x-axis and the right axis, not the y-axis on the left ect. I would like to solve this without using a factor solution like: bb -600/25 * ba lines(a,bb, type=b, pch=21, cex=2, col=3, lwd=2, lty=1) For any kind of help I would be grateful ! -- View this message in context: http://r.789695.n4.nabble.com/additional-axis-different-scale-tp4623210.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. GET FREE SMILEYS FOR YOUR IM EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Dotchart showing mean and median by group
On Thu, May 10, 2012 at 2:24 AM, maxbre mbres...@arpa.veneto.it wrote: hi all I have another question reated to the dotchart: is it possible by means of par() to set a logaritmic scale? If yes, how ? and if not, any alternative solution? 1. This is getting increasingly complicated as new requirements are added but anyways here it is. As before, for the first dotchart call we substitute in our own dotchart (which is the same as R's dotchart except its environment is reset to p so that it picks up anything in p prior to similarly named functions elsewhere in R). This time we also add our own plot.window to p overriding log=. The line marked ## is optional and suppresses writing the axis annotations a second time. As before, this code depends on the internals of dotchart so its not ideal and you might wish to turn to lattice or ggplot 2 but it does give the desired effect while sticking to classic graphics. library(proto) p - proto(dotchart = dotchart, plot.window = function(..., log) graphics::plot.window(..., log = x)) with(p, dotchart(VADeaths, gdata = mean.values)) par(new = TRUE) p[[axis]] - p[[mtext]] - list ## with(p, dotchart(VADeaths, gdata = median.values, gpch = 20)) 2. A variation is to use dotchart2 in Hmisc. It has a version of dotchart that directly supports adding to the plot. Omit the suppressWarnings call below if you don't mind a few spurious warnings. library(Hmisc) groups - col(VADeaths, as.factor = TRUE) labels - rownames(VADeaths)[row(VADeaths)] suppressWarnings({ dotchart2(VADeaths, labels = labels, groups = groups, gdata = mean.values, log = x) dotchart2(VADeaths, labels = labels, groups = groups, gdata = median.values, log = x, pch = 1, add = TRUE) }) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] plotting legend-grob with grid.layout
Hi, I am using ggplot2 and arrange differnet plots into one viewport by dividing it into rows and columns: pushViewport(viewport(layout = grid.layout(nrow=2,ncol=2,widths = unit(c(50, 50), mm),heights = unit(c(50, 50), mm with following function I can extract the legend of a previously defined plot (ggplot2-plot) as a grob: legend - function(plot){ tmp - ggplot_gtable(ggplot_build(plot)) leg - which(sapply(tmp$grobs, function(x) x$name) == guide-box) legend - tmp$grobs[[leg]] } The plot themselves are sent to the viewport with: vplayout - function(x, y) viewport(layout.pos.row = x, layout.pos.col = y) print(p1, vp = vplayout(1, 1)) But, how can I put the legend into the viewport (e.g. colum=1,row=2)... I tried with draw.grob() which works, but then I can define the posiiton... This grid-arraning-viewport stuff is very confusing to me, so maybe someone can help out here... /johannes -- Jetzt informieren: http://mobile.1und1.de/?ac=OM.PW.PW003K20328T7073a __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] additional axis, different scale
On May 10, 2012, at 8:07 AM, John Kane wrote: I don't think there is any other way. There is: a - c(10, 20, 30, 40) b - c(50, 250, 500, 600) ba - b/a par(las=1, mar=c(5,5,.5,5)) plot(a,b, type=b, pch=22, cex=2, col=4, lwd=2, ylim=c(0,650), xlim=c(0,45)) par(new=TRUE) plot(a,ba,type=b, pch=21, cex=2, col=2, lwd=2, lty=1, xlim=c(0,45), yaxt=n) axis(4, at=c(seq(0,25,length=6)), lab=c(seq(0,25,length=6)), col.axis=2 ) # could also specify ylim of c(0,25) to the second plot call. # probably want to have ylab= in one or both of those plot calls, too. But I do agree this can be considered deceptive plotting practice. -- David. On the other hand, most gurus suggest that a dual scales on a graph are not a good thing. What about using a two panel graph? Quick rejigging of your code : = a - c(10, 20, 30, 40) b - c(50, 250, 500, 600) ba - b/a op - par(las=1, mar=c(5,5,.5,5), mfrow=c(2, 1)) plot(a,b, type=b, pch=22, cex=2, col=4, lwd=2, ylim=c(0,650), xlim=c(0,45)) plot (a,ba, type=b, pch=21, cex=2, col=2, lwd=2, lty=1) par(op) == John Kane Kingston ON Canada -Original Message- From: pann...@gwdg.de Sent: Thu, 10 May 2012 04:37:37 -0700 (PDT) To: r-help@r-project.org Subject: [R] additional axis, different scale Dear list, I am looking for a possibility to present results in a more graphical way by adding an axis. But I have trouble relating my data to the added axis. Imagine the following example: a - c(10, 20, 30, 40) b - c(50, 250, 500, 600) ba - b/a par(las=1, mar=c(5,5,.5,5)) plot(a,b, type=b, pch=22, cex=2, col=4, lwd=2, ylim=c(0,650), xlim=c(0,45)) axis(4, at=c(seq(0,600,length=6)), lab=c(seq(0,25,length=6)), col.axis=2 ) lines(a,ba, type=b, pch=21, cex=2, col=2, lwd=2, lty=1) I want the red line to relate its values to the x-axis (a) and axis 4 (on the right) and not as usual to the x-axis (a) and the y-axis (b). This would show the tendency of the red line much clearer which now can't be seen because of the very different scaling. E.g. I want R to know that I am trying to plot the first point of the red line P1(50/5) using the x-axis and the right axis, not the y-axis on the left ect. I would like to solve this without using a factor solution like: bb -600/25 * ba lines(a,bb, type=b, pch=21, cex=2, col=3, lwd=2, lty=1) For any kind of help I would be grateful ! -- View this message in context: http://r.789695.n4.nabble.com/additional-axis-different-scale-tp4623210.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. GET FREE SMILEYS FOR YOUR IM EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Modifying R package code
On 12-05-10 7:38 AM, Brian Smith wrote: Hi, I was trying to change some code in an existing package. I downloaded the source package (say 'package_xx') from CRAN, and changed the R code provided in the /package_xx/R/xx.R. I then saved the changes and did the R CMD INSTALL -l /path to modified package/. You don't want -l in that statement. It says where to install it, not what to install. Simply using R CMD INSTALL /path to modified package/ should be sufficient, assuming you have write permission on the default library. If you don't, then you do need to use -l, but it needs to specify some other location in which to install your package, and after you start R, you need to tell it (using .libPaths()) to look there before looking in the standard place. One other small bit of advice: record the fact that you made a change in the Version field in the DESCRIPTION file. Later, when you are tracking down bugs, it will be useful to remind you that nobody else can duplicate your problems. Duncan Murdoch Do I need to do something else before the changes will be effective? thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] stop calculation in a function
On Thu, May 10, 2012 at 8:02 AM, jeff6868 geoffrey_kl...@etu.u-bourgogne.fr wrote: Thank you for your reply sarah. Well actually I don't try to access x[i+1]. The line where you saw it starts with #. It was just try I wanted to keep (sorry I should have removed it before posting). Sorry, I should really have more coffee before replying to the list. Berend makes a good point about st1. You don't provide sample data, so I can't try it, but here's a modified version of your function that incorporates his advice plus a calculation of the number of terminal NA values to skip. I don't know whether x can have internal NA values as well as terminal, so I wrote a more complex check. If NA values only appear at the end, you can simply use sum(is.na(x)) instead. You could also interrupt the loop, but it seems easier to me to determine the right number of iterations beforehand since you already have the information needed. out2NA - function(x,seuil){ st1 = NULL # Temporal variable memorysing the last correct numeric value# temp - st1[1] - x[1] ind_temp - 1 # Max time gap between two comparisons # ecart_temps - 10 tps - time(x) st1 - numeric(length(x)) endNA - 0 if(is.na(x[length(x)])) { endNA - rle(rev(is.na(x)))$lengths[1] } for (i in 2:(length(x)-endNA)){ if((!is.na(x[i]))){ if((tps[i]-tps[ind_temp] ecart_temps) (abs(x[i]-temp) seuil)){ st1[i] - NA } else { temp - st1[i] - x[i] ind_temp - i } } } return(st1) } But I ask him to access to the next value if conditions in the loop are not verified (restart the comparison from the next value). It works well as long as I have numeric values in my data. But if my data ends with NAs, I have this problem. That's why I'm trying to ask him to stop the calculation in the loop at the last numeric value to avoid this error (don't know if it's the best way to solve it, but it's the main idea I think). Have you got any other idea about this? Thanks a lot! -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] file path
Why not just construct a valid file name and use that in cat? You can then use file.path to join paths together if you want to write to a specific location, as in your example. steve -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Wincent Sent: Wednesday, May 09, 2012 11:15 AM To: Tal Galili Cc: r help Subject: Re: [R] file path Hmm, I don't think it gives what I want. For example, I assign a file name to f, f - a?b.txt file.path(e:,f) [1] e:/a?b.txt The resultant character is not accepted as a file name by Windows OS. On 9 May 2012 20:32, Tal Galili tal.gal...@gmail.com wrote: Hi Wincent, Have a look at: ?file.path Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Wed, May 9, 2012 at 11:03 AM, Wincent ronggui.hu...@gmail.com wrote: Dear all, is there any function to assert whether a file path is legitimate, and to convert any potential file path to a legitimate file path? I automate a batch of files and write them to plain text files with cat(). The file argument of cat() is generated automatically which may contain characters such as ? , unacceptable in Windows OS. What I do at this moment is to strip such characters off with gsub(). Is there any direct way to make legitimate file path without detailed knowledge about the naming rule specific to a OS? Best -- Wincent Ronggui HUANG Sociology Department of Fudan University PhD of City University of Hong Kong http://homepage.fudan.edu.cn/rghuang/cv/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Wincent Ronggui HUANG Sociology Department of Fudan University PhD of City University of Hong Kong http://homepage.fudan.edu.cn/rghuang/cv/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] additional axis, different scale
Oh, yes of course. Thanks. I really don't like dual plots. I ran into one a few days ago that looked to me to be very dubious but I don't have the raw data to replot it in another form. It's a side issue so I'm not going to bother about it but is annoyed me. John Kane Kingston ON Canada -Original Message- From: dwinsem...@comcast.net Sent: Thu, 10 May 2012 08:18:48 -0400 To: jrkrid...@inbox.com Subject: Re: [R] additional axis, different scale On May 10, 2012, at 8:07 AM, John Kane wrote: I don't think there is any other way. There is: a - c(10, 20, 30, 40) b - c(50, 250, 500, 600) ba - b/a par(las=1, mar=c(5,5,.5,5)) plot(a,b, type=b, pch=22, cex=2, col=4, lwd=2, ylim=c(0,650), xlim=c(0,45)) par(new=TRUE) plot(a,ba,type=b, pch=21, cex=2, col=2, lwd=2, lty=1, xlim=c(0,45), yaxt=n) axis(4, at=c(seq(0,25,length=6)), lab=c(seq(0,25,length=6)), col.axis=2 ) # could also specify ylim of c(0,25) to the second plot call. # probably want to have ylab= in one or both of those plot calls, too. But I do agree this can be considered deceptive plotting practice. -- David. On the other hand, most gurus suggest that a dual scales on a graph are not a good thing. What about using a two panel graph? Quick rejigging of your code : = a - c(10, 20, 30, 40) b - c(50, 250, 500, 600) ba - b/a op - par(las=1, mar=c(5,5,.5,5), mfrow=c(2, 1)) plot(a,b, type=b, pch=22, cex=2, col=4, lwd=2, ylim=c(0,650), xlim=c(0,45)) plot (a,ba, type=b, pch=21, cex=2, col=2, lwd=2, lty=1) par(op) == John Kane Kingston ON Canada -Original Message- From: pann...@gwdg.de Sent: Thu, 10 May 2012 04:37:37 -0700 (PDT) To: r-help@r-project.org Subject: [R] additional axis, different scale Dear list, I am looking for a possibility to present results in a more graphical way by adding an axis. But I have trouble relating my data to the added axis. Imagine the following example: a - c(10, 20, 30, 40) b - c(50, 250, 500, 600) ba - b/a par(las=1, mar=c(5,5,.5,5)) plot(a,b, type=b, pch=22, cex=2, col=4, lwd=2, ylim=c(0,650), xlim=c(0,45)) axis(4, at=c(seq(0,600,length=6)), lab=c(seq(0,25,length=6)), col.axis=2 ) lines(a,ba, type=b, pch=21, cex=2, col=2, lwd=2, lty=1) I want the red line to relate its values to the x-axis (a) and axis 4 (on the right) and not as usual to the x-axis (a) and the y-axis (b). This would show the tendency of the red line much clearer which now can't be seen because of the very different scaling. E.g. I want R to know that I am trying to plot the first point of the red line P1(50/5) using the x-axis and the right axis, not the y-axis on the left ect. I would like to solve this without using a factor solution like: bb -600/25 * ba lines(a,bb, type=b, pch=21, cex=2, col=3, lwd=2, lty=1) For any kind of help I would be grateful ! -- View this message in context: http://r.789695.n4.nabble.com/additional-axis-different-scale-tp4623210.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. GET FREE SMILEYS FOR YOUR IM EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT FREE ONLINE PHOTOSHARING - Share your photos online with your friends and family! Visit http://www.inbox.com/photosharing to find out more! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] file path
As I said, the file name is derived automatically from text processing. Thanks all the same. On 10 May 2012 20:35, Upton, Stephen (Steve) (CIV) scup...@nps.edu wrote: Why not just construct a valid file name and use that in cat? You can then use file.path to join paths together if you want to write to a specific location, as in your example. steve -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Wincent Sent: Wednesday, May 09, 2012 11:15 AM To: Tal Galili Cc: r help Subject: Re: [R] file path Hmm, I don't think it gives what I want. For example, I assign a file name to f, f - a?b.txt file.path(e:,f) [1] e:/a?b.txt The resultant character is not accepted as a file name by Windows OS. On 9 May 2012 20:32, Tal Galili tal.gal...@gmail.com wrote: Hi Wincent, Have a look at: ?file.path Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Wed, May 9, 2012 at 11:03 AM, Wincent ronggui.hu...@gmail.com wrote: Dear all, is there any function to assert whether a file path is legitimate, and to convert any potential file path to a legitimate file path? I automate a batch of files and write them to plain text files with cat(). The file argument of cat() is generated automatically which may contain characters such as ? , unacceptable in Windows OS. What I do at this moment is to strip such characters off with gsub(). Is there any direct way to make legitimate file path without detailed knowledge about the naming rule specific to a OS? Best -- Wincent Ronggui HUANG Sociology Department of Fudan University PhD of City University of Hong Kong http://homepage.fudan.edu.cn/rghuang/cv/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Wincent Ronggui HUANG Sociology Department of Fudan University PhD of City University of Hong Kong http://homepage.fudan.edu.cn/rghuang/cv/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Wincent Ronggui HUANG Sociology Department of Fudan University PhD of City University of Hong Kong http://homepage.fudan.edu.cn/rghuang/cv/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] stop calculation in a function
Thanks for your answer too Berend. Yes you're right about x[i+1]. You answered juste before me. Well your idea of declaring all in numeric is great. It avoids my problem. But actually I also have small missing data gaps in the rest of my data (in the middle of numeric values). And one of the aim of my function is to avoid comparison between 2 numeric values which are separated with a long period of time (with NA inside), in order for example not to compare a value of the 1st january and the next numeric value of the 1st april. I'm trying to combine both. For the moment, it works only for data which doesn't ends with NAs as you've understood. With numeric() for st1, the problem of NAs at the end is solved but it creates a new problem with the other NAs (which was OK before). Do you better understand what I'm trying to do? If you have an other idea, It'll be welcomed. Thanks -- View this message in context: http://r.789695.n4.nabble.com/stop-calculation-in-a-function-tp4622964p4623391.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] stop calculation in a function
You're moving the goal posts. If you need to deal with internal as well as terminal NA values in a particular way, it would help to have told us that up front. Please give us some sample data that illustrates what you're really trying to work with, and a full explanation of what you need to accomplish. Sarah On Thu, May 10, 2012 at 8:41 AM, jeff6868 geoffrey_kl...@etu.u-bourgogne.fr wrote: Thanks for your answer too Berend. Yes you're right about x[i+1]. You answered juste before me. Well your idea of declaring all in numeric is great. It avoids my problem. But actually I also have small missing data gaps in the rest of my data (in the middle of numeric values). And one of the aim of my function is to avoid comparison between 2 numeric values which are separated with a long period of time (with NA inside), in order for example not to compare a value of the 1st january and the next numeric value of the 1st april. I'm trying to combine both. For the moment, it works only for data which doesn't ends with NAs as you've understood. With numeric() for st1, the problem of NAs at the end is solved but it creates a new problem with the other NAs (which was OK before). Do you better understand what I'm trying to do? If you have an other idea, It'll be welcomed. Thanks -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] file path
Has any mentioned ?make.names On Thu, May 10, 2012 at 8:39 AM, Wincent ronggui.hu...@gmail.com wrote: As I said, the file name is derived automatically from text processing. Thanks all the same. On 10 May 2012 20:35, Upton, Stephen (Steve) (CIV) scup...@nps.edu wrote: Why not just construct a valid file name and use that in cat? You can then use file.path to join paths together if you want to write to a specific location, as in your example. steve -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Wincent Sent: Wednesday, May 09, 2012 11:15 AM To: Tal Galili Cc: r help Subject: Re: [R] file path Hmm, I don't think it gives what I want. For example, I assign a file name to f, f - a?b.txt file.path(e:,f) [1] e:/a?b.txt The resultant character is not accepted as a file name by Windows OS. On 9 May 2012 20:32, Tal Galili tal.gal...@gmail.com wrote: Hi Wincent, Have a look at: ?file.path Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Wed, May 9, 2012 at 11:03 AM, Wincent ronggui.hu...@gmail.com wrote: Dear all, is there any function to assert whether a file path is legitimate, and to convert any potential file path to a legitimate file path? I automate a batch of files and write them to plain text files with cat(). The file argument of cat() is generated automatically which may contain characters such as ? , unacceptable in Windows OS. What I do at this moment is to strip such characters off with gsub(). Is there any direct way to make legitimate file path without detailed knowledge about the naming rule specific to a OS? Best -- Wincent Ronggui HUANG Sociology Department of Fudan University PhD of City University of Hong Kong http://homepage.fudan.edu.cn/rghuang/cv/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Wincent Ronggui HUANG Sociology Department of Fudan University PhD of City University of Hong Kong http://homepage.fudan.edu.cn/rghuang/cv/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Wincent Ronggui HUANG Sociology Department of Fudan University PhD of City University of Hong Kong http://homepage.fudan.edu.cn/rghuang/cv/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Taking a lead in panel data
I have tried the diff and lag function. I have given an example below. Diff gives me a$var2.shift. I want a$var2.noshift, i.e. var^(t+2)-var^(t) should stay in the row with year=t. Diff shifts it to the t+2 row. a - data.frame(c(rep(2,5), rep(3,5)), c(2005:2009, 2004:2008), c(NA,10,34,23,12, 23,45, NA, 45, NA)) colnames(a) - c(firm,year,var) a - pdata.frame(a) a$var2.shift - diff(a$var, lag=2, difference=1) a$var2.noshift - c(NA, 13,-22,NA, NA,NA, 0, NA, NA, NA) a firm year var var2.shift var2.noshift 2-20052 2005 NA NA NA 2-20062 2006 10 NA 13 2-20072 2007 34 NA -22 2-20082 2008 23 13 NA 2-20092 2009 12-22 NA 3-20043 2004 23 NA NA 3-20053 2005 45 NA0 3-20063 2006 NA NA NA 3-20073 2007 45 0 NA 3-20083 2008 NA NA NA On Tue, May 8, 2012 at 6:21 PM, Liviu Andronic landronim...@gmail.comwrote: On Tue, May 8, 2012 at 12:14 PM, Apoorva Gupta apoorva.ni...@gmail.com wrote: I have checked that. It allows me to get the t-1, t-2 value but not the t+1 value. Is there any other way of achieving this other than using the plm package? It would be easier to help if you provided a minimal reproducible example, as requested in the posting guide. Have you tried diff(x, lag = -1, ...) or lag(x, k = -1, ...) Perhaps this does what you want. Regards Liviu -- Apoorva Gupta Consultant National Institute of Public Finance and Policy [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Split the work for many cores
Dear all, I am using my code the vgram.matrix of packets fields. I have around 500 matrices that I need to pass inside that function and then plot those results. Even though my system has 16 cores is quite clear that I am only using one of those. Would it be able to skip these 500 tasks to the 16 cores, with each processor having around 4 matrices to process? What would you suggest me doing? Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] additional axis, different scale
Hi Jim, hi John, thank you very much for your tips. The plotrix package solves the problem! However, thank you also for the advice that my way of plotting the data might not be the best. I will think about it. So once again thanx ! -- View this message in context: http://r.789695.n4.nabble.com/additional-axis-different-scale-tp4623210p4623313.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] envfit output (vegan package) - not sure what it means
I'm pretty new to R and would appreciate some help interpreting the output of a function that was recommended to me. I've used the *envfit *function in the vegan package to plot vectors of four climate variables onto a species matrix ordination. The output indicates that only a single variable (mean_temp) is significant: ***VECTORS NMDS1 NMDS2r2 Pr(r) precip0.41539 -0.90964 0.29480.112887 wind -0.61937 0.78510 0.0441 0.763237 temp_mean 0.50571-0.86270 0.5839 0.004995 ** pressure-0.668910.74334 0.0688 0.622378 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 P values based on 1000 permutations. I understand that the length of the plotted arrows is proportional to the strength of the correlation between the variable and the ordination, but I'm not sure how to interpret the direction of the arrows. I know that it is the direction of the gradient, but *I don't really understand what gradient that is referring to*. So I'm not sure how to interpret what I'm seeing in the plot, other than the significance of the relationship. Here is the plot, if that helps. Each point is a sampling period; they are numbered from week 1 - week 8. The different shapes represent two different habitats. http://r.789695.n4.nabble.com/file/n4623315/species_abunance_with_environment.jpeg -- View this message in context: http://r.789695.n4.nabble.com/envfit-output-vegan-package-not-sure-what-it-means-tp4623315.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] registry vulnerabilities in R
What about using a Portable Apps style packaging of R? That might solve some of the issues. -- View this message in context: http://r.789695.n4.nabble.com/registry-vulnerabilities-in-R-tp4619217p4623388.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Output result to a csv file
Hi guys, I am applying linear regression model using lm, generate the residual and then need to output the result to a csv file. Here is my script: maxtempstation1.lm = lm( Year ~ station1, data=opencsv) maxstation1.res = resid(maxstation1.lm); maxstation1.res write.csv(maxtempstation1.res, file=maxtempstation1.csv) I can do that without problem, but I have 300 stations!. The general idea is to get all the residuals(for all years) into one csv file. Here is a sample of my data. Year st1 st2 st3st4 st5st6 st7st8 1982 27.75 27.84 29.81 28.24 29.08 27.97 28.92 28.2 1983 28.74 28.71 29.32 29.34 29.48 28.99 29.45 29.43 1984 28.13 28.34 29.64 28.03 28.85 28.03 28.61 28.08 Anybody willing to help? Thanks in advance guys. Eddie __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] envfit output (vegan package) - not sure what it means
cernst crystal.ernst at mail.mcgill.ca writes: I'm pretty new to R and would appreciate some help interpreting the output of a function that was recommended to me. I've used the *envfit *function in the vegan package to plot vectors of four climate variables onto a species matrix ordination. The output indicates that only a single variable (mean_temp) is significant: ***VECTORS NMDS1 NMDS2r2 Pr(r) precip0.41539 -0.90964 0.29480.112887 wind -0.61937 0.78510 0.0441 0.763237 temp_mean 0.50571-0.86270 0.5839 0.004995 ** pressure-0.668910.74334 0.0688 0.622378 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 P values based on 1000 permutations. I understand that the length of the plotted arrows is proportional to the strength of the correlation between the variable and the ordination, but I'm not sure how to interpret the direction of the arrows. I know that it is the direction of the gradient, but *I don't really understand what gradient that is referring to*. So I'm not sure how to interpret what I'm seeing in the plot, other than the significance of the relationship. Crystal, The arrows are labelled: the arrow with label temp_mean refers to the gradient of temp_mean. The arrow points to the direction to which the linear change in temp_mean is the fastest. To see what this means, you can add the corresponding linear trend surface, or its isoclines to the graphs. These isoclines are regularly spaced lines that are perpendicular to the arrow. So this is a linear trend surface, and the arrow points the gradient down the plane. I don't have your data, so I so how to do that in one of the vegan data sets. Just change here your data sets, ordination results and variable ('temp_mean' instead of 'A1' below): require(vegan) data(dune) data(dune.env) ord - rda(dune) plot(ord, dis=sites) ef - envfit(ord ~ A1, data=dune.env) plot(ef) ordisurf(ord ~ A1, data = dune.env, add = TRUE, knots = 1) HTH, Jari Oksanen PS. The density of vegan users is higher in r-sig-ecology than here: consider posting there for a more secured answer. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Random resampling of columns in species association matrices
Hi David, Thank you for your suggestions. I am quite the beginner at R and don’t understand how to actually implement your suggestion and am hoping for some further advice on that, if possible. This is a subset of my data. Rows are host species, and columns parasite species. Three of the parasites are generalists, but P4L is a strict specialist on FORCOL (27 individuals have this parasite). H17L P25L P41L P4L AUTINF39 0 0 0 GLYSPI16 2 15 0 FORCOL1 0 0 27 HYLPOE3 0 2 0 HYLNAE1 4 2 0 MYRMYO 25 2 0 THAARD0 8 0 0 This is a list of host trait values for each of the hosts: abundance weight survival AUTINF488 38 0.48 GLYSPI827 14.10.59 FORCOL156 44.30.55 HYLPOE322 17.50.54 HYLNAE309 14.50.73 MYRMYO 475 20.80.59 THAARD429 18.40.67 And this is an estimate of host specificity of the parasites, incorporating prevalence and phylogeny: Specificity H17L2.08 P25L1.72 P41L2.19 P4L 0 I want to determine whether specificity of the parasites relates to any of the host traits. For this, I would like to do a multiple regression. To avoid psedureplication, I want to include a host species only once in the matrix. So, for H17L, I could pick either of the hosts (except THAARD), etc., but once a host is picked for one parasite, it cannot be picked for another. For example, if I pick GLYSPI for H17L, GLYSPI has to be removed as a choice for P25L and P41L. Thus, I also have to randomize which parasite has its host picked first. In all cases, I want to lock FORCOL and P4L, so FORCOL will not be an option for H17L anymore. This last part I’m still uncertain about, I might just randomly pick hosts for all parasites and then risk losing the strict host species specialists from some matrices. If I make 2 random selections I might end up with: Random1 Random2 H17LAUTINF GLYSPI P25LGLYSPI HYLNAE P41LHYLPOE MYRMYO P4L FORCOL FORCOL For the first random table I would then do a multiple regression on the dependent specificity variable and independent host trait values: Specificity abundance weight survival 2.08 488 38 0.48 1.72 827 14.10.59 2.19 322 17.50.54 0 156 44.30.55 If I generate 1000 randomly selected host-parasite combinations, I would have 1000 such tables, on which I would have to run 1000 independent regressions. Since I’m using model selection and multimodel inference to estimate parameter values, I will end up doing the model selection 1000 times. Your second suggestion makes most sense to me, but I don’t understand how to implement it. Would you (or someone else) please give me some advise on that? Also, once I have the 1000 random host-parasite matrices, how do I link these to the tables of actual values (host traits and parasite specificity)? Thanks so much! Maria -- View this message in context: http://r.789695.n4.nabble.com/Random-resampling-of-columns-in-species-association-matrices-tp4620618p4623563.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] stop calculation in a function
I tried your proposition Sarah (I was answering to Berend when you posted your answer). Well it seems to work! I just had to add afterwords a line to have my NAs again. I converted values = 0 by NA (numeric() in the function did the contrary for the calculation): mydata[mydata==0] - NA At first it was working for such kind of data: NAs just in the middle of my data test - data.frame(c(1,2,3,4,NA,NA,7,8,9,10),c(11,12,NA,14,15,16,17,NA,19,20)) colnames(test)- c(data1,data2) but not for data with NAs at the beginning, in the middle and at the end: test2 - data.frame(c(NA,2,3,4,NA,NA,NA,NA,NA,NA),c(NA,12,13,NA,15,16,17,NA,NA,NA)) colnames(test2)- c(data3,data4) But thanks to your proposition, it seems to work in both cases now! Thanks a lot sarah! -- View this message in context: http://r.789695.n4.nabble.com/stop-calculation-in-a-function-tp4622964p4623584.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Fwd: Re: need help in R
i need help in my coding the first line and the second line works and the ggplot works when i have a code like this and i want to fetch a map and saves it to a directory how can i put it because it gives me an error message Error in load(GGemz) : bad 'file' argument GGemz - ggooglemap(center=center,zoom=13,destfile=Emz.png) save(GGemz,file=GGemz.Rda) load(GGemz) and when i put the GGemz in brackets it gives me an error load(file=GGemz) Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection In addition:Warning message: In readChar(con, 5L, useBytes = TRUE) : i dont have a problem here ggplot()+ geom_tile(aes(x = lon, y = lat, fill = fill), data = GGemz)+ geom_jitter(aes(x=lon,y=lat, color=fieldworker),data=emz)+ scale_fill_identity()+ scale_x_continuous('Longitude', limits = lon_range) + scale_y_continuous('Latitude', limits = lat_range) + scale_colour_discrete('') + opts(title = 'Invitation map of Emzinini, 2012') + coord_equal() this code brings an error says Error in dev.copy2pdf(device = x11, file = paste(mapdir, EmzinoniGG.pdf, : no device to print from i am not sure what does the error mean dev.copy2pdf(device=x11,file=paste(mapdir,EmzinoniGG.pdf,sep=)) dev.off() -- Leah Mathibela mobile:078-3311-491 work:087-7545-997 www.nova.org.za David Winsemius, MD West Hartford, CT No virus found in this message. Checked by AVG - www.avg.com http://www.avg.com -- Leah Mathibela mobile:078-3311-491 work:087-7545-997 www.nova.org.za [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Interweaving of two datasets
Hello, What doesn't work, exactly? I can only see two things: 1. The order of the columns is different, first data.frame in merge instruction comes first. Solution: reverse the order of data.frames in merge. 2. The order of the rows is different, the merge function orders it's output by the common col(s). Solutions: leave as is or use 'order'. # first is the first sheet in attached .xls file, second is the second and result is the third. # 1. res2 - merge(second, first) # 2. result[order(result$name, result$request), ] res2[order(res2$name, res2$request), ] If this isn't it, please state what the problem is, doesn't work is a bit vague. Hope this helps, Rui Barradas lunarossa wrote it doesn't work. Find attached what I need explained in xls. Thank you very very much! http://r.789695.n4.nabble.com/file/n4622912/interweaving_of_2_datasets.xls interweaving_of_2_datasets.xls -- View this message in context: http://r.789695.n4.nabble.com/Interweaving-of-two-datasets-tp4608505p4623624.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] outlier identify in qqplot
Find the data attached, http://r.789695.n4.nabble.com/file/n4623493/mydata.txt mydata.txt The model would be /lmmodel - lm(log(vdep) ~ v1 + sqrt(v2) + v3 +v5 + v6 + v7 + v8 + v9 + v10, data = mydata)/ Thanks again, u...@host.com -- View this message in context: http://r.789695.n4.nabble.com/outlier-identify-in-qqplot-tp4076587p4623493.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Using valgrind to debug R, extracting column of a mts object causes valgrind to crash
Dear all, I'm trying to debug my R package with valgrind, but I cannot get past the point where I load make the data, as valgrind crashes when trying to extract a single time series object of a multivariate mts object. I'm using R 2.15.0 with platform x86_64-redhat-linux-gnu (64-bit). The valgrind.R contains code data(Seatbelts) y-Seatbelts[,VanKilled] And I run valgrind with R -d valgrind --tool=memcheck --leak-check=yes --no-save valgrind.R Results look like this: data(Seatbelts) y-Seatbelts[,VanKilled] vex amd64-IR: unhandled instruction bytes: 0x66 0xF 0x3A 0xB 0xC0 0xC ==31160== valgrind: Unrecognised instruction at address 0x399fe26990. ==31160== Your program just tried to execute an instruction that Valgrind ==31160== did not recognise. There are two possible reasons for this. ==31160== 1. Your program has a bug and erroneously jumped to a non-code ==31160==location. If you are running Memcheck and you just saw a ==31160==warning about a bad jump, it's probably your program's fault. ==31160== 2. The instruction is legitimate but Valgrind doesn't handle it, ==31160==i.e. it's Valgrind's fault. If you think this is the case or ==31160==you are not sure, please let us know and we'll try to fix it. ==31160== Either way, Valgrind will now raise a SIGILL signal which will ==31160== probably kill your program. *** caught illegal operation *** address 0x399fe26990, cause 'illegal opcode' Traceback: 1: ts(y, start = start(x), frequency = frequency(x)) 2: `[.ts`(Seatbelts, , VanKilled) 3: Seatbelts[, VanKilled] aborting ... ==31160== ==31160== HEAP SUMMARY: ==31160== in use at exit: 29,782,377 bytes in 12,590 blocks ==31160== total heap usage: 30,275 allocs, 17,685 frees, 57,159,124 bytes allocated ==31160== ==31160== LEAK SUMMARY: ==31160==definitely lost: 0 bytes in 0 blocks ==31160==indirectly lost: 0 bytes in 0 blocks ==31160== possibly lost: 0 bytes in 0 blocks ==31160==still reachable: 29,782,377 bytes in 12,590 blocks ==31160== suppressed: 0 bytes in 0 blocks ==31160== Reachable blocks (those to which a pointer was found) are not shown. ==31160== To see them, rerun with: --leak-check=full --show-reachable=yes ==31160== ==31160== For counts of detected and suppressed errors, rerun with: -v ==31160== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 2 from 2) Illegal instruction (core dumped) It seems that the crash is caused by the fact that the rows of the Seatbelts are not defined in assignment, but if I use command y-Seatbelts[1:192,VanKilled] the resulting object is not a time series object anymore. Is there some better way to do this? best regards, Jouni [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Problem with factors in NMDS and Envfit
Hi everybody, thanks in advance for your help! I am working with genetic data performing an NMDS to visualize the genetic differentiation of individuals from different species and populations in different site conditions (site variables are all factors), and actually genetic data also. The data base is kind of big ( 1000 individuals x 551 variables) Nmds so far has not worked with the genetic data input as factors it shows me and error (maybe the distance is not the proper?) as integer the NMDS works well ord2-metaMDS(gen_all_nonas,k = 2, distance=euclid, autotransform=F, noshare=T, na.rm=T) When I use envfit to see the correlation of the site factors it does not work until I remove all Nas. Once I do that it works almost good (I can live with the Nas removing) but somehow It show me an error considering the factor: Populations where the individuals come from (Pop) exp_site-envfit(ord2~Pop+Sp+Location+Soil+Water+Flooding+Ca, strata=Sp, na.rm=T)# with strata Error en `colnames-`(`*tmp*`, value = Pop) : attempt to set colnames on object with less than two dimensions I do not know what I am doing wrong, there are more than 40 Populations in the data set but I get this problem. Once I remove Pop from the command It works ok e.g., attach(site_all_nonas) exp_site2-envfit(ord2~Sp+Location+Soil+Water+Flooding+Ca, strata=Sp, na.rm=T)# with strata Sp exp_site2 Goodness of fit: r2 Pr(r) Sp 0.5398 0.001 *** Location 0.4174 0.001 *** Soil 0.0090 0.511 Water0.0103 0.873 Flooding 0.0234 0.515 Ca 0.0334 0.901 --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 P values based on 999 permutations, stratified within strata. - Rodrigo Vargas G. - Silviculture Institute Freiburg University -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-factors-in-NMDS-and-Envfit-tp4623645.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Interweaving of two datasets
Hi Ruri, sorry for my vagueness. The problem is not the order. I tried to merge the datasets as you wrote. The result is that when I input: table(phone) The output is: 0 And this happens for all the variables. -- View this message in context: http://r.789695.n4.nabble.com/Interweaving-of-two-datasets-tp4608505p4623672.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Automating R for Hypothesis Testing
Rui- Thanks this definitely helps, just one quick question. How would you code the values of chi-fm and chi-fms to change based on the degrees of freedom of each model H(i)? Meredith Rui Barradas wrote Hello, Yes, it does help. Now we can see your data and what you're doing. What follows is a suggestion on what you could do, not full solution. (You forgot to say what X1 is, but I don't think it's important to understand the suggestion.) (If I'm wrong, say something.) milwaukeephos - read.csv(milwaukeephos.csv, header=TRUE, stringsAsFactors=FALSE) # list of data.frames, one per month ls1 - split(milwaukeephos, milwaukeephos$month) #- if you want to keep the models, not needed if you don't. # (yoy probably don't) modelH - vector(list, 12) modelHa - vector(list, 12) modelH2 - vector(list, 12) modelH2a - vector(list, 12) #- values to record, these are needed, create them beforehand. chi_fm - numeric(12) chi_fms - numeric(12) # seq_months - c(1:12, 1) # wrap months around. for(i in 1:12){ month_this - seq_months[i] month_next - seq_months[i + 1] lload - c(ls1[[month_this]]$load_kg, ls1[[month_next]]$load_kg) lflow - c(ls1[[month_this]]$flow, ls1[[month_next]]$flow) modelH[[i]] - lm(lload ~ lflow) # If you don't want to keep the models, use modelH only # ( without [[i]] ) # and do the same with X1 # rest of your code for first test goes here chi_fm[i] - bfm %*% var_fm %*% (bunres_fm - bres_fm) # and the same for the second test chi_fms[i] - ...etc... } Hope this helps, Rui Barradas meredith wrote dput: http://r.789695.n4.nabble.com/file/n4620188/milwaukeephos.csv milwaukeephos.csv # Feb-march modelH_febmarch-lm(llfeb_march~lffeb_march) modelHa_febmarch-lm(llfeb_march~X1feb_mar+lffeb_march) anova(modelHa_febmarch) coefficients(modelH_febmarch) (Intercept) lffeb_march -2.4298901.172821 coefficients(modelHa_febmarch) (Intercept) X1feb_mar lffeb_march -2.8957776 -0.5272793 1.3016303 bres_fm-matrix(c(-2.429890,0,1.172821),nrow=3) bunres_fm-matrix(c(-2.8957776,-0.5272793,1.3016303),nrow=3) bfm-t(bunres_fm-bres_fm) fmvect-seq(1,1,length=34) X1a_febmar-seq(0,0,length=9) # dummy variable step 1 X1b_febmar-seq(1,1,length=25) # dummy variable step 2 X1feb_mar-c(X1a_febmar,X1b_febmar) #dummy variable creation # Test Stat Equation for Chisq fmxx-cbind(fmvect,X1feb_mar,lffeb_march) tfmx-t(fmxx) xcom_fm-(tfmx %*% fmxx) xinv_fm-ginv(xcom_fm) var_fm-xinv_fm*0.307 chi_fm-bfm %*% var_fm %*% (bunres_fm-bres_fm) chi_fm # chisq value for recording if less than CV move onto to slope modification modelH2_febmarch-lm(llfeb_march~X3feb_march) modelH2a_febmarch-lm(llfeb_march~X3feb_march+X4feb_march) anova(modelH2a_febmarch) coefficients(modelH2_febmarch) # get coefficients to make beta vectors for test (Intercept) X3feb_march 5.3421301.172821 coefficients(modelH2a_febmarch) (Intercept) X3feb_march X4feb_march 5.2936263 1.0353752 0.2407557 # Test Stat bsres_fm-matrix(c(5.342130,1.172821,0),nrow=3) bsunres_fm-matrix(c(5.2936263,1.0353752,0.2407557),nrow=3) bsfm-t(bsunres_fm-bsres_fm) #X matrix fmxs-cbind(fmvect,X3feb_march,X4feb_march) tfmxs-t(fmxs) xcoms_fm-(tfmxs %*% fmxs) xinvs_fm-ginv(xcoms_fm) var_fms-xinvs_fm*0.341 chi_fms-bsfm %*% var_fms %*% (bsunres_fm-bsres_fm) chi_fms # Record Chisq value Does this help? Here lffeb_march is the combination of Feb and March log flows and llfeb_march is the combination of Feb and March log loads X3: lffeb_march-mean(feb_march) X4: X1*X3 Thanks Rui Barradas wrote Hello, I'm not at all sure if I understand your problem. Does this describe it? test first model for months 1 and 2 if test statistic less than critical value{ test second model for months 1 and 2 print results of the first and second tests? just one of them? } move on to months 2 and 3 etc, until months 12 and 1 Please post example data using dput(dataset). Just copy it's output and paste it in your post. And example code, what you're already doing. (Possibly simplified) Rui Barradas meredith wrote R Users- I have been trying to automate a manual code that I have developed for calling in a .csv file, isolating certain rows and columns that correspond to specified months: something to the effect i=name.csv N=length(i$month) iphos1=0 iphos2=0 isphos3=0 for i=1,N if month=1 iphos1=iphos+1 iphos1(iphos1)=i an so on to call out the months into there own arrays (unless there is a way I can wrap it into the next automation) Next: I would like to run a simple linear regression combining each of the months 1 by 1: for instance I want to run a regression on a combined model from months 1 and 2 and a dummy model for 1 and 2, compare them using a Chi-sq distribution, if Chi-sq is less than the Critical
Re: [R] Dotchart showing mean and median by group
thank you all for the high level contributions and the very helpful feedback; I think I have now enogh material to study for months: what a good lesson learned! cheers max -- View this message in context: http://r.789695.n4.nabble.com/Dotchart-showing-mean-and-median-by-group-tp4619597p4623526.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] png support in R on linux
Hi there, I am sure this question has been posted a couple times before but I could not find a good solution on the web. Is there any way to get png() support in R on SUSE linux? We want to run GenePattern on that server and some workflows use R scripts plotting into pngs. Best wishes Kristian R version 2.14.0 (2011-10-31) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=de_DE.UTF-8 LC_NUMERIC=C [3] LC_TIME=de_DE.UTF-8LC_COLLATE=de_DE.UTF-8 [5] LC_MONETARY=de_DE.UTF-8LC_MESSAGES=de_DE.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] png_0.1-4 loaded via a namespace (and not attached): [1] tools_2.14.0 Linux version 2.6.32.12-0.7-default (geeko@buildhost) (gcc version 4.3.4 [gcc-4_3-branch revision 152973] (SUSE Linux) ) #1 SMP 2010-05-20 11:14:20 +0200 Arbeitsgruppenleiter Integrative Biologie / Head of Integrative Biology Group Abteilung für Strahlenzytogenetik / Research Unit of Radiation Cytogenetics Tel.: +49-89-3187-3515 Helmholtz Zentrum München Deutsches Forschungszentrum für Gesundheit und Umwelt (GmbH) Ingolstädter Landstr. 1 85764 Neuherberg www.helmholtz-muenchen.de Aufsichtsratsvorsitzende: MinDir´in Bärbel Brumme-Bothe Geschäftsführer: Prof. Dr. Günther Wess und Dr. Nikolaus Blum Registergericht: Amtsgericht München HRB 6466 USt-IdNr: DE 129521671 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Interweaving of two datasets
I don't quite follow what you are doing. Here is what Rui was suggesting using your sample data === dat1 - structure(list(name = structure(c(4L, 3L, 5L, 2L, 1L, 6L), .Label = c(Andy, Bruce, Ella, John, Luna, Morgana), class = factor), address = structure(c(2L, 4L, 1L, 3L, 2L, 4L), .Label = c(Kiev street, london road, main avenue, Rome street), class = factor), phone = c(2123L, 2342L, 454L, 56775L, 287678L, 39876L)), .Names = c(name, address, phone), class = data.frame, row.names = c(NA, -6L)) dat2 - structure(list(name = structure(c(4L, 4L, 3L, 3L, 3L, 5L, 5L, 2L, 2L, 2L, 2L, 1L, 6L, 6L, 6L), .Label = c(Andy, Bruce, Ella, John, Luna, Morgana), class = factor), request = structure(c(1L, 5L, 4L, 1L, 3L, 4L, 5L, 5L, 5L, 4L, 4L, 2L, 1L, 4L, 2L), .Label = c(book, cigarettes, drink, food, paper), class = factor)), .Names = c(name, request), class = data.frame, row.names = c(NA, -15L)) mydata - merge(dat1, dat2) mydata === #If you need information about a variable in the merge try something like: table(mydata$phone) Is this of any help? John Kane Kingston ON Canada -Original Message- From: gloriaal...@yahoo.it Sent: Thu, 10 May 2012 07:33:45 -0700 (PDT) To: r-help@r-project.org Subject: Re: [R] Interweaving of two datasets Hi Ruri, sorry for my vagueness. The problem is not the order. I tried to merge the datasets as you wrote. The result is that when I input: table(phone) The output is: 0 And this happens for all the variables. -- View this message in context: http://r.789695.n4.nabble.com/Interweaving-of-two-datasets-tp4608505p4623672.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. GET FREE SMILEYS FOR YOUR IM EMAIL - Learn more at http://www.inbox.com/smileys Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] converting raster image
Dear R users, I was wondering how I can convert a raster image (that made R through interpolation) into an ascii or csv format? this is the last line of my command p - interpolate(r, tpsfit) So p is my raster file which I want to convert into ascii or csv Many thanks Regards Mintewab __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to capture NA values
Dear all, I would like to capture the NA values as produced from my code the str over the return values return int 61 int 65 int 69 int 73 int 101 int NA int NA it looks like that I am getting returned some integer values that are NA and I want to have an if statement for catching those which is the right operator for checking these int NA values in R? Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to capture NA values
On 10-05-2012, at 17:16, Alaios wrote: Dear all, I would like to capture the NA values as produced from my code the str over the return values return int 61 int 65 int 69 int 73 int 101 int NA int NA it looks like that I am getting returned some integer values that are NA and I want to have an if statement for catching those which is the right operator for checking these int NA values in R? How about simply is.na? Berend __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] disagreement in loglikelihood and deviace in GLM with weights leads to different models selected using step()
In species distribution modeling where one uses a large sample of background points to capture background variation in presence\pseudo-absence or use\available models (0\1 response) it is frequently recommended that one weight the data so the sum of the absence weights is equal to the sum of presence weights so that the model isn?t swamped by an overwhelming and arbitrary number of background points. I?m trying to do this in R in the standard glm in the stats package and am a bit confused. I understand the issue with noninteger weights in glm and specifying reasonable starting values to ensure convergence to something meaningful and for any individual model fit I can get mostly the same results. For example I have a dataset with 75 presence and 75 absence if instead I had randomly sampled 3150 background points I could set the weights to 1 for presence and 75/3150 for the background points. I simulate this example by repeating my 75 absences 42 times and setting the weights for the absence to 75/3150 and setting mustart equal to the predicted response from the 75/75 model and fitting glms to each data set. The output agrees in the coefficient estimates null and residual deviance but NOT in the AIC or the value returned from logLik() it appears the AIC is calculated from the likelihood though as I understand it these should be directly related to deviance so I?m not sure why these don?t all agree. My ultimate goal is to fit these models and run automatic model selection using the step function. This doesn?t seem to work for two reasons: 1.it uses the logLik value of likelihood and I feel it should be using .5*resid deviance. I'm not quite sure why these are different 2.it doesn?t use the correct penalty because the degrees of freedom are 3225 rather than something reasonable (I adjust this by multiplying by what I assume is a reasonable penalty so if I were using 75/75 I'd use the penalty k=2 but here I use 2*sum(weight)/length(weight) For an individual model fit for example we have For No Repeated observations: Call: glm(formula = as.formula(paste(response, ~, paste(out$dat$used.covs, collapse = +))), family = binomial, data = test.data) Coefficients: (Intercept) asp_2k_alb beetle_yr bio_1 bio_10 bio_11 -3.057e+01 -3.045e-03 4.474e-01 -1.577e-01 -9.599e-01 2.326e+00 bio_12 bio_13 bio_14 bio_15 bio_16 bio_17 2.205e-02 NA 1.461e-01 1.227e-01 -4.705e-02 -8.138e-02 bio_18 bio_19 bio_4 bio_5 bio_6 bio_7 -9.938e-03 9.128e-03 2.713e-03 -5.724e+04 5.725e+04 5.725e+04 bio_8 bio_9 damage_yr dem_2k_alb dist_line_all dist_pts -4.155e-01 -2.874e-01 -6.129e-01 4.910e-03 -5.575e-05 3.965e-06 dist_trail_3 dist_transgov dist_trans_01 dist_util4568 dist_water eastness -1.510e-04 1.158e-05 NA 8.621e-06 2.392e-04 -4.421e-01 northness slp_2k_albbeetle_all1damage_all1 3.066e-01 2.975e-02 -6.609e+00 1.894e+00 Degrees of Freedom: 149 Total (i.e. Null); 118 Residual Null Deviance: 207.9 Residual Deviance: 112.5AIC: 176.5 logLik(no.rep) 'log Lik.' -56.23042 (df=32) For repeated observations (of course in a real example these wouldn't be repeated observations but oversampled background points): Call: glm(formula = as.formula(paste(response, ~, paste(out$dat$used.covs, collapse = +))), family = binomial, data = psdAbsDat, weights =train$weight) Coefficients: (Intercept) asp_2k_alb beetle_yr bio_1 bio_10 bio_11 -3.057e+01 -3.045e-03 4.474e-01 -1.577e-01 -9.599e-01 2.326e+00 bio_12 bio_13 bio_14 bio_15 bio_16 bio_17 2.205e-02 NA 1.461e-01 1.227e-01 -4.705e-02 -8.138e-02 bio_18 bio_19 bio_4 bio_5 bio_6 bio_7 -9.938e-03 9.128e-03 2.713e-03 -5.724e+04 5.725e+04 5.725e+04 bio_8 bio_9 damage_yr dem_2k_alb dist_line_all dist_pts -4.155e-01 -2.874e-01 -6.129e-01 4.910e-03 -5.575e-05 3.965e-06 dist_trail_3 dist_transgov dist_trans_01 dist_util4568 dist_water eastness -1.510e-04 1.158e-05 NA 8.621e-06 2.392e-04 -4.421e-01 northness slp_2k_albbeetle_all1damage_all1 3.066e-01 2.975e-02 -6.609e+00 1.894e+00 Degrees of Freedom: 3224 Total (i.e. Null); 3193 Residual Null Deviance: 207.9 Residual Deviance: 112.5AIC: 117 logLik(weight) 'log
Re: [R] Automating R for Hypothesis Testing
Hello, I'm glad it helped. As for your second question, I don't know, but I'm not very comfortable with the way you're doing things. Why subtract the coefficients of model 1 from model 2? And why the dummy? Why set model 1 to zero? Isn't it better to use anova's F? After all, it's designed for it, for the linear model... And if you really want/need the dummy, wouldn't a nested anova do it? (F statistic, once again.) anova(model1, model2) is simple and statistically speaking seems to me much better. (I specially don't like the subtraction bit.) Rui Barradas meredith wrote Rui- Thanks this definitely helps, just one quick question. How would you code the values of chi-fm and chi-fms to change based on the degrees of freedom of each model H(i)? Meredith Rui Barradas wrote Hello, Yes, it does help. Now we can see your data and what you're doing. What follows is a suggestion on what you could do, not full solution. (You forgot to say what X1 is, but I don't think it's important to understand the suggestion.) (If I'm wrong, say something.) milwaukeephos - read.csv(milwaukeephos.csv, header=TRUE, stringsAsFactors=FALSE) # list of data.frames, one per month ls1 - split(milwaukeephos, milwaukeephos$month) #- if you want to keep the models, not needed if you don't. # (yoy probably don't) modelH - vector(list, 12) modelHa - vector(list, 12) modelH2 - vector(list, 12) modelH2a - vector(list, 12) #- values to record, these are needed, create them beforehand. chi_fm - numeric(12) chi_fms - numeric(12) # seq_months - c(1:12, 1) # wrap months around. for(i in 1:12){ month_this - seq_months[i] month_next - seq_months[i + 1] lload - c(ls1[[month_this]]$load_kg, ls1[[month_next]]$load_kg) lflow - c(ls1[[month_this]]$flow, ls1[[month_next]]$flow) modelH[[i]] - lm(lload ~ lflow) # If you don't want to keep the models, use modelH only # ( without [[i]] ) # and do the same with X1 # rest of your code for first test goes here chi_fm[i] - bfm %*% var_fm %*% (bunres_fm - bres_fm) # and the same for the second test chi_fms[i] - ...etc... } Hope this helps, Rui Barradas meredith wrote dput: http://r.789695.n4.nabble.com/file/n4620188/milwaukeephos.csv milwaukeephos.csv # Feb-march modelH_febmarch-lm(llfeb_march~lffeb_march) modelHa_febmarch-lm(llfeb_march~X1feb_mar+lffeb_march) anova(modelHa_febmarch) coefficients(modelH_febmarch) (Intercept) lffeb_march -2.4298901.172821 coefficients(modelHa_febmarch) (Intercept) X1feb_mar lffeb_march -2.8957776 -0.5272793 1.3016303 bres_fm-matrix(c(-2.429890,0,1.172821),nrow=3) bunres_fm-matrix(c(-2.8957776,-0.5272793,1.3016303),nrow=3) bfm-t(bunres_fm-bres_fm) fmvect-seq(1,1,length=34) X1a_febmar-seq(0,0,length=9) # dummy variable step 1 X1b_febmar-seq(1,1,length=25) # dummy variable step 2 X1feb_mar-c(X1a_febmar,X1b_febmar) #dummy variable creation # Test Stat Equation for Chisq fmxx-cbind(fmvect,X1feb_mar,lffeb_march) tfmx-t(fmxx) xcom_fm-(tfmx %*% fmxx) xinv_fm-ginv(xcom_fm) var_fm-xinv_fm*0.307 chi_fm-bfm %*% var_fm %*% (bunres_fm-bres_fm) chi_fm # chisq value for recording if less than CV move onto to slope modification modelH2_febmarch-lm(llfeb_march~X3feb_march) modelH2a_febmarch-lm(llfeb_march~X3feb_march+X4feb_march) anova(modelH2a_febmarch) coefficients(modelH2_febmarch) # get coefficients to make beta vectors for test (Intercept) X3feb_march 5.3421301.172821 coefficients(modelH2a_febmarch) (Intercept) X3feb_march X4feb_march 5.2936263 1.0353752 0.2407557 # Test Stat bsres_fm-matrix(c(5.342130,1.172821,0),nrow=3) bsunres_fm-matrix(c(5.2936263,1.0353752,0.2407557),nrow=3) bsfm-t(bsunres_fm-bsres_fm) #X matrix fmxs-cbind(fmvect,X3feb_march,X4feb_march) tfmxs-t(fmxs) xcoms_fm-(tfmxs %*% fmxs) xinvs_fm-ginv(xcoms_fm) var_fms-xinvs_fm*0.341 chi_fms-bsfm %*% var_fms %*% (bsunres_fm-bsres_fm) chi_fms # Record Chisq value Does this help? Here lffeb_march is the combination of Feb and March log flows and llfeb_march is the combination of Feb and March log loads X3: lffeb_march-mean(feb_march) X4: X1*X3 Thanks Rui Barradas wrote Hello, I'm not at all sure if I understand your problem. Does this describe it? test first model for months 1 and 2 if test statistic less than critical value{ test second model for months 1 and 2 print results of the first and second tests? just one of them? } move on to months 2 and 3 etc, until months 12 and 1 Please post example data using dput(dataset). Just copy it's output and paste it in your post. And example code, what you're already doing. (Possibly simplified) Rui Barradas meredith wrote R Users- I have been trying to automate a manual code that I have developed for calling in a .csv file, isolating certain rows and columns that correspond to
Re: [R] Output result to a csv file
Hello, Try station - colnames(opencsv)[-1] mat - matrix(0, nrow=length(station), ncol=nrow(opencsv)) dimnames(mat) - list(station, opencsv$Year) for(st in station){ model - lm(Year~opencsv[, st], data=opencsv) mat[st, ] - residuals(model) } write.csv(mat, opencsv.csv) Hope this helps, Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/Output-result-to-a-csv-file-tp4623510p4623714.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Interweaving of two datasets
With the sample data and the merge as above, table(res2$phone) 454 2123 2342 9876 56775 87678 2 2 3 3 4 1 with(res2, table(name, request)) request name book cigarettes drink food paper Andy 0 1 00 0 Bruce 0 0 02 2 Ella 1 0 11 0 John 1 0 00 1 Luna0 0 01 1 Morgana1 1 01 0 Rui Barradas lunarossa wrote Hi Rui, sorry for my vagueness. The problem is not the order. I tried to merge the datasets as you wrote. The result is that when I input: table(phone) The output is: 0 And this happens for all the variables. -- View this message in context: http://r.789695.n4.nabble.com/Interweaving-of-two-datasets-tp4608505p4623724.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to capture NA values
On May 10, 2012, at 11:16 AM, Alaios wrote: Dear all, I would like to capture the NA values as produced from my code the str over the return values return int 61 int 65 int 69 int 73 int 101 int NA int NA it looks like that I am getting returned some integer values that are NA and I want to have an if statement for catching those which is the right operator for checking these int NA values in R? If you have a vector of mode 'integer' (or numeric) you can get their index locations with: which(is.na(vec)) Logical tests for any NA's would be: !length(which(is.na(vec))) or sum(is.na(vec))==0 or perhaps the most self-documenting method: any(is.na(vec)) -- David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] averaging two tables (rows with columns)
Hi R user,I am struggling to figure out on how I can calculate the average from the two tables in R. Any one can help me? really your help would be grateful- I am spending so much time to figure it out. It should not be so hard, I think. I have very big data but I have created a hypothetical data for simplification. for example I have : table 1 table 1: species occurance data speciesX speciesY speciesZ speciesXX Plot1 1 0 1 0 Plot2 0 1 1 0 Plot3 0 0 0 1 Plot4 1 0 1 0 Table 2 table 2. species tolerance data EnviA EnviB EnviC speciesX 0.21 0.4 0.17 speciesY 0.1 0.15 0.18 speciesXX 0.14 0.16 0.19 You may noticed that table 2 does not have species Z which was in table 1. Now I want to get the average value of species tolerance in each plot based on each environmental value (EnviA or EnviB etc)The example of the out come (final table I was looking for it) Results table 1a: average species tolerance in each plot based on EnviA Result Table 3. Average species tolerance in each plot based on EnviA speciesX speciesY speciesZ speciesXX Average Plot1 0.21 NA Nodata 0.14 0.175 Plot2 NA 0.1 Nodata NA 0.1 Plot3 NA NA Nodata 0.14 0.14 Plot4 0.21 NA Nodata NA 0.21 Result table 1b: average species tolerance in plot based on EnviB Table 4. Average species tolerance in each plot based on EnviB speciesX speciesY speciesZ speciesXX Average Plot1 0.4 NA Nodata 0.16 0.28 Plot2 NA 0.15 Nodata NA 0.15 Plot3 NA NA Nodata 0.16 0.16 Plot4 0.4 NA Nodata NA 0.4 Would any one help me how I can calculate these?Thanks Kristi Golver== [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] averaging two tables (rows with columns)
Kristi, Your data has come through in a totally unreadable layout. Have a look at ?dput as a handy way to present sample data. Just run dput(mydata), copy the output and paste into the email. John Kane Kingston ON Canada -Original Message- From: kristi.glo...@hotmail.com Sent: Thu, 10 May 2012 12:50:43 -0300 To: r-help@r-project.org Subject: [R] averaging two tables (rows with columns) Hi R user,I am struggling to figure out on how I can calculate the average from the two tables in R. Any one can help me? really your help would be grateful- I am spending so much time to figure it out. It should not be so hard, I think. I have very big data but I have created a hypothetical data for simplification. for example I have : table 1 table 1: species occurance data speciesX speciesY speciesZ speciesXX Plot1 1 0 1 0 Plot2 0 1 1 0 Plot3 0 0 0 1 Plot4 1 0 1 0 Table 2 table 2. species tolerance data EnviA EnviB EnviC speciesX 0.21 0.4 0.17 speciesY 0.1 0.15 0.18 speciesXX 0.14 0.16 0.19 You may noticed that table 2 does not have species Z which was in table 1. Now I want to get the average value of species tolerance in each plot based on each environmental value (EnviA or EnviB etc)The example of the out come (final table I was looking for it) Results table 1a: average species tolerance in each plot based on EnviA Result Table 3. Average species tolerance in each plot based on EnviA speciesX speciesY speciesZ speciesXX Average Plot1 0.21 NA Nodata 0.14 0.175 Plot2 NA 0.1 Nodata NA 0.1 Plot3 NA NA Nodata 0.14 0.14 Plot4 0.21 NA Nodata NA 0.21 Result table 1b: average species tolerance in plot based on EnviB Table 4. Average species tolerance in each plot based on EnviB speciesX speciesY speciesZ speciesXX Average Plot1 0.4 NA Nodata 0.16 0.28 Plot2 NA 0.15 Nodata NA 0.15 Plot3 NA NA Nodata 0.16 0.16 Plot4 0.4 NA Nodata NA 0.4 Would any one help me how I can calculate these?Thanks Kristi Golver== [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] PLS Q2 value?
Greetings R users, My interest in the Q2cum score comes my endeavor to replicate SIMCAP PLS-DA analysis in R. I use the exact same dataset. After doing the analysis in R, I can get the exact same R2Ycum. However, the Q2cum is significantly off. Adding the Q2cum of the 1st and 2nd component comes close but that seems unconvincing and I don't understand why the 3rd component Q2cum would be so far off. Below is the code and output: pls.reg.new=plsreg2(newserumvars.sc, newtimematrix, nc=3) pls.reg.new$expvar #this provides the exact R2Y I get in SIMCAP pls.reg.new$Q2cum The Q2cum values should be close to component 1 = .2149 component 2 = .4578 component 3 = .6627 #value of concern All of the R output values are close for the respective class except for the final Q2cum value: Q2cum.B Q2cum.FR8 Q2cum.S45 Q2cum t1 -0.0546 0.3992 0.2973 0.2140 t2 0.2863 0.3824 0.7039 0.4573 t3 0.5839 0.7430 0.6980 0.3735 #not close Done. I have read that the plspm package used LOO cross validation. SIMCAP uses the same method, however it leaves '7' out instead. Perhaps this might be an issue that results in this difference? Any insight or assistance would be most appreciated. I certainly appreciate any time you take to answer my question. Regards, Charles Determan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] averaging two tables (rows with columns)
Hi as already mentioned your data can not be deciphered. Use dput(table1) for sending usable data. From what you describe probably ?aggregate can be used. But without suitable data you hardly get any advice. Regards Petr Hi R user,I am struggling to figure out on how I can calculate the average from the two tables in R. Any one can help me? really your help would be grateful- I am spending so much time to figure it out. It should not be so hard, I think. I have very big data but I have created a hypothetical data for simplification. for example I have : table 1 table 1: species occurance data speciesX speciesY speciesZ speciesXX Plot1 1 0 1 0 Plot2 0 1 1 0 Plot3 0 0 0 1 Plot4 1 0 1 0 Table 2 table 2. species tolerance data EnviA EnviB EnviC speciesX 0.21 0.4 0.17 speciesY 0.1 0.15 0.18 speciesXX 0.14 0.16 0.19 You may noticed that table 2 does not have species Z which was in table 1. Now I want to get the average value of species tolerance in each plot based on each environmental value (EnviA or EnviB etc)The example of the out come (final table I was looking for it) Results table 1a: average species tolerance in each plot based on EnviA Result Table 3. Average species tolerance in each plot based on EnviA speciesX speciesY speciesZ speciesXX Average Plot1 0.21 NA Nodata 0.14 0.175 Plot2 NA 0.1 Nodata NA 0.1 Plot3 NA NA Nodata 0.14 0.14 Plot4 0.21 NA Nodata NA 0.21 Result table 1b: average species tolerance in plot based on EnviB Table 4. Average species tolerance in each plot based on EnviB speciesX speciesY speciesZ speciesXX Average Plot1 0.4 NA Nodata 0.16 0.28 Plot2 NA 0.15 Nodata NA 0.15 Plot3 NA NA Nodata 0.16 0.16 Plot4 0.4 NA Nodata NA 0.4 Would any one help me how I can calculate these?Thanks Kristi Golver== [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with stemDocument
Hi Triss, If you need to stem just one text in the Corupus use a[[n]]-stemDocument Best, -Alex From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] on behalf of Triss.Ashton [triss.ash...@unt.edu] Sent: 02 May 2012 21:09 To: r-help@r-project.org Subject: Re: [R] Help with stemDocument I am having a problem with stemDocuments also. I can make it work by moving the data into a Corpus by using: a - Corpus(VectorSource(df$text)) # create corpus object a - tm_map(a, stemDocument, language = english) but it is horrably slow. I want to stem outside the Corpus object like: df$text - stemDocument(df$text, language = english) but it returns the original text. In fact, using the example in the tm package documentation does not work either: data(crude) crude[[1]] Diamond Shamrock Corp said that effective today it had cut its contract prices for crude oil by 1.50 dlrs a barrel. The reduction brings its posted price for West Texas Intermediate to 16.00 dlrs a barrel, the copany said. The price reduction today was made in the light of falling oil product prices and a weak crude oil market, a company spokeswoman said. Diamond is the latest in a line of U.S. oil companies that have cut its contract, or posted, prices over the last two days citing weak oil markets. Reuter stemDocument(crude[[1]], language = english) # specify language Diamond Shamrock Corp said that effective today it had cut its contract prices for crude oil by 1.50 dlrs a barrel. The reduction brings its posted price for West Texas Intermediate to 16.00 dlrs a barrel, the copany said. The price reduction today was made in the light of falling oil product prices and a weak crude oil market, a company spokeswoman said. Diamond is the latest in a line of U.S. oil companies that have cut its contract, or posted, prices over the last two days citing weak oil markets. Reuter stemDocument(crude[[1]]) # language not specified Diamond Shamrock Corp said that effective today it had cut its contract prices for crude oil by 1.50 dlrs a barrel. The reduction brings its posted price for West Texas Intermediate to 16.00 dlrs a barrel, the copany said. The price reduction today was made in the light of falling oil product prices and a weak crude oil market, a company spokeswoman said. Diamond is the latest in a line of U.S. oil companies that have cut its contract, or posted, prices over the last two days citing weak oil markets. Reuter -- View this message in context: http://r.789695.n4.nabble.com/Help-with-stemDocument-tp4554523p4604022.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Matrix heatmap
Hi what is wrong with heatmap(as.matrix(test), col=my.colors(25)) with test from your dput Regards Petr The heat map generated the correct result: library(gplots) arq -read.table(l) matrix_l -data.matrix(arq) my.colors - colorRampPalette(c (gray0,gray10,gray20,gray30,gray40,gray50,gray60,gray80,gray90,gray100)) heatmap.2(matrix_l,dendrogram=none, Rowv=NA, Colv=NA, col=my.colors(256)) -- Now I have the following file with 5 data, similar to the above: RF2 RF00013 RF00100 RF00381 RF00434 RF00453 RF00165 RF00496 RF00497 RF00014 RF00048 RF00234 RF00163 RF8 RF00094 RF00032 RF00028 RF00216 RF00487 RF00209 RF00465 RF00485 RF00363 RF00366 RF2 63 7 5 7 17 12 14 5 23 3 56 14 72 84 15 64 20 0 1 8 6 65 3 4 RF00013 45 7 4 6 17 12 14 5 23 3 56 12 60 84 15 64 20 0 0 2 2 65 3 4 RF00100 22 1 5 3 2 9 0 0 0 0 5 0 16 8 1 0 0 0 0 0 0 26 2 3 RF00381 63 7 5 13 17 11 3 5 18 3 56 14 33 12 2 15 4 18 12 25 11 69 3 4 RF00434 2 0 0 3 17 11 14 5 23 3 55 12 59 84 15 64 20 0 0 0 0 40 1 3 RF00453 3 1 0 2 16 12 13 3 7 0 45 12 42 78 15 53 20 0 0 0 0 33 2 0 RF00165 0 0 0 2 10 1 14 1 7 0 44 12 38 68 13 48 20 0 0 0 0 18 0 0 RF00496 0 0 0 0 0 0 1 5 6 0 0 0 4 2 0 0 0 0 0 0 0 0 0 0 RF00497 0 0 0 3 10 0 12 5 23 3 40 8 37 77 15 64 20 0 0 0 0 20 0 0 RF00014 0 0 0 0 0 0 0 0 8 3 6 0 0 0 0 0 0 0 0 0 0 0 0 0 RF00048 3 1 0 3 17 10 14 5 23 3 56 12 59 83 15 64 20 0 0 0 0 52 3 3 RF00234 62 7 5 6 17 12 14 5 23 3 56 14 70 84 15 64 20 0 0 0 1 65 3 4 RF00163 63 7 5 7 17 12 14 5 23 3 56 14 75 84 15 64 21 6 1 10 9 65 3 4 RF8 3 1 0 3 17 12 14 5 23 3 56 12 58 84 15 64 20 0 0 0 0 52 3 2 RF00094 0 0 0 0 0 1 11 0 1 0 0 0 34 73 15 49 20 0 0 0 0 12 0 0 RF00032 0 0 0 3 10 1 14 5 23 3 56 12 43 80 15 64 20 0 0 0 0 21 0 0 RF00028 63 7 5 13 17 12 14 5 23 3 56 14 75 84 15 64 30 23 14 25 20 85 3 4 RF00216 63 7 5 13 17 12 14 5 23 3 56 14 75 84 15 64 28 23 14 25 20 85 3 4 RF00487 63 7 5 13 17 12 14 5 23 3 56 14 75 84 15 64 28 20 14 25 16 83 3 4 RF00209 50 7 5 3 2 2 0 0 0 0 1 2 26 4 0 0 1 0 8 25 5 28 3 3 RF00465 59 7 5 10 7 11 0 0 10 3 11 2 32 9 1 3 6 15 5 14 20 63 3 4 RF00485 63 7 5 13 17 12 14 5 23 3 56 14 75 84 15 64 26 17 14 25 19 85 3 4 RF00363 5 3 0 3 10 1 1 5 20 3 50 12 44 24 5 5 0 0 0 0 0 42 3 3 RF00366 8 2 1 4 14 9 13 5 23 3 52 12 51 68 12 8 0 0 0 0 0 48 3 4 Now I have the following file with 5 data, similar to the above: Is represented by an array of 25x25 and 10x10 not like the previous when I give the command dput (arch) it returns me the following output: structure(list(RF2 = c(63L, 45L, 22L, 63L, 2L, 3L, 0L, 0L, 0L, 0L, 3L, 62L, 63L, 3L, 0L, 0L, 63L, 63L, 63L, 50L, 59L, 63L, 5L, 8L), RF00013 = c(7L, 7L, 1L, 7L, 0L, 1L, 0L, 0L, 0L, 0L, 1L, 7L, 7L, 1L, 0L, 0L, 7L, 7L, 7L, 7L, 7L, 7L, 3L, 2L), RF00100 = c(5L, 4L, 5L, 5L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 5L, 5L, 0L, 0L, 0L, 5L, 5L, 5L, 5L, 5L, 5L, 0L, 1L), RF00381 = c(7L, 6L, 3L, 13L, 3L, 2L, 2L, 0L, 3L, 0L, 3L, 6L, 7L, 3L, 0L, 3L, 13L, 13L, 13L, 3L, 10L, 13L, 3L, 4L), RF00434 = c(17L, 17L, 2L, 17L, 17L, 16L, 10L, 0L, 10L, 0L, 17L, 17L, 17L, 17L, 0L, 10L, 17L, 17L, 17L, 2L, 7L, 17L, 10L, 14L), RF00453 = c(12L, 12L, 9L, 11L, 11L, 12L, 1L, 0L, 0L, 0L, 10L, 12L, 12L, 12L, 1L, 1L, 12L, 12L, 12L, 2L, 11L, 12L, 1L, 9L), RF00165 = c(14L, 14L, 0L, 3L, 14L, 13L, 14L, 1L, 12L, 0L, 14L, 14L, 14L, 14L, 11L, 14L, 14L, 14L, 14L, 0L, 0L, 14L, 1L, 13L), RF00496 = c(5L, 5L, 0L, 5L, 5L, 3L, 1L, 5L, 5L, 0L, 5L, 5L, 5L, 5L, 0L, 5L, 5L, 5L, 5L, 0L, 0L, 5L, 5L, 5L ), RF00497 = c(23L, 23L, 0L, 18L, 23L, 7L, 7L, 6L, 23L, 8L, 23L, 23L, 23L, 23L, 1L, 23L, 23L, 23L, 23L, 0L, 10L, 23L, 20L, 23L ), RF00014 = c(3L, 3L, 0L, 3L, 3L, 0L, 0L, 0L, 3L, 3L, 3L, 3L, 3L, 3L, 0L, 3L, 3L, 3L, 3L, 0L, 3L, 3L, 3L, 3L), RF00048 = c(56L, 56L, 5L, 56L,
[R] Outcome~predictor model evaluation, repeated measurements
Dear all, I have simple question regarding how to fit a model (i.e. linear) to the data. Say I have 10 subjects with different phenotypes (dependent var Y, identical for a particular subject) and one predictor variable measured 3 times for each subject (X). By other words: Y Subj X 1 1 1.2 1 1 1.3 1 1 0.7 3 2 2.1 3 2 2.5 3 2 4 5 3 3 5 3 4 5 3 4 ... 20 10 12 20 10 13 20 10 12.5 Subj is a grouping variable. I would like know the correlation of Y with X (Y~X) and the effect of within subject variance on this correlation. And thus, overall significance and correlation. Will it be valid to fit lm to all combinations of x and y and take an average values of p and R-squared? Usually, I estmate the correlation using simple lm between outcome and averaged predictor (1-to-1, i.e. 20 outcomes versus 20 predictors). However, I would like to take in account variations associated with replicated measurements (i.e. the same 20 outcomes versus 20 predictors replicated say 3 times), and, therefore, evaluate slope and intercept variabilities. Do mixed model regression analysis suitable for such an analysis for example using lme function from nlme package? If not, what kind of analysis is most appropriate? Thank you. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] averaging two tables (rows with columns)
Hi John , Petr and R users I am sorry that my data was not readable formate in the last email. Again I am trying to send it. hope this time, that table can be readable.As I mentioned earlier that I was struggling to figure out on how I can calculate the average from the two tables in R. Any one can help me? really your helpwould be grateful- I am spending so much time to figure it out. It should not be so hard, I think.I have very big data but I have created a hypothetical data for simplification.for exampleI have : table 1Table 1: species occurrence data table1 X speciesX speciesY speciesZ speciesXX1 Plot110 1 02 Plot2011 03 plot31 00 14 plot4001 0Table 2: table 2. species tolerance datatable2 X EnviA EnviB EnviC1 SpeciesX 0.21 0.40 0.172 SpeciesY 0.10 0.15 0.183 SpeciesXY 0.14 0.16 0.19You may noticed that table 2 does not have species Z wh! ich was in tableTable 3: Now I want to get the average value of species tolerance in each plot based on each environmental value (EnviA or EnviB etc).The example of the out come (final table I was looking for it).Results table 1a: averages species tolerance in each plot based on EnviAsuch as: table3.a X speciesX speciesY speciesZ speciesXX average1 plot1 0.21 NA Nodata 0.14 0.1752 plot2 NA 0.1 NodataNA 0.1003 plot3 NA NA Nodata 0.14 0.1404 plot4 0.21 NA NodataNA 0.210Table 4 table3.b: Result table 1b: average species tolerance in plot based on EnviB X speciesX speciesY speciesZ speciesXX average1 plot1 0.4 NA Nodata 0.160.282 plot2 NA 0.15 NodataNA0.153 plot3 NA NA Nodata 0.160.164 plot4 0.4 NA NodataNA0.40I hope this time the data would be readable formate. Would any one help me how I! can calculate these?ThanksKristi Golver== To: kristi.glo...@hotmail.com CC: r-help@r-project.org Subject: Re: [R] averaging two tables (rows with columns) From: petr.pi...@precheza.cz Date: Thu, 10 May 2012 18:10:33 +0200 Hi as already mentioned your data can not be deciphered. Use dput(table1) for sending usable data. From what you describe probably ?aggregate can be used. But without suitable data you hardly get any advice. Regards Petr [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] FW: averaging two tables (rows with columns)
Hi R-usuar, I still find the table is not in readable formate. I now forwarded the email.hope it works. I sent it to my account . It was perfect- but when I sent it to R help- then it comes with unreadable formate. This is my last try. If not, then I will try to do in Excel manually. cheers, From: kristi.glo...@hotmail.com To: kristi.glo...@hotmail.com Subject: RE: [R] averaging two tables (rows with columns) Date: Thu, 10 May 2012 14:06:41 -0300 Hi John , Petr and R userI am sorry that my data was not readable formate in the last email. Agin I am trying to send it. hope this time, that table can be readable. As I mentioned earlier that I was struggling to figure out on how I can calculate the average from the two tables in R. Any one can help me? really your helpwould be grateful- I am spending so much time to figure it out. It should not be so hard, I think.I have very big data but I have created a hypothetical data for simplification.for example I have : table 1 Table 1: species occurrence data table1 X speciesX speciesY speciesZ speciesXX1 Plot1101 02 Plot201 1 03 plot3100 14 plot40 01 0 Table 2: table 2. species tolerance data table2 X EnviA EnviB EnviC1 SpeciesX 0.21 0.40 0.172 SpeciesY 0.10 0.15 0.183 SpeciesXY 0.14 0.16 0.19 You may noticed that table 2 does not have species Z which was in table Table 3: Now I want to get the average value of species tolerance in each plot based on each environmental value (EnviA or EnviB etc).The example of the out come (final table I was looking for it). Results table 1a: averages species tolerance in each plot based on EnviA such as: table3.a X speciesX speciesY speciesZ speciesXX average1 plot1 0.21 NA Nodata 0.14 0.1752 plot2 NA 0.1 Nodata NA 0.1003 plot3 NA NA Nodata 0.14 0.1404 plot4 0.21 NA NodataNA 0.210Table 4 table3.b: Result table 1b: average species tolerance in plot based on EnviB X speciesX speciesY speciesZ speciesXX average1 plot1 0.4 NA Nodata 0.160.282 plot2 NA 0.15 NodataNA0.153 plot3 NA NA Nodata 0.160.164 plot4 0.4 NA NodataNA0.40 I hope this time the data would be readable formate. Would any one help me how I can calculate these?Thanks Kristi Golver== Date: Thu, 10 May 2012 08:01:11 -0800 From: jrkrid...@inbox.com Subject: RE: [R] averaging two tables (rows with columns) To: kristi.glo...@hotmail.com; r-help@r-project.org Kristi, Your data has come through in a totally unreadable layout. Have a look at ?dput as a handy way to present sample data. Just run dput(mydata), copy the output and paste into the email. John Kane Kingston ON Canada [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] FW: averaging two tables (rows with columns)
Kristi, Several people have already suggested you use dput() to provide your data. In R, dput(table1) dput(table2) Then copy and paste the output of those commands into your email. There's no way to reliably copy and paste your raw data: using dput() is the best way to provide it. Sarah On Thu, May 10, 2012 at 1:18 PM, Kristi Glover kristi.glo...@hotmail.com wrote: Hi R-usuar, I still find the table is not in readable formate. I now forwarded the email.hope it works. I sent it to my account . It was perfect- but when I sent it to R help- then it comes with unreadable formate. This is my last try. If not, then I will try to do in Excel manually. cheers, From: kristi.glo...@hotmail.com To: kristi.glo...@hotmail.com Subject: RE: [R] averaging two tables (rows with columns) Date: Thu, 10 May 2012 14:06:41 -0300 Hi John , Petr and R userI am sorry that my data was not readable formate in the last email. Agin I am trying to send it. hope this time, that table can be readable. As I mentioned earlier that I was struggling to figure out on how I can calculate the average from the two tables in R. Any one can help me? really your helpwould be grateful- I am spending so much time to figure it out. It should not be so hard, I think.I have very big data but I have created a hypothetical data for simplification.for example I have : table 1 Table 1: species occurrence data table1 X speciesX speciesY speciesZ speciesXX1 Plot1 1 0 1 02 Plot2 0 1 1 03 plot3 1 0 0 14 plot4 0 0 1 0 Table 2: table 2. species tolerance data table2 X EnviA EnviB EnviC1 SpeciesX 0.21 0.40 0.172 SpeciesY 0.10 0.15 0.183 SpeciesXY 0.14 0.16 0.19 You may noticed that table 2 does not have species Z which was in table Table 3: Now I want to get the average value of species tolerance in each plot based on each environmental value (EnviA or EnviB etc).The example of the out come (final table I was looking for it). Results table 1a: averages species tolerance in each plot based on EnviA such as: table3.a X speciesX speciesY speciesZ speciesXX average1 plot1 0.21 NA Nodata 0.14 0.1752 plot2 NA 0.1 Nodata NA 0.1003 plot3 NA NA Nodata 0.14 0.1404 plot4 0.21 NA Nodata NA 0.210Table 4 table3.b: Result table 1b: average species tolerance in plot based on EnviB X speciesX speciesY speciesZ speciesXX average1 plot1 0.4 NA Nodata 0.16 0.282 plot2 NA 0.15 Nodata NA 0.153 plot3 NA NA Nodata 0.16 0.164 plot4 0.4 NA Nodata NA 0.40 I hope this time the data would be readable formate. Would any one help me how I can calculate these?Thanks Kristi Golver== Date: Thu, 10 May 2012 08:01:11 -0800 From: jrkrid...@inbox.com Subject: RE: [R] averaging two tables (rows with columns) To: kristi.glo...@hotmail.com; r-help@r-project.org Kristi, Your data has come through in a totally unreadable layout. Have a look at ?dput as a handy way to present sample data. Just run dput(mydata), copy the output and paste into the email. John Kane Kingston ON Canada __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] FW: averaging two tables (rows with columns)
oppps, Now I used 'dput' function. Again I am sending. I am so sorry for inconvenience. HI R userI am sorry that my data was not readable formate in the last email. Agin I am trying to send it. hope this time, that table can be readable.As I mentioned earlier that I was struggling to figure out on how I can calculate the average from the two tables in R. Any one can help me? really your helpwould be grateful- I am spending so much time to figure it out. It should not be so hard, I think.I have very big data but I have created a hypothetical data for simplification.for exampleI have : table 1Table 1: species occurrence data dput(table1)structure(list(X = structure(1:4, .Label = c(Plot1, Plot2, plot3, plot4), class = factor), speciesX = c(1L, 0L, 1L, 0L), speciesY = c(0L, 1L, 0L, 0L), speciesZ = c(1L, 1L, 0L, 1L), speciesXX = c(0L, 0L, 1L, 0L)), .Names = c(X, speciesX, speciesY, speciesZ, speciesXX), class = data.frame, row.names = c(NA, -4L)) Table 2: table 2. species tolerance data dput(table2)structure(list(X = structure(c(1L, 3L, 2L), .Label = c(SpeciesX, SpeciesXY, SpeciesY), class = factor), EnviA = c(0.21, 0.1, 0.14), EnviB = c(0.4, 0.15, 0.16), EnviC = c(0.17, 0.18, 0.19)), .Names = c(X, EnviA, EnviB, EnviC), class = data.frame, row.names = c(NA, -3L)) You may noticed that table 2 does not have species Z which was in tableTable 3: Now I want to get the average value of species tolerance in each plot based on each environmental value (EnviA or EnviB etc).The example of the out come (final table I was looking for it).Results table 3a: averages species tolerance in each plot based on EnviAsuch as: dput(table3a)structure(list(X = structure(1:4, .Label = c(plot1, plot2, plot3, plot4), class = factor), speciesX = c(0.21, NA, NA, 0.21), speciesY = c(NA, 0.1, NA, NA), speciesZ = structure(c(1L, 1L, 1L, 1L), .Label = Nodata, class = factor), speciesXX = c(0.14, NA, 0.14, NA), av! erage = c(0.175, 0.1, 0.14, 0.21)), .Names = c(X, speciesX, speciesY, speciesZ, speciesXX, average), class = data.frame, row.names = c(NA, -4L)) Table 3b Result table 3b: average species tolerance in plot based on EnviB dput(table3b) structure(list(X = structure(1:4, .Label = c(plot1, plot2, plot3, plot4), class = factor), speciesX = c(0.4, NA, NA, 0.4), speciesY = c(NA, 0.15, NA, NA), speciesZ = structure(c(1L, 1L, 1L, 1L), .Label = Nodata, class = factor), speciesXX = c(0.16, NA, 0.16, NA), average = c(0.28, 0.15, 0.16, 0.4)), .Names = c(X, speciesX, speciesY, speciesZ, speciesXX, average), class = data.frame, row.names = c(NA, -4L))I hope this time the data would be readable formate. Would any one help me how I can calculate these?ThanksKristi Golver== again [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] converting raster image
write.csv() perhaps? I'm not sure what the csv of a raster image is though... What does p look like? str(p) will be important -- if the raster codes (RGB values) are in lists or 3D arrays or something more complex (i.e., if no grayscale) you might need to put them in multiple files. Hope this helps, Michael On Thu, May 10, 2012 at 11:12 AM, Mintewab Bezabih mintewab.beza...@economics.gu.se wrote: Dear R users, I was wondering how I can convert a raster image (that made R through interpolation) into an ascii or csv format? this is the last line of my command p - interpolate(r, tpsfit) So p is my raster file which I want to convert into ascii or csv Many thanks Regards Mintewab __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Split the work for many cores
library(parallel) # Requires R =2.14 mclapply # a parallelized lapply() You can process in parallel, but I'm not sure if it's safe to do graphics in parallel: someone else will need to chime in about that. Best, Michael On Thu, May 10, 2012 at 9:12 AM, Alaios ala...@yahoo.com wrote: Dear all, I am using my code the vgram.matrix of packets fields. I have around 500 matrices that I need to pass inside that function and then plot those results. Even though my system has 16 cores is quite clear that I am only using one of those. Would it be able to skip these 500 tasks to the 16 cores, with each processor having around 4 matrices to process? What would you suggest me doing? Regards Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] FW: averaging two tables (rows with columns)
Kristi The tables , if read in edit mode are vagely readable but please just do as Petr and I suggest. Use the dput command. If you have the table in an R data.frame all you need to do is use the command dput(mytable) I read your two tables into R and did that . Note I called them dat1 dat2. table is a command in R and it is best not to use it as a variable name. Results 1 dput(dat1) structure(list(X = c(Plot1, Plot2, plot3, plot4), speciesX = c(1L, 0L, 1L, 0L), speciesY = c(0L, 1L, 0L, 0L), speciesZ = c(1L, 1L, 0L, 1L), speciesXX = c(0L, 0L, 1L, 0L)), .Names = c(X, speciesX, speciesY, speciesZ, speciesXX), class = data.frame, row.names = c(NA, -4L)) 1 dput(dat2) structure(list(X = c(SpeciesX, SpeciesY, SpeciesXY), EnviA = c(0.21, 0.1, 0.14), EnviB = c(0.4, 0.15, 0.16), EnviC = c(0.17, 0.18, 0.19)), .Names = c(X, EnviA, EnviB, EnviC), class = data.frame, row.names = c(1, 2, 3)) 1 Now you just need to stick variable name and an - in front of the dput material and paste it into R Like THIS mytable1 - structure(list(X = c(Plot1, Plot2, plot3, plot4), speciesX = c(1L, 0L, 1L, 0L), speciesY = c(0L, 1L, 0L, 0L), speciesZ = c(1L, 1L, 0L, 1L), speciesXX = c(0L, 0L, 1L, 0L)), .Names = c(X, speciesX, speciesY, speciesZ, speciesXX), class = data.frame, row.names = c(NA, -4L)) and paste it into R. Now we probably can get somewhere. John Kane Kingston ON Canada -Original Message- From: kristi.glo...@hotmail.com Sent: Thu, 10 May 2012 14:18:50 -0300 To: r-help@r-project.org Subject: [R] FW: averaging two tables (rows with columns) Hi R-usuar, I still find the table is not in readable formate. I now forwarded the email.hope it works. I sent it to my account . It was perfect- but when I sent it to R help- then it comes with unreadable formate. This is my last try. If not, then I will try to do in Excel manually. cheers, From: kristi.glo...@hotmail.com To: kristi.glo...@hotmail.com Subject: RE: [R] averaging two tables (rows with columns) Date: Thu, 10 May 2012 14:06:41 -0300 Hi John , Petr and R userI am sorry that my data was not readable formate in the last email. Agin I am trying to send it. hope this time, that table can be readable. As I mentioned earlier that I was struggling to figure out on how I can calculate the average from the two tables in R. Any one can help me? really your helpwould be grateful- I am spending so much time to figure it out. It should not be so hard, I think.I have very big data but I have created a hypothetical data for simplification.for example I have : table 1 Table 1: species occurrence data table1 X speciesX speciesY speciesZ speciesXX1 Plot1101 02 Plot2 011 03 plot3100 14 plot4001 0 Table 2: table 2. species tolerance data table2 X EnviA EnviB EnviC1 SpeciesX 0.21 0.40 0.172 SpeciesY 0.10 0.15 0.183 SpeciesXY 0.14 0.16 0.19 You may noticed that table 2 does not have species Z which was in table Table 3: Now I want to get the average value of species tolerance in each plot based on each environmental value (EnviA or EnviB etc).The example of the out come (final table I was looking for it). Results table 1a: averages species tolerance in each plot based on EnviA such as: table3.a X speciesX speciesY speciesZ speciesXX average1 plot1 0.21 NA Nodata 0.14 0.1752 plot2 NA 0.1 NodataNA 0.1003 plot3 NA NA Nodata 0.14 0.1404 plot4 0.21 NA NodataNA 0.210Table 4 table3.b: Result table 1b: average species tolerance in plot based on EnviB X speciesX speciesY speciesZ speciesXX average1 plot1 0.4 NA Nodata 0.160.282 plot2 NA 0.15 NodataNA0.153 plot3 NA NA Nodata 0.16 0.164 plot4 0.4 NA NodataNA0.40 I hope this time the data would be readable formate. Would any one help me how I can calculate these?Thanks Kristi Golver== Date: Thu, 10 May 2012 08:01:11 -0800 From: jrkrid...@inbox.com Subject: RE: [R] averaging two tables (rows with columns) To: kristi.glo...@hotmail.com; r-help@r-project.org Kristi, Your data has come through in a totally unreadable layout. Have a look at ?dput as a handy way to present sample data. Just run dput(mydata), copy the output and paste into the email. John Kane Kingston ON Canada [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. GET FREE SMILEYS FOR YOUR IM EMAIL - Learn more at
Re: [R] outlier identify in qqplot
Do you want a qqnorm() instead of a qqplot() ? [Reproducibility also involves posting the code you used that lead to the error / warning] This seems to work for me: # mydata - source(http://r.789695.n4.nabble.com/file/n4623493/mydata.txt;)[[1]] # Have to drop visible attribute lmmodel - lm(log(vdep) ~ v1 + sqrt(v2) + v3 +v5 + v6 + v7 + v8 + v9 + v10, data = mydata) qqnorm(residuals(lmmodel)) # Or if interactive: qqnormInt - function(..., IDENTIFY = TRUE){ qqnorm(...) - X if(IDENTIFY) return(identify(X)) invisisble(X) } qqnormInt(residuals(lmmodel)) Michael On Thu, May 10, 2012 at 9:20 AM, agent dunham crossp...@hotmail.com wrote: Find the data attached, http://r.789695.n4.nabble.com/file/n4623493/mydata.txt mydata.txt The model would be /lmmodel - lm(log(vdep) ~ v1 + sqrt(v2) + v3 +v5 + v6 + v7 + v8 + v9 + v10, data = mydata)/ Thanks again, u...@host.com -- View this message in context: http://r.789695.n4.nabble.com/outlier-identify-in-qqplot-tp4076587p4623493.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] FW: averaging two tables (rows with columns)
Well I'd suggest learning to use the return key. It really helps improve the readability of a posting. Three of the for files came through okay but table3a has a problem. It looks like some kind of extraneous charater(s) got into it but a second or so of editing makes it work so we have all 4 tables now. John Kane Kingston ON Canada -Original Message- From: kristi.glo...@hotmail.com Sent: Thu, 10 May 2012 14:36:51 -0300 To: r-help@r-project.org Subject: Re: [R] FW: averaging two tables (rows with columns) oppps, Now I used 'dput' function. Again I am sending. I am so sorry for inconvenience. HI R userI am sorry that my data was not readable formate in the last email. Agin I am trying to send it. hope this time, that table can be readable.As I mentioned earlier that I was struggling to figure out on how I can calculate the average from the two tables in R. Any one can help me? really your helpwould be grateful- I am spending so much time to figure it out. It should not be so hard, I think.I have very big data but I have created a hypothetical data for simplification.for exampleI have : table 1Table 1: species occurrence data dput(table1)structure(list(X = structure(1:4, .Label = c(Plot1, Plot2, plot3, plot4), class = factor), speciesX = c(1L, 0L, 1L, 0L), speciesY = c(0L, 1L, 0L, 0L), speciesZ = c(1L, 1L, 0L, 1L), speciesXX = c(0L, 0L, 1L, 0L)), .Names = c(X, speciesX, speciesY, speciesZ, speciesXX), class = data.frame, row.names = c(NA, -4L)) Table 2: table 2. species tolerance data dput(table2)structure(list(X = structure(c(1L, 3L, 2L), .Label = c(SpeciesX, SpeciesXY, SpeciesY), class = factor), EnviA = c(0.21, 0.1, 0.14), EnviB = c(0.4, 0.15, 0.16), EnviC = c(0.17, 0.18, 0.19)), .Names = c(X, EnviA, EnviB, EnviC), class = data.frame, row.names = c(NA, -3L)) You may noticed that table 2 does not have species Z which was in tableTable 3: Now I want to get the average value of species tolerance in each plot based on each environmental value (EnviA or EnviB etc).The example of the out come (final table I was looking for it).Results table 3a: averages species tolerance in each plot based on EnviAsuch as: dput(table3a)structure(list(X = structure(1:4, .Label = c(plot1, plot2, plot3, plot4), class = factor), speciesX = c(0.21, NA, NA, 0.21), speciesY = c(NA, 0.1, NA, NA), speciesZ = structure(c(1L, 1L, 1L, 1L), .Label = Nodata, class = factor), speciesXX = c(0.14, NA, 0.14, NA), av! erage = c(0.175, 0.1, 0.14, 0.21)), .Names = c(X, speciesX, speciesY, speciesZ, speciesXX, average), class = data.frame, row.names = c(NA, -4L)) Table 3b Result table 3b: average species tolerance in plot based on EnviB dput(table3b) structure(list(X = structure(1:4, .Label = c(plot1, plot2, plot3, plot4), class = factor), speciesX = c(0.4, NA, NA, 0.4), speciesY = c(NA, 0.15, NA, NA), speciesZ = structure(c(1L, 1L, 1L, 1L), .Label = Nodata, class = factor), speciesXX = c(0.16, NA, 0.16, NA), average = c(0.28, 0.15, 0.16, 0.4)), .Names = c(X, speciesX, speciesY, speciesZ, speciesXX, average), class = data.frame, row.names = c(NA, -4L))I hope this time the data would be readable formate. Would any one help me how I can calculate these?ThanksKristi Golver== again [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Send your photos by email in seconds... TRY FREE IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if3 Works in all emails, instant messengers, blogs, forums and social networks. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] storage of matrices of diff dimension together
Hi, It might be a trivial question but how do you store matrices of different dimensions read from a file or in a loop together? The best solution might be a list but I don't store the first matrix correctly: m = rbind(c(1,2),c(3,4),c(5,6)) t=rbind(c(1,2),c(5,6)) l = list(m) l = list(l,t) #I assumed that at the begining I don't have m and t at the same time to do list(m,t), but I list them, one after the other l [[1]] [[1]][[1]] [,1] [,2] [1,] 1 2 [2,] 3 4 [3,] 5 6 [[2]] [,1] [,2] t 1 2 5 6 thanks Carol [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] storage of matrices of diff dimension together
Hi Carol, m1 - rbind(c(1,2),c(3,4),c(5,6)) m2 - rbind(c(1,2),c(5,6)) mylist - list(m1) c(mylist, list(m2)) [[1]] [,1] [,2] [1,]12 [2,]34 [3,]56 [[2]] [,1] [,2] [1,]12 [2,]56 See the examples in ?c for more information. Sarah On Thu, May 10, 2012 at 2:35 PM, carol white wht_...@yahoo.com wrote: Hi, It might be a trivial question but how do you store matrices of different dimensions read from a file or in a loop together? The best solution might be a list but I don't store the first matrix correctly: m = rbind(c(1,2),c(3,4),c(5,6)) t=rbind(c(1,2),c(5,6)) l = list(m) l = list(l,t) #I assumed that at the begining I don't have m and t at the same time to do list(m,t), but I list them, one after the other l [[1]] [[1]][[1]] [,1] [,2] [1,] 1 2 [2,] 3 4 [3,] 5 6 [[2]] [,1] [,2] t 1 2 5 6 thanks Carol -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] fda problems - version correct?
Dear friends - I am trying to understand fda and working with the 2009 book from Springer. I run the scripts directly from a new installed fda library and include sessionInfo() below. This is from the script fdarm-ch09.R - I seem to have got not fda_2.2.8 but 2.2.7 - is that the problem? Where do I get .8 as I just reinstalled? Best wishes Troels Ring, Nephrology Aalborg, Denmark betavar = coefvar[2]*harmonics[1]^2 + coefvar[3]*harmonics[2]^2 + +coefvar[4]*harmonics[3]^2 Error in `^.fd`(harmonics[1], 2) : FDOBJ does not have a spline basis. sessionInfo() R version 2.15.0 (2012-03-30) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Danish_Denmark.1252 LC_CTYPE=Danish_Denmark.1252 [3] LC_MONETARY=Danish_Denmark.1252 LC_NUMERIC=C [5] LC_TIME=Danish_Denmark.1252 attached base packages: [1] splines stats graphics grDevices utils datasets methods [8] base other attached packages: [1] fda_2.2.7 zoo_1.7-7 loaded via a namespace (and not attached): [1] grid_2.15.0lattice_0.20-6 tools_2.15.0 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] converting raster image
You should provide reproducible code and at the very least declare the packages you are using. I guess this from the package raster? See example in ?raster::interpolate: ## Thin plate spline interpolation with x and y only library(fields) r - raster(system.file(external/test.grd, package=raster)) ra - aggregate(r, 10) xy - data.frame(xyFromCell(ra, 1:ncell(ra))) v - getValues(ra) tps - Tps(xy, v) p - raster(r) p - interpolate(p, tps) One way to convert this to tabular format is to coerce to SpatialGridDataFrame, then write that out with write.table (write.csv): require(sp) head(as.data.frame(as(p, SpatialGridDataFrame))) layer s1 s2 1 1823.450 178420 333980 2 1818.925 178460 333980 3 1814.405 178500 333980 4 1809.876 178540 333980 5 1805.324 178580 333980 6 1800.734 178620 333980 There would be functions in raster to do that more directly, I'm just not that familiar with it. So, x - as.data.frame(as(p, SpatialGridDataFrame)) Now x is just a data.frame with every cell stored explicitly with its centre coordinate, s1 and s2 are the X and Y coordinates, layer is the raster value. Cheers, Mike. On Fri, May 11, 2012 at 1:12 AM, Mintewab Bezabih mintewab.beza...@economics.gu.se wrote: Dear R users, I was wondering how I can convert a raster image (that made R through interpolation) into an ascii or csv format? this is the last line of my command p - interpolate(r, tpsfit) So p is my raster file which I want to convert into ascii or csv Many thanks Regards Mintewab __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Michael Sumner Institute for Marine and Antarctic Studies, University of Tasmania Hobart, Australia e-mail: mdsum...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Resampling question
Hello - I have a population of 100 individuals that I would like to bootstrap 10 times, every time removing 5 *different* individuals. So far, I have done the following: pop - read.table('mypop.txt', header=FALSE) replicate(10, sample(pop, 95, replace=FALSE)) I have not actually gone through each of the 10 files created to make sure no single individual was removed more than once during the 10 bootstraps. But will the above syntax achieve this object? Thanks V __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Barplots inside loop - several data errors, workaround needed
Looking at the documentation for try() I am not sure how it would be best applied in this situation. My background is not extensively programming. Would writing a function first be appropriate? Also, I'm not sure just a simple error catch would solve my first problem. I do, in fact, need it to plot the barplot based on the table which is created above. However, R doesn't like the lack of several columns. Further guidance would be appreciated. -- all the best, Lee Mueller ISA Certified Arborist MI-4148A Registered Forester #46043 On Wed, May 9, 2012 at 4:30 AM, Jim Holtman jholt...@gmail.com wrote: ?try Sent from my iPad On May 8, 2012, at 22:03, Lee muell...@gmail.com wrote: I have a series of data which is managed through a loop. The loop creates pivot tables of my data using the *cast* function in the *reshape*library. For the most part, the data is all plotted correctly. Unfortunately, there are a couple of data sets which create errors and halt the loop. One of the tables looks like the following: dbh Black Walnut 1 8 38.19722 2 10 48.89244 3 12 38.19722 When the loop attempts the barplot() function, the following error is returned: Error in seq_len(p) : argument must be coercible to non-negative integer In other cases, there is simply no data in the specified set of data. Therefore, the table is full of NA's. Obviously, this does not need to be plotted, but I cannot simply remove it from the larger database. I need my loop to continue regardless of if it runs into these issues. *Question: What can I do to ensure the above single variable table will plot correctly? and what can I do to suppress errors on the datasets which do not have data so the loop continues?* full code: http://pastebin.com/LB88hpfM Thank you in advance. -- all the best, Lee Mueller ISA Certified Arborist MI-4148A Registered Forester #46043 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Resampling question
No, it will not, except possibly by chance: if the draws of sample are IID (and they are supposed to be) there's no reason to expect them not to overlap. If you want that -- and I'm not sure it's totally on the level bootstrapping-wise -- you need to decide which ones to remove all in one fell swoop: Something like this: ToDrop - matrix(sample(100, 50, replace = FALSE), ncol = 10) apply(ToDrop, 2, function(x) pop[-x]) Michael On Thu, May 10, 2012 at 7:56 PM, Vikram Chhatre crypticline...@gmail.com wrote: Hello - I have a population of 100 individuals that I would like to bootstrap 10 times, every time removing 5 *different* individuals. So far, I have done the following: pop - read.table('mypop.txt', header=FALSE) replicate(10, sample(pop, 95, replace=FALSE)) I have not actually gone through each of the 10 files created to make sure no single individual was removed more than once during the 10 bootstraps. But will the above syntax achieve this object? Thanks V __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Resampling question
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Vikram Chhatre Sent: Thursday, May 10, 2012 4:57 PM To: r-help@r-project.org Subject: [R] Resampling question Hello - I have a population of 100 individuals that I would like to bootstrap 10 times, every time removing 5 *different* individuals. So far, I have done the following: pop - read.table('mypop.txt', header=FALSE) replicate(10, sample(pop, 95, replace=FALSE)) I have not actually gone through each of the 10 files created to make sure no single individual was removed more than once during the 10 bootstraps. But will the above syntax achieve this object? Thanks V What you are doing is probably more appropriately called a jack-knife, rather than bootstrap. Be that as it may, your approach will not prevent someone being dropped more than once. You might randomly select 50 people without replacement and then drop them 5 at a time from the original population to_drop - sample(100,50,replace=FALSE) rep1 - pop[-to_drop[1:5],] rep2 - pop[-to_drop[6:10],] ... I will let you decide how you want automate this. Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Barplots inside loop - several data errors, workaround needed
Hi, On Thu, May 10, 2012 at 8:35 PM, Lee muell...@gmail.com wrote: Looking at the documentation for try() I am not sure how it would be best applied in this situation. My background is not extensively programming. Would writing a function first be appropriate? Also, I'm not sure just a simple error catch would solve my first problem. I do, in fact, need it to plot the barplot based on the table which is created above. However, R doesn't like the lack of several columns. Further guidance would be appreciated. Consider this block of code that you can run in your R workspace: ~ set.seed(123) random.error - runif(3, 0, 2) 1.5 for (throws.error in random.error) { cat(I'm about to try something\n) result - try({ cat( I'm in the middle of trying something\n) cat( There is a chance it might result in an error\n) if (throws.error) { stop(Error!) } }, silent=TRUE) if (is(result, 'try-error')) { cat(An error occurred while trying something, but I'm OK\n\n) } else { cat(No error occurred while trying something\n\n) } } ~ and the output it gives: ~ I'm about to try something I'm in the middle of trying something There is a chance it might result in an error No error occurred while trying something I'm about to try something I'm in the middle of trying something There is a chance it might result in an error An error occurred while trying something, but I'm OK I'm about to try something I'm in the middle of trying something There is a chance it might result in an error No error occurred while trying something ~ Does that help? -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] moving data from one frame to another
Hello, I am working with two different data frames, and I'd like to move data from one to the other. Here is the first frame: head(five) Week Game.ID VTm VPts HTm HPts HDifferential VDifferential 11 NFL_20050908_OAK@NE OAK 20 NE 3010 -10 21 NFL_20050911_ARI@NYG ARI 19 NYG 4223 -23 31 NFL_20050911_CHI@WAS CHI7 WAS9 2-2 41 NFL_20050911_CIN@CLE CIN 27 CLE 13 -1414 51 NFL_20050911_DAL@SD DAL 28 SD 24-4 4 61 NFL_20050911_DEN@MIA DEN 10 MIA 3424 -24 VTm.f HTm.f average 1 OAKNE 19.4375 2 ARI NYG 19.4375 3 CHI WAS 19.4375 4 CIN CLE 19.4375 5 DALSD 19.4375 6 DEN MIA 19.4375 and here is the other (aggregated means from the first frame). head(fiveINFO) HTm HPts VPts average 1 ARI 19.87500 19.0 19.43750 2 ATL 24.75000 19.12500 21.93750 3 BAL 19.37500 13.75000 16.56250 4 BUF 16.5 17.37500 16.93750 5 CAR 25.12500 23.27273 24.19886 6 CHI 18.8 14.0 16.38889 For reference, this data is looking at NFL scores. I want to take the averages in fiveINFO, frame two, and move them to the corresponding team in the first frame. five is 266 rows long, while fiveINFO is 32 rows — fiveINFO contains each HTm only once, while five contains each one 8-10 times, depending on the number of home games each team plays. I'm imagining I'll need to use some kind of for loop for this, but everything I'm doing is striking out. Help? -- View this message in context: http://r.789695.n4.nabble.com/moving-data-from-one-frame-to-another-tp4625193.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Result of clustering on plot
Hello! I 'm new to R and need your help in one question... I did cluster analysis using kmeans function. I load data from file: This file also contains headers for objects I want to cluster. After making a clustering procedure I display result on plot: And it shows only points (i.e. objects) without their names. Is there any way to mark points on this plot with their names from file? Your help would be very appreciated! Thank you! -- View this message in context: http://r.789695.n4.nabble.com/Result-of-clustering-on-plot-tp4625043.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Can't read xlsx file into R. Seem, Seem to have XLConnect loaded.
Hi Mike, as others have already suggested, there might be a problem with quoting. Otherwise, did you already have a look at the package vignette ( http://cran.r-project.org/web/packages/XLConnect/vignettes/XLConnect.pdf http://cran.r-project.org/web/packages/XLConnect/vignettes/XLConnect.pdf ) that gives a number of examples on how to read/write Excel files? Best regards, Martin -- View this message in context: http://r.789695.n4.nabble.com/Can-t-read-xlsx-file-into-R-Seem-Seem-to-have-XLConnect-loaded-tp469p4624156.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error t value matrix
Hi all, I want to make the following: I want to run a linear regression on each column of a matrix estima on the correspondent column on the matrix estima2. You see I want to regress estima[,1] on estima2[,1] this way to all columns At the same time I want to make a regression adding each time a new observation. You see, the first regression will regress only one observation with one observation (I now this has no sense in this only one observation step) the second turn of observation will make estima[1:2,n] on estima2[1:2,n] for all n. Third stimation will make estima[1:3,n] on estima2[1:3,n] for all n. And so on. Make this, I want to make an output matrix on each t-value associated with the regressor. Conclusion my final matrix called t value should include al the t values on the regression each of them incorporating a new observation, with the same rows and colums than estima. I have tried several thing but I cannot achive. I writte to see if you can guide me¡¡¡ I swear I´m trying. randz-matrix(rnorm(5000),50,100) H-matrix(0,50,100) H[1,]-randz[1,] for (i in 2:50){ if(i 26) { H[i, ] - 0.6 * H[i-1, ] + randz[i, ] } else { H[i, ] - H[i-1, ] + randz[i, ] } } write.table(H, file = datad.txt) g-read.table(datad.txt) hy-nrow(g)-1 estima-H[2:nrow(g), ] estima2-H[ 1:hy, ] mycoef - function (x,y) a-estima b-estima2 f-summary(lm(a~b)) ff-coef(f) ff[2,t value] tvalue - sapply (2:ncol(b) , function (i){ y-a[,i] x-b[,i] mycoef(x,y) } ) print (summary(tvalue)) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] moving data from one frame to another
When I tried doing that, it only merged the averages from column 1 — ARI — and did not spread the averages for ARI, ATL, BAL. Any ideas on how I could keep it from making all of the HTms ARI and all of the averages 19.4375? -- View this message in context: http://r.789695.n4.nabble.com/moving-data-from-one-frame-to-another-tp4625193p4625234.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Coloring subsets of points of a strip chart by quantiles
Hello All, I am trying to color five subsets of points in a series of vertical strip charts by quintiles using the quantile function, but I have not been able to do this successfully, nor have I been able to find an example of this online. I would like to have the E1, E2, and E3 columns plotted on a single plot (containing the three strip charts). I am overlaying the strip chart over a transparent background box plot. ##OK, here's some data (This is probably an inelegant way to do this, but I'm obviously new to R): mdat - matrix(c(round(runif(14,min=50,max=100)),round(runif(14,min=50,max=100)),round(runif(14,min=50,max=100))), nrow = 14, ncol=3, byrow=F,dimnames = list(c(seq(1,14,by=1)),c(E1, E2, E3))) ; mdat - as.data.frame(mdat) mdat E1 E2 E3 1 72 96 95 2 56 81 85 3 57 55 95 4 72 83 89 5 61 65 51 6 80 86 85 7 99 85 100 8 50 98 60 9 79 54 63 10 81 58 96 11 60 74 52 12 56 51 80 13 65 51 75 14 90 88 65 boxplot(mdat, col=transparent, main=mdat, boxwex = 0.25, ylab=Score, cex=2, cex.axis=2, cex.lab=1.5, cex.main=2, las=1, col.main=blue, col.lab=blue, col.axis=blue) stripchart(mdat,vertical=T, col=blue, method=stack, pch=21,cex=2, add=T, bg= rainbow(quantile(mdat, prob = c(.2, .4, .6, .8, 1), na.rm = T),alpha=0.5)) ##Here's the plot, but I don't think that the coloring is behaving as I would like. (1) I don't think that the quantile function is getting applied to each E1/2/3 separately. (2) I don't think that the data is getting cut and colored by (five) ranges that depend upon the quintiles. Any help would be appreciated. Thanks. http://r.789695.n4.nabble.com/file/n4624535/mdat.png -- View this message in context: http://r.789695.n4.nabble.com/Coloring-subsets-of-points-of-a-strip-chart-by-quantiles-tp4624535.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] survival analysis simulation question
Hi, I am trying to simulate a regression on survival data under a few conditions: 1. Under different error distributions 2. Have the error term be dependent on the covariates But I'm not sure how to specify either conditions. I am using the Design package to perform the survival analysis using the survreg, bj, coxph functions. Any help is greatly appreciated. This is what I have so far: survtime - 10*rexp(500) #distribution of survival time cens - ifelse(survtime 10, 0, 1) #indicator for censored/observed survtime - pmin(survtime, 10) #new survival time values with censored info age - rnorm(200, 40, 10) #age variable race - factor(sample(c('a','b'),500,TRUE)) #categorical variable test - bj(Surv(survtime, cens) ~ rcs(age,5) + race) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to do averaging of two tables (rows with columns)
Hi R user, I finally able to send you the table in readable format. I have seen that some of you do send tables in email when asking questions, but why i could not send. Any way some of you helped me to send you the example table in a readable format. now, I want to concentrate on my problem. I am trying to get the information (dat 3) from dat 1 and 2 in R. I have very big data but these data are just hypothetical data. my data structures are exactly same as dat 1 and dat 2. I created dat 3 and dat4 manually to show what information I wanted to have. I am struggling to figure it out how I can do in R. I think it is not difficult. I hope any one can help me. dat1 is the table of species occurrence (o means species absence, 1 means species presence). dat1 - structure(list(X = structure(1:4, .Label = c(Plot1, Plot2, plot3, plot4), class = factor), speciesX = c(1L, 0L, 1L, 0L), speciesY = c(0L, 1L, 0L, 0L), speciesZ = c(1L, 1L, 0L, 1L), speciesXX = c(0L, 0L, 1L, 0L)), .Names = c(X, speciesX, speciesY, speciesZ, speciesXX), class = data.frame, row.names = c(NA, -4L)) dat2 is the species tolerances value in each environmental variable dat2 - structure(list(X = structure(c(1L, 3L, 2L), .Label = c(SpeciesX, SpeciesXX, SpeciesY), class = factor), EnviA = c(0.21, 0.1, 0.14), EnviB = c(0.4, 0.15, 0.16), EnviC = c(0.17, 0.18, 0.19)), .Names = c(X, EnviA, EnviB, EnviC), class = data.frame, row.names = c(NA, -3L)) ## note (here in dat 2 there is no species Z you can see that ) Now, I want to get the average value of tolerances in each grid. like dat 3 the dat3 is based on the column EnviA. dat3 -structure(list(X = structure(1:4, .Label = c(plot1, plot2, plot3, plot4), class = factor), speciesX = c(0.21, NA, NA, 0.21), speciesY = c(NA, 0.1, NA, NA), speciesZ = structure(c(1L, 1L, 1L, 1L), .Label = Nodata, class = factor), speciesXX = c(0.14, NA, 0.14, NA), average = c(0.175, 0.1, 0.14, 0.21)), .Names = c(X, speciesX, speciesY, speciesZ, speciesXX, average), class = data.frame, row.names = c(NA, -4L)) dat4 is same thing as dat3 but here i used EnviB instead of EnviA. dat4 - structure(list(X = structure(1:4, .Label = c(plot1, plot2, plot3, plot4), class = factor), speciesX = c(0.4, NA, NA, 0.4), speciesY = c(NA, 0.15, NA, NA), speciesZ = structure(c(1L, 1L, 1L, 1L), .Label = Nodata, class = factor), speciesXX = c(0.16, NA, 0.16, NA), average = c(0.28, 0.15, 0.16, 0.4)), .Names = c(X, speciesX, speciesY, speciesZ, speciesXX, average), class = data.frame, row.names = c(NA, -4L)) I hope you understand my problem and you can help me. Thanks Kristi [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to combine two tables with different orientation and get mean from the two tables
Hi R user, I finally able to send you the table in readable format. I have seen that some of you do send tables in email when asking questions, but why i could not send. Any way some of you helped me to send you the example table in a readable format. now, I want to concentrate on my problem. I am trying to get the information (dat 3) from dat 1 and 2 in R. I have very big data but these data are just hypothetical data. my data structures are exactly same as dat 1 and dat 2. I created dat 3 and dat4 manually to show what information I wanted to have. I am struggling to figure it out how I can do in R. I think it is not difficult. I hope any one can help me. dat1 is the table of species occurrence (o means species absence, 1 means species presence). dat1 - structure(list(X = structure(1:4, .Label = c(Plot1, Plot2, plot3, plot4), class = factor), speciesX = c(1L, 0L, 1L, 0L), speciesY = c(0L, 1L, 0L, 0L), speciesZ = c(1L, 1L, 0L, 1L), speciesXX = c(0L, 0L, 1L, 0L)), .Names = c(X, speciesX, speciesY, speciesZ, speciesXX), class = data.frame, row.names = c(NA, -4L)) dat2 is the species tolerances value in each environmental variable dat2 - structure(list(X = structure(c(1L, 3L, 2L), .Label = c(SpeciesX, SpeciesXX, SpeciesY), class = factor), EnviA = c(0.21, 0.1, 0.14), EnviB = c(0.4, 0.15, 0.16), EnviC = c(0.17, 0.18, 0.19)), .Names = c(X, EnviA, EnviB, EnviC), class = data.frame, row.names = c(NA, -3L)) ## note (here in dat 2 there is no species Z you can see that ) Now, I want to get the average value of tolerances in each grid. like dat 3 the dat3 is based on the column EnviA. dat3 -structure(list(X = structure(1:4, .Label = c(plot1, plot2, plot3, plot4), class = factor), speciesX = c(0.21, NA, NA, 0.21), speciesY = c(NA, 0.1, NA, NA), speciesZ = structure(c(1L, 1L, 1L, 1L), .Label = Nodata, class = factor), speciesXX = c(0.14, NA, 0.14, NA), average = c(0.175, 0.1, 0.14, 0.21)), .Names = c(X, speciesX, speciesY, speciesZ, speciesXX, average), class = data.frame, row.names = c(NA, -4L)) dat4 is same thing as dat3 but here i used EnviB instead of EnviA. dat4 - structure(list(X = structure(1:4, .Label = c(plot1, plot2, plot3, plot4), class = factor), speciesX = c(0.4, NA, NA, 0.4), speciesY = c(NA, 0.15, NA, NA), speciesZ = structure(c(1L, 1L, 1L, 1L), .Label = Nodata, class = factor), speciesXX = c(0.16, NA, 0.16, NA), average = c(0.28, 0.15, 0.16, 0.4)), .Names = c(X, speciesX, speciesY, speciesZ, speciesXX, average), class = data.frame, row.names = c(NA, -4L)) I hope you understand my problem and you can help me. Thanks Kristi [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Interweaving of two datasets
I tried to do using merge, I think now it works (anyway it is your worth), I wrote: df1-read.csv(df1.csv,head=T) attach(df1) df2-read.csv(df2.csv,head=T) attach(df2) join-merge(df1,df2,by.x=name,by.y=name) Is it correct? Coz I'm very frightened to lose datas or make mistakes -- View this message in context: http://r.789695.n4.nabble.com/Interweaving-of-two-datasets-tp4608505p4624852.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Matrix heatmap
how do I plot only the data below 10? everything is white for the 0-10 and 10-90 is black .. those functions which do this? was bad for such basic questions, but I started tinkering with R is 6 days -- View this message in context: http://r.789695.n4.nabble.com/Matrix-heatmap-tp4619084p4625021.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.