Re: [R] US States percentage change plot
On 10/13/2011 12:45 AM, Michael Charles Bailey I wrote: State Percent.Change 1Alabama0.004040547 2 Alaska -0.000202211 3Arizona -0.002524567 4 Arkansas -0.008525333 5 California0.001828754 6 Colorado0.06150 Hi, Please provide a reproducible example (up to the point where you are stuck), as suggested in the posting guide. good luck, Paul -- Paul Hiemstra, Ph.D. Global Climate Division Royal Netherlands Meteorological Institute (KNMI) Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39 P.O. Box 201 | 3730 AE | De Bilt tel: +31 30 2206 494 http://intamap.geo.uu.nl/~paul http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770 __ 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] SLOW split() function
Using Josh's nice example, with data.table's built-in 'by' (optimised grouping) yields a 6 times speedup (100 seconds down to 15 on my netbook). system.time(all.2b - lapply(si, function(.indx) { coef(lm(y ~ + x, data=d[.indx,])) })) user system elapsed 144.501 0.300 145.525 system.time(all.2c - lapply(si, function(.indx) { minimal.lm(y + = d[.indx, y], x = d[.indx, list(int, x)]) })) user system elapsed 100.819 0.084 101.552 system.time(all.2d - d[,minimal.lm2(y=y, x=cbind(int, x)),by=key]) user system elapsed 15.269 0.012 15.323 # 6 times faster head(all.2c) $`1` coefse x1 0.5152438 0.6277254 x2 0.5621320 0.5754560 $`2` coef se x1 0.2228235 0.312918 x2 0.3312261 0.261529 $`3` coefse x1 -0.1972439 0.4674000 x2 -0.1674313 0.4479957 $`4` coefse x1 -0.13915746 0.2729158 x2 -0.03409833 0.2212416 $`5` coefse x1 0.007969786 0.2389103 x2 -0.083776526 0.2046823 $`6` coefse x1 -0.58576454 0.5677619 x2 -0.07249539 0.5009013 head(all.2d) key coefV2 [1,] 1 0.5152438 0.6277254 [2,] 1 0.5621320 0.5754560 [3,] 2 0.2228235 0.3129180 [4,] 2 0.3312261 0.2615290 [5,] 3 -0.1972439 0.4674000 [6,] 3 -0.1674313 0.4479957 minimal.lm2 # slightly modified version of Josh's function(y, x) { obj - lm.fit(x = x, y = y) resvar - sum(obj$residuals^2)/obj$df.residual p - obj$rank R - .Call(La_chol2inv, x = obj$qr$qr[1L:p, 1L:p, drop = FALSE], size = p, PACKAGE = base) m - min(dim(R)) d - c(R)[1L + 0L:(m - 1L) * (dim(R)[1L] + 1L)] se - sqrt(d * resvar) list(coef = obj$coefficients, se) } -- View this message in context: http://r.789695.n4.nabble.com/SLOW-split-function-tp3892349p3900851.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] nls: singular convergeance
On 13/10/11 18:02, Redding, Matthew wrote: Dear R-experts, I have 28 data points that I would like to fit with a non linear broken-stick -- with three fitted parameters. When I view trace -- and use the final values as lines on the graph of data -- it looks pretty good. Q1. Why am I getting singular convergeance? Q2. Can you suggest another approach that may prove more satisfying? SNIP Have you thought of using the segmented package instead of rolling your own with nls? cheers, Rolf Turner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] using dynamic variable names
(1) See ?paste, ?assign, and ?get. (2) ***Don't*** do it this way!!! Use a list instead. That's the R-ish way of doing things. See ?list. cheers, Rolf Turner On 13/10/11 18:23, Sasso Kocovski wrote: Hi, hopefully you can help me out - thanks in advance. I would like to assign variable (or vectors) names dynamically, hence, after you assign the number of new vectors then they populate for use later in the algorithm. Below is an example: n-5 for (i in (1:n)) { vector_i- c(1:10) } Here what I am trying to do is create n=5 vectors (vector_1, vector_2, vector_3, vector_4, vector_5) that I will use later in my algorithm. I don't want to create a matrix because I will use these in a time series later and the vectors will be of different length, where having '0' will produce wrong results. This may not be possible in R, if so you can also save me time of trying to figure this out on my own. __ 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] US States percentage change plot
On 10/13/2011 11:45 AM, Michael Charles Bailey I wrote: Hi, I would like to make a plot of the US states (or lower 48) that are colored based upon a percentage change column. Ideally, it would gradually be more blue the larger the positive change, and more red the more negative is the change. The data I have looks like: State Percent.Change 1Alabama0.004040547 2 Alaska -0.000202211 3Arizona -0.002524567 4 Arkansas -0.008525333 5 California0.001828754 6 Colorado0.06150 I have read help for the maps library and similar plots online but can't grasp how to map the percentage.change column to the map. thank in advance, Hi Michael, I do a similar thing like this: SEIFAcol-color.scale(AU_SEIFA$SEIFA1dec[1:199], c(1,0.9,0.8,0.8),c(0.8,0.9,0.9,0.8),c(0.8,0.8,0.9,1),xrange=c(1,10)) ... plot(NSWmap,xlim=c(140,max(cdrt09$GeocodeX,na.rm=TRUE)), col=SEIFAcol) SEIFAlegendcol-color.scale(1:10, c(1,0.9,0.8,0.8),c(0.8,0.9,0.9,0.8),c(0.8,0.8,0.9,1)) color.legend(151.8,-37.5,152.3,-34.5,as.character(1:10),SEIFAlegendcol, align=rb,gradient=y) In this case, Statistical Local Areas are being colored on the Index of Relative Social Disadvantage. The call to color.scale calculates a color for each of the 199 SLAs based on their IRSD score. If you want to define different color scales for positive and negative values, see the help page for color.scale (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] nls: singular convergeance
On 13/10/11 21:26, Redding, Matthew wrote: Hi Rolf and others Will this make any difference to the convergence? I have no idea, really. I don't know if convergence issues even arise in the context of the segmented package. I have never encountered any. Try it and see. Shouldn't take more than about 10 minutes, all up. cheers, Rolf - Original Message - From: Rolf Turnerrolf.tur...@xtra.co.nz To: Redding, Matthew Cc: r-help@r-project.orgr-help@r-project.org Sent: Thu Oct 13 18:04:53 2011 Subject: Re: [R] nls: singular convergeance On 13/10/11 18:02, Redding, Matthew wrote: Dear R-experts, I have 28 data points that I would like to fit with a non linear broken-stick -- with three fitted parameters. When I view trace -- and use the final values as lines on the graph of data -- it looks pretty good. Q1. Why am I getting singular convergeance? Q2. Can you suggest another approach that may prove more satisfying? SNIP Have you thought of using the segmented package instead of rolling your own with nls? cheers, Rolf Turner __ 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 map current Europe?
Thank you for answering mails on the R-help mailig list, but please note the posting guide and in particular - you answered only to the mailing list, please also answer to the original poster - for reference, please alsways cite the previous thread, otherwise the answers are not useful without contect Thanks again, Uwe Ligges On 11.10.2011 12:48, fub2011 wrote: hi, see here http://r.789695.n4.nabble.com/Create-a-map-td3689877.html#a3893581 -- View this message in context: http://r.789695.n4.nabble.com/How-to-map-current-Europe-tp3715709p3893588.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] How to map current Europe?
Hi Uwe, When you cc from Nabble it doesn't show as cc'd on r-help. It's a web form with an Email this post to... box. I asked Nabble support (over a year ago) if they could reflect that in the cc field of the post they send to r-help, with no luck. The previous thread is cited automatically in the footer: View this message in context link. I'm replying to this one because I happened to used Nabble to reply in another thread, in the same way, earlier this morning. If it isn't ok to post from Nabble, it's an option to prevent posting from Nabble I believe. To double check, I've sent this reply using Nabble. Did you get the (unreflected) cc? I placed your email address in the email this post to... box. Matthew -- View this message in context: http://r.789695.n4.nabble.com/How-to-map-current-Europe-tp3715709p3900971.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] lattice-dotplot: resize axis
On Wed, Oct 5, 2011 at 5:00 PM, René Mayer ma...@psychologie.tu-dresden.de wrote: dear all, I want to make a dotplot with ratings from Items in 6 ItemsGroups. I reordered the items by rating within each group. I plotted the items by rating conditional on ItemGroup. The ordering works as I wanted but my y-aches labels (items) within each ItemGroup are now unequally spaced, e.g., in some panels there is a gap between one lower rated item and the next higher, to give a picture items=a,e,f,g ItemGroup=n - g| . f| . e| . | | | a| . - How can I correct this? What have I overlooked? A reproducible example would help. -Deepayan # code i've used (from latticeExtra/utilities/resize panels) library(latticeExtra) mean.ratings$item.name - with(mean.ratings, reorder(reorder(item, rating), as.numeric(ItemGroup))) dpratings - dotplot(item.name ~ rating | reorder(ItemGroup, rating), data = mean.ratings, layout = c(1, 6), xlim=c(1,6), aspect = .1, scales = list(y = list(relation = free, cex=.5))) ## approximate resizePanels(dpratings, h = with(mean.ratings, table(reorder(ItemGroup, rating thanks, René __ 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] write.csv naming file after function argument
Dear R-users, I'm writing a program that constructs a dataset. I wish to save the dataset to a file. Here's a very simple example of what I'm trying to do function(x=peter){ y - x/2 write.csv(y, file = ...\x) } The problem is that I want to name the dataset as whatever the name of the input is. In this case peter. How do I do this? Thank you in advance. Kristian [[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] write.csv naming file after function argument
Hi Kristian, If I understand correctly, you probably want to use paste(): myfun - function(x=peter){ y - x/2 filename - paste(x, .csv, sep=) write.csv(y, file = filename) } HTH, Ivan Le 10/13/2011 11:52, Kristian Lind a écrit : Dear R-users, I'm writing a program that constructs a dataset. I wish to save the dataset to a file. Here's a very simple example of what I'm trying to do function(x=peter){ y- x/2 write.csv(y, file = ...\x) } The problem is that I want to name the dataset as whatever the name of the input is. In this case peter. How do I do this? Thank you in advance. Kristian [[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. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Dept. Mammalogy Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php __ 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] Create order of numbers based on a given vector
Hello! If I have a vector vec - c(FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE FALSE) I can I create the following order of numbers based on vector vec: 1, 2, 2, 3, 3, 3, 4, 5 Whenever there is a FALSE I increase the number (starting with 1). Whenever there is a TRUE I set the same number as the previous FALSE has been assigned to. I would be happy for any input Cheers, Syrvn -- View this message in context: http://r.789695.n4.nabble.com/Create-order-of-numbers-based-on-a-given-vector-tp3901158p3901158.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] Create order of numbers based on a given vector
try this: vec - c(FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE) cumsum(!vec) I hope it helps. Best, Dimitris On 10/13/2011 1:15 PM, syrvn wrote: Hello! If I have a vector vec- c(FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE FALSE) I can I create the following order of numbers based on vector vec: 1, 2, 2, 3, 3, 3, 4, 5 Whenever there is a FALSE I increase the number (starting with 1). Whenever there is a TRUE I set the same number as the previous FALSE has been assigned to. I would be happy for any input Cheers, Syrvn -- View this message in context: http://r.789695.n4.nabble.com/Create-order-of-numbers-based-on-a-given-vector-tp3901158p3901158.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. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ __ 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] Create order of numbers based on a given vector
I think you can use the cumsum function. If you think of your falses to 1 and your trues to 0 then you're just sequentially adding the numbers in the vector. x = c(FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE) y = rep(1,length(x))*(1-x) cumsum(y) Hope that helps, Sam On Thu, Oct 13, 2011 at 8:15 AM, syrvn ment...@gmx.net wrote: Hello! If I have a vector vec - c(FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE FALSE) I can I create the following order of numbers based on vector vec: 1, 2, 2, 3, 3, 3, 4, 5 Whenever there is a FALSE I increase the number (starting with 1). Whenever there is a TRUE I set the same number as the previous FALSE has been assigned to. I would be happy for any input Cheers, Syrvn -- View this message in context: http://r.789695.n4.nabble.com/Create-order-of-numbers-based-on-a-given-vector-tp3901158p3901158.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] Create order of numbers based on a given vector
Apologies,it should be ans-cumsum(vec1) On Thu, Oct 13, 2011 at 4:58 PM, Ashim Kapoor ashimkap...@gmail.com wrote: I don't have access to R so I can't test my example but I think this will work. vec ( as defined by you) # flip the false and the trues vec1-ifelse(vec==FALSE,TRUE,FALSE) ans-cumsum(vec) Regards, Ashim On Thu, Oct 13, 2011 at 4:45 PM, syrvn ment...@gmx.net wrote: Hello! If I have a vector vec - c(FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE FALSE) I can I create the following order of numbers based on vector vec: 1, 2, 2, 3, 3, 3, 4, 5 Whenever there is a FALSE I increase the number (starting with 1). Whenever there is a TRUE I set the same number as the previous FALSE has been assigned to. I would be happy for any input Cheers, Syrvn -- View this message in context: http://r.789695.n4.nabble.com/Create-order-of-numbers-based-on-a-given-vector-tp3901158p3901158.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] Create order of numbers based on a given vector
I don't have access to R so I can't test my example but I think this will work. vec ( as defined by you) # flip the false and the trues vec1-ifelse(vec==FALSE,TRUE,FALSE) ans-cumsum(vec) Regards, Ashim On Thu, Oct 13, 2011 at 4:45 PM, syrvn ment...@gmx.net wrote: Hello! If I have a vector vec - c(FALSE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE FALSE) I can I create the following order of numbers based on vector vec: 1, 2, 2, 3, 3, 3, 4, 5 Whenever there is a FALSE I increase the number (starting with 1). Whenever there is a TRUE I set the same number as the previous FALSE has been assigned to. I would be happy for any input Cheers, Syrvn -- View this message in context: http://r.789695.n4.nabble.com/Create-order-of-numbers-based-on-a-given-vector-tp3901158p3901158.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] Legend symbols (line, points) in one column.
Dear R users: I want to have in the same column both symbols, line and points, one for a data, and the other for the model. How can I do that? Or is there other better form to show both data and model in the same graphic? I need to make the difference on time of the same subject (repeated measurements on time) Problem example: ### x-1:5 y-1*x+rnorm(10) data1-data.frame(x,y,type=rep(data,length(x))) model1-lm(y~x,data=data1) data2-data.frame(x=seq(0,6,.1)) data2$y-predict(model1,newdata=data2) data2$type-rep(model,nrow(data2)) dataT-rbind(data1,data2) dataT require(lattice) confMisc1- simpleTheme(pch = c(19,1),lwd=c(2,1),cex=1.5, lty=1,col=c(black)) xyplot(y~x,group=type, type=c(p,l), key=list(space=right,text=list(c(Data,Model)), points=list(pch=c(as.integer(NA),19)), lines=list(lty=c(1,0),lwd=c(2,0))), par.settings=confMisc1, panel=panel.superpose, distribute.type=TRUE, data=dataT) ### __ 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] KS test
anuradha guru wrote on 10/12/2011 11:45:43 PM: Hi! how can I do the Kolmogorov Smirnov test for discrepancy between the estimated and empirical tails? Regards Anuradha A simple search of the help system would have led you to the ks.test() function. ??kolmogorov ?ks.test Jean [[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] Create order of numbers based on a given vector
Hi, thanks for all of your answers! Great solutions for my problem :) Best, syrvn -- View this message in context: http://r.789695.n4.nabble.com/Create-order-of-numbers-based-on-a-given-vector-tp3901158p3901292.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] using dynamic variable names
Rolf Turner wrote on 10/13/2011 03:09:12 AM: (1) See ?paste, ?assign, and ?get. (2) ***Don't*** do it this way!!! Use a list instead. That's the R-ish way of doing things. See ?list. cheers, Rolf Turner On 13/10/11 18:23, Sasso Kocovski wrote: Hi, hopefully you can help me out - thanks in advance. I would like to assign variable (or vectors) names dynamically, hence, after you assign the number of new vectors then they populate for use later in the algorithm. Below is an example: n-5 for (i in (1:n)) { vector_i- c(1:10) } Here what I am trying to do is create n=5 vectors (vector_1, vector_2, vector_3, vector_4, vector_5) that I will use later in my algorithm. I don't want to create a matrix because I will use these in a time series later and the vectors will be of different length, where having '0' will produce wrong results. This may not be possible in R, if so you can also save me time of trying to figure this out on my own. I agree with Rolf, a list would be a good way to do it. Here's an example: n - 5 vectorz - vector(mode=list, length=n) for(i in (1:n)) { veclen - sample(10:20, 1) vectorz[[i]] - sample(1:100, veclen) } vectorz Jean [[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] Fitting a Harmonic Function to Time Series Data
Dear All, I have some time series data where X=month and Y=nutrient concentration (I can have several concentration data for one month). Is there a way to fit for it an Harmonic Function. Is there a package, script,etc which I can use? Thx -- View this message in context: http://r.789695.n4.nabble.com/Fitting-a-Harmonic-Function-to-Time-Series-Data-tp3901266p3901266.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] Question about GAMs
hi! I hope all of you can help me this question for example GAMs: ozonea-gam(newozone~ pressure+maxtemp+s(avetemp,bs=cr)+s(ratio,bs=cr),family=gaussian (link=log),groupA,methods=REML) formula(ozonea) newozone ~ pressure + maxtemp + s(avetemp, bs = cr) + s(ratio,bs = cr) #formula of gams coef(ozonea) # extract the coefficient of GAMs (Intercept) pressure maxtemp s(avetemp).1 s(avetemp).2 s(avetemp).3 s(avetemp).4 s(avetemp).5 s(avetemp).6 s(avetemp).7 s(avetemp).8 s(avetemp).9 s(ratio).1 2.848204561 -0.024662520 -0.095528572 -0.052613005 -0.135309283 0.066243642 0.030937179 0.176267227 0.243405931 0.357027920 0.600628869 0.758581430 0.004653696 s(ratio).2 s(ratio).3 s(ratio).4 s(ratio).5 s(ratio).6 s(ratio).7 s(ratio).8 s(ratio).9 0.156547789 -0.132527837 -0.179947367 -0.208918785 -0.468014803 -0.195498523 -0.813667830 -1.505844690 then, I want to calculate newozone - s(ratio,bs=cr) we define this term (newozone - s(ratio,bs=cr)) is X can i use the coefficient to calculate? -- View this message in context: http://r.789695.n4.nabble.com/Question-about-GAMs-tp3900848p3900848.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] nls: singular convergeance
Hi Rolf and others Will this make any difference to the convergence? Thanks Matt Matt Redding, Ph.D. Soil chemist/Geochemist Principal Scientist Agri-Science Queensland Ph 0746 881372 Mob 0408 787100 Fax 07 46881192 - Original Message - From: Rolf Turner rolf.tur...@xtra.co.nz To: Redding, Matthew Cc: r-help@r-project.org r-help@r-project.org Sent: Thu Oct 13 18:04:53 2011 Subject: Re: [R] nls: singular convergeance On 13/10/11 18:02, Redding, Matthew wrote: Dear R-experts, I have 28 data points that I would like to fit with a non linear broken-stick -- with three fitted parameters. When I view trace -- and use the final values as lines on the graph of data -- it looks pretty good. Q1. Why am I getting singular convergeance? Q2. Can you suggest another approach that may prove more satisfying? SNIP Have you thought of using the segmented package instead of rolling your own with nls? cheers, Rolf Turner We're behind the Bid! GOLD COAST 2018 - XXI COMMONWEALTH GAMES CANDIDATE CITY www.goldcoast2018bid.com DISCLAIMER The information contained in the above e-mail message or messages (which includes any attachments) is confidential and may be legally privileged. It is intended only for the use of the person or entity to which it is addressed. If you are not the addressee any form of disclosure, copying, modification, distribution or any action taken or omitted in reliance on the information is unauthorised. Opinions contained in the message(s) do not necessarily reflect the opinions of the Queensland Government and its authorities. If you received this communication in error, please notify the sender immediately and delete it from your computer system network. __ 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] about the gee function
Dear all, I have been using the gee package, but I have some questions digging into my mind. I am wondering that how the gee function deals with an unbalanced longitudinal design, i.e how it distinguishes the time information of the repeated measures. In the gee function options, only the id information of the clusters is needed but the time information does not. Similarly, if the data has missing values the function deletes the corresponding row and then it combines the former and latter rows (time points). I am wondering that how it recognizes the time point of the deleted rows and distinguishes it from the time point of the latter row. Lastly, does the function is convenient for irregular longitudinal designs? Thank you in advance, Best regards, Ozgur ** Ozgur ASAR Research Assistant Middle East Technical University Department of Statistics 06800, Ankara Turkey Ph: 90-312-2105309 -- View this message in context: http://r.789695.n4.nabble.com/about-the-gee-function-tp3900816p3900816.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] dlm package - set up constraints in the state space
hi, i would like to set up a state space model (linear, gaussian) in the dlm package, with the constraint that the state vector has only positive entries. i have checked the vignette for the package but couldn't find anything giving me a hint on how to do this. any suggestions or pointers are most welcome! thanks kind regards stephan -- View this message in context: http://r.789695.n4.nabble.com/dlm-package-set-up-constraints-in-the-state-space-tp3901025p3901025.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] moving average TTR
Hello, I used the TTR package in R to calculate moving averages. I have a monthly time series and I would like to calculate the moving average over 10 years with an offset of 1 year. It should be something like sma.365 - SMA(data, n=120) Does anyone know how to include in offset? Thanks a lot for your help. Best regards! -- View this message in context: http://r.789695.n4.nabble.com/moving-average-TTR-tp3901080p3901080.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] Counting the number of integers at one swoop
Dear R users, I'd like to count the number of integers in a vector y. Here is an example. y - c(0,1,1,3,3,3,5,5,6) In fact, I know how to count the number of specific number in y. sum(y==0) - 1 sum(y==1) - 2 sum(y==2) - 0 sum(y==3) - 3 sum(y==4) - 0 sum(y==5) - 2 sum(y==6) - 1 However, in one computation I want to get this vector [1,2,0,3,0,2,1]. Thank you in advance. Kathie -- View this message in context: http://r.789695.n4.nabble.com/Counting-the-number-of-integers-at-one-swoop-tp3901215p3901215.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] Issues with gvisMotionChart
Hi, I've just been introduced to this wonderful chart making tool from Google and I've already stumbled. When I am trying to execute this code below, and I double-click to open the html file I cannot see the chart at all !! M - gvisMotionChart(Fruits, Fruit, Year) cathttp://inside-r.org/r-doc/base/cat(M$html$chart, filehttp://inside-r.org/r-doc/base/file=tmp.html) However if I execute : M - gvisMotionChart(Fruits, Fruit, Year) plot(M) then I can see the chart in my browser ! Can anyone help me figure this out ?? Thanks, Ankur This e-mail (and any attachments), is confidential and may be privileged. It may be read, copied and used only by intended recipients. Unauthorized access to this e-mail (or attachments) and disclosure or copying of its contents or any action taken in reliance on it is unlawful. Unintended recipients must notify the sender immediately by e-mail/phone delete it from their system without making any copies or disclosing it to a third person. [[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] Counting the number of integers at one swoop
I think there must be an easier solution, but this works: y - c(0,1,1,3,3,3,5,5,6) x-matrix(0:6,ncol=1) apply(x,1,function(x){length(y[y==x])}) HTH, Daniel Kathie wrote: Dear R users, I'd like to count the number of integers in a vector y. Here is an example. y - c(0,1,1,3,3,3,5,5,6) In fact, I know how to count the number of specific number in y. sum(y==0) - 1 sum(y==1) - 2 sum(y==2) - 0 sum(y==3) - 3 sum(y==4) - 0 sum(y==5) - 2 sum(y==6) - 1 However, in one computation I want to get this vector [1,2,0,3,0,2,1]. Thank you in advance. Kathie -- View this message in context: http://r.789695.n4.nabble.com/Counting-the-number-of-integers-at-one-swoop-tp3901215p3901356.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] Linear programming problem, RGPLK - no feasible solution.
Thank you very much for this! This also solves my original problem. I can't remember at what point I assumed the bounds would be written that way. It was a costly error. Regarding the potential bug, I'm going to report it. R shut down completely every time I ran the program, but didn't when I edited the file to correct the dir term. -- View this message in context: http://r.789695.n4.nabble.com/Re-Linear-programming-problem-RGPLK-no-feasible-solution-tp3890377p3901297.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] Counting the number of integers at one swoop
Table() or more generally tabulate() Though, as a general warning, you may need to be a little careful depending on the source of your data. Once you get into floating point business, the definition of an integer becomes a little less cut and dry. If your data are all integer, the data type, then there's nothing to worry about. Michael On Thu, Oct 13, 2011 at 7:33 AM, Kathie kathryn.lord2...@gmail.com wrote: Dear R users, I'd like to count the number of integers in a vector y. Here is an example. y - c(0,1,1,3,3,3,5,5,6) In fact, I know how to count the number of specific number in y. sum(y==0) - 1 sum(y==1) - 2 sum(y==2) - 0 sum(y==3) - 3 sum(y==4) - 0 sum(y==5) - 2 sum(y==6) - 1 However, in one computation I want to get this vector [1,2,0,3,0,2,1]. Thank you in advance. Kathie -- View this message in context: http://r.789695.n4.nabble.com/Counting-the-number-of-integers-at-one-swoop-tp3901215p3901215.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] write.csv naming file after function argument
Kristian Lind wrote on 10/13/2011 04:52:16 AM: Dear R-users, I'm writing a program that constructs a dataset. I wish to save the dataset to a file. Here's a very simple example of what I'm trying to do function(x=peter){ y - x/2 write.csv(y, file = ...\x) } The problem is that I want to name the dataset as whatever the name of the input is. In this case peter. How do I do this? Thank you in advance. Kristian I think you're looking for something like this foo - function(x){ y - x/2 file.name - paste(...\\, deparse(substitute(x)), .csv, sep=) # I include the print() functions just so you can see what happened print(y) print(file.name) write.csv(y, file=file.name) } peter - 12 foo(peter) Jean [[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] Counting the number of integers at one swoop
Slight addendum, tabulate() ignores zeros so you'll need to do tabulate(y+1). Table will handle zeros but won't look for values that never appear (in your example 2 4). Michael On Thu, Oct 13, 2011 at 8:51 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: Table() or more generally tabulate() Though, as a general warning, you may need to be a little careful depending on the source of your data. Once you get into floating point business, the definition of an integer becomes a little less cut and dry. If your data are all integer, the data type, then there's nothing to worry about. Michael On Thu, Oct 13, 2011 at 7:33 AM, Kathie kathryn.lord2...@gmail.com wrote: Dear R users, I'd like to count the number of integers in a vector y. Here is an example. y - c(0,1,1,3,3,3,5,5,6) In fact, I know how to count the number of specific number in y. sum(y==0) - 1 sum(y==1) - 2 sum(y==2) - 0 sum(y==3) - 3 sum(y==4) - 0 sum(y==5) - 2 sum(y==6) - 1 However, in one computation I want to get this vector [1,2,0,3,0,2,1]. Thank you in advance. Kathie -- View this message in context: http://r.789695.n4.nabble.com/Counting-the-number-of-integers-at-one-swoop-tp3901215p3901215.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] Question about GAMs
I am not an expert on this, but there is a way to check this. You can predict from a gam using predict(ozonea, newdata=...). In the newdata argument you can specify the X-values of interest to you. Thus, you can compare if your predictions are the same when predicted directly from the gam or when predicted by hand. HTH, Daniel pigpigmeow wrote: hi! I hope all of you can help me this question for example GAMs: ozonea-gam(newozone~ pressure+maxtemp+s(avetemp,bs=cr)+s(ratio,bs=cr),family=gaussian (link=log),groupA,methods=REML) formula(ozonea) newozone ~ pressure + maxtemp + s(avetemp, bs = cr) + s(ratio,bs = cr) #formula of gams coef(ozonea) # extract the coefficient of GAMs (Intercept) pressure maxtemp s(avetemp).1 s(avetemp).2 s(avetemp).3 s(avetemp).4 s(avetemp).5 s(avetemp).6 s(avetemp).7 s(avetemp).8 s(avetemp).9 s(ratio).1 2.848204561 -0.024662520 -0.095528572 -0.052613005 -0.135309283 0.066243642 0.030937179 0.176267227 0.243405931 0.357027920 0.600628869 0.758581430 0.004653696 s(ratio).2 s(ratio).3 s(ratio).4 s(ratio).5 s(ratio).6 s(ratio).7 s(ratio).8 s(ratio).9 0.156547789 -0.132527837 -0.179947367 -0.208918785 -0.468014803 -0.195498523 -0.813667830 -1.505844690 then, I want to calculate newozone - s(ratio,bs=cr) we define this term (newozone - s(ratio,bs=cr)) is X can i use the coefficient to calculate? -- View this message in context: http://r.789695.n4.nabble.com/Question-about-GAMs-tp3900848p3901383.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] moving average TTR
I believe the lag() function can be used to rig this up. Something like sma.365 - SMA(lag(data, 12), n=120) # Untested, but seems right Michael On Thu, Oct 13, 2011 at 6:31 AM, Laura janna...@web.de wrote: Hello, I used the TTR package in R to calculate moving averages. I have a monthly time series and I would like to calculate the moving average over 10 years with an offset of 1 year. It should be something like sma.365 - SMA(data, n=120) Does anyone know how to include in offset? Thanks a lot for your help. Best regards! -- View this message in context: http://r.789695.n4.nabble.com/moving-average-TTR-tp3901080p3901080.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] Counting the number of integers at one swoop
try this: y - c(0,1,1,3,3,3,5,5,6) x - tabulate(y+1) names(x) - seq(from = 0, by = 1, length = length(x)) x 0 1 2 3 4 5 6 1 2 0 3 0 2 1 On Thu, Oct 13, 2011 at 7:33 AM, Kathie kathryn.lord2...@gmail.com wrote: Dear R users, I'd like to count the number of integers in a vector y. Here is an example. y - c(0,1,1,3,3,3,5,5,6) In fact, I know how to count the number of specific number in y. sum(y==0) - 1 sum(y==1) - 2 sum(y==2) - 0 sum(y==3) - 3 sum(y==4) - 0 sum(y==5) - 2 sum(y==6) - 1 However, in one computation I want to get this vector [1,2,0,3,0,2,1]. Thank you in advance. Kathie -- View this message in context: http://r.789695.n4.nabble.com/Counting-the-number-of-integers-at-one-swoop-tp3901215p3901215.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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ 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] Counting the number of integers at one swoop
Kathie wrote on 10/13/2011 06:33:59 AM: Dear R users, I'd like to count the number of integers in a vector y. Here is an example. y - c(0,1,1,3,3,3,5,5,6) In fact, I know how to count the number of specific number in y. sum(y==0) - 1 sum(y==1) - 2 sum(y==2) - 0 sum(y==3) - 3 sum(y==4) - 0 sum(y==5) - 2 sum(y==6) - 1 However, in one computation I want to get this vector [1,2,0,3,0,2,1]. Thank you in advance. Kathie tabulate(factor(as.integer(y), levels=0L:6L)) Jean [[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] Package snow: is there any way to check if a cluster is acticve
Sören, have a look at package snowfall which provides sfIsRunning. HTH Claudia Am 13.10.2011 06:34, schrieb Søren Højsgaard: Is there a 'proper' way of checking if cluster is active. For example, I create a cluster called .PBcluster str(.PBcluster) List of 4 $ :List of 3 ..$ con :Classes 'sockconn', 'connection' atomic [1:1] 3 .. .. ..- attr(*, conn_id)=externalptr ..$ host: chr localhost ..$ rank: int 1 ..- attr(*, class)= chr SOCKnode $ :List of 3 Then I stop it with stopCluster(.PBcluster) .PBcluster [[1]] $con Error in summary.connection(x) : invalid connection str(.PBcluster) List of 4 $ :List of 3 ..$ con :Classes 'sockconn', 'connection' atomic [1:1] 3 .. .. ..- attr(*, conn_id)=externalptr ..$ host: chr localhost ..$ rank: int 1 ..- attr(*, class)= chr SOCKnode - but is there a way in which I can check if the cluster is active?? Regards Søren __ 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. -- Claudia Beleites Spectroscopy/Imaging Institute of Photonic Technology Albert-Einstein-Str. 9 07745 Jena Germany email: claudia.belei...@ipht-jena.de phone: +49 3641 206-133 fax: +49 2641 206-399 __ 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] Question about GAMs
I'd be inclined to use predict(ozonea,type=terms) to extract the estimates of s(ratio,bs = cr) that you need. But do you really want newozone - s(ratio,bs=cr) when you've used a log link? best, Simon On 10/13/2011 09:05 AM, pigpigmeow wrote: hi! I hope all of you can help me this question for example GAMs: ozonea-gam(newozone~ pressure+maxtemp+s(avetemp,bs=cr)+s(ratio,bs=cr),family=gaussian (link=log),groupA,methods=REML) formula(ozonea) newozone ~ pressure + maxtemp + s(avetemp, bs = cr) + s(ratio,bs = cr) #formula of gams coef(ozonea) # extract the coefficient of GAMs (Intercept) pressure maxtemp s(avetemp).1 s(avetemp).2 s(avetemp).3 s(avetemp).4 s(avetemp).5 s(avetemp).6 s(avetemp).7 s(avetemp).8 s(avetemp).9 s(ratio).1 2.848204561 -0.024662520 -0.095528572 -0.052613005 -0.135309283 0.066243642 0.030937179 0.176267227 0.243405931 0.357027920 0.600628869 0.758581430 0.004653696 s(ratio).2 s(ratio).3 s(ratio).4 s(ratio).5 s(ratio).6 s(ratio).7 s(ratio).8 s(ratio).9 0.156547789 -0.132527837 -0.179947367 -0.208918785 -0.468014803 -0.195498523 -0.813667830 -1.505844690 then, I want to calculate newozone - s(ratio,bs=cr) we define this term (newozone - s(ratio,bs=cr)) is X can i use the coefficient to calculate? -- View this message in context: http://r.789695.n4.nabble.com/Question-about-GAMs-tp3900848p3900848.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] delete columns which partially match expression
Hello everyone, I'd like to search for certain expressions (characters) in my data.frame and delete the containing columns. So, for example in the below table, I'd like to delete all columns which contain the expression Error. That is, R should delete column C and E from my data. Any ideas? A B C D E 12 33 Error1 71 Error2 Cheers, S.B. [[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] delete columns which partially match expression
try this: x - read.table(textConnection(A B C D E + 12 33 Error1 71 Error2 + 12 33 Error1 71 Error2 + 12 33 Error1 71 Error2 + 12 33 Error1 71 Error2 + 12 33 Error1 71 Error2) + , as.is = TRUE + , header = TRUE + ) closeAllConnections() colMatch - which(apply(x, 2, function(a) any(grepl(Error, a colMatch C E 3 5 # delete columns x[, -colMatch] A B D 1 12 33 71 2 12 33 71 3 12 33 71 4 12 33 71 5 12 33 71 On Thu, Oct 13, 2011 at 9:10 AM, Samir Benzerfa benze...@gmx.ch wrote: Hello everyone, I'd like to search for certain expressions (characters) in my data.frame and delete the containing columns. So, for example in the below table, I'd like to delete all columns which contain the expression Error. That is, R should delete column C and E from my data. Any ideas? A B C D E 12 33 Error1 71 Error2 Cheers, S.B. [[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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ 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] bootstrap means by strata
All - I have an uneven set of replicates and would like to sample from this set X number of times to generate a mean for each grouping variable. I was thinking the boot package would be the thing to use, but now I'm not so sure ... given the discussion here: http://finzi.psych.upenn.edu/Rhelp10/2010-June/243828.html Given these data (a small subset): dput(x) structure(list(numSpp = c(7, 8, 6, 4, 5, 4, 10, 12, 7, 13, 4, 11, 4, 3, 3, 10, 8, 16, 11, 6, 3, 5, 6, 13, 15, 2, 6, 11, 11, 10, 6, 9, 11, 14, 10, 7), TrSeasYr = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3)), .Names = c(numSpp, TrSeasYr), row.names = c(NA, -36L), class = data.frame) #get into R by pasting the above after x- or dget(clipboard) # my grouping var is col 2, data are in col 1 # my attempt using boot library(boot) mn - function(d,f) { mean(d[,1] * f[d[,1]]) } b1 - boot(data = x, mn, R=99, stype = f, strata=x$TrSeasYr) b1 STRATIFIED BOOTSTRAP Call: boot(data = x, statistic = mn, R = 99, stype = f, strata = x$TrSeasYr) Bootstrap Statistics : originalbiasstd. error t1* 8.08 0.13524131.681901 What is the most efficient way to resample, with replacement, and generate means for each grouping variable? Thanks in advance, Tim sessionInfo() R version 2.12.2 (2011-02-25) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] RODBC_1.3-2 boot_1.3-2 loaded via a namespace (and not attached): [1] tools_2.12.2 Timothy G. Howard, Ph.D. Director of Science New York Natural Heritage Program 625 Broadway, 5th floor Albany, NY 12233-4757 (518) 402-8945 facsimile (518) 402-8925 [[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] Axis Formats with library(car)
Dear Krishnan, This behaviour isn't particular to scatterplot() in car. Try setting options(scipen=10) and see ?options. I hope this helps, John John Fox Senator William McMaster Professor of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Krishnan Viswanathan Sent: October-13-11 6:44 AM To: r-help@r-project.org Subject: [R] Axis Formats with library(car) I am trying to develop scatter plots using library(car). However, the output I am getting shows the axis (x and y) in scientific notation. I want to have the axis represented by regular integers (for eg. the X axis i want the upper bound to show as 40,000,000 instead of 4.0e+07). Scanning the r-help archives did not get me the answer. I have uploaded my data here: http://bit.ly/olgMLt (scatter_example.csv). The resulting graph is shown here: http://bit.ly/r8XxUA(business_orig_scatterplot.pdf). My code is as follows: estimation_data - read.csv(scatter_example.csv,head=TRUE,sep=,) library(car) scatterplot(Bus_Orig ~ POP1995, data=estimation_data, xlab=Population (1995), ylab=Business Origins, main=Scatter Plot - State Levels, labels=row.names(estimation_data), boxplots=FALSE) I tried the following as well which gave me no results. # Trying to show #s in non-scientific format for presentation estimation_data$BO - format(estimation_data$Bus_Orig, scientific = FALSE, big.mark = ,) estimation_data$P95 - format(estimation_data$POP1995, scientific = FALSE, big.mark = ,) scatterplot(Bus_Orig ~ POP1995, data=estimation_data, xlab=Population (1995), ylab=Business Origins, main=Scatter Plot - State Levels, xlim=estimation_data$P95, ylim=estimation_data$BO, labels=row.names(estimation_data), boxplots=FALSE) So any pointers to fix this would be helpful. TIA, Krishnan [[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] bootstrap means by strata
Answering my own question. ?sample (!) y - by(x, x$TrSeasYr, function(x) mean(sample(x[,1], size=999, replace = TRUE))) Tim Howard 10/13/2011 9:42 AM All - I have an uneven set of replicates and would like to sample from this set X number of times to generate a mean for each grouping variable. I was thinking the boot package would be the thing to use, but now I'm not so sure ... given the discussion here: http://finzi.psych.upenn.edu/Rhelp10/2010-June/243828.html Given these data (a small subset): dput(x) structure(list(numSpp = c(7, 8, 6, 4, 5, 4, 10, 12, 7, 13, 4, 11, 4, 3, 3, 10, 8, 16, 11, 6, 3, 5, 6, 13, 15, 2, 6, 11, 11, 10, 6, 9, 11, 14, 10, 7), TrSeasYr = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3)), .Names = c(numSpp, TrSeasYr), row.names = c(NA, -36L), class = data.frame) #get into R by pasting the above after x- or dget(clipboard) # my grouping var is col 2, data are in col 1 # my attempt using boot library(boot) mn - function(d,f) { mean(d[,1] * f[d[,1]]) } b1 - boot(data = x, mn, R=99, stype = f, strata=x$TrSeasYr) b1 STRATIFIED BOOTSTRAP Call: boot(data = x, statistic = mn, R = 99, stype = f, strata = x$TrSeasYr) Bootstrap Statistics : originalbiasstd. error t1* 8.08 0.13524131.681901 What is the most efficient way to resample, with replacement, and generate means for each grouping variable? Thanks in advance, Tim sessionInfo() R version 2.12.2 (2011-02-25) Platform: i386-pc-mingw32/i386 (32-bit) locale: [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] RODBC_1.3-2 boot_1.3-2 loaded via a namespace (and not attached): [1] tools_2.12.2 Timothy G. Howard, Ph.D. Director of Science New York Natural Heritage Program 625 Broadway, 5th floor Albany, NY 12233-4757 (518) 402-8945 facsimile (518) 402-8925 [[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 mean for groups of matrix rows?
Dear All, For a vector, I use this xu-1:20 t-rep((1:4),each=5) tapply(xu,t,mean) 1 2 3 4 3 8 13 18 and for a matrix the only way I may guess is: xu [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,]14321432 [2,]21432143 [3,]32143214 [4,]14321432 [5,]21432143 [6,]32143214 t [1] 1 1 1 2 2 2 y [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,]00000000 [2,]00000000 for (i in 1:dim(xu)[2]) y[,i]-tapply(xu[,i],t,mean) y [,1][,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,]2 2.33 2.6732 2.33 2.673 [2,]2 2.33 2.6732 2.33 2.673 I do not like the need to create a matrix (y) for the result. Is there a better way? Thanks, Andrei. [[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] Can I use lm() to fit more than one response and more than one variables in single expression
Dear All, Can I use lm() to fit more than one response in single expression. e.g data is a matrix of these variables R1 R2 R3 X1 X2 X3 1 2 1 1 2 3 Now i wnat to fit R1~X1 R2~X2 R3~X3 in turn, and I don't want to do it use loops of couse it it easy to make it using loops,but the proceed is very slow since the data is very big Can't anybody give me some tips or help, my eamil: guoshicheng2...@yeah.net 2011-10-13 Best wishes Yours Alxe -- Ministry of Education Key Laboratory of Contemporary Anthropology School of Life Sciences, Fudan University 220 Handan Road Shanghai, China 200433 Phone:15216760764 E-mail: guoshicheng2...@yeah.net [[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] xyplot() and confidence interval polygons
Dear all, I'm trying to replicate the panel function behaviour that Deepayan and others discuss here: https://stat.ethz.ch/pipermail/r-help/2007-April/130779.html and Oscar Lamigueiro refers to here and provides sample code for: http://www.r-bloggers.com/confidence-bands-with-lattice-and-r/ where a polygon is generated around lines on panels to display the confidence interval bounds for that line as a polygon around the line. My data consists of counts by ageband and confidence intervals around those counts. I cannot seem to get the prepanel function that the above threads describe to function with my data - I get a message that Argument is not interpretable as logical. I am clearly doing something wrong, but I can't work out where. Here is some sample code and pseudo-data that shows the problem, which is somewhere in the panel.superpose call or the my.panel.bands function as I have defined it. Any guidance much appreciated! Martin Ralphs Methodology Directorate Office for National Statistics UK # Setup package libraries... library(lattice) # Setup sample dataset... area - c(rep(A1,7),rep(A2,7),rep(A3,7),rep(A4,7)) areanm - c(rep(ZONE1,7),rep(ZONE2,7),rep(ZONE3,7),rep(ZONE4,7)) ageband - c(25-29,30-34,35-39,40-44,45-49,50-54,55-59) ageband - rep(ageband,4) est - c(1153,917,691,337,53,144,108,8454,6912,5423,7158,5728,4500,3565,17427,13753, 14466,14464,10303,9231,9248,7807,7814,9259,9492,8568,7339,5939) lci - c(521,380,119,0,0,0,0,6693,5271,4046,5536,4220,3185,2340,14907,11497, 12140,12140,8401,7409,7320,6069,6157,7320,7499,6693,5714,4481) uci - c(1879,1620,1080,639,296,477,296,10307,8528,6954,8863,7180,5815,4660,20093, 16102,16860,16860,12399,11190,11080,9531,9642,11080,11300,10307,9086,7518) data1 - as.data.frame(cbind(area,areanm,ageband),stringsAsFactors=TRUE) data2 - cbind(est,lci,uci) data - cbind(data1,data2) # Setup colour palette (blue, red, green) pallc1 - c(#2F54CB,#BE2C2C,#326C39) # Divide populations by 1000 data$est - data$est / 1000 data$lci - data$lci / 1000 data$uci - data$uci / 1000 my.panel.bands - function(x,y,upper,lower,subscripts, ...,font,fontface) { upper - upper[subscripts] lower - lower[subscripts] panel.polygon(c(x, rev(x)), c(upper, rev(lower)),col=fill,border=FALSE,...) } ptitle - paste(Test Plot\n,Estimate vs Other Sources in Region,sep=) lp1 - xyplot(data$ageband ~ data$est | data$areanm, main=list(label=ptitle,cex=1), layout=c(2,2), panel=function(x,y,...){ panel.superpose(x,y,upper=data$uci,lower=data$lci, panel.groups='my.panel.bands',type=l,col='gray',...) panel.xyplot(x,y,...,col=pallc1,type=l,lty=1,lwd=2) }, as.table=TRUE, grid=h, key=list( text=list(c(Estimate)), space=right, between=0.5, size=2, fontface=plain, cex=0.7, lines=list(col=pallc1,lty=1,lwd=2) ), aspect=565/800, ylab=Age Band, xlab=Count (Thousands), scales=list( y=list(fontface=plain,cex=0.6), x=list(fontface=plain,relation=free,cex=0.6)), strip=strip.custom(bg=#FF,par.strip.text=list(fontface=plain,cex=0.55))) plot(lp1) For the latest data on the economy and society consult National Statistics at http://www.ons.gov.uk * Please Note: Incoming and outgoing email messages are routinely monitored for compliance with our policy on the use of electronic communications * Legal Disclaimer : Any views expressed by the sender of this message are not necessarily those of the Office for National Statistics * The original of this email was scanned for viruses by the Government Secure Intranet virus scanning service supplied by CableWireless Worldwide in partnership with MessageLabs. (CCTM Certificate Number 2009/09/0052.) On leaving the GSi this email was certified virus free. Communications via the GSi may be automatically logged, monitored and/or recorded for legal purposes. __ 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] need help on read.spss
On 11.10.2011 12:07, Smart Guy wrote: Hi, I have one doubt about one of the parameter of 'read.spss()' from 'foreign' package. Here is the syntax :- read.spss ( file, use.value.labels = TRUE, to.data.frame = FALSE, max.value.labels = Inf, trim.factor.names = FALSE, trim_values = TRUE, reencode = NA, use.missings = to.data.frame ) In above syntax when I pass *'to.data.frame= FALSE*' it gives me missing values from SPSS file (that I try to read using read.spss() ). But when I pass '*to.data.frame = TRUE*' then its not giving me missing values. And need to get missing values. According to read.spss() documentation *to.data.frame : return a data frame?* I am curious to know, if we pass *'to.data.frame = TRUE*' , is it going to cause some issue or effect something? I didn't understand the read.spss() documentation correctly. Please explain. Thanks in Advance An R data.frame cannot represent different kinds of missing values, since R just has NA. Therefore, there are two way to import data: to.data.frame=FALSE will read all the information, but into a format you will likely have to postprocess to make it conveniently usable. to.data.frame=TRUE will import into a data.frame, but that cannot represent all the nuances known from the SPSS representation. Uwe Ligges __ 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 I use lm() to fit more than one response and more than one variables in single expression
On 13.10.2011 15:50, guoshicheng2005 wrote: Dear All, Can I use lm() to fit more than one response in single expression. e.g data is a matrix of these variables R1 R2 R3 X1 X2 X3 1 2 1 1 2 3 Now i wnat to fit R1~X1 R2~X2 R3~X3 in turn, and I don't want to do it use loops of couse it it easy to make it using loops,but the proceed is very slow since the data is very big Can't anybody give me some tips or help, my eamil: guoshicheng2...@yeah.net No. You will have to iterate in some way. How big can the data be that this is slow? Anyway, since there may be overhead by calling it via the formula interface,. you can directly fit using an explicitly given Design matrix in lm.fit(). Best, Uwe Ligges 2011-10-13 Best wishes Yours Alxe -- Ministry of Education Key Laboratory of Contemporary Anthropology School of Life Sciences, Fudan University 220 Handan Road Shanghai, China 200433 Phone:15216760764 E-mail: guoshicheng2...@yeah.net [[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] warning with cut2 function
On 11.10.2011 10:25, taby gathoni wrote: Dear r user, please find my attached sample of the dataset i am using to create a crosstable and eventually plot a histogram from the output. I am using the cut2 function to create bins, about 7 of them using the code after reading the data: cluster- cut2(cross_val$value, g=7) What is cut2? I get R cut2 Error: object 'cut2' not found What is cross_val? I get R cross_val Error: object 'cross_val' not found I get the warning: Warning message: In min(xx[xx upper]) : no non-missing arguments to min; returning Inf additionally, the bins become 6 instead of 7 through the crossTable function: cross1-CrossTable(cross_val$factor, cluster,prop.chisq=FALSE,prop.r=FALSE,prop.t=FALSE) What is CrossTable? What is cluster? Please assist me to get my 7 bins. How can i plot an output of the cross table as a historgram of factor rate vs bins? Help us to reproduce at first! Uwe Ligges Any help will be highly appreciated. Kind regards, Taby An idea not coupled with action will never get any bigger than the brain cell it occupied. Arnold Glasgow .. Attempt something large enough that failure is guaranteed…unless God steps in! __ 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] high and lowest with names
Here is a more R'sh solution (speed unknown). Courtesy of Mark Leeds (I modified it a bit to generalize it for a cnt input and get min and max). Again, getting cnt highest and lowest values in the entire matrix and display the data point row and column names with each: x - swiss$Education[1:25] dat = matrix(x,5,5) colnames(dat) = c('a','b','c','d','e') rownames(dat) = c('z','y','x','w','v') cnt = 10 #=== print(dat) a b c d e z 12 7 6 2 10 y 9 7 12 8 3 x 5 8 7 28 12 w 7 7 12 20 6 v 15 13 5 9 1 # MAKE IT A VECTOR FOR EASIER ORDERING datasvec - as.vector(dat) # ORDER IT datasvecordered- order(datasvec) # RECYCLE ROWS AND COLUMNS NAMES FOR EASIER MAPPING recycledcols - rep(colnames(dat),each=nrow(dat)) recycledrows - rep(rownames(dat),times=ncol(dat)) # GET THE VALUES, THE ROW NAMES AND THE COLUMN NAMES len = length(datasvecordered) rr_len = length(recycledrows) rbind(datasvec[datasvecordered][(len-cnt):len],recycledrows[datasvecordered][(rr_len-cnt):rr_len],recycledcols[datasvecordered][(rr_len-cnt):rr_len]) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [1,] 9 9 10 12 12 12 12 13 15 20 28 [2,] y v z z y w x v v w x [3,] a d e a c c e b a d d rbind(datasvec[datasvecordered][1:cnt],recycledrows[datasvecordered][1:cnt],recycledcols[datasvecordered][1:cnt]) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1 2 3 5 5 6 6 7 7 7 [2,] v z y x v z w w z y [3,] e d e a c c e a b b enjoy ben On Wed, Oct 12, 2011 at 11:47 AM, Ben qant ccqu...@gmail.com wrote: Hello, This is my solution. This is pretty fast (tested with a larger data set)! If you have a more elegant way to do it (of similar speed), please reply. Thanks for the help! ## get highest and lowest values and names of a matrix # create sample data x - swiss$Education[1:25] dat = matrix(x,5,5) colnames(dat) = c('a','b','c','d','e') rownames(dat) = c('z','y','x','w','v') #my solution nms = dimnames(dat) #get matrix row and col names cnt = 10 # number of max and mins to get tmp = dat mxs = list(list,cnt) mns = list(list,cnt) for(i in 1:cnt){ #get maxes mx_dims = arrayInd(which.max(tmp), dim(tmp)) # get max dims for entire matrix note: which.max also removes NA's mx_nm = c(nms[[1]][mx_dims[1]],nms[[2]][mx_dims[2]]) #get names mx = tmp[mx_dims] # get max value mxs[[i]] = c(mx,mx_nm) # add max and dim names to list of maxes tmp[mx_dims] = NA #removes last max so new one is found #get mins (basically same as above) mn_dims = arrayInd(which.min(tmp), dim(tmp)) mn_nm = c(nms[[1]][mn_dims[1]],nms[[2]][mn_dims[2]]) mn = tmp[mn_dims] mns[[i]] = c(mn,mn_nm) tmp[mn_dims] = NA } mxs mns # end Regards, Ben On Tue, Oct 11, 2011 at 5:32 PM, Dénes TÓTH tde...@cogpsyphy.hu wrote: which.max is even faster: dims - c(1000,1000) tt - array(rnorm(prod(dims)),dims) # which system.time( replicate(100, which(tt==max(tt), arr.ind=TRUE)) ) # which.max ( arrayInd) system.time( replicate(100, arrayInd(which.max(tt), dims)) ) Best, Denes But it's simpler and probably faster to use R's built-in capabilities. ?which ## note the arr.ind argument!) As an example: test - matrix(rnorm(24), nr = 4) which(test==max(test), arr.ind=TRUE) row col [1,] 2 6 So this gives the row and column indices of the max, from which row and column names can easily be obtained from the dimnames attribute of the matrix. Note: This assumes that the object in question is a matrix, NOT a data frame, for which it would be slightly more complicated. -- Bert On Tue, Oct 11, 2011 at 3:06 PM, Carlos Ortega c...@qualityexcellence.eswrote: Hi, With this code you can find row and col names for the largest value applied to your example: r.m.tmp-apply(dat,1,max) r.max-names(r.m.tmp)[r.m.tmp==max(r.m.tmp)] c.m.tmp-apply(dat,2,max) c.max-names(c.m.tmp)[c.m.tmp==max(c.m.tmp)] It's inmediate how to get the same for the smallest and build a function to calculate everything and return a list. Regards, Carlos Ortega www.qualityexcellence.es 2011/10/11 Ben qant ccqu...@gmail.com Hello, I'm looking to get the values, row names and column names of the largest and smallest values in a matrix. Example (except is does not include the names): x - swiss$Education[1:25] dat = matrix(x,5,5) colnames(dat) = c('a','b','c','d','c') rownames(dat) = c('z','y','x','w','v') dat a b c d c z 12 7 6 2 10 y 9 7 12 8 3 x 5 8 7 28 12 w 7 7 12 20 6 v 15 13 5 9 1 #top 10 sort(dat,partial=n-9:n)[(n-9):n] [1] 9 10 12 12 12 12 13 15 20 28 # bottom 10 sort(dat,partial=1:10)[1:10] [1] 1 2 3 5 5 6 6 7 7 7 ...except I need the rownames and colnames to go along for the ride
Re: [R] Minimization/Optimization under functional constraints
On 12.10.2011 20:13, forget_f1 wrote: Hi, I hope someone can help me with the following issue. I need find the minimum beta that satisfies the following: inf{beta0 | f(x+beta*f(x))*f(x)=0} where f() is a function and x is a sample statistic. Functions such as nlminb and constrOptim minimize a function and output the parameter (under parameter constraints). I need to minimize the parameter (also constraint) under the functional constraint. Obviously, I can start with a vector for beta (starting from 0) and find when the switch from0 to=0 occurs for the functional argument, but was wondering if there is a more efficient method/function. If monotonicity in beta is given , why not minimize (f(x+beta*f(x))*f(x))^2 for beta with the box constrained that beta 0? Uwe Ligges Thanks!!! -- View this message in context: http://r.789695.n4.nabble.com/Minimization-Optimization-under-functional-constraints-tp3899020p3899020.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] Can I use lm() to fit more than one response and more than one variables in single expression
hi: if you make the design matrix correctly, you can fit that using the systemfit function in Arne Henningsen's systemfit package. You need to construct the response by making one long column response of R1 on top of R2 on top of R3. Then you need to make a diagonal X matrix with X1, X2 and X3 being the diagonal elements of X. ( use kronecker since I assume that they are matrices ). Then you can fit it in one shot using the systemfit function with method = OLS and singleEqSigma = TRUE. Check the results of course but that should work. I used this technique recently mark 2011/10/13 Uwe Ligges lig...@statistik.tu-dortmund.de On 13.10.2011 15:50, guoshicheng2005 wrote: Dear All, Can I use lm() to fit more than one response in single expression. e.g data is a matrix of these variables R1 R2 R3 X1 X2 X3 1 2 1 1 2 3 Now i wnat to fit R1~X1 R2~X2 R3~X3 in turn, and I don't want to do it use loops of couse it it easy to make it using loops,but the proceed is very slow since the data is very big Can't anybody give me some tips or help, my eamil: guoshicheng2...@yeah.net No. You will have to iterate in some way. How big can the data be that this is slow? Anyway, since there may be overhead by calling it via the formula interface,. you can directly fit using an explicitly given Design matrix in lm.fit(). Best, Uwe Ligges 2011-10-13 Best wishes Yours Alxe -- Ministry of Education Key Laboratory of Contemporary Anthropology School of Life Sciences, Fudan University 220 Handan Road Shanghai, China 200433 Phone:15216760764 E-mail: guoshicheng2...@yeah.net [[alternative HTML version deleted]] __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.html 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] Minimization/Optimization under functional constraints
You can use the DEoptim function in DEoptim package and to include a line of code within your objective function that assigns a very high value when the constraints are not satisfied. I have tried that and it works. - Juan David Ospina Arango School of Statistics Universidad Nacional de Colombia, Colombia Laboratoire de Traitement du Signal et de l'Image Université de Rennes 1, France -- View this message in context: http://r.789695.n4.nabble.com/Minimization-Optimization-under-functional-constraints-tp3899020p3901757.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] binomial GLM quasi separation
Hi all, I have run a (glm) analysis where the dependent variable is the gender (family=binomial) and the predictors are percentages. I get a warning saying fitted probabilities numerically 0 or 1 occurred that is indicating that quasi-separation or separation is occurring. This makes sense given that one of these predictors have a very influential effect that is depending on a specific threshold separating these effects, in other words in my analysis one of these variables predicts males about the 80% of times when its values are less or equal to zero and females about the 80% when its values are greater than zero. I have been looking at other posts about this but I haven’t understood how I should act when the separation (or quasi separation) is not a statistical artifact but it is something real. As suggested in http://r.789695.n4.nabble.com/OT-quasi-separation-in-a-logistic-GLM-td875726.html#a3850331 http://r.789695.n4.nabble.com/OT-quasi-separation-in-a-logistic-GLM-td875726.html#a3850331 (the last post is mine) I tried to use brglm procedure that uses a penalized maximum likelihood but it made no difference. What would you do if you were in my shoes? Thanks in advance for any help. Simone -- View this message in context: http://r.789695.n4.nabble.com/binomial-GLM-quasi-separation-tp3901687p3901687.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] Question about GAMs
I'm confused... I type .. predict.gam(ozonea,type=s(ratio,bs=cr)) pressure maxtemp s(avetemp) s(ratio) 1 -0.0459102290 -0.185178463 0.263358446 -0.164558673 2 -0.0286464652 -0.194731320 0.199315027 0.727823293 30.0478073459 -0.013227033 0.002228896 0.342373202 4 -0.0089164494 0.082301539 -0.037331159 -0.067260889 50.0675373617 0.024984396 -0.047067786 -0.357569389 60.0823348735 0.101407254 -0.075884852 -1.485036738 7 -0.0977015204 0.177830112 -0.094755158 0.236575309 8 -0.0903027645 0.225594398 -0.113346667 0.435141242 90.0206785742 0.187382969 -0.066346157 -0.256133513 10 -0.1371615520 0.101407254 -0.131656887 0.145057584 11 -0.0477674066 -0.181001505 0.260279546 0.180513043 12 -0.0921599421 -0.009050075 -0.020511366 0.281470433 13 0.0681464361 -0.219212934 0.335348247 0.270813178 .. I want to show s(ratio,bs=cr) term, and show the warning message Warning message: In predict.gam(ozonea, type = s(ratio, bs = cr)) : Unknown type, reset to terms. I don't understand what does it mean. By the way, i use log-link function, should I convert log-link function of newozone to fitted value of newozone? 1. log(newozone) - s(ratio,bs=cr) = x then exp(x) 2. exp(newozone) - s(ratio,bs=cr) =X then x which one is correct? so confused -- View this message in context: http://r.789695.n4.nabble.com/Question-about-GAMs-tp3900848p3901842.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 transfer the variable into function in this code?
I think you made it very clearly. thx -- View this message in context: http://r.789695.n4.nabble.com/How-to-transfer-the-variable-into-function-in-this-code-tp3899576p3901817.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] variable scope for deltavar function from emdbook
This is R, not S-Plus. In the first two lines you have expr - as.expression(substitute(fun)) nvals - length(eval(expr, envir = as.list(meanval))) Simplified example: y - 0 fn1 - function(){ y - 1 fn1sub - function() print(y) fn1sub() } fn2sub - function() print(y) fn2 - function(){ y - 2 fn2sub() } fn1() # 1 fn2() # 0 So, if you do not want to pass the objects, but just use the symbols, you have to make sure the objects go into the environment you are evaluating the stuff in, or you have to ask the user to pass these objects to deltavar in another way. This is a similar region of the hell as evaluating glm() within a function and using its formula interface. Best, Uwe Ligges On 11.10.2011 14:09, Ben Bolker wrote: adadadadat gmx.at writes: Working example: -- library(emdbook) fn- function() { browser() y- 2 print(deltavar(y*b2, meanval=c(b2=3), Sigma=1) ) } x- 2 print(deltavar(x*b1, meanval=c(b1=3), Sigma=1) ) y-3 fn() running this returns 4 for the first function call, which is fine. For the call of deltavar in fn(), I get 9, i.e. the function uses y-3 instead of the local y-2. If y- is commented, deltavar returns an error. So why is the function not using the local variable and how do I make it use it? The real problem is that I (the author) don't understand scoping in R, and how to manipulate it, as well as I'd like to. I will work on this (any tips from the R-helpers appreciated). In the meantime, you could try out one of the other available delta-method calculators, such as the one in the msm package (library(sos); findFn({delta method})). More text to try to make gmane happy Ben Bolker __ 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] delete columns which partially match expression
Be careful with the idiom x[, -which(columnIsBad)] If no columns are bad this leads to x[, -integer(0)] which is a data.rame with no columns, exactly the opposite of what you want. x[, !columnIsBad] doesn't have that problem. However, if you can't tell if a column is bad or not (i.e., columnIsBad contains an NA) you will have to process columnIsBad to turn that NA into a definite TRUE or FALSE. Finally, add the drop=FALSE argument to [] in case the result would be a one-column data.frame to prevent it from being converted to the column itself. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of jim holtman Sent: Thursday, October 13, 2011 6:24 AM To: Samir Benzerfa Cc: r-help@r-project.org Subject: Re: [R] delete columns which partially match expression try this: x - read.table(textConnection(A B C D E + 12 33 Error1 71 Error2 + 12 33 Error1 71 Error2 + 12 33 Error1 71 Error2 + 12 33 Error1 71 Error2 + 12 33 Error1 71 Error2) + , as.is = TRUE + , header = TRUE + ) closeAllConnections() colMatch - which(apply(x, 2, function(a) any(grepl(Error, a colMatch C E 3 5 # delete columns x[, -colMatch] A B D 1 12 33 71 2 12 33 71 3 12 33 71 4 12 33 71 5 12 33 71 On Thu, Oct 13, 2011 at 9:10 AM, Samir Benzerfa benze...@gmx.ch wrote: Hello everyone, I'd like to search for certain expressions (characters) in my data.frame and delete the containing columns. So, for example in the below table, I'd like to delete all columns which contain the expression Error. That is, R should delete column C and E from my data. Any ideas? A B C D E 12 33 Error1 71 Error2 Cheers, S.B. [[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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ 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] Question about GAMs
On Thu, 2011-10-13 at 08:20 -0700, pigpigmeow wrote: I'm confused... I type .. predict.gam(ozonea,type=s(ratio,bs=cr)) That is not a valid 'type'; normally you'd use `type = terms` or `type = iterms`, depending on whether you want (any) standard errors to include the uncertainty about the intercept. pressure maxtemp s(avetemp) s(ratio) 1 -0.0459102290 -0.185178463 0.263358446 -0.164558673 2 -0.0286464652 -0.194731320 0.199315027 0.727823293 30.0478073459 -0.013227033 0.002228896 0.342373202 4 -0.0089164494 0.082301539 -0.037331159 -0.067260889 50.0675373617 0.024984396 -0.047067786 -0.357569389 60.0823348735 0.101407254 -0.075884852 -1.485036738 7 -0.0977015204 0.177830112 -0.094755158 0.236575309 8 -0.0903027645 0.225594398 -0.113346667 0.435141242 90.0206785742 0.187382969 -0.066346157 -0.256133513 10 -0.1371615520 0.101407254 -0.131656887 0.145057584 11 -0.0477674066 -0.181001505 0.260279546 0.180513043 12 -0.0921599421 -0.009050075 -0.020511366 0.281470433 13 0.0681464361 -0.219212934 0.335348247 0.270813178 .. I want to show s(ratio,bs=cr) term, and show the warning message Warning message: In predict.gam(ozonea, type = s(ratio, bs = cr)) : Unknown type, reset to terms. I don't understand what does it mean. So if the above comments I made are not sufficient to explain this, read ?predict.gam and see what the allowed options for the 'type' argument are. G By the way, i use log-link function, should I convert log-link function of newozone to fitted value of newozone? 1. log(newozone) - s(ratio,bs=cr) = x then exp(x) 2. exp(newozone) - s(ratio,bs=cr) =X then x which one is correct? so confused -- View this message in context: http://r.789695.n4.nabble.com/Question-about-GAMs-tp3900848p3901842.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. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% 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] high and lowest with names
On Oct 13, 2011, at 10:42 AM, Ben qant wrote: Here is a more R'sh solution (speed unknown). Really? The intermediate, potentially large, objects seem to be proliferating. Courtesy of Mark Leeds (I modified it a bit to generalize it for a cnt input and get min and max). Again, getting cnt highest and lowest values in the entire matrix and display the data point row and column names with each: 1) For max (or min) I would have thought that one could have much more easily gathered the maximum and minimum locations with: which(x == max(x), arr.ind=TRUE) # Bert Gunter's discarded suggestion ... and used the results as indices into x or rownames(x) or colnames(x). But I made no earlier comments because it did not appear that you had provided the swiss$Education object in a form that could be easily extracted for testing. I see now that setting up a similar object was fairly easy, but would encourage you to consider the `dput` function for such problem construction in the future; dat2 - matrix(sample(1:25, 25), 5,5) colnames(dat2) = c('a','b','c','d','e') rownames(dat2) = c('z','y','x','w','v') arrns - which(dat2 == max(dat2), arr.ind=TRUE) arrns row col v 5 1 colnames(dat2)[arrns[,2]] ; rownames(dat2)[arrns[,1]] [1] a [1] v 2) For display of all results with row/column labels : rbind(dat2, rownames(dat2)[row(dat2)], colnames(dat2)[row(dat2)]) 3) For display of values of bottom five and top five: dat2five - which(dat2 = c(dat2)[order(dat2)][5], arr.ind=TRUE) rbind( dat2LT5= dat2[dat2five], Rows = rownames(dat2)[ dat2five[,1] ], Cols = colnames(dat2)[ dat2five[,2] ]) #-- [,1] [,2] [,3] [,4] [,5] dat2LT5 2 3 5 1 4 Rowsx w y y x Colsa a c d d dat2topfive - which(dat2 = c(dat2)[rev(order(dat2))][5], arr.ind=TRUE) rbind( dat2top5= dat2[dat2topfive], Rows = rownames(dat2)[ dat2topfive[,1] ], Cols = colnames(dat2)[ dat2topfive[,2] ]) #--- [,1] [,2] [,3] [,4] [,5] dat2top5 24 25 23 22 21 Rows z v y w v Cols a a b e e x - swiss$Education[1:25] dat = matrix(x,5,5) colnames(dat) = c('a','b','c','d','e') rownames(dat) = c('z','y','x','w','v') cnt = 10 #=== print(dat) a b c d e z 12 7 6 2 10 y 9 7 12 8 3 x 5 8 7 28 12 w 7 7 12 20 6 v 15 13 5 9 1 # MAKE IT A VECTOR FOR EASIER ORDERING datasvec - as.vector(dat) # ORDER IT datasvecordered- order(datasvec) # RECYCLE ROWS AND COLUMNS NAMES FOR EASIER MAPPING recycledcols - rep(colnames(dat),each=nrow(dat)) recycledrows - rep(rownames(dat),times=ncol(dat)) # GET THE VALUES, THE ROW NAMES AND THE COLUMN NAMES len = length(datasvecordered) rr_len = length(recycledrows) rbind(datasvec[datasvecordered][(len- cnt):len],recycledrows[datasvecordered][(rr_len- cnt):rr_len],recycledcols[datasvecordered][(rr_len-cnt):rr_len]) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [1,] 9 9 10 12 12 12 12 13 15 20 28 [2,] y v z z y w x v v w x [3,] a d e a c c e b a d d rbind(datasvec[datasvecordered][1:cnt],recycledrows[datasvecordered] [1:cnt],recycledcols[datasvecordered][1:cnt]) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1 2 3 5 5 6 6 7 7 7 [2,] v z y x v z w w z y [3,] e d e a c c e a b b enjoy ben On Wed, Oct 12, 2011 at 11:47 AM, Ben qant ccqu...@gmail.com wrote: Hello, This is my solution. This is pretty fast (tested with a larger data set)! If you have a more elegant way to do it (of similar speed), please reply. Thanks for the help! ## get highest and lowest values and names of a matrix # create sample data x - swiss$Education[1:25] dat = matrix(x,5,5) colnames(dat) = c('a','b','c','d','e') rownames(dat) = c('z','y','x','w','v') #my solution nms = dimnames(dat) #get matrix row and col names cnt = 10 # number of max and mins to get tmp = dat mxs = list(list,cnt) mns = list(list,cnt) for(i in 1:cnt){ #get maxes mx_dims = arrayInd(which.max(tmp), dim(tmp)) # get max dims for entire matrix note: which.max also removes NA's mx_nm = c(nms[[1]][mx_dims[1]],nms[[2]][mx_dims[2]]) #get names mx = tmp[mx_dims] # get max value mxs[[i]] = c(mx,mx_nm) # add max and dim names to list of maxes tmp[mx_dims] = NA #removes last max so new one is found #get mins (basically same as above) mn_dims = arrayInd(which.min(tmp), dim(tmp)) mn_nm = c(nms[[1]][mn_dims[1]],nms[[2]][mn_dims[2]]) mn = tmp[mn_dims] mns[[i]] = c(mn,mn_nm) tmp[mn_dims] = NA } mxs mns # end Regards, Ben On Tue, Oct 11, 2011 at 5:32 PM, Dénes TÓTH tde...@cogpsyphy.hu wrote: which.max is even faster: dims - c(1000,1000) tt - array(rnorm(prod(dims)),dims) # which system.time( replicate(100, which(tt==max(tt), arr.ind=TRUE)) ) # which.max ( arrayInd) system.time( replicate(100, arrayInd(which.max(tt), dims)) ) Best, Denes But it's simpler and
[R] Help package for Growing Neural Gas
Hi, somebody knows a package for running Growing Neural Gas in R. Thanks in advance, -- Alejandro Coca UN __ 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] high and lowest with names
Besides being a much better solution, it displays ties (which I see as a benefit). For example, if I ask for 5 I get 8 for top values since 12 occurs 3 times. Here is the same thing David posted with slight mods to generalize it a bit for cnt: x - swiss$Education[1:25] dat = matrix(x,5,5) colnames(dat) = c('a','b','c','d','e') rownames(dat) = c('z','y','x','w','v') cnt = 5 #=== dattop - which(dat = c(dat)[rev(order(dat))][cnt], arr.ind=TRUE) rbind( top = dat[dattop], rows = rownames(dat)[ dattop[,1] ], cols = colnames(dat)[ dattop[,2] ]) datbot - which(dat = c(dat)[order(dat)][cnt], arr.ind=TRUE) rbind( bot = dat[datbot], rows = rownames(dat)[ datbot[,1] ], cols = colnames(dat)[ datbot[,2] ]) Thanks David! Ben On Thu, Oct 13, 2011 at 9:48 AM, David Winsemius dwinsem...@comcast.netwrote: On Oct 13, 2011, at 10:42 AM, Ben qant wrote: Here is a more R'sh solution (speed unknown). Really? The intermediate, potentially large, objects seem to be proliferating. Courtesy of Mark Leeds (I modified it a bit to generalize it for a cnt input and get min and max). Again, getting cnt highest and lowest values in the entire matrix and display the data point row and column names with each: 1) For max (or min) I would have thought that one could have much more easily gathered the maximum and minimum locations with: which(x == max(x), arr.ind=TRUE) # Bert Gunter's discarded suggestion ... and used the results as indices into x or rownames(x) or colnames(x). But I made no earlier comments because it did not appear that you had provided the swiss$Education object in a form that could be easily extracted for testing. I see now that setting up a similar object was fairly easy, but would encourage you to consider the `dput` function for such problem construction in the future; dat2 - matrix(sample(1:25, 25), 5,5) colnames(dat2) = c('a','b','c','d','e') rownames(dat2) = c('z','y','x','w','v') arrns - which(dat2 == max(dat2), arr.ind=TRUE) arrns row col v 5 1 colnames(dat2)[arrns[,2]] ; rownames(dat2)[arrns[,1]] [1] a [1] v 2) For display of all results with row/column labels : rbind(dat2, rownames(dat2)[row(dat2)], colnames(dat2)[row(dat2)]) 3) For display of values of bottom five and top five: dat2five - which(dat2 = c(dat2)[order(dat2)][5], arr.ind=TRUE) rbind( dat2LT5= dat2[dat2five], Rows = rownames(dat2)[ dat2five[,1] ], Cols = colnames(dat2)[ dat2five[,2] ]) #-- [,1] [,2] [,3] [,4] [,5] dat2LT5 2 3 5 1 4 Rowsx w y y x Colsa a c d d dat2topfive - which(dat2 = c(dat2)[rev(order(dat2))][5], arr.ind=TRUE) rbind( dat2top5= dat2[dat2topfive], Rows = rownames(dat2)[ dat2topfive[,1] ], Cols = colnames(dat2)[ dat2topfive[,2] ]) #--- [,1] [,2] [,3] [,4] [,5] dat2top5 24 25 23 22 21 Rows z v y w v Cols a a b e e x - swiss$Education[1:25] dat = matrix(x,5,5) colnames(dat) = c('a','b','c','d','e') rownames(dat) = c('z','y','x','w','v') cnt = 10 #=**== print(dat) a b c d e z 12 7 6 2 10 y 9 7 12 8 3 x 5 8 7 28 12 w 7 7 12 20 6 v 15 13 5 9 1 # MAKE IT A VECTOR FOR EASIER ORDERING datasvec - as.vector(dat) # ORDER IT datasvecordered- order(datasvec) # RECYCLE ROWS AND COLUMNS NAMES FOR EASIER MAPPING recycledcols - rep(colnames(dat),each=nrow(**dat)) recycledrows - rep(rownames(dat),times=ncol(**dat)) # GET THE VALUES, THE ROW NAMES AND THE COLUMN NAMES len = length(datasvecordered) rr_len = length(recycledrows) rbind(datasvec[**datasvecordered][(len-cnt):**len],recycledrows[** datasvecordered][(rr_len-cnt):**rr_len],recycledcols[** datasvecordered][(rr_len-cnt):**rr_len]) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [1,] 9 9 10 12 12 12 12 13 15 20 28 [2,] y v z z y w x v v w x [3,] a d e a c c e b a d d rbind(datasvec[**datasvecordered][1:cnt],** recycledrows[datasvecordered][**1:cnt],recycledcols[** datasvecordered][1:cnt]) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1 2 3 5 5 6 6 7 7 7 [2,] v z y x v z w w z y [3,] e d e a c c e a b b enjoy ben On Wed, Oct 12, 2011 at 11:47 AM, Ben qant ccqu...@gmail.com wrote: Hello, This is my solution. This is pretty fast (tested with a larger data set)! If you have a more elegant way to do it (of similar speed), please reply. Thanks for the help! ## get highest and lowest values and names of a matrix # create sample data x - swiss$Education[1:25] dat = matrix(x,5,5) colnames(dat) = c('a','b','c','d','e') rownames(dat) = c('z','y','x','w','v') #my solution nms = dimnames(dat) #get matrix row and col names cnt = 10 # number of max and mins to get tmp = dat mxs = list(list,cnt) mns
Re: [R] Help package for Growing Neural Gas
On Oct 13, 2011, at 12:12 PM, Alejandro Coca Castro wrote: Hi, somebody knows a package for running Growing Neural Gas in R. require(sos) findFn(Growing Neural Gas) found 0 matches x has zero rows; nothing to display. Warning message: In findFn(Growing Neural Gas) : HIT not found in HTML; processing one page only. findFn(Neural Gas) found 5 matches -- 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] [Related Topic] need help on read.spss
Would it be worthwhile to update the read.spss implementation using the more recent discoveries from the PSPP group? I don't mean to copy their code; but to use the ideas in their code. Is anyone working on this? I wouldn't want the effort to be duplicated. On Thu, 2011-10-13 at 16:22 +0200, Uwe Ligges wrote: On 11.10.2011 12:07, Smart Guy wrote: Hi, I have one doubt about one of the parameter of 'read.spss()' from 'foreign' package. Here is the syntax :- read.spss ( file, use.value.labels = TRUE, to.data.frame = FALSE, max.value.labels = Inf, trim.factor.names = FALSE, trim_values = TRUE, reencode = NA, use.missings = to.data.frame ) In above syntax when I pass *'to.data.frame= FALSE*' it gives me missing values from SPSS file (that I try to read using read.spss() ). But when I pass '*to.data.frame = TRUE*' then its not giving me missing values. And need to get missing values. According to read.spss() documentation *to.data.frame : return a data frame?* I am curious to know, if we pass *'to.data.frame = TRUE*' , is it going to cause some issue or effect something? I didn't understand the read.spss() documentation correctly. Please explain. Thanks in Advance An R data.frame cannot represent different kinds of missing values, since R just has NA. Therefore, there are two way to import data: to.data.frame=FALSE will read all the information, but into a format you will likely have to postprocess to make it conveniently usable. to.data.frame=TRUE will import into a data.frame, but that cannot represent all the nuances known from the SPSS representation. Uwe Ligges __ 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] pass an element in a list() from R to C
Functions with prototypes of the form SEXP myfunc(SEXP, SEXP, ..., SEXP) must be called via .Call(), not .C(). Also, you declared myfunction as returning SEXP but returned nothing. Try ending the function with return R_NilValue; You should change the default compiler flags to report all warnings (-Wall if you are using gcc). And you left off a line or two of C code that must have been there, or you code would have compiled due to errors #include R.h /* not needed if Rinternals is included */ #include Rinternals.h Study 'Writing R Extensions' and work through the examples in it. In particular, look at section 5.9. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of teazrq Sent: Wednesday, October 12, 2011 7:52 PM To: r-help@r-project.org Subject: Re: [R] pass an element in a list() from R to C so, I did this: B= list(a = 1, b = 2, c = 3) .C(myfunction, B) the c code is : SEXP myfunction(SEXP matrix_temp) { Rprintf(this element is %6.3f, REAL(VECTOR_ELT(matrix_temp,1))[0]); } but after runing the R code, it says Error: VECTOR_ELT() can only be applied to a 'list', not a 'NULL' I guess this is because I did not acturally pass a list to the c function, but why is that? -- View this message in context: http://r.789695.n4.nabble.com/pass-an-element-in-a-list-from-R-to-C- tp3900221p3900426.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] Question about GAMs
On Oct 13, 2011, at 11:20 AM, pigpigmeow wrote: I'm confused... I type .. predict.gam(ozonea,type=s(ratio,bs=cr)) pressure maxtemp s(avetemp) s(ratio) 1 -0.0459102290 -0.185178463 0.263358446 -0.164558673 2 -0.0286464652 -0.194731320 0.199315027 0.727823293 30.0478073459 -0.013227033 0.002228896 0.342373202 4 -0.0089164494 0.082301539 -0.037331159 -0.067260889 50.0675373617 0.024984396 -0.047067786 -0.357569389 60.0823348735 0.101407254 -0.075884852 -1.485036738 7 -0.0977015204 0.177830112 -0.094755158 0.236575309 8 -0.0903027645 0.225594398 -0.113346667 0.435141242 90.0206785742 0.187382969 -0.066346157 -0.256133513 10 -0.1371615520 0.101407254 -0.131656887 0.145057584 11 -0.0477674066 -0.181001505 0.260279546 0.180513043 12 -0.0921599421 -0.009050075 -0.020511366 0.281470433 13 0.0681464361 -0.219212934 0.335348247 0.270813178 .. I want to show s(ratio,bs=cr) term, and show the warning message Warning message: In predict.gam(ozonea, type = s(ratio, bs = cr)) : Unknown type, reset to terms. I don't understand what does it mean. By the way, i use log-link function, should I convert log-link function of newozone to fitted value of newozone? 1. log(newozone) - s(ratio,bs=cr) = x then exp(x) Perhaps. I do not see 'newozone' defined anywhere above and can only speculateo speculate. I'm pretty sure Wood's uncopied comment was intended to remind you that differences in the log (regression) scale are equivalent to ratios on the measured scales. So either : exp( diff(coef, log(measured_or_external_baseline) ) ) # OR exp(coef)/measured_or_external_baseline How that is properly calculated in pkg:mgcv is a separate issue and Simpson has suggested you read the help pages more carefully. 2. exp(newozone) - s(ratio,bs=cr) =X then x Probably incorrect. which one is correct? so confused 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.
[R] Remove specific rows in a matrix/data.frame
Hi, imagine the following matrix/data.frame Letter Number a 1 a 1 b 1 b 0 c 0 c 1 d 0 d 0 If the numbers for two identical letters are also identical then I want to remove either the first or the second row of that letter. If for a letter the numbers are 1 and 0 I want to remove the row with the 0. That means if the code works I would and up with the following matrix/data.frame Letter Number a 1 b 1 c 1 d 1 Many thanks, Syrvn -- View this message in context: http://r.789695.n4.nabble.com/Remove-specific-rows-in-a-matrix-data-frame-tp3902149p3902149.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] Remove specific rows in a matrix/data.frame
On Oct 13, 2011, at 12:42 PM, syrvn wrote: Hi, imagine the following matrix/data.frame Letter Number a 1 a 1 b 1 b 0 c 0 c 1 d 0 d 0 If the numbers for two identical letters are also identical then I want to remove either the first or the second row of that letter. If for a letter the numbers are 1 and 0 I want to remove the row with the 0. ?duplicated That means if the code works I would and up with the following matrix/data.frame Letter Number a 1 b 1 c 1 d 1 But with no 1's associated with 'd' this does not make sense. Many thanks, Syrvn 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] How to mean for groups of matrix rows?
Andrey wrote on 10/13/2011 08:40:21 AM: Dear All, For a vector, I use this xu-1:20 t-rep((1:4),each=5) tapply(xu,t,mean) 1 2 3 4 3 8 13 18 and for a matrix the only way I may guess is: xu [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,]14321432 [2,]21432143 [3,]32143214 [4,]14321432 [5,]21432143 [6,]32143214 t [1] 1 1 1 2 2 2 y [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,]00000000 [2,]00000000 for (i in 1:dim(xu)[2]) y[,i]-tapply(xu[,i],t,mean) y [,1][,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,]2 2.33 2.6732 2.33 2.673 [2,]2 2.33 2.6732 2.33 2.673 I do not like the need to create a matrix (y) for the result. Is there a better way? Thanks, Andrei. apply(xu, 2, tapply, t, mean) Jean [[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] Remove specific rows in a matrix/data.frame
Hi Syrvn, how about this dtf-read.table(textConnection(Letter Number a 1 a 1 b 1 b 0 c 0 c 1 d 0 d 0),header=T) aggregate(Number~Letter,data=dtf,max) cheers. Am 13.10.2011 18:42, schrieb syrvn: Hi, imagine the following matrix/data.frame Letter Number a 1 a 1 b 1 b 0 c 0 c 1 d 0 d 0 If the numbers for two identical letters are also identical then I want to remove either the first or the second row of that letter. If for a letter the numbers are 1 and 0 I want to remove the row with the 0. That means if the code works I would and up with the following matrix/data.frame Letter Number a 1 b 1 c 1 d 1 Many thanks, Syrvn -- View this message in context: http://r.789695.n4.nabble.com/Remove-specific-rows-in-a-matrix-data-frame-tp3902149p3902149.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. -- Eik Vettorazzi Department of Medical Biometry and Epidemiology University Medical Center Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 -- Pflichtangaben gemäß Gesetz über elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG): Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; Gerichtsstand: Hamburg Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus __ 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] Remove specific rows in a matrix/data.frame
try this: x - read.table(textConnection(Letter Number + a 1 + a 1 + b 1 + b 0 + c 0 + c 1 + d 0 + d 0), as.is = TRUE, header = TRUE) closeAllConnections() # following assumes that there are pairs of numbers result - do.call(rbind, lapply(split(x, x$Letter), function(.pair){ + if (all(.pair$Number[1L] == .pair$Number)) return(.pair[1L, ]) + is1 - which(.pair$Number == 1) + if (length(is1) == 1) return(.pair[is1, ]) + else return(NULL) + })) result Letter Number a a 1 b b 1 c c 1 d d 0 On Thu, Oct 13, 2011 at 12:42 PM, syrvn ment...@gmx.net wrote: Hi, imagine the following matrix/data.frame Letter Number a 1 a 1 b 1 b 0 c 0 c 1 d 0 d 0 If the numbers for two identical letters are also identical then I want to remove either the first or the second row of that letter. If for a letter the numbers are 1 and 0 I want to remove the row with the 0. That means if the code works I would and up with the following matrix/data.frame Letter Number a 1 b 1 c 1 d 1 Many thanks, Syrvn -- View this message in context: http://r.789695.n4.nabble.com/Remove-specific-rows-in-a-matrix-data-frame-tp3902149p3902149.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. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ 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] Remove specific rows in a matrix/data.frame
Why would you end up with d1 in your output if you don't have a d1 in your original data frame? Are you saying that, when both letters have a zero after them, you want to replace one of them with a 1? -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of syrvn Sent: Thursday, October 13, 2011 9:43 AM To: r-help@r-project.org Subject: [R] Remove specific rows in a matrix/data.frame Hi, imagine the following matrix/data.frame Letter Number a 1 a 1 b 1 b 0 c 0 c 1 d 0 d 0 If the numbers for two identical letters are also identical then I want to remove either the first or the second row of that letter. If for a letter the numbers are 1 and 0 I want to remove the row with the 0. That means if the code works I would and up with the following matrix/data.frame Letter Number a 1 b 1 c 1 d 1 Many thanks, Syrvn -- View this message in context: http://r.789695.n4.nabble.com/Remove-specific-rows-in-a-matrix-data-frame-tp3902149p3902149.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] Remove specific rows in a matrix/data.frame
syrvn wrote on 10/13/2011 11:42:44 AM: Hi, imagine the following matrix/data.frame Letter Number a 1 a 1 b 1 b 0 c 0 c 1 d 0 d 0 If the numbers for two identical letters are also identical then I want to remove either the first or the second row of that letter. If for a letter the numbers are 1 and 0 I want to remove the row with the 0. That means if the code works I would and up with the following matrix/data.frame Letter Number a 1 b 1 c 1 d 1 Many thanks, Syrvn I assume that you made a typo when showing the results you want. Following your explanation, this is what I get: df - data.frame(Letter=letters[rep(1:4, rep(2, 4))], Number=c(1, 1, 1, 0, 0, 1, 0, 0)) # first, get rid of duplicates df2 - df[!duplicated(df), ] # then, get rid of 0s from letters that have both 0 and 1 both01 - tapply(df2$Number, df2$Letter, function(x) any(as.integer(x)==0) any(as.integer(x)==1)) delete - df2$Letter %in% names(both01)[both01] as.integer(df2$Number)==0 df3 - df2[!delete, ] # result df3 Letter Number 1 a 1 3 b 1 6 c 1 7 d 0 Jean [[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] Remove specific rows in a matrix/data.frame
Thanks for your answers! Will check them now :) Yes, sorry, I was wrong. Letter Number d 0 d 0 should be: Letter Number d 0 after applying the algorithm! -- View this message in context: http://r.789695.n4.nabble.com/Remove-specific-rows-in-a-matrix-data-frame-tp3902149p3902216.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] Remove specific rows in a matrix/data.frame
Hello again, dtf-read.table(textConnection(Letter Test Number a b 1 a b 1 b b 1 b b 0 c b 0 c b 1 d b 0 d b 0),header=T) aggregate(Number ~ Letter,data=dtf,max) how can I adjust this solution that the results also includes Test? I tried: aggregate(Number ~ Letter,data=dtf,max,by=list(Letter, Test, Number)) But it breaks with the following error message: Error in aggregate.data.frame(mf[1L], mf[-1L], FUN = FUN, ...) : arguments must have same length -- View this message in context: http://r.789695.n4.nabble.com/Remove-specific-rows-in-a-matrix-data-frame-tp3902149p3902286.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] getting data associated with coordinates in a spatial data frame
Thank you Sarah. I tried your suggestion, and if I coerce it into a normal data.frame, that method works. But if you've already made the data into a SpatialPixelsDataFrame and run coordinates (both from the package sp) so that the columns x and y become a single column coordinates with the format (0, 17) for x and y, how do you then call or manipulate data at a specific location? The following: e[e$coordinates==(0,17),] Doesn't work. -Original Message- From: Sarah Goslee [mailto:sarah.gos...@gmail.com] Sent: Wednesday, October 12, 2011 5:34 PM To: Bailey, Daniel Cc: r-help@r-project.org Subject: Re: [R] getting data associated with coordinates in a spatial data frame Hi, On Wed, Oct 12, 2011 at 3:37 PM, Bailey, Daniel bai...@spu.edu wrote: If I know the specific coordinate in a spatial data frame, how can I access the data at that coordinate? My coordinates are labeled x and y in a data.frame e. The data is in column leachate. I want to say, basically: e$leachate@coordinates(2,3mailto:e$leachate@coordinates(2,3). That's kind of mangled, but what about: e[e$x == my.x e$y == my.y, leachate] (Depending on the form of your coordinates, you may also have to invoke FAQ 7.31.) Sarah Thanks, Daniel -- 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] x axis
Dear R users, I am quite desperate for help. I haven't used R in a couple of years and I'm currently finishing a masters project and running out of time to figure out my problem. I have read and tried the examples on many websites, in your forums and R Help yet still can't manage to change the x axis. I am using R 2.8.0 on windows. I'm sure there must be a way to do this as many people's questions seem more difficult. My problem is that I need to change the numbers on the x axis from the default. This is my scatter plot so far: x - c(0, 50, 100, 250, 500, 750, 1000, 1500, 2000, 2500, 3000) y - c(640, 585, 152, 85, 348, 922, 518, 82, 83, 591, 79) plot(y~x, type = p, xlab = Distance (m), ylab = Concentrations (mg/kg), xlim = c(0,3000), ylim = c(0,1000), col =black, pch = 19, sub = Lead, font.sub = 2) text(0,640, mine average, pos = 4, col = red, cex= 0.6) abline(h=c(21), lty = 2, col = green, lwd =1) abline(h=c(36), lty = 3, col = blue, lwd = 1) abline(h=c(190), lty = 1, col =red, lwd = 2) legend(1700, 1000, c(Control, Dutch List - Optimum, Dutch List - Action), col = c(3,4,2), lty = c(2,3,1), cex = 0.8, lwd = c(1,1,2)) R automatically changes the x axis to 0, 500, 100, 1500, 2000, 2500, 3000. I've tried a few things you've already said to other people with problems but all I get is error. I would really appreciate some help as I've no one else to ask (the uni I've studied my masters in does not use R). Yours faithfully, Lauren. [[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] Alphabetical sequence of data along the x-axis in a box plot
The easiest work-around I've found for this problem is to create a vector in your data frame just using numbers to order them how you want, create a separate labeling data frame with those numbers and corresponding text labels, and then enter the vector with the grouping names from the labeling frame in boxplot's 'names' argument. As such: dir - D:\\ setwd(dir) data - read.csv(ODR.csv) type - read.csv(soil_type.csv) boxplot(data=data, Sat..ODR~Type_num, *names=type$Soil.type*, col=light green, main=ODR by soil type, xlab=Soil type, ylab=ODR) The labeling data frame should look something like this: data.frame(type) Type_num Soil.type 11 DCL 22 UCL 33 Sand Hope this helps! -- View this message in context: http://r.789695.n4.nabble.com/Alphabetical-sequence-of-data-along-the-x-axis-in-a-box-plot-tp2716131p3901884.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] GLM and Neg. Binomial models
Hi userRs! I am trying to fit some GLM-poisson and neg.binomial. The neg. Binomial model is to account for over-dispersion. When I fit the poisson model i get: (Dispersion parameter for poisson family taken to be 1) However, if I estimate the dispersion coefficient by means of: sum(residuals(fit,type=pearson)^2)/fit$df.res I obtained 2.4. This is theory means over-dispersion since 2.41. I do not understand what the relation is between (Dispersion parameter for poisson family taken to be 1) and 2.4. In a similar fashion, when i fit the neg. binomial model I obtain: (Dispersion parameter for Negative Binomial(0.1717) family taken to be 1) Whereas the estimation of the dispersion coefficient as stated above is: 1.4 Why Dispersion parameter and my calculation are not the same? Any thoughts will be much appreciate it . -- View this message in context: http://r.789695.n4.nabble.com/GLM-and-Neg-Binomial-models-tp3902173p3902173.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] getting data associated with coordinates in a spatial data frame
It's going to depend how the coordinates are stored within the data frame. Do you perhaps know if they are factors or character strings? (I'm not familiar with the package). If you don't know, type str(NAMEOFYOUROBJECT) and we can help interpret the output. Untested, I think this would actually work for both though: e[as.character(e$coordinates)==(0,17),] Michael On Thu, Oct 13, 2011 at 2:05 PM, Bailey, Daniel bai...@spu.edu wrote: Thank you Sarah. I tried your suggestion, and if I coerce it into a normal data.frame, that method works. But if you've already made the data into a SpatialPixelsDataFrame and run coordinates (both from the package sp) so that the columns x and y become a single column coordinates with the format (0, 17) for x and y, how do you then call or manipulate data at a specific location? The following: e[e$coordinates==(0,17),] Doesn't work. -Original Message- From: Sarah Goslee [mailto:sarah.gos...@gmail.com] Sent: Wednesday, October 12, 2011 5:34 PM To: Bailey, Daniel Cc: r-help@r-project.org Subject: Re: [R] getting data associated with coordinates in a spatial data frame Hi, On Wed, Oct 12, 2011 at 3:37 PM, Bailey, Daniel bai...@spu.edu wrote: If I know the specific coordinate in a spatial data frame, how can I access the data at that coordinate? My coordinates are labeled x and y in a data.frame e. The data is in column leachate. I want to say, basically: e$leachate@coordinates(2,3mailto:e$leachate@coordinates(2,3). That's kind of mangled, but what about: e[e$x == my.x e$y == my.y, leachate] (Depending on the form of your coordinates, you may also have to invoke FAQ 7.31.) Sarah Thanks, Daniel -- 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] x axis
In your plot call, you can use xaxt = n to turn off the default x axis tick marks, then add axis(1, at = VARIABLEWHEREYOUWANTTICKMARKS) # If you want ticks at the x you put in, its just axis(1, at = x) to get ticks where you want them. There's also a label= argument if you want them to be labled as something other than the numbers. Hope this helps, Michael On Thu, Oct 13, 2011 at 11:42 AM, lauren mcdonagh cleverlolli...@yahoo.ie wrote: Dear R users, I am quite desperate for help. I haven't used R in a couple of years and I'm currently finishing a masters project and running out of time to figure out my problem. I have read and tried the examples on many websites, in your forums and R Help yet still can't manage to change the x axis. I am using R 2.8.0 on windows. I'm sure there must be a way to do this as many people's questions seem more difficult. My problem is that I need to change the numbers on the x axis from the default. This is my scatter plot so far: x - c(0, 50, 100, 250, 500, 750, 1000, 1500, 2000, 2500, 3000) y - c(640, 585, 152, 85, 348, 922, 518, 82, 83, 591, 79) plot(y~x, type = p, xlab = Distance (m), ylab = Concentrations (mg/kg), xlim = c(0,3000), ylim = c(0,1000), col =black, pch = 19, sub = Lead, font.sub = 2) text(0,640, mine average, pos = 4, col = red, cex= 0.6) abline(h=c(21), lty = 2, col = green, lwd =1) abline(h=c(36), lty = 3, col = blue, lwd = 1) abline(h=c(190), lty = 1, col =red, lwd = 2) legend(1700, 1000, c(Control, Dutch List - Optimum, Dutch List - Action), col = c(3,4,2), lty = c(2,3,1), cex = 0.8, lwd = c(1,1,2)) R automatically changes the x axis to 0, 500, 100, 1500, 2000, 2500, 3000. I've tried a few things you've already said to other people with problems but all I get is error. I would really appreciate some help as I've no one else to ask (the uni I've studied my masters in does not use R). Yours faithfully, Lauren. [[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] getting data associated with coordinates in a spatial data frame
Michael, Thank you for the tips. The suggestion didn't work though. Here is the output of str(e): Formal class 'SpatialPointsDataFrame' [package sp] with 5 slots ..@ data :'data.frame': 168 obs. of 2 variables: .. ..$ catchcandata: num [1:168] 47.2 50.4 53.7 58 69.8 ... .. ..$ section : Factor w/ 1 level 16 Sept F9: 1 NA NA NA NA NA NA NA NA NA ... ..@ coords.nrs : int [1:2] 1 2 ..@ coords : num [1:168, 1:2] 0 0 0 0 0 ... .. ..- attr(*, dimnames)=List of 2 .. .. ..$ : NULL .. .. ..$ : chr [1:2] x y ..@ bbox : num [1:2, 1:2] 0 0 48.8 17.1 .. ..- attr(*, dimnames)=List of 2 .. .. ..$ : chr [1:2] x y .. .. ..$ : chr [1:2] min max ..@ proj4string:Formal class 'CRS' [package sp] with 1 slots .. .. ..@ projargs: chr NA -Original Message- From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com] Sent: Thursday, October 13, 2011 11:13 AM To: Bailey, Daniel Cc: Sarah Goslee; r-help@r-project.org Subject: Re: [R] getting data associated with coordinates in a spatial data frame It's going to depend how the coordinates are stored within the data frame. Do you perhaps know if they are factors or character strings? (I'm not familiar with the package). If you don't know, type str(NAMEOFYOUROBJECT) and we can help interpret the output. Untested, I think this would actually work for both though: e[as.character(e$coordinates)==(0,17),] Michael On Thu, Oct 13, 2011 at 2:05 PM, Bailey, Daniel bai...@spu.edu wrote: Thank you Sarah. I tried your suggestion, and if I coerce it into a normal data.frame, that method works. But if you've already made the data into a SpatialPixelsDataFrame and run coordinates (both from the package sp) so that the columns x and y become a single column coordinates with the format (0, 17) for x and y, how do you then call or manipulate data at a specific location? The following: e[e$coordinates==(0,17),] Doesn't work. -Original Message- From: Sarah Goslee [mailto:sarah.gos...@gmail.com] Sent: Wednesday, October 12, 2011 5:34 PM To: Bailey, Daniel Cc: r-help@r-project.org Subject: Re: [R] getting data associated with coordinates in a spatial data frame Hi, On Wed, Oct 12, 2011 at 3:37 PM, Bailey, Daniel bai...@spu.edu wrote: If I know the specific coordinate in a spatial data frame, how can I access the data at that coordinate? My coordinates are labeled x and y in a data.frame e. The data is in column leachate. I want to say, basically: e$leachate@coordinates(2,3mailto:e$leachate@coordinates(2,3). That's kind of mangled, but what about: e[e$x == my.x e$y == my.y, leachate] (Depending on the form of your coordinates, you may also have to invoke FAQ 7.31.) Sarah Thanks, Daniel -- 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] getting data associated with coordinates in a spatial data frame
Because SpatialPointsDataFrame is S4 object, you may try index by @ e@coords or coordinates(e) Weidong Gu On Thu, Oct 13, 2011 at 2:18 PM, Bailey, Daniel bai...@spu.edu wrote: Michael, Thank you for the tips. The suggestion didn't work though. Here is the output of str(e): Formal class 'SpatialPointsDataFrame' [package sp] with 5 slots ..@ data :'data.frame': 168 obs. of 2 variables: .. ..$ catchcandata: num [1:168] 47.2 50.4 53.7 58 69.8 ... .. ..$ section : Factor w/ 1 level 16 Sept F9: 1 NA NA NA NA NA NA NA NA NA ... ..@ coords.nrs : int [1:2] 1 2 ..@ coords : num [1:168, 1:2] 0 0 0 0 0 ... .. ..- attr(*, dimnames)=List of 2 .. .. ..$ : NULL .. .. ..$ : chr [1:2] x y ..@ bbox : num [1:2, 1:2] 0 0 48.8 17.1 .. ..- attr(*, dimnames)=List of 2 .. .. ..$ : chr [1:2] x y .. .. ..$ : chr [1:2] min max ..@ proj4string:Formal class 'CRS' [package sp] with 1 slots .. .. ..@ projargs: chr NA -Original Message- From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com] Sent: Thursday, October 13, 2011 11:13 AM To: Bailey, Daniel Cc: Sarah Goslee; r-help@r-project.org Subject: Re: [R] getting data associated with coordinates in a spatial data frame It's going to depend how the coordinates are stored within the data frame. Do you perhaps know if they are factors or character strings? (I'm not familiar with the package). If you don't know, type str(NAMEOFYOUROBJECT) and we can help interpret the output. Untested, I think this would actually work for both though: e[as.character(e$coordinates)==(0,17),] Michael On Thu, Oct 13, 2011 at 2:05 PM, Bailey, Daniel bai...@spu.edu wrote: Thank you Sarah. I tried your suggestion, and if I coerce it into a normal data.frame, that method works. But if you've already made the data into a SpatialPixelsDataFrame and run coordinates (both from the package sp) so that the columns x and y become a single column coordinates with the format (0, 17) for x and y, how do you then call or manipulate data at a specific location? The following: e[e$coordinates==(0,17),] Doesn't work. -Original Message- From: Sarah Goslee [mailto:sarah.gos...@gmail.com] Sent: Wednesday, October 12, 2011 5:34 PM To: Bailey, Daniel Cc: r-help@r-project.org Subject: Re: [R] getting data associated with coordinates in a spatial data frame Hi, On Wed, Oct 12, 2011 at 3:37 PM, Bailey, Daniel bai...@spu.edu wrote: If I know the specific coordinate in a spatial data frame, how can I access the data at that coordinate? My coordinates are labeled x and y in a data.frame e. The data is in column leachate. I want to say, basically: e$leachate@coordinates(2,3mailto:e$leachate@coordinates(2,3). That's kind of mangled, but what about: e[e$x == my.x e$y == my.y, leachate] (Depending on the form of your coordinates, you may also have to invoke FAQ 7.31.) Sarah Thanks, Daniel -- 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. __ 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] US States percentage change plot
Unless your audience is mainly interested in Texas and California and is completely content to ignore Rhode Island, then I would suggest that you look at the state.vbm map in the TeachingDemos package that works with the maptools package. The example there shows coloring based on a variable. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Michael Charles Bailey I Sent: Wednesday, October 12, 2011 6:46 PM To: r-help@r-project.org Subject: [R] US States percentage change plot Hi, I would like to make a plot of the US states (or lower 48) that are colored based upon a percentage change column. Ideally, it would gradually be more blue the larger the positive change, and more red the more negative is the change. The data I have looks like: State Percent.Change 1Alabama0.004040547 2 Alaska -0.000202211 3Arizona -0.002524567 4 Arkansas -0.008525333 5 California0.001828754 6 Colorado0.06150 I have read help for the maps library and similar plots online but can't grasp how to map the percentage.change column to the map. thank in advance, Michael Bailey [[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] getting data associated with coordinates in a spatial data frame
Hi, On Thu, Oct 13, 2011 at 2:05 PM, Bailey, Daniel bai...@spu.edu wrote: Thank you Sarah. I tried your suggestion, and if I coerce it into a normal data.frame, that method works. But if you've already made the data into a SpatialPixelsDataFrame and run coordinates (both from the package sp) so that the columns x and y become a single column coordinates with the format (0, 17) for x and y, how do you then call or manipulate data at a specific location? The following: e[e$coordinates==(0,17),] Doesn't work. They don't become a single column but rather a single matrix with two columns, and (0, 17) isn't the correct way to specify a vector. You can identify particular coordinates using the form I offered earlier, and then use that to subset the data slot of your SGPF. Using built-in data: library(sp) data(meuse.grid) m = SpatialPixelsDataFrame(points = meuse.grid[c(x, y)], data = meuse.grid) m@data[coordinates(m)[,x] == 181100 coordinates(m)[,y] == 333660,] There ought to be a more elegant way to match coordinates (other than the do.call() and paste() approach), but I'm not sure what it is. Sarah -- 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] getting data associated with coordinates in a spatial data frame
Ah yes, my eternal nemesis the S4 class... You were basically there with e[e$coordinates==(0,17),] but for some access stuff that comes from the SpatialDataPointsFrame class. You'll probably want to do this in two steps: coords = coordinates(e) ## Use the access function coordinates to get a 2xn matrix of coordinates x and y; ## you could also do this with coords = e@coords as Weidong noted but it's discouraged e[coords[,x] == my.x coords[,y] == my.y, leachate] I can't test it on your data, but I think this will do it. data(meuse.grid) coordinates(meuse.grid) - ~x+y M = meuse.grid coords = coordinates(M) M[(coords[,x] == 179220) (coords[,y] == 329620), soil] Hope this helps, Michael On Thu, Oct 13, 2011 at 2:18 PM, Bailey, Daniel bai...@spu.edu wrote: Michael, Thank you for the tips. The suggestion didn't work though. Here is the output of str(e): Formal class 'SpatialPointsDataFrame' [package sp] with 5 slots ..@ data :'data.frame': 168 obs. of 2 variables: .. ..$ catchcandata: num [1:168] 47.2 50.4 53.7 58 69.8 ... .. ..$ section : Factor w/ 1 level 16 Sept F9: 1 NA NA NA NA NA NA NA NA NA ... ..@ coords.nrs : int [1:2] 1 2 ..@ coords : num [1:168, 1:2] 0 0 0 0 0 ... .. ..- attr(*, dimnames)=List of 2 .. .. ..$ : NULL .. .. ..$ : chr [1:2] x y ..@ bbox : num [1:2, 1:2] 0 0 48.8 17.1 .. ..- attr(*, dimnames)=List of 2 .. .. ..$ : chr [1:2] x y .. .. ..$ : chr [1:2] min max ..@ proj4string:Formal class 'CRS' [package sp] with 1 slots .. .. ..@ projargs: chr NA -Original Message- From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com] Sent: Thursday, October 13, 2011 11:13 AM To: Bailey, Daniel Cc: Sarah Goslee; r-help@r-project.org Subject: Re: [R] getting data associated with coordinates in a spatial data frame It's going to depend how the coordinates are stored within the data frame. Do you perhaps know if they are factors or character strings? (I'm not familiar with the package). If you don't know, type str(NAMEOFYOUROBJECT) and we can help interpret the output. Untested, I think this would actually work for both though: e[as.character(e$coordinates)==(0,17),] Michael On Thu, Oct 13, 2011 at 2:05 PM, Bailey, Daniel bai...@spu.edu wrote: Thank you Sarah. I tried your suggestion, and if I coerce it into a normal data.frame, that method works. But if you've already made the data into a SpatialPixelsDataFrame and run coordinates (both from the package sp) so that the columns x and y become a single column coordinates with the format (0, 17) for x and y, how do you then call or manipulate data at a specific location? The following: e[e$coordinates==(0,17),] Doesn't work. -Original Message- From: Sarah Goslee [mailto:sarah.gos...@gmail.com] Sent: Wednesday, October 12, 2011 5:34 PM To: Bailey, Daniel Cc: r-help@r-project.org Subject: Re: [R] getting data associated with coordinates in a spatial data frame Hi, On Wed, Oct 12, 2011 at 3:37 PM, Bailey, Daniel bai...@spu.edu wrote: If I know the specific coordinate in a spatial data frame, how can I access the data at that coordinate? My coordinates are labeled x and y in a data.frame e. The data is in column leachate. I want to say, basically: e$leachate@coordinates(2,3mailto:e$leachate@coordinates(2,3). That's kind of mangled, but what about: e[e$x == my.x e$y == my.y, leachate] (Depending on the form of your coordinates, you may also have to invoke FAQ 7.31.) Sarah Thanks, Daniel -- 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.
[R] OT RE: US States percentage change plot
OT question: can R produce Cartograms? Here's an example of World Population: http://www.worldmapper.org/display.php?selected=2 This might make Texas smaller and Rhode Island larger Robert Farley LACMTA -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Greg Snow Sent: Thursday, October 13, 2011 11:28 To: Michael Charles Bailey I; r-help@r-project.org Subject: Re: [R] US States percentage change plot Unless your audience is mainly interested in Texas and California and is completely content to ignore Rhode Island, then I would suggest that you look at the state.vbm map in the TeachingDemos package that works with the maptools package. The example there shows coloring based on a variable. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Michael Charles Bailey I Sent: Wednesday, October 12, 2011 6:46 PM To: r-help@r-project.org Subject: [R] US States percentage change plot Hi, I would like to make a plot of the US states (or lower 48) that are colored based upon a percentage change column. Ideally, it would gradually be more blue the larger the positive change, and more red the more negative is the change. The data I have looks like: State Percent.Change 1Alabama0.004040547 2 Alaska -0.000202211 3Arizona -0.002524567 4 Arkansas -0.008525333 5 California0.001828754 6 Colorado0.06150 I have read help for the maps library and similar plots online but can't grasp how to map the percentage.change column to the map. thank in advance, Michael Bailey [[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. __ 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] getting data associated with coordinates in a spatial data frame
Michael, that's half of the problem solved (whew!!). Now how do I change the data at that location? This is not an intuitive way to manipulate data. -Original Message- From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com] Sent: Thursday, October 13, 2011 11:35 AM To: Bailey, Daniel Cc: Sarah Goslee; r-help@r-project.org Subject: Re: [R] getting data associated with coordinates in a spatial data frame Ah yes, my eternal nemesis the S4 class... You were basically there with e[e$coordinates==(0,17),] but for some access stuff that comes from the SpatialDataPointsFrame class. You'll probably want to do this in two steps: coords = coordinates(e) ## Use the access function coordinates to get a 2xn matrix of coordinates x and y; ## you could also do this with coords = e@coords as Weidong noted but it's discouraged e[coords[,x] == my.x coords[,y] == my.y, leachate] I can't test it on your data, but I think this will do it. data(meuse.grid) coordinates(meuse.grid) - ~x+y M = meuse.grid coords = coordinates(M) M[(coords[,x] == 179220) (coords[,y] == 329620), soil] Hope this helps, Michael On Thu, Oct 13, 2011 at 2:18 PM, Bailey, Daniel bai...@spu.edu wrote: Michael, Thank you for the tips. The suggestion didn't work though. Here is the output of str(e): Formal class 'SpatialPointsDataFrame' [package sp] with 5 slots ..@ data :'data.frame': 168 obs. of 2 variables: .. ..$ catchcandata: num [1:168] 47.2 50.4 53.7 58 69.8 ... .. ..$ section : Factor w/ 1 level 16 Sept F9: 1 NA NA NA NA NA NA NA NA NA ... ..@ coords.nrs : int [1:2] 1 2 ..@ coords : num [1:168, 1:2] 0 0 0 0 0 ... .. ..- attr(*, dimnames)=List of 2 .. .. ..$ : NULL .. .. ..$ : chr [1:2] x y ..@ bbox : num [1:2, 1:2] 0 0 48.8 17.1 .. ..- attr(*, dimnames)=List of 2 .. .. ..$ : chr [1:2] x y .. .. ..$ : chr [1:2] min max ..@ proj4string:Formal class 'CRS' [package sp] with 1 slots .. .. ..@ projargs: chr NA -Original Message- From: R. Michael Weylandt [mailto:michael.weyla...@gmail.com] Sent: Thursday, October 13, 2011 11:13 AM To: Bailey, Daniel Cc: Sarah Goslee; r-help@r-project.org Subject: Re: [R] getting data associated with coordinates in a spatial data frame It's going to depend how the coordinates are stored within the data frame. Do you perhaps know if they are factors or character strings? (I'm not familiar with the package). If you don't know, type str(NAMEOFYOUROBJECT) and we can help interpret the output. Untested, I think this would actually work for both though: e[as.character(e$coordinates)==(0,17),] Michael On Thu, Oct 13, 2011 at 2:05 PM, Bailey, Daniel bai...@spu.edu wrote: Thank you Sarah. I tried your suggestion, and if I coerce it into a normal data.frame, that method works. But if you've already made the data into a SpatialPixelsDataFrame and run coordinates (both from the package sp) so that the columns x and y become a single column coordinates with the format (0, 17) for x and y, how do you then call or manipulate data at a specific location? The following: e[e$coordinates==(0,17),] Doesn't work. -Original Message- From: Sarah Goslee [mailto:sarah.gos...@gmail.com] Sent: Wednesday, October 12, 2011 5:34 PM To: Bailey, Daniel Cc: r-help@r-project.org Subject: Re: [R] getting data associated with coordinates in a spatial data frame Hi, On Wed, Oct 12, 2011 at 3:37 PM, Bailey, Daniel bai...@spu.edu wrote: If I know the specific coordinate in a spatial data frame, how can I access the data at that coordinate? My coordinates are labeled x and y in a data.frame e. The data is in column leachate. I want to say, basically: e$leachate@coordinates(2,3mailto:e$leachate@coordinates(2,3). That's kind of mangled, but what about: e[e$x == my.x e$y == my.y, leachate] (Depending on the form of your coordinates, you may also have to invoke FAQ 7.31.) Sarah Thanks, Daniel -- 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] getting data associated with coordinates in a spatial data frame
On Thu, Oct 13, 2011 at 2:44 PM, Bailey, Daniel bai...@spu.edu wrote: Michael, that's half of the problem solved (whew!!). Now how do I change the data at that location? You assign it a new value, just as for any assignment. Using the example from my previous email: data(meuse.grid) m = SpatialPixelsDataFrame(points = meuse.grid[c(x, y)], data = meuse.grid) m@data[coordinates(m)[,x] == 181100 coordinates(m)[,y] == 333660,] x y part.a part.b dist soil ffreq 5 181100 333660 1 001 1 m@data[coordinates(m)[,x] == 181100 coordinates(m)[,y] == 333660, soil] - 5 m@data[coordinates(m)[,x] == 181100 coordinates(m)[,y] == 333660,] x y part.a part.b dist soil ffreq 5 181100 333660 1 005 1 This is not an intuitive way to manipulate data. That's not what it's *for*. SGDFs are for storing and working with spatial data, where all the components are needed for the spatial reference. If you need to manipulate a lot of things, you're better off doing it before you construct the SGDF, or you can cheat by extracting the data slot, working with it, then reassigning it as a single unit. mydata - m@data # do stuff m@data - mydata You might also benefit from reading Applied Spatial Data Analysis with R by Bivand et al. Sarah -- 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] getting data associated with coordinates in a spatial data frame
Woohoo! Thank you Sarah and Michael. You are rock stars! Daniel -Original Message- From: Sarah Goslee [mailto:sarah.gos...@gmail.com] Sent: Thursday, October 13, 2011 11:54 AM To: Bailey, Daniel Cc: r-help@r-project.org Subject: Re: [R] getting data associated with coordinates in a spatial data frame On Thu, Oct 13, 2011 at 2:44 PM, Bailey, Daniel bai...@spu.edu wrote: Michael, that's half of the problem solved (whew!!). Now how do I change the data at that location? You assign it a new value, just as for any assignment. Using the example from my previous email: data(meuse.grid) m = SpatialPixelsDataFrame(points = meuse.grid[c(x, y)], data = meuse.grid) m@data[coordinates(m)[,x] == 181100 coordinates(m)[,y] == 333660,] x y part.a part.b dist soil ffreq 5 181100 333660 1 001 1 m@data[coordinates(m)[,x] == 181100 coordinates(m)[,y] == 333660, soil] - 5 m@data[coordinates(m)[,x] == 181100 coordinates(m)[,y] == 333660,] x y part.a part.b dist soil ffreq 5 181100 333660 1 005 1 This is not an intuitive way to manipulate data. That's not what it's *for*. SGDFs are for storing and working with spatial data, where all the components are needed for the spatial reference. If you need to manipulate a lot of things, you're better off doing it before you construct the SGDF, or you can cheat by extracting the data slot, working with it, then reassigning it as a single unit. mydata - m@data # do stuff m@data - mydata You might also benefit from reading Applied Spatial Data Analysis with R by Bivand et al. Sarah -- 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] Remove specific rows in a matrix/data.frame
Hi, just put it in the formula: aggregate(Number ~ Letter+Test,data=dtf,max) cheers Am 13.10.2011 19:30, schrieb syrvn: Hello again, dtf-read.table(textConnection(Letter Test Number a b 1 a b 1 b b 1 b b 0 c b 0 c b 1 d b 0 d b 0),header=T) aggregate(Number ~ Letter,data=dtf,max) how can I adjust this solution that the results also includes Test? I tried: aggregate(Number ~ Letter,data=dtf,max,by=list(Letter, Test, Number)) But it breaks with the following error message: Error in aggregate.data.frame(mf[1L], mf[-1L], FUN = FUN, ...) : arguments must have same length -- View this message in context: http://r.789695.n4.nabble.com/Remove-specific-rows-in-a-matrix-data-frame-tp3902149p3902286.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. -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 __ 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] GLM and Neg. Binomial models
D_Tomas tomasmeca at hotmail.com writes: Hi userRs! I am trying to fit some GLM-poisson and neg.binomial. The neg. Binomial model is to account for over-dispersion. When I fit the poisson model i get: (Dispersion parameter for poisson family taken to be 1) However, if I estimate the dispersion coefficient by means of: sum(residuals(fit,type=pearson)^2)/fit$df.res I obtained 2.4. This is theory means over-dispersion since 2.41. I do not understand what the relation is between (Dispersion parameter for poisson family taken to be 1) and 2.4. This means that the fit that glm() does assumes a scale parameter of 1: that is, it assumes the data are Poisson and does not try to estimate a scale parameter. For example, try running example(glm) [to generate the glm.D93 object, which is the result of a glm() Poisson fit] and then: summary(update(glm.D93,family=quasipoisson)) -- which will show you that the dispersion parameter is estimated as 1.2933. I would guess that if you use a quasipoisson model you will get an estimated scale parameter close to 2.4 (maybe not exactly 2.4, since there are different ways to estimate the dispersion and I don't remember exactly how it is done in this case). In a similar fashion, when i fit the neg. binomial model I obtain: (Dispersion parameter for Negative Binomial(0.1717) family taken to be 1) Whereas the estimation of the dispersion coefficient as stated above is: 1.4 Do you mean 2.4? Why Dispersion parameter and my calculation are not the same? Any thoughts will be much appreciate it . This one is a little harder to explain, but here goes: the negative binomial distribution is not technically in the exponential family *unless* the dispersion parameter is set to a constant (=0.1717 in this case). The way glm.nb (which I assume you used) works is that it wraps calls to glm() in an outer loop which attempts to estimate the dispersion parameter. However, this dispersion parameter does not enter the equations in exactly the same way as a regular scale parameter would in a standard GLM (e.g. if family were gaussian or Gamma). Ben Bolker __ 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] binomial GLM quasi separation
lincoln miseno77 at hotmail.com writes: Hi all, I have run a (glm) analysis where the dependent variable is the gender (family=binomial) and the predictors are percentages. I get a warning saying fitted probabilities numerically 0 or 1 occurred that is indicating that quasi-separation or separation is occurring. This makes sense given that one of these predictors have a very influential effect that is depending on a specific threshold separating these effects, in other words in my analysis one of these variables predicts males about the 80% of times when its values are less or equal to zero and females about the 80% when its values are greater than zero. I have been looking at other posts about this but I haven’t understood how I should act when the separation (or quasi separation) is not a statistical artifact but it is something real. As suggested in http://r.789695.n4.nabble.com/ OT-quasi-separation-in-a-logistic-GLM-td875726.html#a3850331 http://r.789695.n4.nabble.com/ OT-quasi-separation-in-a-logistic-GLM-td875726.html#a3850331 [warning, broke URLs to make gmane happy] (the last post is mine) I tried to use brglm procedure that uses a penalized maximum likelihood but it made no difference. I'm not sure what's going on here, and I don't know why brglm() shouldn't work ... from a squint at your Nabble post (I can't really see the figure very well), I agree that the hcp profile is funky, but I wouldn't immediately conclude that the profile is bad -- in particular, it seems that the x-axis range is -45 to -15, rather than something like (-600,-300) as I would expect from the estimated parameter (ca. -400) and standard error (ca. 60). I would start by setting which=3 (to confine your attention to the hcp parameter) and messing around with the gridsize, stepsize, stdn parameters in profileModel to see what's going on. If that doesn't work you might have to post data, or a subset of data, in order to get any more help ... __ 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] Question: Self selection bias and censoring in R
Hi All, I am a relative newbie to R and have the following problem I was trying to solve. I had taken a look at the 'sample selection' package but was having trouble applying it to my use case and was wondering if anyone out there had done something similar and could share code or documentation either using this package or any other packages. I have a website page that I am subjecting to a statistical test, so I have 2 flavors a test and a control and am measuring a task completion for both. My null hypothesis is p(users completing task on control page) = p(users completing task on test page). I can randomly split the users to each page, run this test and perform a simple Z test ( prop.test() ) to compare proportions and get my answer. However to get to the test/control page users have to 'opt in' so I am inducing a self selection bias, they also then have the ability to 'opt out' if they want thereby introducing censoring. I can randomly split the traffic between test and control for users that are opted in but I have no control over which users opt in and if they decide to opt out mid test. Any pointers to examples, links, papers, R code etc. on how to update my simple Z test for proportions to accommodate this would be most welcome, or alternative approaches in R. Best regards, Mary __ 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] OT RE: US States percentage change plot
One package that you can use is Rcartogram from Omegahat, although it took me a long long time to figure out how to use it for real maps. I noticed there was another unpublished package named cart in R-Forge, and I have never tried it. I also want to know if there are other R packages that have as simple usage as take the polygon coordinates and warp the polygons according to a variable. At least for Rcartogram, it is not so easy (due to the design of the C code by other authors). Maybe I'm going in a wrong direction (no cartogram algorithm is so straightforward?). Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Thu, Oct 13, 2011 at 1:43 PM, Farley, Robert farl...@metro.net wrote: OT question: can R produce Cartograms? Here's an example of World Population: http://www.worldmapper.org/display.php?selected=2 This might make Texas smaller and Rhode Island larger Robert Farley LACMTA -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Greg Snow Sent: Thursday, October 13, 2011 11:28 To: Michael Charles Bailey I; r-help@r-project.org Subject: Re: [R] US States percentage change plot Unless your audience is mainly interested in Texas and California and is completely content to ignore Rhode Island, then I would suggest that you look at the state.vbm map in the TeachingDemos package that works with the maptools package. The example there shows coloring based on a variable. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Michael Charles Bailey I Sent: Wednesday, October 12, 2011 6:46 PM To: r-help@r-project.org Subject: [R] US States percentage change plot Hi, I would like to make a plot of the US states (or lower 48) that are colored based upon a percentage change column. Ideally, it would gradually be more blue the larger the positive change, and more red the more negative is the change. The data I have looks like: State Percent.Change 1 Alabama 0.004040547 2 Alaska -0.000202211 3 Arizona -0.002524567 4 Arkansas -0.008525333 5 California 0.001828754 6 Colorado 0.06150 I have read help for the maps library and similar plots online but can't grasp how to map the percentage.change column to the map. thank in advance, Michael Bailey [[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. __ 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] SLOW split() function
Very nice! I am quite impressed at how flexible data.table is. On Thu, Oct 13, 2011 at 1:05 AM, Matthew Dowle mdo...@mdowle.plus.com wrote: Using Josh's nice example, with data.table's built-in 'by' (optimised grouping) yields a 6 times speedup (100 seconds down to 15 on my netbook). system.time(all.2b - lapply(si, function(.indx) { coef(lm(y ~ + x, data=d[.indx,])) })) user system elapsed 144.501 0.300 145.525 system.time(all.2c - lapply(si, function(.indx) { minimal.lm(y + = d[.indx, y], x = d[.indx, list(int, x)]) })) user system elapsed 100.819 0.084 101.552 system.time(all.2d - d[,minimal.lm2(y=y, x=cbind(int, x)),by=key]) user system elapsed 15.269 0.012 15.323 # 6 times faster head(all.2c) $`1` coef se x1 0.5152438 0.6277254 x2 0.5621320 0.5754560 $`2` coef se x1 0.2228235 0.312918 x2 0.3312261 0.261529 $`3` coef se x1 -0.1972439 0.4674000 x2 -0.1674313 0.4479957 $`4` coef se x1 -0.13915746 0.2729158 x2 -0.03409833 0.2212416 $`5` coef se x1 0.007969786 0.2389103 x2 -0.083776526 0.2046823 $`6` coef se x1 -0.58576454 0.5677619 x2 -0.07249539 0.5009013 head(all.2d) key coef V2 [1,] 1 0.5152438 0.6277254 [2,] 1 0.5621320 0.5754560 [3,] 2 0.2228235 0.3129180 [4,] 2 0.3312261 0.2615290 [5,] 3 -0.1972439 0.4674000 [6,] 3 -0.1674313 0.4479957 minimal.lm2 # slightly modified version of Josh's function(y, x) { obj - lm.fit(x = x, y = y) resvar - sum(obj$residuals^2)/obj$df.residual p - obj$rank R - .Call(La_chol2inv, x = obj$qr$qr[1L:p, 1L:p, drop = FALSE], size = p, PACKAGE = base) m - min(dim(R)) d - c(R)[1L + 0L:(m - 1L) * (dim(R)[1L] + 1L)] se - sqrt(d * resvar) list(coef = obj$coefficients, se) } -- View this message in context: http://r.789695.n4.nabble.com/SLOW-split-function-tp3892349p3900851.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. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.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] x axis
There are lots of options since you did not tell us what you want on the axis (or what you have tried). For example if you want more than 6 tick marks/labels, replace xlim=c(0, 3000) with xaxp=c(0, 3000, 12) to get labels every 250 meters instead of 500. Depending on the size of the graph window you may need to add cex.axis=.8 to reduce the text size to fit the labels in the available space. Likewise xaxp=c(0, 3000, 3) would reduce the number of labels to every 1000 meters. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of R. Michael Weylandt Sent: Thursday, October 13, 2011 1:17 PM To: lauren mcdonagh Cc: r-help@r-project.org Subject: Re: [R] x axis In your plot call, you can use xaxt = n to turn off the default x axis tick marks, then add axis(1, at = VARIABLEWHEREYOUWANTTICKMARKS) # If you want ticks at the x you put in, its just axis(1, at = x) to get ticks where you want them. There's also a label= argument if you want them to be labled as something other than the numbers. Hope this helps, Michael On Thu, Oct 13, 2011 at 11:42 AM, lauren mcdonagh cleverlolli...@yahoo.ie wrote: Dear R users, I am quite desperate for help. I haven't used R in a couple of years and I'm currently finishing a masters project and running out of time to figure out my problem. I have read and tried the examples on many websites, in your forums and R Help yet still can't manage to change the x axis. I am using R 2.8.0 on windows. I'm sure there must be a way to do this as many people's questions seem more difficult. My problem is that I need to change the numbers on the x axis from the default. This is my scatter plot so far: x - c(0, 50, 100, 250, 500, 750, 1000, 1500, 2000, 2500, 3000) y - c(640, 585, 152, 85, 348, 922, 518, 82, 83, 591, 79) plot(y~x, type = p, xlab = Distance (m), ylab = Concentrations (mg/kg), xlim = c(0,3000), ylim = c(0,1000), col =black, pch = 19, sub = Lead, font.sub = 2) text(0,640, mine average, pos = 4, col = red, cex= 0.6) abline(h=c(21), lty = 2, col = green, lwd =1) abline(h=c(36), lty = 3, col = blue, lwd = 1) abline(h=c(190), lty = 1, col =red, lwd = 2) legend(1700, 1000, c(Control, Dutch List - Optimum, Dutch List - Action), col = c(3,4,2), lty = c(2,3,1), cex = 0.8, lwd = c(1,1,2)) R automatically changes the x axis to 0, 500, 100, 1500, 2000, 2500, 3000. I've tried a few things you've already said to other people with problems but all I get is error. I would really appreciate some help as I've no one else to ask (the uni I've studied my masters in does not use R). Yours faithfully, Lauren. [[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. __ 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 plot two surfaces with lattice::wireframe
Hi all, I'd like to plot the Real and Imaginary parts of some f(z) as two different surfaces in wireframe (the row/column axes are the real and imag axes). I know I can do it by, roughly speaking, something like plotz - expand.grid(x={range of Re(z)}, y={range of Im(z), groups=1:2) plotz$func-c(Re(f(z),Im(f(z)) wireframe(func~x*y,data=plotz,groups=groups) But that seems like a clunky way to go, especially if I happen to have started out with a nice matrix of the f(z) values. So, is there some simpler way to write the formula in wireframe? I envision, for a matrix of complex values zmat, pseudocode: wireframe(c(Re(zmat),Im(zmat), groups=1:2) -- and yes, I'm fully aware that without a connection between the 'groups' variable and zmat, this won't work as written. All suggestions (including read the help file for {some lattice func I didn't know about} ) greatfully accepted. Carl -- - Sent from my Cray XK6 __ 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 to ... import the data from Excel
Hi, i had same problem with xlsReadWrite. this function loads a required package. try this: xls.getshlib() -- View this message in context: http://r.789695.n4.nabble.com/help-to-import-the-data-from-Excel-tp3893382p3902973.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.