Re: [R] Question with uniroot function
You really need to read the help page for uniroot. The sign needs to be different at the ends of the starting interval. This is a typical limitation of numerical root finders. --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On April 15, 2015 7:20:04 PM PDT, li li wrote: >Hi all, >In the following code, I am trying to use uniroot function to solve for >the root (a and b in code below) for function f1. >I am not sure why uniroot function does not give the answer since when >we >look the graph, the function does cross 0 twice. >Any suggestion? > Thanks. > Hanna > >u1 <- -3 >u2 <- 4 >pi0 <- 0.8 > >f1 <- function(lambda,z,p1){ >lambda*(p1*exp(u1*z-u1^2/2)+(0.2-p1)*exp(u2*z-u2^2/2))-(1-lambda)*pi0} > >a <- uniroot(f1, lower =-10, upper = 0, > tol = 1e-20,p1=0.15,lambda=0.998)$root > >b <- uniroot(f1, lower =0, upper = 10, > tol = 1e-20,p1=0.15,lambda=0.998)$root > >x <- seq(-20,20, by=0.1) >y <- numeric(length(x)) >for (i in 1:length(x)){y[i] <- f1(x[i],p1=0.15,lambda=0.998)} >plot(y ~ x, ylim=c(-1,1)) >abline(h=0) > > [[alternative HTML version deleted]] > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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 with uniroot function
Hi all, In the following code, I am trying to use uniroot function to solve for the root (a and b in code below) for function f1. I am not sure why uniroot function does not give the answer since when we look the graph, the function does cross 0 twice. Any suggestion? Thanks. Hanna u1 <- -3 u2 <- 4 pi0 <- 0.8 f1 <- function(lambda,z,p1){ lambda*(p1*exp(u1*z-u1^2/2)+(0.2-p1)*exp(u2*z-u2^2/2))-(1-lambda)*pi0} a <- uniroot(f1, lower =-10, upper = 0, tol = 1e-20,p1=0.15,lambda=0.998)$root b <- uniroot(f1, lower =0, upper = 10, tol = 1e-20,p1=0.15,lambda=0.998)$root x <- seq(-20,20, by=0.1) y <- numeric(length(x)) for (i in 1:length(x)){y[i] <- f1(x[i],p1=0.15,lambda=0.998)} plot(y ~ x, ylim=c(-1,1)) abline(h=0) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] REngine hangs when called within java code
Dear All, I'm creating a project which uses both java and R. I created the java class named MyClass and within that wrote two separate methods (graphing1() and fitness()) to call the r scripts. public void graphing1() throws IOException { String newargs1[] = {"--no-save"}; Rengine r1 = new Rengine(newargs1, false, null); r1.eval("source('test2.R')"); r1.end(); } public void fitness() throws IOException { String newargs1[] = {"--no-save"}; Rengine r3 = new Rengine(newargs1, false, null); r3.eval("source('A.R')"); r3.eval("source('B.R')"); r3.end(); } Both of the above methods are in java class MyClass. >From another class in the same project for which I created a gui, I accessed the fitness() function and it worked fine. But when I try to call the graphing1() function it did not work. (both were called through the gui) The programme hangs at ; Rengine r1 = new Rengine(newargs1, false, null); without any notification. In both instances I called the function as follows: 1st instance: MyClass test=new MyClass(); test.fitness() ; 2nd instance: MyClass test1 = new MyClass(); test1.graphing1(); All the 3 scripts are coded to create png files. test2.R and A.R scripts use the ROCR library and B.R do not use any. All the 3 files end with dev.off() statement. I have installed R 3.1.3. I’m using netbeans as the editor and working in windows environment. The 3 scripts work fine when executed in R environment. The issue arises when it’s called from the java code. I'm a student who is new to R and was struggling to solve this issue for several weeks. Your help is greatly appreciated. Thanks in advance. REngine hangs when called within java code -- problem.pdf Description: Adobe PDF document __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] adding a bravais pearson test to spplot
Hi,First : thanks for your answerThis is my first post on the R-help forum and I'm not familiar with the way how to should post. I am not searching for "an example from scratch" as you said, I am able to build my own codes so I'm only looking for tips : packages, functions that can help my issue (help that does not mean a "code" ready for use")I'm very polite and I'am shocked by the way your give your answer Bilel Le Mercredi 15 avril 2015 15h40, Jeff Newmiller a écrit : Well, creating an example from scratch to show you how it is done can be a lot of work, and depending on your specific data such code can end up being wasted work. For this reason the polite thing to do is to provide a minimal reproducible example that list readers can use to start from. [1] Also, you should read the Posting Guide, which warns you that the R mailing lists are plain text only, so if you post HTML as you did then at best we don't see what you see and at worst it is corrupted. The Guide also mentions that there are different lists with different topics, and the topic of your question is probably best addressed on the R-sig-geo mailing list. It looks nontrivial to me, but there might be a canned solution out there. --- Jeff Newmiller The . . Go Live... DCN: Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. rote: >Dear all, >My name is Bilel and I'am a PhD student from Tunisia working on climate >modelling. My issue today is how to add a Bravais Pearson test as a >contour plot to an existing spplot map. Precisely, I have plotted a >SpatialPixelsDataFrame of Pearson correlation coefficients between >simulated and observed precipitation over the Mediterranean basin using >spplot and I need to now add a contour line of the statically >significant correlation coefficient at 95% CI.I have been vainly trying >for several days to solve this issue, so I really need your help please >Best regards Bilel > [[alternative HTML version deleted]] > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] scan - open text file as list
Thanks. Actually, I thought there was a way to do it with scan only ... 2015-04-15 16:40 GMT+02:00 William Dunlap : > > strsplit(x=sub(pattern="^\\* ", replacement="", x=test), split=" ") > [[1]] > [1] "a" "b" "d" > > [[2]] > [1] "z" "u" "i" "h" "hh" > > [[3]] > [1] "h" "bh" "kk" > > > Bill Dunlap > TIBCO Software > wdunlap tibco.com > > On Tue, Apr 14, 2015 at 2:34 PM, Hermann Norpois > wrote: > >> Hello, >> >> I try to open a text file test.txt with the content >> >> * a b d >> * z u i h hh >> * h bh kk >> >> so that I get a list with each line as a vector with the letters as >> elements of the the vector. >> >> My approach ... >> test <- scan ("test.txt", what="character", sep="\n") >> Read 3 items >> > test.list <- lapply (test, function (x) {a <- unlist (strsplit(x," ")); >> a >> <- a[-1]}) >> > test.list >> [[1]] >> [1] "a" "b" "d" >> >> [[2]] >> [1] "z" "u" "i" "h" "hh" >> >> [[3]] >> [1] "h" "bh" "kk" >> >> ... the result is okay but I dont think it is an elegant solution. One >> comment: I dont know how many lines my "real" test.txt will have. >> Thanks Hermann >> >> [[alternative HTML version deleted]] >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >> https://stat.ethz.ch/mailman/listinfo/r-help >> PLEASE do read the posting guide >> http://www.R-project.org/posting-guide.html >> and provide commented, minimal, self-contained, reproducible code. >> > > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] adding a bravais pearson test to spplot
I also suggest you take this question to R-Sig-geo. Since spplot() is built on the lattice package, adding new elements to an existing plot is, in my experience, difficult to learn how to do. If you can possibly start with plot() instead of spplot() you will, I think, find it much easier to add contour lines. It will all depend on what kind of objects your data are. Here is an example that might help, or at least give you a few more things to look at. > library(sp) > library(maptools) Checking rgeos availability: TRUE > data(meuse.grid) > coordinates(meuse.grid) <- c('x','y') > meuse.grid <- as(meuse.grid, 'SpatialPixelsDataFrame') > im <- as.image.SpatialGridDataFrame(meuse.grid['dist']) > cl <- ContourLines2SLDF(contourLines(im)) > spplot(cl) -- Don MacQueen Lawrence Livermore National Laboratory 7000 East Ave., L-627 Livermore, CA 94550 925-423-1062 On 4/15/15, 3:15 AM, "fathalli bilel" wrote: >Dear all, >My name is Bilel and I'am a PhD student from Tunisia working on climate >modelling. My issue today is how to add a Bravais Pearson test as a >contour plot to an existing spplot map. Precisely, I have plotted a >SpatialPixelsDataFrame of Pearson correlation coefficients between >simulated and observed precipitation over the Mediterranean basin using >spplot and I need to now add a contour line of the statically significant >correlation coefficient at 95% CI.I have been vainly trying for several >days to solve this issue, so I really need your help please >Best regards Bilel > [[alternative HTML version deleted]] > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] adding a bravais pearson test to spplot
I think we need basic code and sample data to see what you are doing. Have a look at http://adv-r.had.co.nz/Reproducibility.html and/or http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example for some hints. For this last link it is a good idea to follow the " reproducible example " link for more concrete suggestions. As Jeff has pointed out, this is not likely to be the best place to post. A more specialized group as he suggested is more likely to be able to help. John Kane Kingston ON Canada > -Original Message- > From: bilelfatha...@yahoo.fr > Sent: Wed, 15 Apr 2015 10:15:46 + (UTC) > To: r-help@r-project.org > Subject: [R] adding a bravais pearson test to spplot > > Dear all, > My name is Bilel and I'am a PhD student from Tunisia working on climate > modelling. My issue today is how to add a Bravais Pearson test as a > contour plot to an existing spplot map. Precisely, I have plotted a > SpatialPixelsDataFrame of Pearson correlation coefficients between > simulated and observed precipitation over the Mediterranean basin using > spplot and I need to now add a contour line of the statically significant > correlation coefficient at 95% CI.I have been vainly trying for several > days to solve this issue, so I really need your help please > Best regards Bilel > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] adding a bravais pearson test to spplot
I think you did not read my answer very carefully... there is a better mailing list for your question. The rest of my comments were intended to educate you, not chastise you. Mailing lists require careful communication, and you do need to improve on your end or you will have "bad luck" getting help in the lists because few people will guess right about what you really need. I did fail to put in the reference [1] which is very helpful; I am sorry for that omission. [1] http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On April 15, 2015 8:04:20 AM PDT, fathalli bilel wrote: >Hi,First : thanks for your answerThis is my first post on the R-help >forum and I'm not familiar with the way how to should post. I am not >searching for "an example from scratch" as you said, I am able to build >my own codes so I'm only looking for tips : packages, functions that >can help my issue (help that does not mean a "code" ready for use")I'm >very polite and I'am shocked by the way your give your answer >Bilel > > >Le Mercredi 15 avril 2015 15h40, Jeff Newmiller > a écrit : > > >Well, creating an example from scratch to show you how it is done can >be a lot of work, and depending on your specific data such code can end >up being wasted work. For this reason the polite thing to do is to >provide a minimal reproducible example that list readers can use to >start from. [1] > >Also, you should read the Posting Guide, which warns you that the R >mailing lists are plain text only, so if you post HTML as you did then >at best we don't see what you see and at worst it is corrupted. The >Guide also mentions that there are different lists with different >topics, and the topic of your question is probably best addressed on >the R-sig-geo mailing list. It looks nontrivial to me, but there might >be a canned solution out there. >--- >Jeff Newmiller The . . Go >Live... >DCN: Basics: ##.#. ##.#. Live >Go... > Live: OO#.. Dead: OO#.. Playing >Research Engineer (Solar/Batteries O.O#. #.O#. with >/Software/Embedded Controllers) .OO#. .OO#. >rocks...1k >--- > >Sent from my phone. Please excuse my brevity. > >On April 15, 2015 3:15:46 AM PDT, fathalli bilel > wrote: >>Dear all, >>My name is Bilel and I'am a PhD student from Tunisia working on >climate >>modelling. My issue today is how to add a Bravais Pearson test as a >>contour plot to an existing spplot map. Precisely, I have plotted a >>SpatialPixelsDataFrame of Pearson correlation coefficients between >>simulated and observed precipitation over the Mediterranean basin >using >>spplot and I need to now add a contour line of the statically >>significant correlation coefficient at 95% CI.I have been vainly >trying >>for several days to solve this issue, so I really need your help >please >>Best regards Bilel >> [[alternative HTML version deleted]] >> >>__ >>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] adding a bravais pearson test to spplot
Well, creating an example from scratch to show you how it is done can be a lot of work, and depending on your specific data such code can end up being wasted work. For this reason the polite thing to do is to provide a minimal reproducible example that list readers can use to start from. [1] Also, you should read the Posting Guide, which warns you that the R mailing lists are plain text only, so if you post HTML as you did then at best we don't see what you see and at worst it is corrupted. The Guide also mentions that there are different lists with different topics, and the topic of your question is probably best addressed on the R-sig-geo mailing list. It looks nontrivial to me, but there might be a canned solution out there. --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On April 15, 2015 3:15:46 AM PDT, fathalli bilel wrote: >Dear all, >My name is Bilel and I'am a PhD student from Tunisia working on climate >modelling. My issue today is how to add a Bravais Pearson test as a >contour plot to an existing spplot map. Precisely, I have plotted a >SpatialPixelsDataFrame of Pearson correlation coefficients between >simulated and observed precipitation over the Mediterranean basin using >spplot and I need to now add a contour line of the statically >significant correlation coefficient at 95% CI.I have been vainly trying >for several days to solve this issue, so I really need your help please >Best regards Bilel > [[alternative HTML version deleted]] > >__ >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] scan - open text file as list
> strsplit(x=sub(pattern="^\\* ", replacement="", x=test), split=" ") [[1]] [1] "a" "b" "d" [[2]] [1] "z" "u" "i" "h" "hh" [[3]] [1] "h" "bh" "kk" Bill Dunlap TIBCO Software wdunlap tibco.com On Tue, Apr 14, 2015 at 2:34 PM, Hermann Norpois wrote: > Hello, > > I try to open a text file test.txt with the content > > * a b d > * z u i h hh > * h bh kk > > so that I get a list with each line as a vector with the letters as > elements of the the vector. > > My approach ... > test <- scan ("test.txt", what="character", sep="\n") > Read 3 items > > test.list <- lapply (test, function (x) {a <- unlist (strsplit(x," ")); a > <- a[-1]}) > > test.list > [[1]] > [1] "a" "b" "d" > > [[2]] > [1] "z" "u" "i" "h" "hh" > > [[3]] > [1] "h" "bh" "kk" > > ... the result is okay but I dont think it is an elegant solution. One > comment: I dont know how many lines my "real" test.txt will have. > Thanks Hermann > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] What does exp(-coef) mean?
On 15 Apr 2015, at 13:11 , Anniek wrote: > I know that exp(coef) is the Hazard Ratio, but in a certain output posted > down here also a exp(-coef) is present. > > exp(coef) exp(-coef) lower .95 upper .95 > ns(CD4, 4)1 0.29058 3.4413 0.1440750.5861 > ns(CD4, 4)2 0.0987010.1316 0.0290750.3351 > ns(CD4, 4)3 0.0347528.7806 0.0073750.1637 > ns(CD4, 4)4 0.10211 9.7933 0.0192340.5421 > drug[T.ddI] 1.31900 0.7582 0.9897481.7578 > AZT[T.failure] 1.46116 0.6844 1.0878391.9626 > > What does exp(-coef) mean? > The inverse hazard ratio. (As in e^-x = 1/e^x). > Thank you in advance! > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/What-does-exp-coef-mean-tp4705897.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Office: A 4.23 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] adding a bravais pearson test to spplot
Dear all, My name is Bilel and I'am a PhD student from Tunisia working on climate modelling. My issue today is how to add a Bravais Pearson test as a contour plot to an existing spplot map. Precisely, I have plotted a SpatialPixelsDataFrame of Pearson correlation coefficients between simulated and observed precipitation over the Mediterranean basin using spplot and I need to now add a contour line of the statically significant correlation coefficient at 95% CI.I have been vainly trying for several days to solve this issue, so I really need your help please Best regards Bilel [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] What does exp(-coef) mean?
I know that exp(coef) is the Hazard Ratio, but in a certain output posted down here also a exp(-coef) is present. exp(coef) exp(-coef) lower .95 upper .95 ns(CD4, 4)1 0.29058 3.4413 0.1440750.5861 ns(CD4, 4)2 0.0987010.1316 0.0290750.3351 ns(CD4, 4)3 0.0347528.7806 0.0073750.1637 ns(CD4, 4)4 0.10211 9.7933 0.0192340.5421 drug[T.ddI] 1.31900 0.7582 0.9897481.7578 AZT[T.failure] 1.46116 0.6844 1.0878391.9626 What does exp(-coef) mean? Thank you in advance! -- View this message in context: http://r.789695.n4.nabble.com/What-does-exp-coef-mean-tp4705897.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] Make a Excel chart by R code
John Kane Kingston ON Canada > -Original Message- > From: miao...@gmail.com > Sent: Wed, 15 Apr 2015 11:54:13 +0800 > To: r-help@r-project.org > Subject: [R] Make a Excel chart by R code > > Hi, > >I understand that there're many great graphic packages in R (e.g., > ggplot2) . Nevertheless, my office uses Excel extensively. Oh dear what a pity Cryer, Jonathan D. “Problems with Using Microsoft Excel for Statistics.” In Joint Statistical Meetings, 2001. http://www.amstat.org/sections/srms/proceedings/y2001/proceed/00470.pdf. Unless you need to have the graphs updating all the time in Calc would it not be just as handy to produce the charts/graphs in R and just import them into your final product. A little bit more work but far superiour graphics and easier maintenance of the graphs. It is much easier to change one line (or one word of code) than to start frenzied clicking all over again. Can't remember your password? Do you need a strong and secure password? Use Password manager! It stores your passwords & protects your account. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] : automated levene test and other tests for variable datasets
Hello Michael, thank you for the reply, it realy helped me to simplify my script. Basically all my questions are a bit the same, but with your hint I could solve most of my problems. Met vriendelijke groeten - With kind regards, Joachim Audenaert onderzoeker gewasbescherming - crop protection researcher PCS | proefcentrum voor sierteelt - ornamental plant research Schaessestraat 18, 9070 Destelbergen, België T: +32 (0)9 353 94 71 | F: +32 (0)9 353 94 95 E: joachim.audena...@pcsierteelt.be | W: www.pcsierteelt.be From: Michael Dewey To: Joachim Audenaert , r-help@r-project.org Date: 14/04/2015 18:17 Subject:Re: [R] : automated levene test and other tests for variable datasets You ask quite a lot of questions, I have given some hints about your first example inline On 14/04/2015 09:07, Joachim Audenaert wrote: > Hello all, > > I am writing a script for statistical comparison of means. I'm doing many > field trials with plants, where we have to compare the efficacy of > different treatments on, different groups of plants. Therefore I would > like to automate this script so it can be used for different datasets of > different experiments (which will have different dimensions). An example > dataset is given here under, I would like to compare if the data of 5 > columns (A,B,C,D,E) are statistically different from each other, where A, > B, C, D and A are different treatments of my plants and I have 5 > replications for this experiment > > dataset <- structure(list(A = c(62, 55, 57, 103, 59), B = c(36, 24, 61, > 19, 79), C = c(33, 97, 54, 48, 166), D = c(106, 82, 116, 85, 94), E = > c(32, 16, 9, 7, 46)), .Names = c("A", "B", "C", "D","E"), row.names = > c(NA, 5L), class = "data.frame") > > 1) First I would like to do a levene test to check the equality of > variances of my datasets. Currently I do this as follows: > > library("car") > attach(dataset) Usually best to avoid this and use the data=parameter or with or within > y <- c(A,B,C,D,E) you could use unlist( ) here > group <- as.factor(c(rep(1, length(A)), rep(2, length(B)),rep(3, > length(C)), rep(4, length(D)),rep(5, length(E you can get the lengths which you need with lengtha <- lapply(dataset, length) or lengths <- sapply(dataset, length) depending then rep(letters[1:length(lengths)], lengths) should get you the group variable you want. I have just typed all those in so there may be typos but at least you know where to look. I am not suggesting that I think automating all statistical analyses is necessarily a good idea either. > leveneTest(y, group) > > Is there a way to automate this for all types of datasets, so that I can > use the same script for a datasets with any number of columns of data to > compare? My above script only works for a dataset with 5 columns to > compare > > 2) For my boxplots I use > > boxplot(dataset) > > which gives me all the boxplots of each dataset, so this is how I want it > > 3) To check normality I currently use the kolmogorov smirnov test as > follows > > ks.test(A,pnorm) > ks.test(B,pnorm) > ks.test(C,pnorm) > ks.test(D,pnorm) > ks.test(E,pnorm) > > Is there a way to replace the A, B, C, ... on the five lines into one line > of entry so that the kolmogorov smirnov test is done on all columns of my > dataset at once? > > 4) if data is normally distributed and the variances are equal I want to > do a t-test and do pairwise comparison, currently like this > > pairwise.t.test(y,group,p.adjust.method = "none") > > if data is not normally distributed or variances are unequal I do a > pairwise comparison with the wilcoxon test > > pairwise.wilcox.test(y,group,p.adjust.method = "none") > > But again I would like to make this easier, is there a way to replace the > y and group in my datalineby something so it works for any size of > dataset? > > 5) Once I have my paiwise comparison results I know which groups are > statistically different from others, so I can add a and b and c to > different groups in my graph. Currently I do this on a sheet of paper by > comparing them one by one. Is there also a way to automate this? So R > gives me for example something like this > > A: a > B: a > C: b > D: ab > E: c > > All help and commentys are welcome. I'm quite new to R and not a > statistical genious, so if I'm overseeing things or thinking in a wrong > way please let me know how I can improve my way of working. In short I > would like to build a script that can compare the means of different > groups of data and check if they are statistically diiferent > > Met vriendelijke groeten - With kind regards, > > Joachim Audenaert > onderzoeker gewasbescherming - crop protection researcher > > PCS | proefcentrum voor sierteelt - ornamental plant research > > Schaessestraat 18, 9070 Destelbergen, Belgi� > T: +32 (0)9 353 94 71 | F: +32 (0)9 353 94 95 > E: joachim.audena...@pcsierteelt.be | W: www.pcsierteelt.be > > Heb je je individuele begeleiding bemesting (CVBB) al aangevraagd? | Het
Re: [R] : automated levene test and other tests for variable datasets
Thank you very much for the reply Thierry, It was very useful for me, currently I updated my script as follows, to be able to use the same script for different datasets: adapting my dataset : y <- melt(dataset, na.rm=TRUE) where "na.rm = true" ommits missing data points variable <- y[,1] value <- y[,2] and then for the tests leveneTest(value~variable,y) apply(dataset,MARGIN=2,FUN=function(x) ks.test(x,pnorm)$p.value) pairwise.t.test(value,variable,p.adjust.method = "none") pairwise.wilcox.test(value,variable,p.adjust.method = "none") Met vriendelijke groeten - With kind regards, Joachim Audenaert onderzoeker gewasbescherming - crop protection researcher PCS | proefcentrum voor sierteelt - ornamental plant research Schaessestraat 18, 9070 Destelbergen, Belgi� T: +32 (0)9 353 94 71 | F: +32 (0)9 353 94 95 E: joachim.audena...@pcsierteelt.be | W: www.pcsierteelt.be From: Thierry Onkelinx To: Joachim Audenaert Cc: "r-help@r-project.org" Date: 15/04/2015 13:31 Subject:Re: [R] : automated levene test and other tests for variable datasets Dear Joachim, Storing your data in a long format will make this a lot easier. library(reshape2) long.data <- melt(dataset, measure.var = c("A", "B", "C", "D", "E")) library(car) leveneTest(value ~ variable, data = long.data) library(plyr) ddply(long.data, "variable", function(x){ks.test(x$value}) Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey 2015-04-14 10:07 GMT+02:00 Joachim Audenaert < joachim.audena...@pcsierteelt.be>: Hello all, I am writing a script for statistical comparison of means. I'm doing many field trials with plants, where we have to compare the efficacy of different treatments on, different groups of plants. Therefore I would like to automate this script so it can be used for different datasets of different experiments (which will have different dimensions). An example dataset is given here under, I would like to compare if the data of 5 columns (A,B,C,D,E) are statistically different from each other, where A, B, C, D and A are different treatments of my plants and I have 5 replications for this experiment dataset <- structure(list(A = c(62, 55, 57, 103, 59), B = c(36, 24, 61, 19, 79), C = c(33, 97, 54, 48, 166), D = c(106, 82, 116, 85, 94), E = c(32, 16, 9, 7, 46)), .Names = c("A", "B", "C", "D","E"), row.names = c(NA, 5L), class = "data.frame") 1) First I would like to do a levene test to check the equality of variances of my datasets. Currently I do this as follows: library("car") attach(dataset) y <- c(A,B,C,D,E) group <- as.factor(c(rep(1, length(A)), rep(2, length(B)),rep(3, length(C)), rep(4, length(D)),rep(5, length(E leveneTest(y, group) Is there a way to automate this for all types of datasets, so that I can use the same script for a datasets with any number of columns of data to compare? My above script only works for a dataset with 5 columns to compare 2) For my boxplots I use boxplot(dataset) which gives me all the boxplots of each dataset, so this is how I want it 3) To check normality I currently use the kolmogorov smirnov test as follows ks.test(A,pnorm) ks.test(B,pnorm) ks.test(C,pnorm) ks.test(D,pnorm) ks.test(E,pnorm) Is there a way to replace the A, B, C, ... on the five lines into one line of entry so that the kolmogorov smirnov test is done on all columns of my dataset at once? 4) if data is normally distributed and the variances are equal I want to do a t-test and do pairwise comparison, currently like this pairwise.t.test(y,group,p.adjust.method = "none") if data is not normally distributed or variances are unequal I do a pairwise comparison with the wilcoxon test pairwise.wilcox.test(y,group,p.adjust.method = "none") But again I would like to make this easier, is there a way to replace the y and group in my datalineby something so it works for any size of dataset? 5) Once I have my paiwise comparison results I know which groups are statistically different from others, so I can add a and b and c to different groups in my graph. Currently I do this on a sheet of paper by comparing them one by one. Is there also a way to automate this? So R gives me for example something like this A: a B: a C: b D: ab E: c All help and commentys are welcome. I'm quite new to R and not a statistical genious, so if I'm overseeing things or thinking in a wrong way please let me know how
Re: [R] Make a Excel chart by R code
By this, do you mean you want to use R to send data to Excel and have Excel create the graph without your intervention, or to use R to create a graph that looks like one of those that Excel produces? David On 4/14/2015 9:54 PM, jpm miao wrote: Hi, I understand that there're many great graphic packages in R (e.g., ggplot2) . Nevertheless, my office uses Excel extensively. Is there any package in R that produces Excel graphs by R codes? Thanks! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- David K Stevens, P.E., Ph.D. Professor and Head, Environmental Engineering Civil and Environmental Engineering Utah Water Research Laboratory 8200 Old Main Hill Logan, UT 84322-8200 435 797 3229 - voice 435 797 1363 - fax david.stev...@usu.edu __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] ClickStream package: How to expand mc plot?
Hi, I produced a mc plot with this package, but the plot is cluttered in the middle. Is there a way to expand the plot so its parts are more clear? Simon __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] : automated levene test and other tests for variable datasets
Dear Joachim, Storing your data in a long format will make this a lot easier. library(reshape2) long.data <- melt(dataset, measure.var = c("A", "B", "C", "D", "E")) library(car) leveneTest(value ~ variable, data = long.data) library(plyr) ddply(long.data, "variable", function(x){ks.test(x$value}) Best regards, ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance Kliniekstraat 25 1070 Anderlecht Belgium To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey 2015-04-14 10:07 GMT+02:00 Joachim Audenaert < joachim.audena...@pcsierteelt.be>: > Hello all, > > I am writing a script for statistical comparison of means. I'm doing many > field trials with plants, where we have to compare the efficacy of > different treatments on, different groups of plants. Therefore I would > like to automate this script so it can be used for different datasets of > different experiments (which will have different dimensions). An example > dataset is given here under, I would like to compare if the data of 5 > columns (A,B,C,D,E) are statistically different from each other, where A, > B, C, D and A are different treatments of my plants and I have 5 > replications for this experiment > > dataset <- structure(list(A = c(62, 55, 57, 103, 59), B = c(36, 24, 61, > 19, 79), C = c(33, 97, 54, 48, 166), D = c(106, 82, 116, 85, 94), E = > c(32, 16, 9, 7, 46)), .Names = c("A", "B", "C", "D","E"), row.names = > c(NA, 5L), class = "data.frame") > > 1) First I would like to do a levene test to check the equality of > variances of my datasets. Currently I do this as follows: > > library("car") > attach(dataset) > y <- c(A,B,C,D,E) > group <- as.factor(c(rep(1, length(A)), rep(2, length(B)),rep(3, > length(C)), rep(4, length(D)),rep(5, length(E > leveneTest(y, group) > > Is there a way to automate this for all types of datasets, so that I can > use the same script for a datasets with any number of columns of data to > compare? My above script only works for a dataset with 5 columns to > compare > > 2) For my boxplots I use > > boxplot(dataset) > > which gives me all the boxplots of each dataset, so this is how I want it > > 3) To check normality I currently use the kolmogorov smirnov test as > follows > > ks.test(A,pnorm) > ks.test(B,pnorm) > ks.test(C,pnorm) > ks.test(D,pnorm) > ks.test(E,pnorm) > > Is there a way to replace the A, B, C, ... on the five lines into one line > of entry so that the kolmogorov smirnov test is done on all columns of my > dataset at once? > > 4) if data is normally distributed and the variances are equal I want to > do a t-test and do pairwise comparison, currently like this > > pairwise.t.test(y,group,p.adjust.method = "none") > > if data is not normally distributed or variances are unequal I do a > pairwise comparison with the wilcoxon test > > pairwise.wilcox.test(y,group,p.adjust.method = "none") > > But again I would like to make this easier, is there a way to replace the > y and group in my datalineby something so it works for any size of > dataset? > > 5) Once I have my paiwise comparison results I know which groups are > statistically different from others, so I can add a and b and c to > different groups in my graph. Currently I do this on a sheet of paper by > comparing them one by one. Is there also a way to automate this? So R > gives me for example something like this > > A: a > B: a > C: b > D: ab > E: c > > All help and commentys are welcome. I'm quite new to R and not a > statistical genious, so if I'm overseeing things or thinking in a wrong > way please let me know how I can improve my way of working. In short I > would like to build a script that can compare the means of different > groups of data and check if they are statistically diiferent > > Met vriendelijke groeten - With kind regards, > > Joachim Audenaert > onderzoeker gewasbescherming - crop protection researcher > > PCS | proefcentrum voor sierteelt - ornamental plant research > > Schaessestraat 18, 9070 Destelbergen, België > T: +32 (0)9 353 94 71 | F: +32 (0)9 353 94 95 > E: joachim.audena...@pcsierteelt.be | W: www.pcsierteelt.be > > Heb je je individuele begeleiding bemesting (CVBB) al aangevraagd? | Het > PCS op LinkedIn > Disclaimer | Please consider the environment before printing. Think green, > keep it on the screen! > [[alternative HTML version deleted]] > > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do
Re: [R] scan - open text file as list
Hi Hermann, This isn't much more elegant, but test.list<-sapply(test,function(x) { strsplit(x," ") },simplify=TRUE) names(test.list)<-NULL Jim On 4/15/15, Hermann Norpois wrote: > Hello, > > I try to open a text file test.txt with the content > > * a b d > * z u i h hh > * h bh kk > > so that I get a list with each line as a vector with the letters as > elements of the the vector. > > My approach ... > test <- scan ("test.txt", what="character", sep="\n") > Read 3 items >> test.list <- lapply (test, function (x) {a <- unlist (strsplit(x," ")); a > <- a[-1]}) >> test.list > [[1]] > [1] "a" "b" "d" > > [[2]] > [1] "z" "u" "i" "h" "hh" > > [[3]] > [1] "h" "bh" "kk" > > ... the result is okay but I dont think it is an elegant solution. One > comment: I dont know how many lines my "real" test.txt will have. > Thanks Hermann > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/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] (no subject)
Hi Dot, Jeff's guess is probably correct, but perhaps you could describe the crazy tick marks and the repeating labels a little more. I suspect that if "newdate" was a character variable you wouldn't get a plot at all, and if it is a factor, a few of the labels might identify what went wrong. Jim > On April 14, 2015 5:04:48 PM PDT, Dot Lundberg > wrote: >>New to R. Having trouble with the xaxis in this code. The tick marks >>are >>crazy and the labels repeat. Any suggestions? >> >>par(mar=c(5,5,5,5)) >> >>plot(LPB_PPT_R$newdate,LPB_PPT_R$Rain_cm,pch=0,type="l",col="black",yaxt="n",ylim=c(0,8),ylab="") >>axis(side=2, at=c(0,2,4,6,8)) >>mtext("Precipitation (cm)", side = 2, line=2.5, at=4) >>mtext("Date", side=1, line=2.5) >>axis.Date(1, at=seq(min(LPB_PPT_R$newdate), >>max(LPB_PPT_R$newdate),las=2,by="1 weeks"),format="%m-%Y") >> >>par(new=TRUE) >> >>plot(LPB_PPT_R$newdate,LPB_PPT_R$Cum_PPT,pch=1,type="l",col="grey",yaxt="n",ylim=c(0,100), >>ylab="") >>axis(side=4, at=c(0,50,100)) >>mtext("Cumulative Precipitation (cm)", side=4, line=2.5, at=50, >>col="grey") >> >> [[alternative HTML version deleted]] >> >>__ >>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see >>https://stat.ethz.ch/mailman/listinfo/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 -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.