Re: [R] Fwd: The StructTS method
On 23/03/2012 18:43, Fretheim, Alexander H wrote: To whomever it may concern, I'm a young Industrial Engineer working on Senior Design at Georgia Tech and have found the StructTS method to be excellent for the training set for my forecasting project. There's only one problem: I don't actually understand what a Structural Time Series IS. I've looked up resources on it, and get that essentially you're dividing the Time Series in to additive components dependent on time, but have no idea how your method works or why. I've also looked at the documentation, which is great from a programmers standpoint and gives at least a basic format but without any idea as to how optimization occurs. Would you be able to even just supply some C code (which I could open in notebook, hopefully) showing how the method works/optimizes/heuristically recommends and why? This is what references are for. From ?StructTS: References: Brockwell, P. J. & Davis, R. A. (1996). _Introduction to Time Series and Forecasting_. Springer, New York. Sections 8.2 and 8.5. Durbin, J. and Koopman, S. J. (2001) _Time Series Analysis by State Space Methods._ Oxford University Press. Harvey, A. C. (1989) _Forecasting, Structural Time Series Models and the Kalman Filter_. Cambridge University Press. Harvey, A. C. (1993) _Time Series Models_. 2nd Edition, Harvester Wheatsheaf. The last is the best place to start. R is *not* a statistics tutorial. Beyond that, R is Open Source and you can read all the source code for yourself. Sincerely, Alexander Fretheim -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] video recorded simulations in R?
Hi everyone, Is it possible to video record simulations in R? Say, for instance, I am plotting samples using MCMC algorithm, and then showing its convergence after 1 iterations. I was wondering if anyone has done this before? [[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] julian() and numerical noise
julian() is in the package base. chron only provides julian.default to avoid the error Uwe observed. If you look at the code for julian.default, it's not too hard to see why date will be slightly more sensitive to "numeric fuzz"whether that's intentional (or even a good/bad thing) is somewhat hard to say, but I'd guess the maintainer didn't really consider a use case involving one quadrillionth of a day. Is it problematic for you? If so, a workaround is not hard to provide Michael On Fri, Mar 23, 2012 at 4:17 PM, Andreas Eckner wrote: > Sorry, forgot to mention: R version 2.14.2 > > The function julian() is part of the "chron" package of the base > distribution. > > On 3/23/2012 2:47 PM, Uwe Ligges wrote: >> >> On 23.03.2012 15:45, Andreas Eckner wrote: >>> >>> Hi, >>> >>> does anybody know if the following behavior of julian() is intentional? >>> >>> > julian(2, 1, 2012) - julian(2 - 1e-15, 1, 2012) >>> [1] 1 >>> > julian(2, 1, 2012) - julian(2, 1 - 1e-15, 2012) >>> [1] 0 >>> > julian(2, 1, 2012) - julian(2, 1, 2012 - 1e-15) >>> [1] 0 >>> >>> In other words, julian() is subject to numerical noise in the 'day' >>> argument, but not in the 'month' and 'year' argument? Another example: >>> >>> > julian(2 - 1e-15, 1, 2012) - julian(1 - 1e-15, 1, 2012) >>> [1] 30 >> >> >> >> Which vbersion of R are you talking about? >> >> I get: >> >> > julian(2, 1, 2012) - julian(2 - 1e-15, 1, 2012) >> Error in UseMethod("julian") : >> no applicable method for 'julian' applied to an object of class >> "c('double', 'numeric')" >> >> >> Uwe Ligges >> >> >>> Thanks, >>> Andreas >>> >>> __ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/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] Fwd: The StructTS method
On Mar 23, 2012, at 11:43 AM, Fretheim, Alexander H wrote: > > > To whomever it may concern, > > I'm a young Industrial Engineer working on Senior Design at Georgia Tech > and have found the StructTS method to be excellent for the training set for > my forecasting project. There's only one problem: I don't actually understand > what a Structural Time Series IS. I've looked up resources on it, and get > that essentially you're dividing the Time Series in to additive components > dependent on time, but have no idea how your method works or why. I've also > looked at the documentation, which is great from a programmers standpoint and > gives at least a basic format but without any idea as to how optimization > occurs. Would you be able to even just supply some C code (which I could open > in notebook, hopefully) showing how the method works/optimizes/heuristically > recommends and why? > > Sincerely, > > Alexander Fretheim http://www.jstatsoft.org/v41 -Roy ** "The contents of this message do not reflect any position of the U.S. Government or NOAA." ** Roy Mendelssohn Supervisory Operations Research Analyst NOAA/NMFS Environmental Research Division Southwest Fisheries Science Center 1352 Lighthouse Avenue Pacific Grove, CA 93950-2097 e-mail: roy.mendelss...@noaa.gov (Note new e-mail address) voice: (831)-648-9029 fax: (831)-648-8440 www: http://www.pfeg.noaa.gov/ "Old age and treachery will overcome youth and skill." "From those who have been given much, much will be expected" "the arc of the moral universe is long, but it bends toward justice" -MLK Jr. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 make output more lovely
If you know LaTeX, Hmisc::latex, xtable [package], and tables [package] all provide auto-generated output for many common results. Otherwise, you'll need to be more specific than "other form" -- there are quite a few of those. Michael On Fri, Mar 23, 2012 at 9:56 PM, mrzung wrote: > Hi, I'm trying to make output of my function easier to see and more lovely. > > As u know, R output is not easy to see for beginner of study or anyone not > expert > so I want to transform the output into other form. > Output of my function is just long text with some numerical result and > table. > > Is there a way to solve it? > > Thanks. > > > -- > View this message in context: > http://r.789695.n4.nabble.com/how-to-make-output-more-lovely-tp4500589p4500589.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] Please sponsor me
letting this through was my fault. I read the subject line and assumed it was for google summer code. in the future, when unsure, I'll read the body. On Fri, Mar 23, 2012 at 7:45 PM, JustGiving wrote: > Hello > > I'm raising money for Breast Cancer Care and I'd really appreciate your > support. > > It's easy to donate online with a credit or debit card - just go to my > JustGiving page: > > http://www.justgiving.com/Veronica-John > > JustGiving sends your donation straight to Breast Cancer Care and > automatically reclaims Gift Aid on all eligible donations, so what you give > is worth even more. I hope you'll join me in supporting Breast Cancer Care. > > Thank you. > > Veronica > > P.S. I used JustGiving to send this email, so please don't reply to it. > Replies go to JustGiving, not to me! > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Vectorize (scalar) function
? Vectorize is the one you need here. primitives are probably more subtle than you need and there's no such thing as a "scalar" function by that name. Michael On Fri, Mar 23, 2012 at 5:12 PM, casperyc wrote: > Hi all, > > myint=function(mu,sigma){ > integrate(function(x) dnorm(x,mu,sigma)/(1+exp(-x)),-Inf,Inf)$value > } > > x=seq(0,50,length=3000) > x=x[-1] > plot(x,myint(4,x)) # not working yet > > I think I have to 'Vectorize' it somehow? > > What's a scalar function? and a primitive function? > > Thanks. > > casper > > > > > - > ### > PhD candidate in Statistics > School of Mathematics, Statistics and Actuarial Science, University of Kent > ### > > -- > View this message in context: > http://r.789695.n4.nabble.com/Vectorize-scalar-function-tp4500181p4500181.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] R numerical integration
Hi all, Is there any other packages to do numerical integration other than the default 'integrate'? Basically, I am integrating: integrate(function(x) dnorm(x,mu,sigma)/(1+exp(-x)),-Inf,Inf)$value The integration is ok provided sigma is >0. However, when mu=-1.645074 and sigma=17535.26 It stopped working. On the other hand, Maple gives me a value of 0.5005299403. It is an important line of the coding that I am doing and I am looking for some package that is able to do numerical integration efficiently (fast and accurate to a tol=1e-4). I have tried 'cubature', which does not give me anything even after 10 minutes. Thanks. casper - ### PhD candidate in Statistics School of Mathematics, Statistics and Actuarial Science, University of Kent ### -- View this message in context: http://r.789695.n4.nabble.com/R-numerical-integration-tp4500095p4500095.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] julian() and numerical noise
Sorry, forgot to mention: R version 2.14.2 The function julian() is part of the "chron" package of the base distribution. On 3/23/2012 2:47 PM, Uwe Ligges wrote: On 23.03.2012 15:45, Andreas Eckner wrote: Hi, does anybody know if the following behavior of julian() is intentional? > julian(2, 1, 2012) - julian(2 - 1e-15, 1, 2012) [1] 1 > julian(2, 1, 2012) - julian(2, 1 - 1e-15, 2012) [1] 0 > julian(2, 1, 2012) - julian(2, 1, 2012 - 1e-15) [1] 0 In other words, julian() is subject to numerical noise in the 'day' argument, but not in the 'month' and 'year' argument? Another example: > julian(2 - 1e-15, 1, 2012) - julian(1 - 1e-15, 1, 2012) [1] 30 Which vbersion of R are you talking about? I get: > julian(2, 1, 2012) - julian(2 - 1e-15, 1, 2012) Error in UseMethod("julian") : no applicable method for 'julian' applied to an object of class "c('double', 'numeric')" Uwe Ligges Thanks, Andreas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] show and produce PDF file with pdf() and dev.off( ) in function
1) thats not a function (i'm sure just a mistake) 2) Just add another plot line myplot <- function(x){ plot(x) pdf("xplot.pdf") plot(x) dev.off() } myplot(1:20) casperyc wrote > > Hi all, > > I know how to use pdf() and dev.off() to produce and save a graph. > > However, when I put them in a function say > > myplot(x=1:20){ > pdf("xplot.pdf") > plot(x) > dev.off() > } > > the function work. But is there a way show the graph in R as well as > saving it to the workspace? > > Thanks. > > casper > -- View this message in context: http://r.789695.n4.nabble.com/show-and-produce-PDF-file-with-pdf-and-dev-off-in-function-tp4500213p4500595.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] Quicker way to apply values to a function
Hi Petr, Thanks for confirming that the integral is bounded. I was thinking about the same thing. However, this requires that 'sigma' is positive. The actual problem occurred in my optimization routine, where i have set the parameter sigma=exp(para), where para is the logit of a uniform random variable. To avoid sigma being too small, i also used if ( round(sigma,3)==0 ) { sigma=0.5 } However, I still have the following error: during optimization using 'optim' Error in integrate(function(x) dnorm(x, mu, sigma)/(1 + exp(-x)), -Inf, : the integral is probably divergent I think, it's still caused by 'small' sigma, but is there a way to fix it? Or should I use another way to randomly generate sigma>0? Thanks. casper - ### PhD candidate in Statistics School of Mathematics, Statistics and Actuarial Science, University of Kent ### -- View this message in context: http://r.789695.n4.nabble.com/Quicker-way-to-apply-values-to-a-function-tp4497293p4500014.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] how to make output more lovely
Hi, I'm trying to make output of my function easier to see and more lovely. As u know, R output is not easy to see for beginner of study or anyone not expert so I want to transform the output into other form. Output of my function is just long text with some numerical result and table. Is there a way to solve it? Thanks. -- View this message in context: http://r.789695.n4.nabble.com/how-to-make-output-more-lovely-tp4500589p4500589.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] Please sponsor me
Hello I'm raising money for Breast Cancer Care and I'd really appreciate your support. It's easy to donate online with a credit or debit card - just go to my JustGiving page: http://www.justgiving.com/Veronica-John JustGiving sends your donation straight to Breast Cancer Care and automatically reclaims Gift Aid on all eligible donations, so what you give is worth even more. I hope you'll join me in supporting Breast Cancer Care. Thank you. Veronica P.S. I used JustGiving to send this email, so please don't reply to it. Replies go to JustGiving, not to me! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 convert factors to numbers
As.numeric(as.character(factor.level.to.convert)) On Mar 23, 2012 11:40 AM, "sandro" wrote: > Hello, I am relatively new to using R. > > The text file contains the date and price . I want to read and manipulate > the data in R. However, when I use read.table, it treats all of the data > as > "factors" and I do not know how to treat the data as numbers: > > http://r.789695.n4.nabble.com/file/n4498828/p_diarios.txt p_diarios.txt > > setwd ("C:\\Users\\Sandro\\Dropbox\\R") > data.precios <- read.table ("p_diarios.txt ", header =TRUE > , dec=",", sep="\t") > Time <- data.precios$time # 01.02.2004 - 12.05.2011 > Price <- data.precios$price # Historical spot price > log.Price <- log(data.precios$price) > Error en Math.factor(c(12L, 126L, 213L, 342L, 160L, 186L, 219L, 37L, 54L, > : > log not meaningful for factors > > As you can see, I cannot calculate the price logarithms. > > Any help is appreciated. > > Sandro > > -- > View this message in context: > http://r.789695.n4.nabble.com/How-to-convert-factors-to-numbers-tp4498828p4498828.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. > [[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] Using MuMIn - error message
Hello, I hope that you can bare with me. I am new to models, but I think I have a pretty godd understanding of how to run them now, including how to use AICc and Anova. The issue is that I have many factors that I wish to compare so doing each one at a time would take forever. I came across the MuMIn package and I was so excited, however I am getting an error message and i don't know why. Firstly it is a mixed model that I am running with lme4. The .csv file that it comes from has more factors than I will probably use but I only listed the ones that I wanted to test. I had also coded the ones that are labels and not continuous data using the as.factor command and I ran the most complex model and ran summary() and it seemed to have worked fine. My model was: fm2test<-lmer(Feeding~MF.vs.OF+Age.class+tide.h.l+Site+HDp+(1|Brood), data=ABMtest.df) and then I wanted to use the dredge command as so: dd<-dredge(fm2test, trace=TRUE, rank="AICc", REML=FALSE) I got an error: Error in UseMethod("fixef") : no applicable method for 'fixef' applied to an object of class "mer" I have no idea how to fix this. I have looked at ?dredge but cannot find anything there and I am very new to R so any help would be greatly appreciated. I want to run all the possible models using the factors and then want to identify those models which best explain Feeding. I also have other models to run and in addition I have more factors to use but wanted to do this first as a test. Could someone also advise me on a way to list all models in order and if each model is accessible in order to compare with Anova? Thank you so much in advance. Rachel -- View this message in context: http://r.789695.n4.nabble.com/Using-MuMIn-error-message-tp4500236p4500236.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] show and produce PDF file with pdf() and dev.off( ) in function
Hi all, I know how to use pdf() and dev.off() to produce and save a graph. However, when I put them in a function say myplot(x=1:20){ pdf("xplot.pdf") plot(x) dev.off() } the function work. But is there a way show the graph in R as well as saving it to the workspace? Thanks. casper - ### PhD candidate in Statistics School of Mathematics, Statistics and Actuarial Science, University of Kent ### -- View this message in context: http://r.789695.n4.nabble.com/show-and-produce-PDF-file-with-pdf-and-dev-off-in-function-tp4500213p4500213.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Fwd: The StructTS method
To whomever it may concern, I'm a young Industrial Engineer working on Senior Design at Georgia Tech and have found the StructTS method to be excellent for the training set for my forecasting project. There's only one problem: I don't actually understand what a Structural Time Series IS. I've looked up resources on it, and get that essentially you're dividing the Time Series in to additive components dependent on time, but have no idea how your method works or why. I've also looked at the documentation, which is great from a programmers standpoint and gives at least a basic format but without any idea as to how optimization occurs. Would you be able to even just supply some C code (which I could open in notebook, hopefully) showing how the method works/optimizes/heuristically recommends and why? Sincerely, Alexander Fretheim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] GDType information
Hi, I used GDALinfo("MOD13Q1.A2001049.h13v11.005.2007002215512.250m_16_days_EVI.tif") and got the results: rows10 columns 11 bands 1 origin.x150701.4 origin.y7744897 res.x 250 res.y 250 ysign -1 oblique.x 0 oblique.y 0 driver GTiff projection +proj=utm +zone=23 +south +datum=WGS84 +units=m +no_defs file/MOD13Q1.A2001049.h13v11.005.2007002215512.250m_16_days_EVI.tif apparent band summary: GDType Bmin Bmax Bmean Bsd hasNoDataValue NoDataValue 1 Int16 -32768 32767 0 0 FALSE 0 Metadata: AREA_OR_POINT=Point TIFFTAG_SOFTWARE=MODIS Reprojection Tool v4.1 March 2009 *How to read the information GDType?* Julio [[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] Vectorize (scalar) function
Hi all, myint=function(mu,sigma){ integrate(function(x) dnorm(x,mu,sigma)/(1+exp(-x)),-Inf,Inf)$value } x=seq(0,50,length=3000) x=x[-1] plot(x,myint(4,x)) # not working yet I think I have to 'Vectorize' it somehow? What's a scalar function? and a primitive function? Thanks. casper - ### PhD candidate in Statistics School of Mathematics, Statistics and Actuarial Science, University of Kent ### -- View this message in context: http://r.789695.n4.nabble.com/Vectorize-scalar-function-tp4500181p4500181.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 wireframe outer box but keep ticks
Wow, that worked liked a charm. I will include the entire working example of how to remove the outer box without losing the ticks: test = data.frame(expand.grid(c(1:10), c(1:10))) z = test[,1] + test[,2] test = cbind(test, z) names(test) = c("x", "y", "z") require(lattice) wireframe(z ~ x*y, data = test, scales=list(arrows=F,col=1), par.settings = list(axis.line = list(col = "transparent")), ) Many thanks!!! --Seth This electronic message contains information generated by the USDA solely for the intended recipients. Any unauthorized interception of this message or the use or disclosure of the information it contains may violate the law and subject the violator to civil or criminal penalties. If you believe you have received this message in error, please notify the sender and delete the email immediately. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 wireframe outer box but keep ticks
On Fri, Mar 23, 2012 at 2:07 PM, Bigelow, Seth W -FS wrote: > ilai/keren: > > Thanks for your response. It's not the 3d bounding box that I wish to > eliminate, but the box that surrounds the whole figure and is drawn > automatically (I call this the outer box, in contrast to the inner, 3d > bounding box). Hmm... But than what you called 'the usual way' should work. Maybe you just overlooked "resetting" the scales list? Is this what you want? wireframe(z ~ x*y, data = test, scales=list(arrows=F,col=1), par.settings = list(axis.line = list(col = "transparent"))) The ticks attached to the bounding box are connected, in the software, to the outer box. I'm assembling a number of these graphs on one page, and the outer box makes the whole figure look clunky. Lattice is an incredible piece of software! but these small details can be difficult to nail down. > > --Seth > > -Original Message- > From: ila...@gmail.com [mailto:ila...@gmail.com] On Behalf Of ilai > Sent: Friday, March 23, 2012 11:10 AM > To: Bigelow, Seth W -FS > Cc: r-help@r-project.org > Subject: Re: [R] Remove wireframe outer box but keep ticks > > See 'box.3d' in trellis.par.get() : > > wireframe(z ~ x*y, data = test, > scales=list(arrows=F), > par.settings = list(box.3d = list(col=NA))) > > Note you can have some finer control: > > wireframe(z ~ x*y, data = test, > scales=list(arrows=F), > par.settings = list(box.3d = list(col=c(1,2,NA,NA,3,NA,4,5,6))) > ) > > Hope this helps > > > On Fri, Mar 23, 2012 at 3:59 AM, Bigelow, Seth W -FS > wrote: >> I would like to eliminate the outer box around a lattice wireframe >> graph, but the usual recommended solution, which is to assign a color of >> 'transparent' to the axis.line parameter, eliminates ticks if the 'arrows=F' >> command is used, as shown in the following example: >> >> test = data.frame(expand.grid(c(1:10), c(1:10))) z = test[,1] + >> test[,2] test = cbind(test, z) >> names(test) = c("x", "y", "z") >> require(lattice) >> wireframe(z ~ x*y, data = test, >> scales=list(arrows=F), >> par.settings = list(axis.line = list(col = "transparent")), >> ) >> >> Is there a way to eliminate the box but keep the ticks? >> >> >> Seth W. Bigelow, Ph.D. >> Research Ecologist >> USDA-FS Pacific Southwest Research Station >> Ph: (802)-379-3444 >> >> >> >> >> >> This electronic message contains information generated by the USDA solely >> for the intended recipients. Any unauthorized interception of this message >> or the use or disclosure of the information it contains may violate the law >> and subject the violator to civil or criminal penalties. If you believe you >> have received this message in error, please notify the sender and delete the >> email immediately. >> >> [[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] quantmod getOptionChain Not Work
Sorry about that: two small mistakes and I imagine there are a few more I've missed. This should actually work: ### library(XML) readYahooOptions <- function(Symbols, Exp, ...){ parse.expiry <- function(x) { if(is.null(x)) return(NULL) if(inherits(x, "Date") || inherits(x, "POSIXt")) return(format(x, "%Y-%m")) if (nchar(x) == 5L) { x <- sprintf(substring(x, 4, 5), match(substring(x, 1, 3), month.abb), fmt = "20%s-%02i") } else if (nchar(x) == 6L) { x <- paste(substring(x, 1, 4), substring(x, 5, 6), sep = "-") } return(x) } clean.opt.table <- function(tableIn){ tableOut <- sapply(tableIn[,-2], function(x) as.numeric(gsub(",","",x))) rownames(tableOut) <- tableIn[,2] tableOut } if(missing(Exp)) optURL <- paste(paste("http://finance.yahoo.com/q/op?s",Symbols,sep="=";),"Options",sep="+") else optURL <- paste(paste("http://finance.yahoo.com/q/op?s=",Symbols,"&m=",parse.expiry(Exp),sep=""),"Options",sep="+") if(!missing(Exp) && is.null(Exp)) { optPage <- readLines(optURL) optPage <- optPage[grep("View By Expiration", optPage)] allExp <- gregexpr("m=", optPage)[[1]][-1] + 2 allExp <- substring(optPage, allExp, allExp + 6) allExp <- allExp[seq_len(length(allExp)-1)] # Last one seems useless ? return(structure(lapply(allExp, readYahooOptions, Symbols=Symbols), .Names=format(as.yearmon(allExp } stopifnot(require("XML")) optURL <- readHTMLTable(optURL) # Not smart to hard code these but it's a 'good-enough' hack for now # Also, what is table 9 on this page? list(calls = clean.opt.table(optURL[[10]]), puts = clean.opt.table(optURL[[14]]), symbol = Symbols) } On Fri, Mar 23, 2012 at 6:44 PM, R. Michael Weylandt wrote: > I just got around to taking a look at this, but below is a fix. It > seems like yahoo finance redesigned the page and rather than reparsing > all their HTML, I'll use Duncan TL's XML package to make life happier. > (I loathe HTML parsing) > > This isn't thoroughly tested and it'll break if yahoo redesigns things > again (I hardcode the table numbers for now) but it seems to work well > enough. Let me know if you have any errors with it. If Jeff likes it, > it should be a drop-in replacement for the getOptionChain.yahoo for > quantmod with a name change. > > Feedback welcome, > > Michael > > # > > library(XML) > > readYahooOptions <- function(Symbols, Exp, ...){ > parse.expiry <- function(x) { > if(is.null(x)) > return(NULL) > > if(inherits(x, "Date") || inherits(x, "POSIXt")) > return(format(x, "%Y-%m")) > > if (nchar(x) == 5L) { > x <- sprintf(substring(x, 4, 5), match(substring(x, > 1, 3), > month.abb), fmt = "20%s-%02i") > } > else if (nchar(x) == 6L) { > x <- paste(substring(x, 1, 4), substring(x, 5, 6), > sep = "-") > } > return(x) > } > > clean.opt.table <- function(tableIn){ > tableOut <- lapply(tableIn[,-2], function(x) as.numeric(gsub(",","",x))) > rownames(tableOut) <- tableIn[,2] > } > > if(missing(Exp)) > optURL <- > paste(paste("http://finance.yahoo.com/q/op?s",Symbols,sep="=";),"Options",sep="+") > else > optURL <- > paste(paste("http://finance.yahoo.com/q/op?s=",Symbols,"&m=",parse.expiry(Exp),sep=""),"Options",sep="+") > > if(!missing(Exp) && is.null(Exp)) { > optPage <- readLines(optURL) > optPage <- optPage[grep("View By Expiration", optPage)] > allExp <- gregexpr("m=", optPage)[[1]][-1] + 2 > allExp <- substring(optPage, allExp, allExp + 6) > allExp <- allExp[seq_len(length(allExp)-1)] # Last one seems > useless ? Always true? > return(structure(lapply(allExp, readYahooOptions, > Symbols=Symbols), .Names=format(as.yearmon(allExp > } > > stopifnot(require("XML")) > > optURL <- readHTMLTable(optURL) > > # Not smart to hard code these but it's a 'good-enough' hack for now > # Also, what is table 9 on this page? > CALLS <- optURL[[10]] > PUTS <- optURL[[14]] > > list(calls = CALLS, puts = PUTS, symbol = Symbols) > } > > > ### > > On Sun, Mar 4, 2012 at 2:18 PM, Sparks, John James wrote: >> Dear R Helpers, >> >> I am still having trouble with the getOptionChain command in quantmod. I >> have the latest version of quantmod, etc. so I was under the impression >> that the problem was solved with updates to the package. >> >> If someone could let me know what I need to install in order to make this >> work, I would really appreciate it. >> >> My error message as session info are shown below. Thanks a bunch. >> --John Sparks >> >> R version 2.14.2 (2012-02-29) >> Platform: i386-pc-mingw32/i386 (32-bit) >> >> locale: >> [1] LC_COLLATE=English_United States.1252 LC
Re: [R] How to draw table in Latex without using xtable?
Hi I have not been following the thread and please excuse the length and width of this - this is a large example of what you can do using xtable and a data.frame the data.frame is copied to xx in the chunck Table6H and reworked in the table itself resulting in a good presentation in a pdf. It just happens to be a \sidewaystable because of size you need \usepackage{booktabs} in the preliminary. I put a space between the lines in the header. A similar thing would apply to \longtable \begin{sidewaystable}[h] \caption[Ewe numbers drenched by dcode and date by Farm]% {Ewe numbers drenched by code and date by Farm}% \label{tab:GPS6}% \pdfbookmark[3]{Table:~6 Ewe numbers drenched by code and date by Farm}% {tab:6}\label{tab:6}% \centering \begin{small} \begin{tabular}{l *{24}{D{.}{.}{3.0}} } \toprule \addlinespace[3pt] % Header & \multicolumn{24}{c}{Drench Code}\\ \addlinespace[2pt] \cmidrule(lr){2-25} \addlinespace[2pt] % Table6H <>= xx <- pparasiteE.tfNw for (j in 2:dim(xx)[2]) xx[xx[,j]==0,j] <- NA xx[,1] <- as.character(xx[,1]) # datasets xx[,1] <- paste(xx[,1], apply(pparasiteE.ds,1,function(x) paste(ifelse(x[2] > 0,"*","\\;\\;"),ifelse(x[1] > 0,"*","\\;\\;"), sep = "") )) out <- unique(sub("[^01]+", "", names(xx)[-1]) ) out <- c("\\multicolumn{1}{c}{Drench} & %\n", paste("\\multicolumn{3}{c}{", out, rep(c("} & %\n", "} "), c(length(out)-1, 1)), sep = ""), "\n" ) cat(out,"\n", sep = "") rm(out) out <- rep(Farms, (dim(xx)[2]-1)/3) out <- c("\\addlinespace[2pt]\n\\cmidrule(lr){2-4}\n\\cmidrule(lr){5-7}\n\\cmidrule(lr){8-10}\n\\cmidrule(lr){11-13}\n\\cmidrule(lr){14-16}\n\\cmidrule(lr){17-19}\n\\cmidrule(lr){20-22}\n\\cmidrule(lr){23-25}\n\n\\addlinespace[2pt]\n\n\\multicolumn{1}{c}{Date} & %\n", paste("\\multicolumn{1}{c}{", out, rep(c("} & %\n", "} "), c(length(out)-1, 1)), sep = ""), "\n" ) cat(out, sep = "") rm(out) @ %% 6 end \addlinespace[3pt] \midrule \addlinespace[5pt] %Table6 <>= print( xtable(xx , digits = rep(c(0), dim(xx)[2]+1), ), type= "latex", tabular.environment = "tabular", include.rownames = FALSE, include.colnames = FALSE, only.contents = TRUE, NA.string = "\\multicolumn{1}{c}{$\\;\\cdots\\;$}", sanitize.text.function = function(x){x}, hline.after = NULL ) ## xtable @ % Table6 end \addlinespace[5pt] \bottomrule \end{tabular} \end{small} \end{sidewaystable} \setlength\tabcolsep{7pt} HTH Duncan Duncan Mackay Department of Agronomy and Soil Science The University of New England Armidale NSW 2351 Email : home: mac...@northnet.com.au At 06:59 24/03/2012, you wrote: You can use xtable() or latex() and then edit the columns names in the generated .tex file. That is a much better plan than reinventing either of those functions. On Thu, Mar 22, 2012 at 3:46 AM, Manish Gupta wrote: > Hi, > > I am working on table suing R and Latex. I am writing .Rnw file first in > which i m reading input file and storing into dataframe. After filtering > certain values from this dataframe. I am planning to display it. I don't > want to use xtable since i need to change column names. > > *Sample .Rnw file* > > @ > <>= > cat("\begin{table}[ht]") > cat("\begin{center}") > cat("\begin{tabular}{lr}") > cat ("\hline") > cat ("& Df & Sum Sq & Mean Sq & F value & Pr($>$F) \\") > cat ("\hline") > cat("block & 5 & 343.29 & 68.66 & 4.45 & 0.0159 \\") > cat ("N & 1 & 189.28 & 189.28 & 12.26 & 0.0044 \\") > cat ("P & 1 & 8.40 & 8.40 & 0.54 & 0.4749 \\") > cat ("K & 1 & 95.20 & 95.20 & 6.17 & 0.0288 \\") > cat ("N:P & 1 & 21.28 & 21.28 & 1.38 & 0.2632 \\") > cat ("N:K & 1 & 33.13 & 33.13 & 2.15 & 0.1686 \\") > cat ("P:K & 1 & 0.48 & 0.48 & 0.03 & 0.8628 \\") > cat ("Residuals & 12 & 185.29 & 15.44 & & \\") > cat ("\hline") > cat("\end{tabular}") > cat("\end{center}") > cat("\end{table}") > @ > > But i am getting error cat("\" not supported. In my case tabular values > are variable. How can i fix my pblm? > > Regards > > -- > View this message in context: > http://r.789695.n4.nabble.com/How-to-draw-table-in-Latex-without-using-xtable-tp4494781p4494781.html > Sent from the R help mailing list archive at Nabble.com. >[[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible c
Re: [R] quantmod getOptionChain Not Work
I just got around to taking a look at this, but below is a fix. It seems like yahoo finance redesigned the page and rather than reparsing all their HTML, I'll use Duncan TL's XML package to make life happier. (I loathe HTML parsing) This isn't thoroughly tested and it'll break if yahoo redesigns things again (I hardcode the table numbers for now) but it seems to work well enough. Let me know if you have any errors with it. If Jeff likes it, it should be a drop-in replacement for the getOptionChain.yahoo for quantmod with a name change. Feedback welcome, Michael # library(XML) readYahooOptions <- function(Symbols, Exp, ...){ parse.expiry <- function(x) { if(is.null(x)) return(NULL) if(inherits(x, "Date") || inherits(x, "POSIXt")) return(format(x, "%Y-%m")) if (nchar(x) == 5L) { x <- sprintf(substring(x, 4, 5), match(substring(x, 1, 3), month.abb), fmt = "20%s-%02i") } else if (nchar(x) == 6L) { x <- paste(substring(x, 1, 4), substring(x, 5, 6), sep = "-") } return(x) } clean.opt.table <- function(tableIn){ tableOut <- lapply(tableIn[,-2], function(x) as.numeric(gsub(",","",x))) rownames(tableOut) <- tableIn[,2] } if(missing(Exp)) optURL <- paste(paste("http://finance.yahoo.com/q/op?s",Symbols,sep="=";),"Options",sep="+") else optURL <- paste(paste("http://finance.yahoo.com/q/op?s=",Symbols,"&m=",parse.expiry(Exp),sep=""),"Options",sep="+") if(!missing(Exp) && is.null(Exp)) { optPage <- readLines(optURL) optPage <- optPage[grep("View By Expiration", optPage)] allExp <- gregexpr("m=", optPage)[[1]][-1] + 2 allExp <- substring(optPage, allExp, allExp + 6) allExp <- allExp[seq_len(length(allExp)-1)] # Last one seems useless ? Always true? return(structure(lapply(allExp, readYahooOptions, Symbols=Symbols), .Names=format(as.yearmon(allExp } stopifnot(require("XML")) optURL <- readHTMLTable(optURL) # Not smart to hard code these but it's a 'good-enough' hack for now # Also, what is table 9 on this page? CALLS <- optURL[[10]] PUTS <- optURL[[14]] list(calls = CALLS, puts = PUTS, symbol = Symbols) } ### On Sun, Mar 4, 2012 at 2:18 PM, Sparks, John James wrote: > Dear R Helpers, > > I am still having trouble with the getOptionChain command in quantmod. I > have the latest version of quantmod, etc. so I was under the impression > that the problem was solved with updates to the package. > > If someone could let me know what I need to install in order to make this > work, I would really appreciate it. > > My error message as session info are shown below. Thanks a bunch. > --John Sparks > > R version 2.14.2 (2012-02-29) > Platform: i386-pc-mingw32/i386 (32-bit) > > locale: > [1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United > States.1252 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] pomp_0.40-2 deSolve_1.10-3 subplex_1.1-3 mvtnorm_0.9-9992 > quantmod_0.3-17 TTR_0.21-0 xts_0.8-2 zoo_1.7-7 > Defaults_1.1-1 > > loaded via a namespace (and not attached): > [1] grid_2.14.2 lattice_0.20-0 tools_2.14.2 >> AAPL.OPT<-getOptionChain("AAPL") > Error in puts[, 2] : incorrect number of dimensions >> AAPL.OPT<-getOptionChain("AAPL",NULL) > Error in puts[, 2] : incorrect number of dimensions >> > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] plot a BARPLOT with sd deviation bar up and down
On Mar 23, 2012, at 21:32 , Sarah Goslee wrote: > The discussion here is likely to be helpful: > https://stat.ethz.ch/pipermail/r-help/2011-February/269185.html > > as is: > http://www.rseek.org/?cx=010923144343702598753%3Aboaz1reyxd4&q=barplot+error+bars&sa=Search+functions%2C+lists%2C+and+more&cof=FORID%3A11&siteurl=www.rseek.org%2F&ref= ...as is: example(barplot) # well, almost; just apply brains > > Beyond that, it isn't clear to me that your question is not homework-related. > > Sarah > > On Fri, Mar 23, 2012 at 4:11 PM, gianni lavaredo > wrote: >> dear Researchers, >> >> i am looking for a function to plot a barplot for each mean value and the >> related standard deviation, and i can close my week. This is an example of >> my data set. >> >> really Thanks in advance for any help or suggestions >> >> Gianni >> >> >> My.mean <- data.frame(Mean=c(0.4108926,0.3949009,0.4520346, >> 0.4091665,0.4664066,0.3048296,0.4297226,0.4056383, >> 0.4127453,0.3568891,0.3933964,0.3892999,0.4052982, >> 0.377359,0.3831106,0.4248397,0.4403693,0.9389882)) >> >> My.SD <- data.frame(SD = c(0.3225084,0.3756248,0.3708947, >> 0.2899242,0.394396,0.4920173,0.2674820,0.3233239,0.2913170, >> 0.4542726,0.4031899,0.2893581,0.403938,0.3686252,0.4014624, >> 0.4105261,0.2811270,0.4088456,0.4889143,0.3949252,1.338804)) >> > > -- > 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. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Nonparametric bivariate distribution estimation and sampling
On Mar 23, 2012, at 3:55 PM, heyi xiao wrote: David, Thanks a lot for the specific suggestions. That’s very helpful. My question 1 is fully answered now. I guess I am not clear enough for my question 2. I would like to generate a random sample using the estimated probability density (as a result of my question 1) as the reference distribution. Say, I get a matrix of the estimated density (at some grid points) using MASS::kde2d. How can I use that result as a reference distribution to sample data from? I know it is a trivial issue for parametric distributions like bivariate normal, but what about such a nonparametric bivariate reference distribution? Any particular procedures or functions I can use? See if this works: data(geyser, package="MASS") x <- cbind(geyser$duration, geyser$waiting) est <- bkde2D(x, bandwidth=c(0.7, 7)) # Heh, I realized after I did this that I started with KernSmooth::bkde2D # and checked the results with MASS::kde2d # only difference appears to be name of density matrix # Construct a dataframe with X.Y information and the data from the bivariate density. # The output of bkde2D with n=50 is: #List of 3 #$ x1 : num [1:51] -0.2167 -0.0823 0.052 0.1863 0.3207 ... # $ x2 : num [1:51] 32.5 34.2 35.9 37.7 39.4 ... # $ fhat: num [1:51, 1:51] 3.05e-19 2.17e-19 3.25e-19 2.17e-19 0.00 ... # The index X.Y could be X + 51*Y and there would be a 1:1 mapping from (X,Y) to X.Y # and the fhat values would be properly arranged dfrm <- expand.grid(X=1:51, Y=1:51) dfrm$fhat <- c(est$fhat) #Sample randomly from X.Y with length=51*51 using the fhat values for prob. # The X.Y "index" never actually gets computed # but is implicit in the order of the data.frame sampfrm <- dfrm[sample(51*51, 300, prob=est$fhat) , ] f2 <- with(sampfrm, MASS::kde2d(X, Y, n = 50, lims = c(0, 51, 0, 51)) ) persp(f2) # Looks reasonable to my eye anyway. -- David. The reason I don’t want to use sampling (with replacement, I can sample more data than I have without replacement), as this will generate lots of duplicate data points, if I want to generated bigger dataset yet my raw data do not have a big sample size. The scatter plot of the sampled data doesn’t look good this way. Heyi --- On Fri, 3/23/12, David Winsemius wrote: From: David Winsemius Subject: Re: [R] Nonparametric bivariate distribution estimation and sampling To: "heyi xiao" Cc: "Sarah Goslee" , r-help@r-project.org Date: Friday, March 23, 2012, 2:20 PM On Mar 23, 2012, at 1:53 PM, heyi xiao wrote: Sarah, Thanks for the response. I actually have several years of working experience with R and statistics, although may not be as good as you. that’s why I am here ;) I dug deeper into R documentations and previous R-help posts, and couldn’t found anything particular help. Again, I want to do two things: (1) estimate the probability density of this bivariate distribution using some nonparametric method (kernel, spline etc); ?MASS::kde2d ?KernSmooth::bkde2D ?ade4::s.kde2d help(package=locfit) (2) sample a big dataset from this bivariate distribution for a simulation study. What is wrong with `sample`? # to get sample of size n without replacement set.seed(42) dfrm[ sample(1:NROW(dfrm), n) , ] --David. If my questions are not clear enough show my how I can improve, or which part is not clear enough. If you have any particular suggestions/comments, you are more than welcome. Thanks! Heyi --- On Fri, 3/23/12, Sarah Goslee wrote: From: Sarah Goslee Subject: Re: [R] Nonparametric bivariate distribution estimation and sampling To: "heyi xiao" Cc: r-help@r-project.org Date: Friday, March 23, 2012, 12:26 PM R can do all of that and more. But you'll need to put some work in reading about how to use R, about the statistical methods involved, and about how to use them to best effect. You might want, for instance, generalized additive models. Or not. If your question isn't more fully-formed than this, your best bet is almost certainly to talk to a local statistician, spend some time working with R, and then come back to the list with specific questions. Sarah On Fri, Mar 23, 2012 at 12:17 PM, heyi xiao wrote: Dear all, I have a bivariate dataset from a preliminary study. I want to do two things: (1) estimate the probability density of this bivariate distribution using some nonparametric method (kernel, spline etc); (2) sample a big dataset from this bivariate distribution for a simulation study. Is there any good method or package I can use in R for my work? I don’t want parametric models like bivariate normal distribution etc, as I would like to accurate model my data. I don’t want to use the bootstrapping approach, i.e. sampling with replacement, as this will generate lots of duplicate data points. Any thoughts or input will be highly appreciated! Heyi --Sarah Goslee http://www.functionaldiversity.org __
Re: [R] How to draw table in Latex without using xtable?
You can use xtable() or latex() and then edit the columns names in the generated .tex file. That is a much better plan than reinventing either of those functions. On Thu, Mar 22, 2012 at 3:46 AM, Manish Gupta wrote: > Hi, > > I am working on table suing R and Latex. I am writing .Rnw file first in > which i m reading input file and storing into dataframe. After filtering > certain values from this dataframe. I am planning to display it. I don't > want to use xtable since i need to change column names. > > *Sample .Rnw file* > > @ > <>= > cat("\begin{table}[ht]") > cat("\begin{center}") > cat("\begin{tabular}{lr}") > cat ("\hline") > cat ("& Df & Sum Sq & Mean Sq & F value & Pr($>$F) \\") > cat ("\hline") > cat("block & 5 & 343.29 & 68.66 & 4.45 & 0.0159 \\") > cat ("N & 1 & 189.28 & 189.28 & 12.26 & 0.0044 \\") > cat ("P & 1 & 8.40 & 8.40 & 0.54 & 0.4749 \\") > cat ("K & 1 & 95.20 & 95.20 & 6.17 & 0.0288 \\") > cat ("N:P & 1 & 21.28 & 21.28 & 1.38 & 0.2632 \\") > cat ("N:K & 1 & 33.13 & 33.13 & 2.15 & 0.1686 \\") > cat ("P:K & 1 & 0.48 & 0.48 & 0.03 & 0.8628 \\") > cat ("Residuals & 12 & 185.29 & 15.44 & & \\") > cat ("\hline") > cat("\end{tabular}") > cat("\end{center}") > cat("\end{table}") > @ > > But i am getting error cat("\" not supported. In my case tabular values > are variable. How can i fix my pblm? > > Regards > > -- > View this message in context: > http://r.789695.n4.nabble.com/How-to-draw-table-in-Latex-without-using-xtable-tp4494781p4494781.html > Sent from the R help mailing list archive at Nabble.com. >[[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Memory Utilization on R
Taking a look at your script: there are a some potential optimizations you can do: # Fine poi <- as.character(top.GSM396290) #5000 characters x.data <- h1[,c(1,7:9)] # 485577 obs of 4 variables # Pre-allocate the space x <- vector("list", 485577) # x <- list() # Do the "a" stuff once outside the loop so you aren't doing it 485577 times a <- strsplit(as.character(x.data[, "UCSC_REFGENE_NAME"]), ";") # Lets use an apply statement instead of a for loop # vapply is the fastest since we prespecify the return type. x.data[vapply(a, function(x) any(poi %in% x), logical(1)), ] I think this will do what you wanted (and hopefully much faster) Note that you could probably tune this further but I think this strikes a good balance between clarity and performance (for now) Hope this helps, Michael On Fri, Mar 23, 2012 at 11:52 AM, Kurinji Pandiyan wrote: > > Thank you for the input. > > As it were, I realized that my script is utilizing a lot more memory than > I claimed - it was initially using 3 GB but has gone up to 20.24 active but > 29.63 assigned to the R session. > > The script has run overnight and now I don't think it is active anymore > since I keep getting the error message that I am out of startup disk space > for application memory. > > I am attaching screen shots of my RAM usage distribution (given that there > is no fluctuation in the usage by the R session I believe it is not running > anymore) and of my available HD. > > > > > > Here is my script - > > poi <- as.character(top.GSM396290) #5000 characters > x.data <- h1[,c(1,7:9)] # 485577 obs of 4 variables > head(x.data) > > x <- list() > > for(i in 1:485577){ > a <- as.character(x.data[i, "UCSC_REFGENE_NAME"]) > a <- unlist(strsplit(a, ";")) > if(any(poi %in% a) == TRUE) {x[[i]] <- x.data[i,]} > } > > # this step completed in a few hours > > x <- do.call(rbind, x) # this step has been running overnight and is still > stuck > > Thanks, I really appreciate the help. > Kurinji > > On Thu, Mar 22, 2012 at 10:44 PM, R. Michael Weylandt > wrote: >> >> Well... what makes you think you are hitting memory constraints then? >> If you have significantly less than 3GB of data, it shouldn't surprise >> you if R never needs more than 3GB of memory. >> >> You could just be running your scripts inefficiently...it's an extreme >> example, but all the memory and gigaflopping in the world can't speed >> this up (by much): >> >> for(i in seq_len(1e6)) Sys.sleep(10) >> >> Perhaps you should look into profiling tools or parallel >> computation...if you can post a representative example of your >> scripts, we might be able to give performance pointers. >> >> Michael >> >> On Fri, Mar 23, 2012 at 1:33 AM, Kurinji Pandiyan >> wrote: >> > Yes, I am. >> > >> > Thank you, >> > Kurinji >> > >> > On Mar 22, 2012, at 10:27 PM, "R. Michael Weylandt" >> > wrote: >> > >> >> Use 64bit R? >> >> >> >> Michael >> >> >> >> On Thu, Mar 22, 2012 at 5:22 PM, Kurinji Pandiyan >> >> wrote: >> >>> Hello, >> >>> >> >>> I have a 32 GB RAM Mac Pro with a 2*2.4 GHz quad core processor and >> >>> 2TB >> >>> storage. Despite this having so much memory, I am not able to get R >> >>> to >> >>> utilize much more than 3 GBs. Some of my scripts take hours to run >> >>> but I >> >>> would think they would be much faster if more memory is utilized. How >> >>> do I >> >>> optimize the memory usage on R by my Mac Pro? >> >>> >> >>> Thank you! >> >>> Kurinji >> >>> >> >>> [[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] plot a BARPLOT with sd deviation bar up and down
The discussion here is likely to be helpful: https://stat.ethz.ch/pipermail/r-help/2011-February/269185.html as is: http://www.rseek.org/?cx=010923144343702598753%3Aboaz1reyxd4&q=barplot+error+bars&sa=Search+functions%2C+lists%2C+and+more&cof=FORID%3A11&siteurl=www.rseek.org%2F&ref= Beyond that, it isn't clear to me that your question is not homework-related. Sarah On Fri, Mar 23, 2012 at 4:11 PM, gianni lavaredo wrote: > dear Researchers, > > i am looking for a function to plot a barplot for each mean value and the > related standard deviation, and i can close my week. This is an example of > my data set. > > really Thanks in advance for any help or suggestions > > Gianni > > > My.mean <- data.frame(Mean=c(0.4108926,0.3949009,0.4520346, > 0.4091665,0.4664066,0.3048296,0.4297226,0.4056383, > 0.4127453,0.3568891,0.3933964,0.3892999,0.4052982, > 0.377359,0.3831106,0.4248397,0.4403693,0.9389882)) > > My.SD <- data.frame(SD = c(0.3225084,0.3756248,0.3708947, > 0.2899242,0.394396,0.4920173,0.2674820,0.3233239,0.2913170, > 0.4542726,0.4031899,0.2893581,0.403938,0.3686252,0.4014624, > 0.4105261,0.2811270,0.4088456,0.4889143,0.3949252,1.338804)) > -- 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] "source" option
Dear R experts---has someone written a wrapper for the "source" function that opens a sink file in the same name as the .R file and closes it at the end (including when there is an error that aborts)? the first part is easy, but I am not sure how to not patch myself an empty sink() after any R program print/abort sequences have played out. besides, "sink=TRUE, split=TRUE" could be a nice additional option to "source". sincerely, /iaw Ivo Welch (ivo.we...@gmail.com) [[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] plot a BARPLOT with sd deviation bar up and down
Hello, I think there's no function in R to print error bars. I once found one in a blog which I'm using. errorbar <- function(x, y, upper, lower=upper, length=0.02, vert=TRUE, ...){ if(!doPlot) return() if(length(x) != length(y) | length(y) !=length(lower) | length(lower) != length(upper)) stop("vectors must be same length") if(vert){ arrows(x, y+upper, x, y-lower, angle=90, code=3, length=length, ...) }else{ arrows(x+upper, y, x-upper, y, angle=90, code=3, length=length, ...) } } Regards! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] plot a BARPLOT with sd deviation bar up and down
dear Researchers, i am looking for a function to plot a barplot for each mean value and the related standard deviation, and i can close my week. This is an example of my data set. really Thanks in advance for any help or suggestions Gianni My.mean <- data.frame(Mean=c(0.4108926,0.3949009,0.4520346, 0.4091665,0.4664066,0.3048296,0.4297226,0.4056383, 0.4127453,0.3568891,0.3933964,0.3892999,0.4052982, 0.377359,0.3831106,0.4248397,0.4403693,0.9389882)) My.SD <- data.frame(SD = c(0.3225084,0.3756248,0.3708947, 0.2899242,0.394396,0.4920173,0.2674820,0.3233239,0.2913170, 0.4542726,0.4031899,0.2893581,0.403938,0.3686252,0.4014624, 0.4105261,0.2811270,0.4088456,0.4889143,0.3949252,1.338804)) [[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 wireframe outer box but keep ticks
ilai/keren: Thanks for your response. It's not the 3d bounding box that I wish to eliminate, but the box that surrounds the whole figure and is drawn automatically (I call this the outer box, in contrast to the inner, 3d bounding box). The ticks attached to the bounding box are connected, in the software, to the outer box. I'm assembling a number of these graphs on one page, and the outer box makes the whole figure look clunky. Lattice is an incredible piece of software! but these small details can be difficult to nail down. --Seth -Original Message- From: ila...@gmail.com [mailto:ila...@gmail.com] On Behalf Of ilai Sent: Friday, March 23, 2012 11:10 AM To: Bigelow, Seth W -FS Cc: r-help@r-project.org Subject: Re: [R] Remove wireframe outer box but keep ticks See 'box.3d' in trellis.par.get() : wireframe(z ~ x*y, data = test, scales=list(arrows=F), par.settings = list(box.3d = list(col=NA))) Note you can have some finer control: wireframe(z ~ x*y, data = test, scales=list(arrows=F), par.settings = list(box.3d = list(col=c(1,2,NA,NA,3,NA,4,5,6))) ) Hope this helps On Fri, Mar 23, 2012 at 3:59 AM, Bigelow, Seth W -FS wrote: > I would like to eliminate the outer box around a lattice wireframe > graph, but the usual recommended solution, which is to assign a color of > 'transparent' to the axis.line parameter, eliminates ticks if the 'arrows=F' > command is used, as shown in the following example: > > test = data.frame(expand.grid(c(1:10), c(1:10))) z = test[,1] + > test[,2] test = cbind(test, z) > names(test) = c("x", "y", "z") > require(lattice) > wireframe(z ~ x*y, data = test, > scales=list(arrows=F), > par.settings = list(axis.line = list(col = "transparent")), > ) > > Is there a way to eliminate the box but keep the ticks? > > > Seth W. Bigelow, Ph.D. > Research Ecologist > USDA-FS Pacific Southwest Research Station > Ph: (802)-379-3444 > > > > > > This electronic message contains information generated by the USDA solely for > the intended recipients. Any unauthorized interception of this message or the > use or disclosure of the information it contains may violate the law and > subject the violator to civil or criminal penalties. If you believe you have > received this message in error, please notify the sender and delete the email > immediately. > > [[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] How to draw table in Latex without using xtable?
I don't know xtable but you could try escaping the backslashes in your strings. cat("\\begin{table}[ht]") etc. Regards! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Nonparametric bivariate distribution estimation and sampling
David, Thanks a lot for the specific suggestions. That’s very helpful. My question 1 is fully answered now. I guess I am not clear enough for my question 2. I would like to generate a random sample using the estimated probability density (as a result of my question 1) as the reference distribution. Say, I get a matrix of the estimated density (at some grid points) using MASS::kde2d. How can I use that result as a reference distribution to sample data from? I know it is a trivial issue for parametric distributions like bivariate normal, but what about such a nonparametric bivariate reference distribution? Any particular procedures or functions I can use? The reason I don’t want to use sampling (with replacement, I can sample more data than I have without replacement), as this will generate lots of duplicate data points, if I want to generated bigger dataset yet my raw data do not have a big sample size. The scatter plot of the sampled data doesn’t look good this way. Heyi --- On Fri, 3/23/12, David Winsemius wrote: > From: David Winsemius > Subject: Re: [R] Nonparametric bivariate distribution estimation and sampling > To: "heyi xiao" > Cc: "Sarah Goslee" , r-help@r-project.org > Date: Friday, March 23, 2012, 2:20 PM > > On Mar 23, 2012, at 1:53 PM, heyi xiao wrote: > > > Sarah, > > Thanks for the response. I actually have several years > of working experience with R and statistics, although may > not be as good as you. that’s why I am here ;) I dug > deeper into R documentations and previous R-help posts, and > couldn’t found anything particular help. Again, I want to > do two things: (1) estimate the probability density of this > bivariate distribution using some nonparametric method > (kernel, spline etc); > > ?MASS::kde2d > ?KernSmooth::bkde2D > ?ade4::s.kde2d > help(package=locfit) > > > (2) sample a big dataset from this bivariate > distribution for a simulation study. > > What is wrong with `sample`? > > # to get sample of size n without replacement > set.seed(42) > dfrm[ sample(1:NROW(dfrm), n) , ] > > --David. > > If my questions are not clear enough show my how I can > improve, or which part is not clear enough. If you have any > particular suggestions/comments, you are more than welcome. > Thanks! > > Heyi > > > > > > --- On Fri, 3/23/12, Sarah Goslee > wrote: > > > >> From: Sarah Goslee > >> Subject: Re: [R] Nonparametric bivariate > distribution estimation and sampling > >> To: "heyi xiao" > >> Cc: r-help@r-project.org > >> Date: Friday, March 23, 2012, 12:26 PM > >> R can do all of that and more. > >> > >> But you'll need to put some work in reading about > how to use > >> R, about > >> the statistical methods involved, and about how to > use them > >> to best > >> effect. You might want, for instance, generalized > additive > >> models. Or > >> not. If your question isn't more fully-formed than > this, > >> your best bet > >> is almost certainly to talk to a local > statistician, spend > >> some time > >> working with R, and then come back to the list > with > >> specific > >> questions. > >> > >> Sarah > >> > >> On Fri, Mar 23, 2012 at 12:17 PM, heyi xiao > >> wrote: > >>> Dear all, > >>> I have a bivariate dataset from a preliminary > study. I > >> want to do two things: (1) estimate the probability > density > >> of this bivariate distribution using some > nonparametric > >> method (kernel, spline etc); (2) sample a big > dataset from > >> this bivariate distribution for a simulation > study. > >>> Is there any good method or package I can use > in R for > >> my work? I don’t want parametric models like > bivariate > >> normal distribution etc, as I would like to > accurate model > >> my data. I don’t want to use the bootstrapping > approach, > >> i.e. sampling with replacement, as this will > generate lots > >> of duplicate data points. Any thoughts or input > will be > >> highly appreciated! > >>> Heyi > >>> > >>> > >> > >> --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. > > 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 write and analyze data with 3 dimensions
You could put this data into a 3 dimensional array and then use the apply function to apply a function (such as mean) over which ever variables you choose. Or you could put the data into a data frame in long format where you have your 3 variable indices in 3 columns, then the data in a 4th column. Then use the tapply function to apply the mean (or other function) to groups based on the indices of choice. If you want to do fancier things in either case then look into the reshape2 and plyr packages for ways of shaping the data and taking the data apart into pieces, apply a function to each piece, then put it all back together again. On Tue, Mar 20, 2012 at 11:16 AM, jorge Rogrigues wrote: > Suppose I have data organized in the following way: > (P_i, M_j, S_k) > > where i, j and k and indexes for sets. > I would like to analyze the data to get for example the following > information: > what is the average over k for > (P_i, M_j) > or what is the average over j and k for P_i. > > My question is what would be the way of doing this in R. > Specifically how should I write the data in a csv file > and how do I read the data from the csv file into R and perform these basic > operations. > > Thank you. > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gregory (Greg) L. Snow Ph.D. 538...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Memory limits for MDSplot in randomForest package
Hello, I am struggling to produce an MDS plot using the randomForest package with a moderately large data set. My data set has one categorical response variables, 7 predictor variables and just under 19000 observations. That means my proximity matrix is approximately 133000 by 133000 which is quite large. To train a random forest on this large a dataset I have to use my institutions high performance computer. Using this setup I was able to train a randomForest with the proximity argument set to TRUE. At this point I wanted to construct an MDSplot using the following: MDSplot(nech.rf, nech.d$pd.fl, palette=c(1,2,3), pch=as.numeric(nech.d$pd.fl)) where "nech.rf" is the randomForest object and "nech.d$pd.fl" is the classification factor. Now with the architecture listed below, I've been waiting for approximately 2 days for this to run. My issue is that I am not sure if this will ever run. Can anyone recommend a way to tweak the MDSplot function to run a little faster? I tried changing the cmdscale arguments (i.e. eigenvalues) within the MDSplot function a little but that didn't seem to have any effect of the overall running time using a much smaller data set. Or even if someone could comment whether I am dreaming that this will actually ever run? This is probably the best computer that I will have access to so I was hoping that somehow I could get this to run. I was just hoping that someone reading the list might have some experience with randomForests and using large datasets and might be able to comment on my situation. Below the architecture information I have constructed a dummy example to illustrate what I am doing but given the nature of the problem, this doesn't completely reflect my situation. Any help would be much appreciated! Thanks! Sam Computer specs and sessionInfo() OS: Suse Linux Memory: 64 GB Processors: Intel Itanium 2, 64 x 1500 MHz And: > sessionInfo() R version 2.6.2 (2008-02-08) ia64-unknown-linux-gnu locale: LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] randomForest_4.6-6 loaded via a namespace (and not attached): [1] rcompgen_0.1-17 ### # Dummy Example ### require(randomForest) set.seed(17) ## Number of points x <- 10 df <- rbind( data.frame(var1=runif(x, 10, 50), var2=runif(x, 2, 7), var3=runif(x, 0.2, 0.35), var4=runif(x, 1, 2), var5=runif(x, 5, 8), var6=runif(x, 1, 2), var7=runif(x, 5, 8), cls=factor("CLASS-2") ) , data.frame(var1=runif(x, 10, 50), var2=runif(x, -3, 3), var3=runif(x, 0.1, 0.25), var4=runif(x, 1, 2), var5=runif(x, 5, 8), var6=runif(x, 1, 2), var7=runif(x, 5, 8), cls=factor("CLASS-1") ) ) df.rf<-randomForest(y=df[,8],x=df[,1:7], proximity=TRUE, importance=TRUE) MDSplot(df.rf, df$cls, k=2, palette=c(1,2,3,4), pch=as.numeric(df$cls)) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with R package forecast
On Mar 23, 2012, at 8:47 AM, jason wrote: When I type library() to see what is installed the following list in RED comes up. Packages in library '/home/jason/R/i686-pc-linux-gnu-library/2.13': This suggests you are using an old copy of R. Many time the current repository will only be serving packages for the current version of R and you will need to locate an archived package if you are for some reason reluctant to upgrade. abind Combine multi-dimensional arrays aplpack Another Plot PACKage: stem.leaf, bagplot, snipped useless list. It doesn't matter much what packages you have installed as far as what appears on that pick-list, although I do see upon updating package::forecast that it also installed Rcpp_0.9.10.tgz' and RcppArmadillo_0.2.36.tgz' When I type install.packages(), select the mirror, the following list of packages appears but the package FORECAST is not listed Please see attchament http://r.789695.n4.nabble.com/file/n4498680/08.png Well, it would not have been spelled that way, but it's either not in that repository (which you didn't tell us) or it's not available for your R version and OS combination (which I guess you did tell us.) -- 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] Append to files in loop
On Mar 23, 2012, at 2:19 PM, Luisin Galindo, PhD wrote: Hi ReXperts, I have a file 'XFile' In your R workspace or not? Will assume this is an R dataframe. With the same number of columns as the files to be updated? Will assume that the number of columns is the same and that you also want row.names. What about separators? Will assume commas for purposes of example. that I wish to append to the end of file1, file2, file3, file4, and file 5. Can't figure out how to set up the loop. Please help. for (i in c("file1", 'file2', 'file3', 'file4', 'file 5') ){ write.table( Xfile, file=i, sep="," , colnames=FALSE, append=TRUE) } [[alternative HTML version deleted]] Please post in plain text. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] trouble for parsing HTML files
Le vendredi 23 mars 2012 à 08:10 +0100, Julien Velcin a écrit : > Here it is: > > R version 2.14.2 (2012-02-29) > Platform: i386-apple-darwin9.8.0/i386 (32-bit) > > locale: > [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 I guess the OS uses a French locale? Maybe the discrepancy between R locale and the OS's is the problem. Can you try with a French locale? This would be strange, because UTF-8 should be the same in both settings, but still worth a try... Else, please do this and post the output, just in case: url <- "http://www.huffingtonpost.com/social/GraniteSkyline?action=fans"; lines <- readLines(url) head(lines) library(tools) showNonASCII(head(lines)) Hope this helps __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Rcmd build -binary -- problem
On 23-03-2012, at 18:43, Stephen Eick wrote: > . > I don't understand your comment about "you explicitly asked not to > send HTML, as you always were..." Is this in regards to using gmail?? > No. It means please configure your mail client to send mail in plain text. Please do not send in html format. When one receives mail fro R-help you can see this message (at least I can) >>> >>>[[alternative HTML version deleted]] >>> R-help doesn't want an HTML version. Berend __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to convert factors to numbers
On Mar 23, 2012, at 9:38 AM, sandro wrote: Hello, I am relatively new to using R. The text file contains the date and price . I want to read and manipulate the data in R. However, when I use read.table, it treats all of the data as "factors" and I do not know how to treat the data as numbers: http://r.789695.n4.nabble.com/file/n4498828/p_diarios.txt p_diarios.txt setwd ("C:\\Users\\Sandro\\Dropbox\\R") data.precios <- read.table ("p_diarios.txt ", header =TRUE , dec=",", sep="\t") Why are you using dec="," when you have decimal points in the file? Time <- data.precios$time # 01.02.2004 - 12.05.2011 Price <- data.precios$price # Historical spot price log.Price <- log(data.precios$price) Error en Math.factor(c(12L, 126L, 213L, 342L, 160L, 186L, 219L, 37L, 54L, : log not meaningful for factors As you can see, I cannot calculate the price logarithms. You could read the FAQ on this matter ... number 7.21 or in that general vicinity. But it would be easier to fix the error in your input statement. -- 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 convert digits to specified decimal vectors
format sprintf Michael On Fri, Mar 23, 2012 at 8:16 AM, sagarnikam123 wrote: >> x > [1] 7 8 9 10 11 12 > > convert such that > > 7. > 8. > 9. > 10.000 > 11.000 > 12.000 > > total size of 5 digits for each value > > > -- > View this message in context: > http://r.789695.n4.nabble.com/how-to-convert-digits-to-specified-decimal-vectors-tp4498588p4498588.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] Rcmd build -binary -- problem
On Mar 23, 2012, at 1:43 PM, Stephen Eick wrote: Nope. I tried -- too. I tried many other variations too. Any suggestions? R>Rcmd build --binary thinc Rcmd build --binary thinc Warning: unknown option '--binary' * checking for file 'thinc/DESCRIPTION' ... OK * preparing 'thinc': * checking DESCRIPTION meta-information ... OK * cleaning src * checking for LF line-endings in source and make files * checking for empty or unneeded directories Removed empty directory 'thinc/data' * building 'thinc_1.0.tar.gz' I don't understand your comment about "you explicitly asked not to send HTML, as you always were..." Is this in regards to using gmail?? It is in regards to your not using gmail properly. -- David. On Thu, Mar 22, 2012 at 5:01 PM, Prof Brian Ripley wrote: On 22/03/2012 17:33, Stephen Eick wrote: Hi. I need a bit of help. I'm running Windows 7 and "out of the box" versions of Rtools and R (version 2.14.2) and am trying to compile a package that worked before. When I run the command: Rcmd build -binary mypackage Warning: unknown option '-binary' i get a warning and it creates the tar.gz file but not the zip file like before. Something has changed with the more recent versions of R. Any suggestions on how to make the .zip file? Nothing has changed. It is --binary (two hyphens) as it always was (and you explicitly asked not to send HTML, as you always were). [[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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to convert factors to numbers
On 23.03.2012 15:31, chuck.01 wrote: Using your posed data, the variable price was numeric: data.precios<- read.table("http://r.789695.n4.nabble.com/file/n4498828/p_diarios.txt";, header=T) str(data.precios) 'data.frame': 1996 obs. of 2 variables: $ time : int 37988 37991 37993 37994 37995 37998 37999 38000 38001 38002 ... $ price: num 18.1 26.1 30.9 34.7 27.6 ... HOWEVER! If I follow your code (eg. using " read.table(... , dec=",", sep="\t")": data.precios<- read.table("http://r.789695.n4.nabble.com/file/n4498828/p_diarios.txt";, header =TRUE , dec=",", sep="\t") str(data.precios) 'data.frame': 1996 obs. of 2 variables: $ time : int 37988 37991 37993 37994 37995 37998 37999 38000 38001 38002 ... $ price: Factor w/ 1639 levels "10.80","12.53",..: 12 126 213 342 160 186 219 37 54 69 ... It is a factor but I can change it like this: Price<- as.numeric(data.precios$price) Never ever! It will convertwed to the intergers representing the former factors. You probbaly want as.numeric(as.character(...)) and have to look why R has not read it as a numeric right away. Uwe Ligges str(lPrice) num [1:1996] 12 126 213 342 160 186 219 37 54 69 ... I think avoiding it ever becoming a factor would be the better path. Good luck. sandro wrote Hello, I am relatively new to using R. The text file contains the date and price . I want to read and manipulate the data in R. However, when I use read.table, it treats all of the data as "factors" and I do not know how to treat the data as numbers: http://r.789695.n4.nabble.com/file/n4498828/p_diarios.txt p_diarios.txt setwd ("C:\\Users\\Sandro\\Dropbox\\R") data.precios<- read.table ("p_diarios.txt ", header =TRUE , dec=",", sep="\t") Time<- data.precios$time # 01.02.2004 - 12.05.2011 Price<- data.precios$price # Historical spot price log.Price<- log(data.precios$price) Error en Math.factor(c(12L, 126L, 213L, 342L, 160L, 186L, 219L, 37L, 54L, : log not meaningful for factors As you can see, I cannot calculate the price logarithms. Any help is appreciated. Sandro -- View this message in context: http://r.789695.n4.nabble.com/How-to-convert-factors-to-numbers-tp4498828p4499019.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] Rcmd build -binary -- problem
On 23.03.2012 18:43, Stephen Eick wrote: Nope. I tried -- too. I tried many other variations too. Any suggestions? R>Rcmd build --binary thinc Rcmd build --binary thinc Warning: unknown option '--binary' * checking for file 'thinc/DESCRIPTION' ... OK * preparing 'thinc': * checking DESCRIPTION meta-information ... OK * cleaning src * checking for LF line-endings in source and make files * checking for empty or unneeded directories Removed empty directory 'thinc/data' * building 'thinc_1.0.tar.gz' Brian Ripley was probably confused by the obvious typo you had in your first request. R CMD build --binary is defunct nowadays, please use, as suggested for many many years: R CMD INSTALL --build in order to produce Windows binaries. Best, Uwe Ligges I don't understand your comment about "you explicitly asked not to send HTML, as you always were..." Is this in regards to using gmail?? On Thu, Mar 22, 2012 at 5:01 PM, Prof Brian Ripley wrote: On 22/03/2012 17:33, Stephen Eick wrote: Hi. I need a bit of help. I'm running Windows 7 and "out of the box" versions of Rtools and R (version 2.14.2) and am trying to compile a package that worked before. When I run the command: Rcmd build -binary mypackage Warning: unknown option '-binary' i get a warning and it creates the tar.gz file but not the zip file like before. Something has changed with the more recent versions of R. Any suggestions on how to make the .zip file? Nothing has changed. It is --binary (two hyphens) as it always was (and you explicitly asked not to send HTML, as you always were). [[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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] R conditional matrix operations - advanced condition
On 23-03-2012, at 17:29, Lukasz Kielpinski wrote: > Hello List! > > I stumbled across an efficiency problem - calculation that would be > probably done very fast as a matrix operation I must perform as a > for-loop. > My intention was to do a conditional operation in matrix depending on > the information in first column (summing as many data points from > vector my_data as the number specified in the first column of the > matrix) but the result is that the function takes the condition only > from the first row of column for calculations in every row. > Is it possible to solve this problem as a matrix calculation or I have > to iterate over each row? (which I suppose is much slower) > > #problem looks like: > my_mat <- matrix(1:50,ncol=2) > my_mat <- cbind(my_mat,0) #here I have a matrix with empty third > column where I want to store my results > my_data <- rnorm(25) #this is a dataset I want to use for filling the > third column > #and I did > my_mat[,3] <- sum(my_data[1:my_mat[,1]]) + my_mat[,2] > #which didn't work as I expected If I understand that this correctly I think you should do this my_data.csum <- cumsum(my_data) my_mat[,3] <- my_data.csum[my_mat[,1]] + my_mat[,2] Berend __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] julian() and numerical noise
On 23.03.2012 15:45, Andreas Eckner wrote: Hi, does anybody know if the following behavior of julian() is intentional? > julian(2, 1, 2012) - julian(2 - 1e-15, 1, 2012) [1] 1 > julian(2, 1, 2012) - julian(2, 1 - 1e-15, 2012) [1] 0 > julian(2, 1, 2012) - julian(2, 1, 2012 - 1e-15) [1] 0 In other words, julian() is subject to numerical noise in the 'day' argument, but not in the 'month' and 'year' argument? Another example: > julian(2 - 1e-15, 1, 2012) - julian(1 - 1e-15, 1, 2012) [1] 30 Which vbersion of R are you talking about? I get: > julian(2, 1, 2012) - julian(2 - 1e-15, 1, 2012) Error in UseMethod("julian") : no applicable method for 'julian' applied to an object of class "c('double', 'numeric')" Uwe Ligges Thanks, Andreas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with R package forecast
On 23.03.2012 13:47, jason wrote: When I type library() to see what is installed the following list in RED comes up. Packages in library '/home/jason/R/i686-pc-linux-gnu-library/2.13': abind Combine multi-dimensional arrays aplpack Another Plot PACKage: stem.leaf, bagplot, faces, spin3R, and some slider functions biglm bounded memory linear and generalized linear models DBI R Database Interface forensimStatistical tools for the interpretation of forensic DNA mixtures leaps regression subset selection quadprogFunctions to solve Quadratic Programming Problems. RSQLite SQLite interface for R RUnit R Unit test framework tseries Time series analysis and computational finance zoo S3 Infrastructure for Regular and Irregular Time Series (Z's ordered observations) Packages in library '/usr/lib/R/site-library': abind Combine multi-dimensional arrays car Companion to Applied Regression chron Chronological objects which can handle dates and times colorspace Color Space Manipulation effects Effect Displays for Linear, Generalized Linear, Multinomial-Logit, and Proportional-Odds Logit Models Hmisc Harrell Miscellaneous lmtest Testing Linear Regression Models multcompSimultaneous Inference in General Parametric Models mvtnorm Multivariate Normal and t Distributions Rcmdr R Commander relimp Relative Contribution of Effects in a Regression Model rgl 3D visualization device system (OpenGL) rkward Provides some helper functions for the RKWard frontend rkwardtests RKWard Plugin Test Suite Framework sandwichRobust Covariance Matrix Estimators sm Smoothing methods for nonparametric regression and density estimation strucchange Testing, Monitoring and Dating Structural Changes zoo S3 Infrastructure for Regular and Irregular Time Series (Z's ordered observations) Packages in library '/usr/lib/R/library': baseThe R Base Package bootBootstrap Functions (originally by Angelo Canty for S) class Functions for Classification cluster Cluster Analysis Extended Rousseeuw et al. codetools Code Analysis Tools for R compilerThe R Compiler Package datasetsThe R Datasets Package foreign Read Data Stored by Minitab, S, SAS, SPSS, Stata, Systat, dBase, ... graphicsThe R Graphics Package grDevices The R Graphics Devices and Support for Colours and Fonts gridThe Grid Graphics Package KernSmooth Functions for kernel smoothing for Wand& Jones (1995) lattice Lattice Graphics MASSSupport Functions and Datasets for Venables and Ripley's MASS Matrix Sparse and Dense Matrix Classes and Methods methods Formal Methods and Classes mgcvGAMs with GCV/AIC/REML smoothness estimation and GAMMs by PQL nlmeLinear and Nonlinear Mixed Effects Models nnetFeed-forward Neural Networks and Multinomial Log-Linear Models rpart Recursive Partitioning spatial Functions for Kriging and Point Pattern Analysis splines Regression Spline Functions and Classes stats The R Stats Package stats4 Statistical Functions using S4 Classes survivalSurvival analysis, including penalised likelihood. tcltk Tcl/Tk Interface tools Tools for Package Development utils The R Utils Package When I type install.packages(), select the mirror, the following list of packages appears but the package FORECAST is not listed Please see attchament http://r.789695.n4.nabble.com/file/n4498680/08.png Any suggestions ? Yes, see http://cran.r-project.org/web/packages/forecast/index.html and find the current forecast version depends on R >= 2.14.0 wh
[R] Append to files in loop
Hi ReXperts, I have a file 'XFile' that I wish to append to the end of file1, file2, file3, file4, and file 5. Can't figure out how to set up the loop. Please help. Thank you, -- Luisin Galindo, PhD Director, Departamento de Medicina Matematica Centro de Estudios Avansados en Simulacion, Analysis, y Modelacion Puerto Castilla, Spanish Honduras Centro America [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] FW: fdp and Rgraphviz
1. Why do you ask here rather than the author of thr webpage? 2. Reading the comments suggests you are lacking a graphviz installation that includes the fdp command. Uwe Ligges On 23.03.2012 13:09, Heba S wrote: Hello, I am beginner user of R. I am trying to use GeneNet package. I started by the example on this link: http://strimmerlab.org/software/genenet/download/arabidopsis-net.R However I am getting an error at this line:system("fdp -T svg -o arthdyn.svg arthdyn.dot") # SVG format sh: fdp: command not found I tried to search how to intall the fdp command but could not find explanation. I am running my code on Rstudio .95.263 and Mac OS X 10.6.8 Can you please help me to solve this problem or is there is another way to visualize the network Thanks, H [[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] svycoxph and test statistics
Hello, I have been using the function 'svycoxph' in the Dr. Lumley's survey package (version 3.26) to compute coefficient estimates for Cox regression. I have noticed the p-values output are based on normal distribution (like in coxph); however in svyglm (and in other software, such as Stata or SAS) the p-values are computed via the t distribution with degrees of freedom equal to the number of PSUs minus number of strata. I am wondering why there is a difference here? Thank you very much, Chirag Patel Stanford University c...@stanford.edu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] predict () for LDA and GLM
1. Not reproducible for me (gives an ERROR). 2. Please try to make examples "minimal", as the psoting guide suggests. 3. Please follow my advice and provide "A correct formula describing the model with separate variables with the data.frame passed to the data argument of the lda() function." That means like: lda(Species ~ Sepal.Length, data=iris) and the same for predict() afterwards. Best, Uwe Ligges On 22.03.2012 14:02, palanski wrote: Here is the full code. Look to the last part, denoted #(f) for the question being asked in this post: #(a) Split datapoints into training (70 points) and test (30 points) sets. #Read in ass4-data.txt and ass3-phodata.txt ass4data = read.delim('http://www.moseslab.csb.utoronto.ca/alan/ass4-data.txt', header = FALSE, sep = "\t") #Separate all positive and negative hits ass4q1.neg = ass4data[which(ass4data[,1] == 0),] ass4q1.pos = ass4data[which(ass4data[,1] == 1),] #Reset row names rownames(ass4q1.neg) = NULL rownames(ass4q1.pos) = NULL #Sample 70% (35 out of 50 in each positive/negative set) for training set, rest for testing set ass4q1.negRid = sample(1:nrow(ass4q1.neg),floor(0.7*nrow(ass4q1.neg))) ass4q1.posRid = sample(1:nrow(ass4q1.pos),floor(0.7*nrow(ass4q1.pos))) #Combine negative and positive values from each data set to create training and testing arrays ass4q1.trainSet = as.matrix(rbind(ass4q1.neg[ass4q1.negRid,], ass4q1.pos[ass4q1.posRid,])) ass4q1.testSet = rbind(ass4q1.neg[-(ass4q1.negRid),],ass4q1.pos[-(ass4q1.posRid),]) #Reset row names rownames(ass4q1.trainSet) = NULL rownames(ass4q1.testSet) = NULL ass4q1.trainSetDF = as.data.frame(ass4q1.trainSet) ass4q1.trainSetDF$V1 = factor(ass4q1.trainSetDF$V1) ass4q1.testSetDF = as.data.frame(ass4q1.testSet) ass4q1.testSetDF$V1 = factor(ass4q1.testSetDF$V1) ## #(b)Load MASS, e1071 and glmnet library(MASS) library(e1071) library(glmnet) # #(c)How many features does the data contain? #The data contains 32 features (columns of data) # #(d)How does the number of parameters required for Naïve Bayes, LDA, and Logistic #Regression (unregularized) scale as a function of the number of features? #If Y is binary with features, then the number of parameters is P(Y). #NaiveBayes #P(Y) = p • (mew(Y=1), mew(Y=0), sigma(Y=1), sigma(Y=0)) # = 1 + 4p #Linear Discriminant Analysis #Have to estimate one covariance matrix and p mean values for each class. #To compute the covariance matrix is p x p, but since the upper or lower halfsymetrical, we disregard half, but include the #middle diagonal by multiplying p x (p + 1) and dividing by 2. #Calculating p mean values for each class is 2p (2 classes of binary Y). #Thus: P(Y) = (p(p + 1) / 2) + 2p #Logistic Regression #P(Y) = 1 + p #To plot the relationship: ass4q1.dVS= matrixmatrix(,ncol(ass4q1.trainSet)-1,3) for (p in 1:ncol(ass4q1.trainSet)-1){ ass4q1.dVS[p,1] = (1 + (4*p)) ass4q1.dVS[p,2] = ((p *(p + 1) / 2) + 2*p) ass4q1.dVS[p,3] = (1 + p) } png('ass4q1.dVS.png') plot(ass4q1.dVS[,2], type="o", col="blue",ylim=c(0,max(ass4q1.dVS)), ann=FALSE) lines(ass4q1.dVS[,1], type="o", pch=22, lty=2, col="red") lines(ass4q1.dVS[,3], type="o", pch=23, lty=3, col="green") title(main = "Number of parameters as a function of features", col.main="red", font.main=4) title(xlab= "Features", col.lab="red") title(ylab= "Parameters", col.lab="red") legend(1, max(ass4q1.dVS), c("LDA", "Naive Bayes", "Logistic Regression"), cex=0.8, col=c("blue","red","green"), pch=21:23, lty=1:3) dev.off() # #(e)Train Naïve Bayes, LDA and Logistic Regression to classify the training data #using the first two, four, eight, 16 or 32 features, starting from the left of the file. Plot #the classification error (FP + FN)/(TP+FP+TN+FN) on the training data as a function #of the number of parameters for each method. #Contingency table organized as: #TN FN #FP TP #Organize tables to store data: ass4q1.dNBtable = matrix(,5,2) ass4q1.dLDAtable = matrix(,5,2) ass4q1.dGLMtable = matrix(,5,2) i = 1 for(p in c(2,4,8,16,32)){ ass4q1.dNBtable[i,1] = (1 + (4*p)) ass4q1.dLDAtable[i,1] = ((p *(p + 1) / 2) + 2*p) ass4q1.dGLMtable[i,1] = (1+p) i = i+1 } #Copying blank tables for part (f) ass4q1.dNBtable.testData = ass4q1.dNBtable ass4q1.dLDAtable.testData = ass4q1.dLDAtable ass4q1.dGLMtable.testData = ass4q1.dGLMtable # #(e)Train Naïve Bayes, LDA and Logistic Regression to classify the training data #using the first two, four, eight, 16 or 32 features, starting from the left of the file. Plot #the classification error (FP + FN)/(TP+FP+TN+FN) on the training data as a function #of the number of parameters for each method. #Contingency table organized as: #TN FN #FP TP #Organize tables to store data: ass4q1.dNBtable = matrix(,5,2) ass4q1.dLDAtable = matrix(,5,2) ass4q1.dGLMtable = matrix(,5,2) i = 1 for(p in c(2,4,8,16,32)){ ass4q1.dNBtable[i,1] = (1 + (4*p)) ass4q1.dLDAtable[i,1] = ((
Re: [R] How to export hexbin tables?
Michael... It WORKS!!! Finally, the most elegant way was yours: /aux.table <- sapply(.) write.table(aux.table, file="hexbin.table.ascii", sep="\t")/ Thanks! hope be useful to R-users! -- View this message in context: http://r.789695.n4.nabble.com/How-to-export-hexbin-tables-tp4496035p4499568.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] how to cluster rows of words in a text file
Hi: I am trying to cluster the rows of a text file with kmeans: I load the data as follows file1 <- read.csv("somefile.csv") and the file can be viewed having the following line of words > file1 1 word1 word3 word4 word1 2 word1 word4 word3 word1 3 word4 word2 word4 word3 4 word4 word2 word1 word3 5 word2 word2 word4 word2 file_as_matrix <- as.matrix(file1); Now, I want to apply some clustering algorithm such as kmeans to cluster the rows in the file to get the following output: Cluster1 word1 word3 word4 word1 word1 word4 word3 word1 Cluster2 word4 word2 word4 word3 word4 word2 word1 word3 word2 word2 word4 word2 But as kmeans takes as input numeric matrix of data, it cannot be used to cluster the rows in this case. Is there any simple way to cluster the rows of such a text file? An example code would be really useful. Thanks and regards: debb __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 do you scale variables which consist of tokens
Dear All, Let's suppose there's a case when you want to make a prediction using range of variables. Some variables are represented as set of words (tokens). For example there is a training set: x1,x2,..,x7, y where y - to be predicted (despite of the model to be used for prediction), and let's say: x4 - variable which presented as words from google search query (number of words may be different in each observation). For example: x4=(how,grow,tree) and can be presented in hashed form: x4=(1,2,3) I need to scale this variable (x4) to be able to use it in model. I was thinking about scaling it with TF-IDF. In this way I can represent each observation of x4 as a scaled vector with N elements like: x4=(0.0175105020782697,...0.019135397913606) //scaled with TF-IDF However, it still isn't scaled properly (please correct me if I'm wrong) since I need x4 to be presented as INTEGRAL value for each observation to be able to use it in model. I assume the result of scaling should look like: x4=0.06789324432 //integral value Do you have any ideas how to do this? Appreciate for any ideas. -Aleksei [[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] Rcmd build -binary -- problem
Nope. I tried -- too. I tried many other variations too. Any suggestions? R>Rcmd build --binary thinc Rcmd build --binary thinc Warning: unknown option '--binary' * checking for file 'thinc/DESCRIPTION' ... OK * preparing 'thinc': * checking DESCRIPTION meta-information ... OK * cleaning src * checking for LF line-endings in source and make files * checking for empty or unneeded directories Removed empty directory 'thinc/data' * building 'thinc_1.0.tar.gz' I don't understand your comment about "you explicitly asked not to send HTML, as you always were..." Is this in regards to using gmail?? On Thu, Mar 22, 2012 at 5:01 PM, Prof Brian Ripley wrote: > > On 22/03/2012 17:33, Stephen Eick wrote: >> >> Hi. I need a bit of help. I'm running Windows 7 and "out of the box" >> versions of Rtools and R (version 2.14.2) and am trying to compile a >> package that worked before. When I run the command: >> >>> Rcmd build -binary mypackage >>> Warning: unknown option '-binary' >> >> >> i get a warning and it creates the tar.gz file but not the zip file like >> before. Something has changed with the more recent versions of R. Any >> suggestions on how to make the .zip file? > > > Nothing has changed. It is --binary (two hyphens) as it always was (and you > explicitly asked not to send HTML, as you always were). > >> >> [[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. > > > > -- > Brian D. Ripley, rip...@stats.ox.ac.uk > Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ > University of Oxford, Tel: +44 1865 272861 (self) > 1 South Parks Road, +44 1865 272866 (PA) > Oxford OX1 3TG, UK Fax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 convert factors to numbers
Using your posed data, the variable price was numeric: data.precios <- read.table("http://r.789695.n4.nabble.com/file/n4498828/p_diarios.txt";, header=T) str(data.precios) 'data.frame': 1996 obs. of 2 variables: $ time : int 37988 37991 37993 37994 37995 37998 37999 38000 38001 38002 ... $ price: num 18.1 26.1 30.9 34.7 27.6 ... HOWEVER! If I follow your code (eg. using " read.table(... , dec=",", sep="\t")": data.precios <- read.table("http://r.789695.n4.nabble.com/file/n4498828/p_diarios.txt";, header =TRUE , dec=",", sep="\t") > str(data.precios) 'data.frame': 1996 obs. of 2 variables: $ time : int 37988 37991 37993 37994 37995 37998 37999 38000 38001 38002 ... $ price: Factor w/ 1639 levels "10.80","12.53",..: 12 126 213 342 160 186 219 37 54 69 ... It is a factor but I can change it like this: > Price <- as.numeric(data.precios$price) > str(lPrice) num [1:1996] 12 126 213 342 160 186 219 37 54 69 ... I think avoiding it ever becoming a factor would be the better path. Good luck. sandro wrote > > Hello, I am relatively new to using R. > > The text file contains the date and price . I want to read and manipulate > the data in R. However, when I use read.table, it treats all of the data > as "factors" and I do not know how to treat the data as numbers: > > http://r.789695.n4.nabble.com/file/n4498828/p_diarios.txt p_diarios.txt > > setwd ("C:\\Users\\Sandro\\Dropbox\\R") > data.precios <- read.table ("p_diarios.txt ", header =TRUE > , dec=",", sep="\t") > Time <- data.precios$time # 01.02.2004 - 12.05.2011 > Price <- data.precios$price # Historical spot price > log.Price <- log(data.precios$price) > Error en Math.factor(c(12L, 126L, 213L, 342L, 160L, 186L, 219L, 37L, 54L, > : > log not meaningful for factors > > As you can see, I cannot calculate the price logarithms. > > Any help is appreciated. > > Sandro > -- View this message in context: http://r.789695.n4.nabble.com/How-to-convert-factors-to-numbers-tp4498828p4499019.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] How to convert factors to numbers
Hello, I am relatively new to using R. The text file contains the date and price . I want to read and manipulate the data in R. However, when I use read.table, it treats all of the data as "factors" and I do not know how to treat the data as numbers: http://r.789695.n4.nabble.com/file/n4498828/p_diarios.txt p_diarios.txt setwd ("C:\\Users\\Sandro\\Dropbox\\R") data.precios <- read.table ("p_diarios.txt ", header =TRUE , dec=",", sep="\t") Time <- data.precios$time # 01.02.2004 - 12.05.2011 Price <- data.precios$price # Historical spot price log.Price <- log(data.precios$price) Error en Math.factor(c(12L, 126L, 213L, 342L, 160L, 186L, 219L, 37L, 54L, : log not meaningful for factors As you can see, I cannot calculate the price logarithms. Any help is appreciated. Sandro -- View this message in context: http://r.789695.n4.nabble.com/How-to-convert-factors-to-numbers-tp4498828p4498828.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] a question about using function ssanova of package gss in R version 2.14.1 (2011-12-22)
Dear all, I am trying to use ssanova of the gss package but met some error that I cannot figure out the answer for. Here is the code I am using to explain the problem. library(gss) set.seed(5732) x=(1:100)/100 y=1+3*sin(2*pi*x)+2*(x>0.7)+rnorm(x) x1=rnorm(100) x2=rnorm(100) part.fit=ssanova(y~x, partial=~cbind(x1,x2)) summary(part.fit) part.fit=ssanova(y~x, partial=~cbind(as.numeric(x1),x2)) summary(part.fit) Basically this line of code "part.fit=ssanova(y~x, partial=~cbind(x1,x2))" does not run correctly while the following one "part.fit=ssanova(y~x, partial=~cbind(as.numeric(x1),x2))" works. I am not sure why I need to apply "as.numeric" to x1? I appreciate any help you may provide. At the end I copy and paste the error message I got after running the above piece of code. Best, Chris R version 2.14.1 (2011-12-22) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-redhat-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(gss) > > set.seed(5732) > x=(1:100)/100 > y=1+3*sin(2*pi*x)+2*(x>0.7)+rnorm(x) > > > > x1=rnorm(100) > x2=rnorm(100) > > part.fit=ssanova(y~x, partial=~cbind(x1,x2)) > > summary(part.fit) Error in cbind(s, matx.p[, label]) : subscript out of bounds > > part.fit=ssanova(y~x, partial=~cbind(as.numeric(x1),x2)) > > summary(part.fit) Call: ssanova(formula = y ~ x, partial = ~cbind(as.numeric(x1), x2)) Estimate of error standard deviation: 1.138695 Residuals: Min1QMedian3Q Max -2.459471 -0.89 0.161822 0.772589 2.529363 Residual sum of squares: 123.6758 R square: 0.630952 Penalty associated with the fit: 12.70742 > [[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] Help with R package forecast
When I type library() to see what is installed the following list in RED comes up. Packages in library '/home/jason/R/i686-pc-linux-gnu-library/2.13': abind Combine multi-dimensional arrays aplpack Another Plot PACKage: stem.leaf, bagplot, faces, spin3R, and some slider functions biglm bounded memory linear and generalized linear models DBI R Database Interface forensimStatistical tools for the interpretation of forensic DNA mixtures leaps regression subset selection quadprogFunctions to solve Quadratic Programming Problems. RSQLite SQLite interface for R RUnit R Unit test framework tseries Time series analysis and computational finance zoo S3 Infrastructure for Regular and Irregular Time Series (Z's ordered observations) Packages in library '/usr/lib/R/site-library': abind Combine multi-dimensional arrays car Companion to Applied Regression chron Chronological objects which can handle dates and times colorspace Color Space Manipulation effects Effect Displays for Linear, Generalized Linear, Multinomial-Logit, and Proportional-Odds Logit Models Hmisc Harrell Miscellaneous lmtest Testing Linear Regression Models multcompSimultaneous Inference in General Parametric Models mvtnorm Multivariate Normal and t Distributions Rcmdr R Commander relimp Relative Contribution of Effects in a Regression Model rgl 3D visualization device system (OpenGL) rkward Provides some helper functions for the RKWard frontend rkwardtests RKWard Plugin Test Suite Framework sandwichRobust Covariance Matrix Estimators sm Smoothing methods for nonparametric regression and density estimation strucchange Testing, Monitoring and Dating Structural Changes zoo S3 Infrastructure for Regular and Irregular Time Series (Z's ordered observations) Packages in library '/usr/lib/R/library': baseThe R Base Package bootBootstrap Functions (originally by Angelo Canty for S) class Functions for Classification cluster Cluster Analysis Extended Rousseeuw et al. codetools Code Analysis Tools for R compilerThe R Compiler Package datasetsThe R Datasets Package foreign Read Data Stored by Minitab, S, SAS, SPSS, Stata, Systat, dBase, ... graphicsThe R Graphics Package grDevices The R Graphics Devices and Support for Colours and Fonts gridThe Grid Graphics Package KernSmooth Functions for kernel smoothing for Wand & Jones (1995) lattice Lattice Graphics MASSSupport Functions and Datasets for Venables and Ripley's MASS Matrix Sparse and Dense Matrix Classes and Methods methods Formal Methods and Classes mgcvGAMs with GCV/AIC/REML smoothness estimation and GAMMs by PQL nlmeLinear and Nonlinear Mixed Effects Models nnetFeed-forward Neural Networks and Multinomial Log-Linear Models rpart Recursive Partitioning spatial Functions for Kriging and Point Pattern Analysis splines Regression Spline Functions and Classes stats The R Stats Package stats4 Statistical Functions using S4 Classes survivalSurvival analysis, including penalised likelihood. tcltk Tcl/Tk Interface tools Tools for Package Development utils The R Utils Package When I type install.packages(), select the mirror, the following list of packages appears but the package FORECAST is not listed Please see attchament http://r.789695.n4.nabble.com/file/n4498680/08.png Any suggestions ? thanks in advance Jason -- View this message in context: http://r.789695.n4.nabble.com/Re-Help-with-R-package-forecast-tp4498680p4498680.html Sent from the R help mailing list archive at Na
[R] julian() and numerical noise
Hi, does anybody know if the following behavior of julian() is intentional? > julian(2, 1, 2012) - julian(2 - 1e-15, 1, 2012) [1] 1 > julian(2, 1, 2012) - julian(2, 1 - 1e-15, 2012) [1] 0 > julian(2, 1, 2012) - julian(2, 1, 2012 - 1e-15) [1] 0 In other words, julian() is subject to numerical noise in the 'day' argument, but not in the 'month' and 'year' argument? Another example: > julian(2 - 1e-15, 1, 2012) - julian(1 - 1e-15, 1, 2012) [1] 30 Thanks, Andreas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] FW: fdp and Rgraphviz
Hello, I am beginner user of R. I am trying to use GeneNet package. I started by the example on this link: http://strimmerlab.org/software/genenet/download/arabidopsis-net.R However I am getting an error at this line:system("fdp -T svg -o arthdyn.svg arthdyn.dot") # SVG format sh: fdp: command not found I tried to search how to intall the fdp command but could not find explanation. I am running my code on Rstudio .95.263 and Mac OS X 10.6.8 Can you please help me to solve this problem or is there is another way to visualize the network Thanks, H [[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 convert digits to specified decimal vectors
> x [1] 7 8 9 10 11 12 convert such that 7. 8. 9. 10.000 11.000 12.000 total size of 5 digits for each value -- View this message in context: http://r.789695.n4.nabble.com/how-to-convert-digits-to-specified-decimal-vectors-tp4498588p4498588.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] fdp c
Hello, I am beginner user of R. I am trying to use GeneNet package. I started by the example on this link: http://strimmerlab.org/software/genenet/download/arabidopsis-net.R However I am getting an error at this line:system("fdp -T svg -o arthdyn.svg arthdyn.dot") # SVG format sh: fdp: command not found I tried to search how to intall the fdp command but could not find explanation. I am running my code on Rstudio .95.263 and Mac OS X 10.6.8 Can you please help me to solve this problem or is there is another way to visualize the network Thanks, H [[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] R conditional matrix operations - advanced condition
Hello List! I stumbled across an efficiency problem - calculation that would be probably done very fast as a matrix operation I must perform as a for-loop. My intention was to do a conditional operation in matrix depending on the information in first column (summing as many data points from vector my_data as the number specified in the first column of the matrix) but the result is that the function takes the condition only from the first row of column for calculations in every row. Is it possible to solve this problem as a matrix calculation or I have to iterate over each row? (which I suppose is much slower) #problem looks like: my_mat <- matrix(1:50,ncol=2) my_mat <- cbind(my_mat,0) #here I have a matrix with empty third column where I want to store my results my_data <- rnorm(25) #this is a dataset I want to use for filling the third column #and I did my_mat[,3] <- sum(my_data[1:my_mat[,1]]) + my_mat[,2] #which didn't work as I expected Hope I will get some suggestions, Lukasz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Plotting patient drug timelines using ggplot2 (or some other means) -- Help!!!
On Mar 23, 2012, at 2:15 PM, Paul Miller wrote: Hi Michael and Petr, Apologize for my failure to grasp what you were saying. My code is up and running now. Noticed what might be a shortcoming of my ggplot code. I have some instances where a drug starts and stops and then starts and stops again. It looks like my graphs show just a single unbroken line segment though. Put in NA entries at times you do not want plotted. Not sure exactly how that gets handled in ggplot but since plotting nothing was the "usual" behavior in base and lattice graphics, I would think that would have gotten carried over. I ordered Hadley Wickham's ggplot2 book earlier today. So hopefully I'll be able to figure that out myself once the book arrives. Thank you Michael, Petr, and Bert for your help with this. Thanks especially to Michael for patiently answering all my questions over the last day or so. Paul 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] Plotting patient drug timelines using ggplot2 (or some other means) -- Help!!!
The ggplot book is quite good, but be forewarned, there have been some structural changes of late and some of the book code won't work quite as is anymore: this document describes them (the changes, not the old code) in some detail if you start hitting those sorts of things: https://github.com/downloads/hadley/ggplot2/guide-col.pdf Best of luck, Michael On Fri, Mar 23, 2012 at 2:15 PM, Paul Miller wrote: > Hi Michael and Petr, > > Apologize for my failure to grasp what you were saying. My code is up and > running now. > > Noticed what might be a shortcoming of my ggplot code. I have some instances > where a drug starts and stops and then starts and stops again. It looks like > my graphs show just a single unbroken line segment though. > I ordered Hadley Wickham's ggplot2 book earlier today. So hopefully I'll be > able to figure that out myself once the book arrives. > > Thank you Michael, Petr, and Bert for your help with this. Thanks especially > to Michael for patiently answering all my questions over the last day or so. > > Paul > > > > --- On Fri, 3/23/12, R. Michael Weylandt wrote: > >> From: R. Michael Weylandt >> Subject: Re: [R] Plotting patient drug timelines using ggplot2 (or some >> other means) -- Help!!! >> To: "Paul Miller" >> Cc: "Petr PIKAL" , r-help@r-project.org >> Received: Friday, March 23, 2012, 9:37 AM >> You didn't do what I said. >> >> Once you make the list of data.frame()s "TempData", each >> single >> element is a data.frame and that is what you need to pass to >> ggplot -- >> in the loop construct I set up, the individual data frame is >> called >> temp so you need to have ggplot(temp). >> >> As I said before, >> >> ## Do all your stuff -- just change "TestData" to "temp" so >> you are >> using the right data.frame >> >> I'll be a little more direct this time: >> >> for(temp in TempData){ >> >> png(filename = paste("plot", unique(temp$key_line), ".png", >> sep = ""), >> width=600, height=300) >> p <- ggplot(temp, aes(value, drug)) + geom_line(size = 6) >> + >> xlab("Time") + ylab("") + theme_bw() + opts(title = >> paste("Pattern = >> ", unique(temp$pattern), " \n (profile_key = ", >> unique(temp$profile_key), ", line = ", unique(temp$line), ") >> \n", sep >> = "")) + opts(axis.text.x = theme_blank()) >> print(p) >> dev.off() >> } >> >> Michael >> >> >> On Fri, Mar 23, 2012 at 10:22 AM, Paul Miller >> wrote: >> > Hi Michael and Petr, >> > >> > You both seem to have hit on the idea of splitting the >> TestData in order to do by group processing. Trouble is that >> ggplot2 doesn't seem to like lists very much. >> > >> > When I run the code: >> > >> > TempData <- split(TestData, TestData$key_line) >> > TempData >> > >> > for(temp in TempData){ >> > >> > png(filename = paste("plot", unique(TempData$key_line), >> ".png", sep = ""), width=600, height=300) >> > >> > ggplot(TempData, aes(value, drug)) + geom_line(size = >> 6) + xlab("Time") + ylab("") + theme_bw() + >> > opts(title = paste("Pattern = >> ", unique(TempData$pattern), " \n (profile_key = ", >> unique(TempData$profile_key), ", line = ", >> unique(TempData$line), ") \n", sep = "")) + >> > opts(axis.text.x = >> theme_blank() ) >> > dev.off() >> > >> > } >> > >> > I get the error message: >> > >> > "Error: ggplot2 doesn't know how to deal with data of >> class list" >> > >> > Are there any other good ways of doing the looping? >> Sorry to trouble you with this. If I had more time, I'd just >> struggle with it for awhile and figure it out myself. >> > >> > I tried embedding my ggplot code into print() as Petr >> suggested. I didn't think it would help but wanted to try >> just in case. No dice -- ggplot just doesn't seem to like >> lists. >> > >> > Thanks, >> > >> > Paul >> > >> > >> > >> > --- On Fri, 3/23/12, R. Michael Weylandt >> wrote: >> > >> >> From: R. Michael Weylandt >> >> Subject: Re: [R] Plotting patient drug timelines >> using ggplot2 (or some other means) -- Help!!! >> >> To: "Paul Miller" >> >> Cc: r-help@r-project.org >> >> Received: Friday, March 23, 2012, 8:52 AM >> >> Inline. >> >> >> >> On Fri, Mar 23, 2012 at 9:40 AM, Paul Miller >> >> wrote: >> >> > Hi Michael, >> >> > >> >> > Added a little more to my code (see below). It >> now >> >> automatically sets the name of the file. It also >> does a >> >> better job of spacing the text for pattern and >> patient x >> >> line at the top of the graph. >> >> > >> >> > I really like the way this looks now. I just >> need to >> >> figure out how to loop through the data using my >> "key_line" >> >> (patient x line) variable. >> >> > >> >> > One of the things I've noticed while learning >> R is that >> >> things I think will be difficult often go >> surprisingly well. >> >> It's the things that I think will be easy that I >> wind up >> >> struggling with. Right now I'm struggling with >> figuring out >> >> how to loop through the data to produce plot11, >> plot 12, >> >> plot21, and plot22. >> >> > >> >> > Em
Re: [R] Nonparametric bivariate distribution estimation and sampling
On Mar 23, 2012, at 1:53 PM, heyi xiao wrote: Sarah, Thanks for the response. I actually have several years of working experience with R and statistics, although may not be as good as you. that’s why I am here ;) I dug deeper into R documentations and previous R-help posts, and couldn’t found anything particular help. Again, I want to do two things: (1) estimate the probability density of this bivariate distribution using some nonparametric method (kernel, spline etc); ?MASS::kde2d ?KernSmooth::bkde2D ?ade4::s.kde2d help(package=locfit) (2) sample a big dataset from this bivariate distribution for a simulation study. What is wrong with `sample`? # to get sample of size n without replacement set.seed(42) dfrm[ sample(1:NROW(dfrm), n) , ] -- David. If my questions are not clear enough show my how I can improve, or which part is not clear enough. If you have any particular suggestions/comments, you are more than welcome. Thanks! Heyi --- On Fri, 3/23/12, Sarah Goslee wrote: From: Sarah Goslee Subject: Re: [R] Nonparametric bivariate distribution estimation and sampling To: "heyi xiao" Cc: r-help@r-project.org Date: Friday, March 23, 2012, 12:26 PM R can do all of that and more. But you'll need to put some work in reading about how to use R, about the statistical methods involved, and about how to use them to best effect. You might want, for instance, generalized additive models. Or not. If your question isn't more fully-formed than this, your best bet is almost certainly to talk to a local statistician, spend some time working with R, and then come back to the list with specific questions. Sarah On Fri, Mar 23, 2012 at 12:17 PM, heyi xiao wrote: Dear all, I have a bivariate dataset from a preliminary study. I want to do two things: (1) estimate the probability density of this bivariate distribution using some nonparametric method (kernel, spline etc); (2) sample a big dataset from this bivariate distribution for a simulation study. Is there any good method or package I can use in R for my work? I don’t want parametric models like bivariate normal distribution etc, as I would like to accurate model my data. I don’t want to use the bootstrapping approach, i.e. sampling with replacement, as this will generate lots of duplicate data points. Any thoughts or input will be highly appreciated! Heyi -- 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. 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] Plotting patient drug timelines using ggplot2 (or some other means) -- Help!!!
Hi Michael and Petr, Apologize for my failure to grasp what you were saying. My code is up and running now. Noticed what might be a shortcoming of my ggplot code. I have some instances where a drug starts and stops and then starts and stops again. It looks like my graphs show just a single unbroken line segment though. I ordered Hadley Wickham's ggplot2 book earlier today. So hopefully I'll be able to figure that out myself once the book arrives. Thank you Michael, Petr, and Bert for your help with this. Thanks especially to Michael for patiently answering all my questions over the last day or so. Paul --- On Fri, 3/23/12, R. Michael Weylandt wrote: > From: R. Michael Weylandt > Subject: Re: [R] Plotting patient drug timelines using ggplot2 (or some other > means) -- Help!!! > To: "Paul Miller" > Cc: "Petr PIKAL" , r-help@r-project.org > Received: Friday, March 23, 2012, 9:37 AM > You didn't do what I said. > > Once you make the list of data.frame()s "TempData", each > single > element is a data.frame and that is what you need to pass to > ggplot -- > in the loop construct I set up, the individual data frame is > called > temp so you need to have ggplot(temp). > > As I said before, > > ## Do all your stuff -- just change "TestData" to "temp" so > you are > using the right data.frame > > I'll be a little more direct this time: > > for(temp in TempData){ > > png(filename = paste("plot", unique(temp$key_line), ".png", > sep = ""), > width=600, height=300) > p <- ggplot(temp, aes(value, drug)) + geom_line(size = 6) > + > xlab("Time") + ylab("") + theme_bw() + opts(title = > paste("Pattern = > ", unique(temp$pattern), " \n (profile_key = ", > unique(temp$profile_key), ", line = ", unique(temp$line), ") > \n", sep > = "")) + opts(axis.text.x = theme_blank()) > print(p) > dev.off() > } > > Michael > > > On Fri, Mar 23, 2012 at 10:22 AM, Paul Miller > wrote: > > Hi Michael and Petr, > > > > You both seem to have hit on the idea of splitting the > TestData in order to do by group processing. Trouble is that > ggplot2 doesn't seem to like lists very much. > > > > When I run the code: > > > > TempData <- split(TestData, TestData$key_line) > > TempData > > > > for(temp in TempData){ > > > > png(filename = paste("plot", unique(TempData$key_line), > ".png", sep = ""), width=600, height=300) > > > > ggplot(TempData, aes(value, drug)) + geom_line(size = > 6) + xlab("Time") + ylab("") + theme_bw() + > > opts(title = paste("Pattern = > ", unique(TempData$pattern), " \n (profile_key = ", > unique(TempData$profile_key), ", line = ", > unique(TempData$line), ") \n", sep = "")) + > > opts(axis.text.x = > theme_blank() ) > > dev.off() > > > > } > > > > I get the error message: > > > > "Error: ggplot2 doesn't know how to deal with data of > class list" > > > > Are there any other good ways of doing the looping? > Sorry to trouble you with this. If I had more time, I'd just > struggle with it for awhile and figure it out myself. > > > > I tried embedding my ggplot code into print() as Petr > suggested. I didn't think it would help but wanted to try > just in case. No dice -- ggplot just doesn't seem to like > lists. > > > > Thanks, > > > > Paul > > > > > > > > --- On Fri, 3/23/12, R. Michael Weylandt > wrote: > > > >> From: R. Michael Weylandt > >> Subject: Re: [R] Plotting patient drug timelines > using ggplot2 (or some other means) -- Help!!! > >> To: "Paul Miller" > >> Cc: r-help@r-project.org > >> Received: Friday, March 23, 2012, 8:52 AM > >> Inline. > >> > >> On Fri, Mar 23, 2012 at 9:40 AM, Paul Miller > >> wrote: > >> > Hi Michael, > >> > > >> > Added a little more to my code (see below). It > now > >> automatically sets the name of the file. It also > does a > >> better job of spacing the text for pattern and > patient x > >> line at the top of the graph. > >> > > >> > I really like the way this looks now. I just > need to > >> figure out how to loop through the data using my > "key_line" > >> (patient x line) variable. > >> > > >> > One of the things I've noticed while learning > R is that > >> things I think will be difficult often go > surprisingly well. > >> It's the things that I think will be easy that I > wind up > >> struggling with. Right now I'm struggling with > figuring out > >> how to loop through the data to produce plot11, > plot 12, > >> plot21, and plot22. > >> > > >> > Embarassing. But there it is. > >> > > >> > Can you show me how to do that? In the > meantime, I keep > >> working on it and may figure it out on my own. > >> > > >> > Thanks, > >> > > >> > Paul > >> > > >> > > >> > connection <- textConnection(" > >> > 1/1/Drug A/ Begin (A), Begin (B), End (B), > End > >> (A)/0./21.000 > >> > 1/1/Drug B/ Begin (A), Begin (B), End (B), > End > >> (A)/0.7143/18.000 > >> > 1/2/Drug A/ Begin (A, B, C), End (A, B), End > >> (C)/0./20.000 > >> > 1/2/Drug B/ Begin (A, B, C), End (A, B), End > >> (C)/0./20.000 > >> > 1/2/Drug
Re: [R] Nonparametric bivariate distribution estimation and sampling
Sarah, Thanks for the response. I actually have several years of working experience with R and statistics, although may not be as good as you. that’s why I am here ;) I dug deeper into R documentations and previous R-help posts, and couldn’t found anything particular help. Again, I want to do two things: (1) estimate the probability density of this bivariate distribution using some nonparametric method (kernel, spline etc); (2) sample a big dataset from this bivariate distribution for a simulation study. If my questions are not clear enough show my how I can improve, or which part is not clear enough. If you have any particular suggestions/comments, you are more than welcome. Thanks! Heyi --- On Fri, 3/23/12, Sarah Goslee wrote: > From: Sarah Goslee > Subject: Re: [R] Nonparametric bivariate distribution estimation and sampling > To: "heyi xiao" > Cc: r-help@r-project.org > Date: Friday, March 23, 2012, 12:26 PM > R can do all of that and more. > > But you'll need to put some work in reading about how to use > R, about > the statistical methods involved, and about how to use them > to best > effect. You might want, for instance, generalized additive > models. Or > not. If your question isn't more fully-formed than this, > your best bet > is almost certainly to talk to a local statistician, spend > some time > working with R, and then come back to the list with > specific > questions. > > Sarah > > On Fri, Mar 23, 2012 at 12:17 PM, heyi xiao > wrote: > > Dear all, > > I have a bivariate dataset from a preliminary study. I > want to do two things: (1) estimate the probability density > of this bivariate distribution using some nonparametric > method (kernel, spline etc); (2) sample a big dataset from > this bivariate distribution for a simulation study. > > Is there any good method or package I can use in R for > my work? I don’t want parametric models like bivariate > normal distribution etc, as I would like to accurate model > my data. I don’t want to use the bootstrapping approach, > i.e. sampling with replacement, as this will generate lots > of duplicate data points. Any thoughts or input will be > highly appreciated! > > Heyi > > > > > > -- > 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] call for CSDA special issue
Dear useRs, it may be of interest to some of you that Computational Statistics & Data Analysis (CSDA) is having a special issue on statistical algorithms that are accompanied by corresponding R packages. For details see the call below. Best regards, Z - CSDA Special Issue on STATISTICAL ALGORITHMS AND SOFTWARE IN R COMPUTATIONAL STATISTICS & DATA ANALYSIS CALL FOR PAPERS Special Issue on STATISTICAL ALGORITHMS AND SOFTWARE IN R http://www.elsevier.com/locate/csda http://www.compstat2012.org/SpecialIssues/SASR.pdf The R system for statistical computing and graphics can be considered the most important statistical software package, being increasingly used as a programing environment. R's capabilities for contributed extension packages make it easy to deploy new R code to the community. This special issue is devoted to statistical algorithms and software in R. Methodological contributions combined with sound R implementations are strongly encouraged. The paper as well as the R software will be reviewed. R code should be clearly documented and typically be prepared in form of an extension package available through one of the standard repositories (such as CRAN or Bioconductor). Replication scripts for all examples from the paper need to be provided, demonstrating the usefulness of the R code and the methodology/algorithm. All topics related to computational statistics are of interest. The papers should have a methodological component and should provide a solid R implementation in order to be considered for publication. Authors who are uncertain about the suitability of their papers should contact the special issue editors. All submissions must contain original unpublished work not being considered for publication elsewhere. Submissions will be refereed according to standard procedures for Computational Statistics & Data Analysis. Information about the journal can be found at http://www.elsevier.com/locate/csda. The deadline for submissions is 30th June 2012. However, papers can be submitted at any time; and, when they have been received, they will enter the editorial system immediately. Papers for the special issue should be submitted using the Elsevier Electronic Submission tool EES: http://ees.elsevier.com/csda. In the EES please choose the special issue on "Statistical Algorithms and Software in R" and the Co-Editor responsible for the special issues. The special issue editors: Peter Filzmoser, Vienna University of Technology, Austria. E-mail: p.filzmo...@tuwien.ac.at Cristian Gatu, "Alexandru I. Cuza" University of Iasi, Romania. E-mail: cg...@info.uaic.ro Achim Zeileis, Universitat Innsbruck, Austria. achim.zeil...@r-project.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] Order of terms in formula changes aov() results
On Mar 22, 2012, at 5:06 PM, Stuart Luppescu wrote: Hello, This one is very perplexing. I have teacher observation data, with factors teacher ID, observer ID, component, grade and subject. When I do this, aov(data=ratings.prin.22, rating ~ obsid.f + tid.f + subject.f + grade.f + comp.f) I get this: Terms: obsid.f tid.f grade.fcomp.f Residuals Sum of Squares 306.23399 221.38173 1.7 14.52831 279.05780 Deg. of Freedom7487 2 9 1406 This looks right. What about the missing SS for subject.f? There are about 82 observers so 74 degrees of freedom for obsid.f is OK. But if I do this (just reordering the terms in the formula): aov(data=ratings.prin.22, rating ~ comp.f + grade.f + subject.f + tid.f + obsid.f) I get this: Terms: comp.f grade.f subject.ftid.f obsid.f Residuals Sum of Squares 15.0923 23.39685.9982 499.3568 0. 279.0578 Deg. of Freedom94 4 1523 1406 Now obsid.f only has 3 degrees of freedom and the sum of squares is 0.00. Could this be due to the unbalanced design? I would have guessed collinearity. If someone can explain this to me I would be very grateful. -- Stuart Luppescu -=- slu .at. ccsr.uchicago.edu 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] Nonparametric bivariate distribution estimation and sampling
R can do all of that and more. But you'll need to put some work in reading about how to use R, about the statistical methods involved, and about how to use them to best effect. You might want, for instance, generalized additive models. Or not. If your question isn't more fully-formed than this, your best bet is almost certainly to talk to a local statistician, spend some time working with R, and then come back to the list with specific questions. Sarah On Fri, Mar 23, 2012 at 12:17 PM, heyi xiao wrote: > Dear all, > I have a bivariate dataset from a preliminary study. I want to do two things: > (1) estimate the probability density of this bivariate distribution using > some nonparametric method (kernel, spline etc); (2) sample a big dataset from > this bivariate distribution for a simulation study. > Is there any good method or package I can use in R for my work? I don’t want > parametric models like bivariate normal distribution etc, as I would like to > accurate model my data. I don’t want to use the bootstrapping approach, i.e. > sampling with replacement, as this will generate lots of duplicate data > points. Any thoughts or input will be highly appreciated! > Heyi > > -- 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] Nonparametric bivariate distribution estimation and sampling
Dear all, I have a bivariate dataset from a preliminary study. I want to do two things: (1) estimate the probability density of this bivariate distribution using some nonparametric method (kernel, spline etc); (2) sample a big dataset from this bivariate distribution for a simulation study. Is there any good method or package I can use in R for my work? I don’t want parametric models like bivariate normal distribution etc, as I would like to accurate model my data. I don’t want to use the bootstrapping approach, i.e. sampling with replacement, as this will generate lots of duplicate data points. Any thoughts or input will be highly appreciated! Heyi __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Order of terms in formula changes aov() results
Hi, It seems that you have an unbalanced anova case which can be complicated in interpretation. This question has been addressed in the list you can search of previous mails. Basically, for unbalanced data (or unorthorgonal), estimates of SS of a factor depends on other factors. Type I SS (which is the method by aov) is a sequential method. Therefore, order of variables in the model matters. For your situation, you may want to use type II or type III SS (check Anova in car) because they are estimates adjusted for other variables in the model, thus order-independent. Weidong Gu On Thu, Mar 22, 2012 at 5:06 PM, Stuart Luppescu wrote: > Hello, This one is very perplexing. I have teacher observation data, > with factors teacher ID, observer ID, component, grade and subject. When > I do this, > > aov(data=ratings.prin.22, rating ~ obsid.f + tid.f + subject.f + grade.f + > comp.f) > > I get this: > > Terms: > obsid.f tid.f grade.f comp.f Residuals > Sum of Squares 306.23399 221.38173 1.7 14.52831 279.05780 > Deg. of Freedom 74 87 2 9 1406 > > This looks right. There are about 82 observers so 74 degrees of freedom > for obsid.f is OK. But if I do this (just reordering the terms in the > formula): > > aov(data=ratings.prin.22, rating ~ comp.f + grade.f + subject.f + tid.f + > obsid.f) > > I get this: > > Terms: > comp.f grade.f subject.f tid.f obsid.f Residuals > Sum of Squares 15.0923 23.3968 5.9982 499.3568 0. 279.0578 > Deg. of Freedom 9 4 4 152 3 1406 > > Now obsid.f only has 3 degrees of freedom and the sum of squares is > 0.00. Could this be due to the unbalanced design? > > If someone can explain this to me I would be very grateful. > > -- > Stuart Luppescu -=- slu .at. ccsr.uchicago.edu > University of Chicago -=- CCSR > 才文と智奈美の父 -=- Kernel 3.2.1-gentoo-r2 > Tony Plate: There looks to be a typo in the R-exts > manual: [...] Peter Dalgaard: 'svn blame' tells me > that this was Brian's addition in rev.35362 [...] > Brian D. Ripley: I prefer 'svn praise' myself. > Peter Dalgaard: Or 'svn annotate'. I think it > depends on what I'm looking for, plus the risk > that the author (perpetrator, contributor) might > be me... -- Tony Plate, Peter Dalgaard and > Brian D. Ripley (about a typo in the > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] calling java from R and using java time series double precision array
2012/3/23 Back again today at trying to learn R. These are the results of a run I made. I understand very little of this. sapply() helps me get the array returned from a method. Strings and doubles returned from a method don't seem to need sapply(). I want to learn how to fetch the constant array at the end of this run. I would like other education about this situation also. > library(rJava) > .jinit() > .jaddClassPath("C:/ad/j") > print(.jclassPath()) [1] "C:\\Users\\ENVY17\\Documents\\R\\win-library\\2.13\\rJava\\java" [2] "C:\\ad\\j" > qsLin <- .jnew("CalqsLin") > calStg <- "20110424235959" > print(calStg) [1] "20110424235959" > dblTim <- > .jcall(qsLin,returnSig="D","linTimOfCalqsStgIsLev",calStg,as.integer(-4)) > print(dblTim,digits=20) [1] 63470908799.0 > calStg <- > .jcall(qsLin,returnSig="S","calqsStgOfLinTimIsLev",dblTim,as.integer(-4)) > print(calStg) [1] "20110424235959" > dblTim <- > .jcall(qsLin,returnSig="D","linTimOfCalqsStgIsLev",calStg,as.integer(-4)) > print(dblTim,digits=20) [1] 63470908799.0 > arj34Ret <- > sapply(.jcall(qsLin,returnSig="[[D","arReturnTEST"),.jevalArray) > #public final static double[][] arReturnTEST() { //this is the java > method used > # double[][]retArr=new double[3][4]; > # for(int i=0;i<3;i++)for(int j=0;j<4;j++)retArr[i][j]=i*1000+j; > # return(retArr); > #} > print(arj34Ret) # notice that the first java index is the column in R > print [,1] [,2] [,3] [1,]0 1000 2000 [2,]1 1001 2001 [3,]2 1002 2002 [4,]3 1003 2003 > connArr <- .jevalArray(qsLin.conArr) # conArr is java two dim array of > double precision constants Error in .jevalArray(qsLin.conArr) : object 'qsLin.conArr' not found > #public static double[][]conArr= { { 1001,1002,1003,1004 }, { > 2001,2002,2003,2004 }, { 3001,3002,3003,3004 } }; > print(connArr) Error in print(connArr) : object 'connArr' not found > -- View this message in context: http://r.789695.n4.nabble.com/calling-java-from-R-and-using-java-time-series-double-precision-array-tp4494581p4499206.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] trouble for parsing HTML files
No idea at this point; perhaps get in touch with the maintainer (email given by maintainer("XML")) and see if he has any insights. Sorry I can't get this one for you: without being able to reproduce it (the odd error message with the euro sign) myself, I'm pretty stumped. If you do get to a solution, I'd be quite interested to hear it. Best, Michael On Fri, Mar 23, 2012 at 11:26 AM, Julien Velcin wrote: > Thank you for your comments Michael, but : > >> i) The website is generating different content for you than for Milan >> and me [wild guess] > > > It'd be highly surprising. If this is the case, I don't know what I can do > to fix it. > >> ii) Something in the OS 10.5 -> 10.6 difference [process of elimination] > > > Ok, I've to wait for buying a new laptop with 10.6... > >> iii) Perhaps a shortlived bug in 2.14.2 -- can you update to 2.15 and >> see if it still throws that error? [the only one I know how to do >> anything for] > > > I've just updated with the last 2.15 version, but the error is still here > :(. > > Any other suggestion? Must I buy a PC? > > Julien > > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] trouble for parsing HTML files
Thank you for your comments Michael, but : i) The website is generating different content for you than for Milan and me [wild guess] It'd be highly surprising. If this is the case, I don't know what I can do to fix it. ii) Something in the OS 10.5 -> 10.6 difference [process of elimination] Ok, I've to wait for buying a new laptop with 10.6... iii) Perhaps a shortlived bug in 2.14.2 -- can you update to 2.15 and see if it still throws that error? [the only one I know how to do anything for] I've just updated with the last 2.15 version, but the error is still here :(. Any other suggestion? Must I buy a PC? Julien __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 wireframe outer box but keep ticks
See 'box.3d' in trellis.par.get() : wireframe(z ~ x*y, data = test, scales=list(arrows=F), par.settings = list(box.3d = list(col=NA))) Note you can have some finer control: wireframe(z ~ x*y, data = test, scales=list(arrows=F), par.settings = list(box.3d = list(col=c(1,2,NA,NA,3,NA,4,5,6))) ) Hope this helps On Fri, Mar 23, 2012 at 3:59 AM, Bigelow, Seth W -FS wrote: > I would like to eliminate the outer box around a lattice wireframe graph, but > the usual recommended solution, which is to assign a color of 'transparent' > to the axis.line parameter, > eliminates ticks if the 'arrows=F' command is used, as shown in the following > example: > > test = data.frame(expand.grid(c(1:10), c(1:10))) > z = test[,1] + test[,2] > test = cbind(test, z) > names(test) = c("x", "y", "z") > require(lattice) > wireframe(z ~ x*y, data = test, > scales=list(arrows=F), > par.settings = list(axis.line = list(col = "transparent")), > ) > > Is there a way to eliminate the box but keep the ticks? > > > Seth W. Bigelow, Ph.D. > Research Ecologist > USDA-FS Pacific Southwest Research Station > Ph: (802)-379-3444 > > > > > > This electronic message contains information generated by the USDA solely for > the intended recipients. Any unauthorized interception of this message or the > use or disclosure of the information it contains may violate the law and > subject the violator to civil or criminal penalties. If you believe you have > received this message in error, please notify the sender and delete the email > immediately. > > [[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] [slightly OT] le: will a new point shift the solution question
Hello, Is there an R function that given a linear regression solution for a data set will answer in the most efficient way whether a new data point shifts the solution or not? or whether the new solution would differ by less than some error. I need this in the context of an iterative method and such a function would spare a lot of time. The closest answer I can find to this, involves keeping track of the QR and updating it with a row append. I would like to only get a boolean answer because a 'no' answer would spare tons of flops. Many thanks in advance, Best regards, Giovanni __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Plotting patient drug timelines using ggplot2 (or some other means) -- Help!!!
Hi > > Hi Michael and Petr, > > You both seem to have hit on the idea of splitting the TestData in order > to do by group processing. Trouble is that ggplot2 doesn't seem to like > lists very much. > > When I run the code: > > TempData <- split(TestData, TestData$key_line) > TempData > > for(temp in TempData){ > > png(filename = paste("plot", unique(TempData$key_line), ".png", sep = ""), > width=600, height=300) > You must use print and select from your TempData list only one value by subsetting it by temp. You need to use propper subsetting also in creating png plots. In each cycle you will select values by TempData[temp]. Regards Petr print( ggplot(TempData[temp], aes(value, drug)) + geom_line(size = 6) + xlab("Time") + ylab("") + theme_bw() + opts(title = paste("Pattern = ", unique(TempData$pattern), " \n (profile_key = ", unique(TempData$profile_key), ", line = ", unique(TempData$line), ") \n", sep = "")) + opts(axis.text.x = theme_blank() ) ) > ggplot(TempData, aes(value, drug)) + geom_line(size = 6) + xlab("Time") + > ylab("") + theme_bw() + > opts(title = paste("Pattern = ", unique(TempData > $pattern), " \n (profile_key = ", unique(TempData$profile_key), ", line = > ", unique(TempData$line), ") \n", sep = "")) + >opts(axis.text.x = theme_blank() ) > dev.off() > > } > > I get the error message: > > "Error: ggplot2 doesn't know how to deal with data of class list" > > Are there any other good ways of doing the looping? Sorry to trouble you > with this. If I had more time, I'd just struggle with it for awhile and > figure it out myself. > > I tried embedding my ggplot code into print() as Petr suggested. I didn't > think it would help but wanted to try just in case. No dice -- ggplot just > doesn't seem to like lists. > > Thanks, > > Paul > > > > --- On Fri, 3/23/12, R. Michael Weylandt wrote: > > > From: R. Michael Weylandt > > Subject: Re: [R] Plotting patient drug timelines using ggplot2 (or some > other means) -- Help!!! > > To: "Paul Miller" > > Cc: r-help@r-project.org > > Received: Friday, March 23, 2012, 8:52 AM > > Inline. > > > > On Fri, Mar 23, 2012 at 9:40 AM, Paul Miller > > wrote: > > > Hi Michael, > > > > > > Added a little more to my code (see below). It now > > automatically sets the name of the file. It also does a > > better job of spacing the text for pattern and patient x > > line at the top of the graph. > > > > > > I really like the way this looks now. I just need to > > figure out how to loop through the data using my "key_line" > > (patient x line) variable. > > > > > > One of the things I've noticed while learning R is that > > things I think will be difficult often go surprisingly well. > > It's the things that I think will be easy that I wind up > > struggling with. Right now I'm struggling with figuring out > > how to loop through the data to produce plot11, plot 12, > > plot21, and plot22. > > > > > > Embarassing. But there it is. > > > > > > Can you show me how to do that? In the meantime, I keep > > working on it and may figure it out on my own. > > > > > > Thanks, > > > > > > Paul > > > > > > > > > connection <- textConnection(" > > > 1/1/Drug A/ Begin (A), Begin (B), End (B), End > > (A)/0./21.000 > > > 1/1/Drug B/ Begin (A), Begin (B), End (B), End > > (A)/0.7143/18.000 > > > 1/2/Drug A/ Begin (A, B, C), End (A, B), End > > (C)/0./20.000 > > > 1/2/Drug B/ Begin (A, B, C), End (A, B), End > > (C)/0./20.000 > > > 1/2/Drug C/ Begin (A, B, C), End (A, B), End > > (C)/0./36.000 > > > 2/1/Drug A/ Begin (A, B), End (A, B), Begin (C), End > > (C), Begin (D), End (D)/0./7.429 > > > 2/1/Drug B/ Begin (A, B), End (A, B), Begin (C), End > > (C), Begin (D), End (D)/ 0./7.429 > > > 2/1/Drug C/ Begin (A, B), End (A, B), Begin (C), End > > (C), Begin (D), End (D)/ 14.5714/21.857 > > > 2/1/Drug D/ Begin (A, B), End (A, B), Begin (C), End > > (C), Begin (D), End (D)/ 25.4286/231.286 > > > 2/2/Drug A/ Begin (A, B), End (A, B)/0./35.286 > > > 2/2/Drug B/ Begin (A, B), End (A, B)/0./35.286 > > > ") > > > > > > TestData <- data.frame(scan(connection, > > list(profile_key=0, line=0, drug="", pattern="", > > start_drug=0, stop_drug=0), sep="/")) > > > TestData <- TestData[TestData$profile_key == 1 & > > TestData$line == 1,] > > > TestData > > > > > > require(reshape) > > > TestData <- melt(TestData, measure.vars = > > c("start_drug", "stop_drug")) > > > TestData$drug <- factor(TestData$drug, levels = > > c("Drug D", "Drug C", "Drug B", "Drug A")) > > > TestData$key_line <- > > with(TestData,paste(profile_key, line, sep = "")) > > > TestData > > > > Useful trick: if you use dput() you can send this all in a > > much more > > concise fashion: > > > > structure(list(profile_key = c(1, 1, 1, 1), line = c(1, 1, > > 1, > > 1), drug = structure(c(4L, 3L, 4L, 3L), .Label = c("Drug > > D", > > "Drug C", "Drug B", "Drug A"), class = "factor"), pattern = > > structure(c(4L, > >
Re: [R] Plotting patient drug timelines using ggplot2 (or some other means) -- Help!!!
You didn't do what I said. Once you make the list of data.frame()s "TempData", each single element is a data.frame and that is what you need to pass to ggplot -- in the loop construct I set up, the individual data frame is called temp so you need to have ggplot(temp). As I said before, ## Do all your stuff -- just change "TestData" to "temp" so you are using the right data.frame I'll be a little more direct this time: for(temp in TempData){ png(filename = paste("plot", unique(temp$key_line), ".png", sep = ""), width=600, height=300) p <- ggplot(temp, aes(value, drug)) + geom_line(size = 6) + xlab("Time") + ylab("") + theme_bw() + opts(title = paste("Pattern = ", unique(temp$pattern), " \n (profile_key = ", unique(temp$profile_key), ", line = ", unique(temp$line), ") \n", sep = "")) + opts(axis.text.x = theme_blank()) print(p) dev.off() } Michael On Fri, Mar 23, 2012 at 10:22 AM, Paul Miller wrote: > Hi Michael and Petr, > > You both seem to have hit on the idea of splitting the TestData in order to > do by group processing. Trouble is that ggplot2 doesn't seem to like lists > very much. > > When I run the code: > > TempData <- split(TestData, TestData$key_line) > TempData > > for(temp in TempData){ > > png(filename = paste("plot", unique(TempData$key_line), ".png", sep = ""), > width=600, height=300) > > ggplot(TempData, aes(value, drug)) + geom_line(size = 6) + xlab("Time") + > ylab("") + theme_bw() + > opts(title = paste("Pattern = ", unique(TempData$pattern), " > \n (profile_key = ", unique(TempData$profile_key), ", line = ", > unique(TempData$line), ") \n", sep = "")) + > opts(axis.text.x = theme_blank() ) > dev.off() > > } > > I get the error message: > > "Error: ggplot2 doesn't know how to deal with data of class list" > > Are there any other good ways of doing the looping? Sorry to trouble you with > this. If I had more time, I'd just struggle with it for awhile and figure it > out myself. > > I tried embedding my ggplot code into print() as Petr suggested. I didn't > think it would help but wanted to try just in case. No dice -- ggplot just > doesn't seem to like lists. > > Thanks, > > Paul > > > > --- On Fri, 3/23/12, R. Michael Weylandt wrote: > >> From: R. Michael Weylandt >> Subject: Re: [R] Plotting patient drug timelines using ggplot2 (or some >> other means) -- Help!!! >> To: "Paul Miller" >> Cc: r-help@r-project.org >> Received: Friday, March 23, 2012, 8:52 AM >> Inline. >> >> On Fri, Mar 23, 2012 at 9:40 AM, Paul Miller >> wrote: >> > Hi Michael, >> > >> > Added a little more to my code (see below). It now >> automatically sets the name of the file. It also does a >> better job of spacing the text for pattern and patient x >> line at the top of the graph. >> > >> > I really like the way this looks now. I just need to >> figure out how to loop through the data using my "key_line" >> (patient x line) variable. >> > >> > One of the things I've noticed while learning R is that >> things I think will be difficult often go surprisingly well. >> It's the things that I think will be easy that I wind up >> struggling with. Right now I'm struggling with figuring out >> how to loop through the data to produce plot11, plot 12, >> plot21, and plot22. >> > >> > Embarassing. But there it is. >> > >> > Can you show me how to do that? In the meantime, I keep >> working on it and may figure it out on my own. >> > >> > Thanks, >> > >> > Paul >> > >> > >> > connection <- textConnection(" >> > 1/1/Drug A/ Begin (A), Begin (B), End (B), End >> (A)/0./21.000 >> > 1/1/Drug B/ Begin (A), Begin (B), End (B), End >> (A)/0.7143/18.000 >> > 1/2/Drug A/ Begin (A, B, C), End (A, B), End >> (C)/0./20.000 >> > 1/2/Drug B/ Begin (A, B, C), End (A, B), End >> (C)/0./20.000 >> > 1/2/Drug C/ Begin (A, B, C), End (A, B), End >> (C)/0./36.000 >> > 2/1/Drug A/ Begin (A, B), End (A, B), Begin (C), End >> (C), Begin (D), End (D)/0./7.429 >> > 2/1/Drug B/ Begin (A, B), End (A, B), Begin (C), End >> (C), Begin (D), End (D)/ 0./7.429 >> > 2/1/Drug C/ Begin (A, B), End (A, B), Begin (C), End >> (C), Begin (D), End (D)/ 14.5714/21.857 >> > 2/1/Drug D/ Begin (A, B), End (A, B), Begin (C), End >> (C), Begin (D), End (D)/ 25.4286/231.286 >> > 2/2/Drug A/ Begin (A, B), End (A, B)/0./35.286 >> > 2/2/Drug B/ Begin (A, B), End (A, B)/0./35.286 >> > ") >> > >> > TestData <- data.frame(scan(connection, >> list(profile_key=0, line=0, drug="", pattern="", >> start_drug=0, stop_drug=0), sep="/")) >> > TestData <- TestData[TestData$profile_key == 1 & >> TestData$line == 1,] >> > TestData >> > >> > require(reshape) >> > TestData <- melt(TestData, measure.vars = >> c("start_drug", "stop_drug")) >> > TestData$drug <- factor(TestData$drug, levels = >> c("Drug D", "Drug C", "Drug B", "Drug A")) >> > TestData$key_line <- >> with(TestData,paste(profile_key, line, sep = "")) >> > TestData >> >> Useful trick: if you use dput() you can send this all in a >> mu
Re: [R] Computing High Order Derivatives (Numerically)
Dear Petr Savicky, this helped indeed. Thank you very much. Gildas - Mail original - > De: "Petr Savicky" > À: r-help@r-project.org > Envoyé: Vendredi 23 Mars 2012 09:39:37 > Objet: Re: [R] Computing High Order Derivatives (Numerically) > On Fri, Mar 23, 2012 at 12:35:57AM +0100, Gildas Mazo wrote: > > Dear R users, > > > > Let f be a function over d variables x1,..,xd. I want to compute the > > k^th-order derivative with respect to x1,..,xk (k<=d). I have a by > > hand solution (see below) using an iterating code using D. However, > > I expect d to be high and f to be complicated. Then I want a vector > > x to be the input, instead of x1,..,xd. How to avoid the x1 <- x[1]; > > x2 <- x[2], etc steps in the code below? Moreover, D uses symbolic > > differentation and then eval evaluates the output to get a numerical > > result. But is there a way to compute the desired derivatives > > numerically directly (without using symbolic calculus at all)? > > Finally, what is the most efficient and fast way to get a numerical > > result for such derivatives? > > > > Thank you very much in advance, > > Gildas > > > > ### Code ### > > ### dif takes a function f, an order k, and a vector x as input. f > > must be a function of x1,..,xd with d >= k. The correspondance is > > done between xi and x[i]. The expression for f must be at the last > > row of the body function. > > dif <- function(f,k,x){ > > o <- list() > > n <- length(body(f)) > > o[[1]] <- body(f)[[n]] > > for (i in 1:k){ > > xi <- paste("x",i,sep="") > > o[[i+1]] <- D(o[[i]],name=xi) > > } > > x1 <- x[1] > > x2 <- x[2] > > x3 <- x[3] > > eval(o[[k+1]]) > > } > > > > ### Examples ### > > ## function to differentiate > > f <- function(x){ > > x1 <- x[1] > > x2 <- x[2] > > x3 <- x[3] > > 0.5*x1*x2*x3^2 > > } > > ## derivative w.r.t. x1, x2 and x3 at the point (1,2,3). > > dif(f,3,c(1,2,3)) > > > > ### My Questions ### > > ## how to avoid to write by hand xi <- x[i] ?? > > ## is there a way in R to compute such derivatives without using > > symbolic calculation but numerical compuation instead. > > Hi. > > For the first question, try the following > > dif <- function(f,k,x){ > o <- list() > n <- length(body(f)) > o[[1]] <- body(f)[[n]] > for (i in 1:k){ > xi <- paste("x",i,sep="") > o[[i+1]] <- D(o[[i]],name=xi) > assign(xi, x[i]) > } > eval(o[[k+1]]) > } > > For the second question, try the following. > > x <- c(1, 2, 3) > k <- length(x) > grid <- as.matrix(expand.grid(rep(list(c(0, 1)), times=k))) > signs <- 1 - 2*(rowSums(1 - grid) %% 2) > for (eps in 2^-(5:20)) { > xeps <- eps*grid + rep(x, each=nrow(grid)) > print(sum(signs*apply(xeps, 1, FUN=f))/eps^k) > } > > [1] 3.015625 > [1] 3.007812 > [1] 3.003906 > [1] 3.001953 > [1] 3.000977 > [1] 3.000488 > [1] 3.000244 > [1] 3.000122 > [1] 3 > [1] 3 > [1] 3 > [1] 3 > [1] 4 > [1] 0 > [1] 0 > [1] 0 > > If the above is computed in an exact arithmetic, then > with "eps" converging to zero, the result converges to > the required derivative. Since the numerical computations > are done with a rounding error, too small "eps" yields > a completely wrong result. The choice of a good "eps" > depends on the function and on "k". For a high "k", there > may even be no good "eps". See the considerations at > > http://en.wikipedia.org/wiki/Numerical_derivative > > where the choice of "eps" is discussed in the simplest > case of a univariate function. > > Hope this helps. > > Petr Savicky. > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- Gildas Mazo PhD student MISTIS team at INRIA Grenoble, France __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Plotting patient drug timelines using ggplot2 (or some other means) -- Help!!!
Hi Michael and Petr, You both seem to have hit on the idea of splitting the TestData in order to do by group processing. Trouble is that ggplot2 doesn't seem to like lists very much. When I run the code: TempData <- split(TestData, TestData$key_line) TempData for(temp in TempData){ png(filename = paste("plot", unique(TempData$key_line), ".png", sep = ""), width=600, height=300) ggplot(TempData, aes(value, drug)) + geom_line(size = 6) + xlab("Time") + ylab("") + theme_bw() + opts(title = paste("Pattern = ", unique(TempData$pattern), " \n (profile_key = ", unique(TempData$profile_key), ", line = ", unique(TempData$line), ") \n", sep = "")) + opts(axis.text.x = theme_blank() ) dev.off() } I get the error message: "Error: ggplot2 doesn't know how to deal with data of class list" Are there any other good ways of doing the looping? Sorry to trouble you with this. If I had more time, I'd just struggle with it for awhile and figure it out myself. I tried embedding my ggplot code into print() as Petr suggested. I didn't think it would help but wanted to try just in case. No dice -- ggplot just doesn't seem to like lists. Thanks, Paul --- On Fri, 3/23/12, R. Michael Weylandt wrote: > From: R. Michael Weylandt > Subject: Re: [R] Plotting patient drug timelines using ggplot2 (or some other > means) -- Help!!! > To: "Paul Miller" > Cc: r-help@r-project.org > Received: Friday, March 23, 2012, 8:52 AM > Inline. > > On Fri, Mar 23, 2012 at 9:40 AM, Paul Miller > wrote: > > Hi Michael, > > > > Added a little more to my code (see below). It now > automatically sets the name of the file. It also does a > better job of spacing the text for pattern and patient x > line at the top of the graph. > > > > I really like the way this looks now. I just need to > figure out how to loop through the data using my "key_line" > (patient x line) variable. > > > > One of the things I've noticed while learning R is that > things I think will be difficult often go surprisingly well. > It's the things that I think will be easy that I wind up > struggling with. Right now I'm struggling with figuring out > how to loop through the data to produce plot11, plot 12, > plot21, and plot22. > > > > Embarassing. But there it is. > > > > Can you show me how to do that? In the meantime, I keep > working on it and may figure it out on my own. > > > > Thanks, > > > > Paul > > > > > > connection <- textConnection(" > > 1/1/Drug A/ Begin (A), Begin (B), End (B), End > (A)/0./21.000 > > 1/1/Drug B/ Begin (A), Begin (B), End (B), End > (A)/0.7143/18.000 > > 1/2/Drug A/ Begin (A, B, C), End (A, B), End > (C)/0./20.000 > > 1/2/Drug B/ Begin (A, B, C), End (A, B), End > (C)/0./20.000 > > 1/2/Drug C/ Begin (A, B, C), End (A, B), End > (C)/0./36.000 > > 2/1/Drug A/ Begin (A, B), End (A, B), Begin (C), End > (C), Begin (D), End (D)/0./7.429 > > 2/1/Drug B/ Begin (A, B), End (A, B), Begin (C), End > (C), Begin (D), End (D)/ 0./7.429 > > 2/1/Drug C/ Begin (A, B), End (A, B), Begin (C), End > (C), Begin (D), End (D)/ 14.5714/21.857 > > 2/1/Drug D/ Begin (A, B), End (A, B), Begin (C), End > (C), Begin (D), End (D)/ 25.4286/231.286 > > 2/2/Drug A/ Begin (A, B), End (A, B)/0./35.286 > > 2/2/Drug B/ Begin (A, B), End (A, B)/0./35.286 > > ") > > > > TestData <- data.frame(scan(connection, > list(profile_key=0, line=0, drug="", pattern="", > start_drug=0, stop_drug=0), sep="/")) > > TestData <- TestData[TestData$profile_key == 1 & > TestData$line == 1,] > > TestData > > > > require(reshape) > > TestData <- melt(TestData, measure.vars = > c("start_drug", "stop_drug")) > > TestData$drug <- factor(TestData$drug, levels = > c("Drug D", "Drug C", "Drug B", "Drug A")) > > TestData$key_line <- > with(TestData,paste(profile_key, line, sep = "")) > > TestData > > Useful trick: if you use dput() you can send this all in a > much more > concise fashion: > > structure(list(profile_key = c(1, 1, 1, 1), line = c(1, 1, > 1, > 1), drug = structure(c(4L, 3L, 4L, 3L), .Label = c("Drug > D", > "Drug C", "Drug B", "Drug A"), class = "factor"), pattern = > structure(c(4L, > 4L, 4L, 4L), .Label = c(" Begin (A, B, C), End (A, B), End > (C)", > " Begin (A, B), End (A, B)", " Begin (A, B), End (A, B), > Begin (C), > End (C), Begin (D), End (D)", > " Begin (A), Begin (B), End (B), End (A)"), class = > "factor"), > variable = structure(c(1L, 1L, 2L, 2L), .Label > = c("start_drug", > "stop_drug"), class = "factor"), value = c(0, > 0.7143, 21, > 18), key_line = c("11", "11", "11", "11")), > .Names = c("profile_key", > "line", "drug", "pattern", "variable", "value", "key_line"), > row.names = c(NA, > -4L), class = "data.frame") > > > > > > require(ggplot2) > > > > png(filename = paste("plot", unique(TestData$key_line), > ".png", sep = ""), width=600, height=300) > > > > ggplot(TestData, aes(value, drug)) + geom_line(size = > 6) + xlab("Time") + ylab("") + theme_bw() + > >
Re: [R] Comples Boxplots in R . Resources
Dear Alex, Have a look at the ggplot2 package n <- 3502 junk <- list(list(matrix(rnorm(n), ncol = 1), matrix(rnorm(n, sd = 2), ncol = 1)), list(matrix(rnorm(n, mean = 1), ncol = 1), matrix(rnorm(n, mean = 1, sd = 2), ncol = 1)), list(matrix(rnorm(n, mean = 1), ncol = 1), matrix(rnorm(n, mean = -1, sd = 0.5), ncol = 1))) dataset <- do.call(rbind, lapply(seq_along(junk), function(i){ data.frame(set = i, status = c(rep("On", nrow(junk[[i]][[1]])), rep("Off", nrow(junk[[i]][[2]]))), value = unlist(junk[[i]])) })) dataset$set <- factor(dataset$set) library(ggplot2) ggplot(dataset, aes(x = set, y = value, linetype = status)) + geom_boxplot() 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 + 32 2 525 02 51 + 32 54 43 61 85 thierry.onkel...@inbo.be www.inbo.be 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 -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens R. Michael Weylandt Verzonden: vrijdag 23 maart 2012 14:09 Aan: Alaios CC: R help Onderwerp: Re: [R] Comples Boxplots in R . Resources Take a look at example(boxplot) and example(bxp) I think the last one for boxplot (with the guinea pig teeth!) will work for you and I believe you can manipulate the linetype the same way they do color there. Though looking at your data, it seems problematic that your values are so differentif that's problematic of your real data, you'll need to scale them to match or use multiple facets / panels as the examples demonstrate. Michael On Fri, Mar 23, 2012 at 7:05 AM, Alaios wrote: > Dear all, > I want to have a box plot for 7 datasets I have. The different here is that > each of these 7 data sets has two status . The on and off. > > So I give a small example below with 2 data sets only > > List of 2 > $ :List of 2 > ..$ : num [1:3502, 1] 0 0 0 0 0 0 0 0 0 0 ... # On Status > ..$ : num [1:3502, 1] 102884 102884 102884 102884 102884 ... # Off > status > $ :List of 2 > ..$ : num [1:3502, 1] 0 0 0 0 0 0 0 0 0 0 ... # On Status > ..$ : num [1:3502, 1] 102884 102884 102884 102884 102884 ... # Off > status > > > I would like to print all these information in a same boxplot where in each > tick instead of having one box, I want it to have two boxes.. one for the on > status and one for the off status. Even better it would be great if the on > boxes will be plotted by solid lines and the off boxes with dashed lines. > > I understand that this is a bit complex, so do you know if there are few > references to read how I can do that in R? > > I would like to thank you in advance for your help > > B.R > Alex > > [[alternative HTML version deleted]] > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Plotting patient drug timelines using ggplot2 (or some other means) -- Help!!!
Hi > Added a little more to my code (see below). It now automatically sets the > name of the file. It also does a better job of spacing the text for > pattern and patient x line at the top of the graph. > > I really like the way this looks now. I just need to figure out how to > loop through the data using my "key_line" (patient x line) variable. > > One of the things I've noticed while learning R is that things I think > will be difficult often go surprisingly well. It's the things that I think > will be easy that I wind up struggling with. Right now I'm struggling with > figuring out how to loop through the data to produce plot11, plot 12, > plot21, and plot22. > > Embarassing. But there it is. I would split original TestData to required groups according profile_key and line to a list. After that you can go through resulting list in a cycle for (i in length of a list) { all manipulation melting and plotting } Do not forget to enclose ggplot to print(ggplot). Regards Petr > > Can you show me how to do that? In the meantime, I keep working on it and > may figure it out on my own. > > Thanks, > > Paul > > > connection <- textConnection(" > 1/1/Drug A/ Begin (A), Begin (B), End (B), End (A)/0./21.000 > 1/1/Drug B/ Begin (A), Begin (B), End (B), End (A)/0.7143/18.000 > 1/2/Drug A/ Begin (A, B, C), End (A, B), End (C)/0./20.000 > 1/2/Drug B/ Begin (A, B, C), End (A, B), End (C)/0./20.000 > 1/2/Drug C/ Begin (A, B, C), End (A, B), End (C)/0./36.000 > 2/1/Drug A/ Begin (A, B), End (A, B), Begin (C), End (C), Begin (D), End > (D)/0./7.429 > 2/1/Drug B/ Begin (A, B), End (A, B), Begin (C), End (C), Begin (D), End > (D)/ 0./7.429 > 2/1/Drug C/ Begin (A, B), End (A, B), Begin (C), End (C), Begin (D), End > (D)/ 14.5714/21.857 > 2/1/Drug D/ Begin (A, B), End (A, B), Begin (C), End (C), Begin (D), End > (D)/ 25.4286/231.286 > 2/2/Drug A/ Begin (A, B), End (A, B)/0./35.286 > 2/2/Drug B/ Begin (A, B), End (A, B)/0./35.286 > ") > > TestData <- data.frame(scan(connection, list(profile_key=0, line=0, > drug="", pattern="", start_drug=0, stop_drug=0), sep="/")) > TestData <- TestData[TestData$profile_key == 1 & TestData$line == 1,] > TestData > > require(reshape) > TestData <- melt(TestData, measure.vars = c("start_drug", "stop_drug")) > TestData$drug <- factor(TestData$drug, levels = c("Drug D", "Drug C", > "Drug B", "Drug A")) > TestData$key_line <- with(TestData,paste(profile_key, line, sep = "")) > TestData > > require(ggplot2) > > png(filename = paste("plot", unique(TestData$key_line), ".png", sep = ""), > width=600, height=300) > > ggplot(TestData, aes(value, drug)) + geom_line(size = 6) + xlab("Time") + > ylab("") + theme_bw() + > opts(title = paste("Pattern = ", unique(TestData > $pattern), " \n (profile_key = ", unique(TestData$profile_key), ", line = > ", unique(TestData$line), ") \n", sep = "")) + >opts(axis.text.x = theme_blank() ) > > dev.off() > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] Plotting patient drug timelines using ggplot2 (or some other means) -- Help!!!
Inline. On Fri, Mar 23, 2012 at 9:40 AM, Paul Miller wrote: > Hi Michael, > > Added a little more to my code (see below). It now automatically sets the > name of the file. It also does a better job of spacing the text for pattern > and patient x line at the top of the graph. > > I really like the way this looks now. I just need to figure out how to loop > through the data using my "key_line" (patient x line) variable. > > One of the things I've noticed while learning R is that things I think will > be difficult often go surprisingly well. It's the things that I think will be > easy that I wind up struggling with. Right now I'm struggling with figuring > out how to loop through the data to produce plot11, plot 12, plot21, and > plot22. > > Embarassing. But there it is. > > Can you show me how to do that? In the meantime, I keep working on it and may > figure it out on my own. > > Thanks, > > Paul > > > connection <- textConnection(" > 1/1/Drug A/ Begin (A), Begin (B), End (B), End (A)/0./21.000 > 1/1/Drug B/ Begin (A), Begin (B), End (B), End (A)/0.7143/18.000 > 1/2/Drug A/ Begin (A, B, C), End (A, B), End (C)/0./20.000 > 1/2/Drug B/ Begin (A, B, C), End (A, B), End (C)/0./20.000 > 1/2/Drug C/ Begin (A, B, C), End (A, B), End (C)/0./36.000 > 2/1/Drug A/ Begin (A, B), End (A, B), Begin (C), End (C), Begin (D), End > (D)/0./7.429 > 2/1/Drug B/ Begin (A, B), End (A, B), Begin (C), End (C), Begin (D), End (D)/ > 0./7.429 > 2/1/Drug C/ Begin (A, B), End (A, B), Begin (C), End (C), Begin (D), End (D)/ > 14.5714/21.857 > 2/1/Drug D/ Begin (A, B), End (A, B), Begin (C), End (C), Begin (D), End (D)/ > 25.4286/231.286 > 2/2/Drug A/ Begin (A, B), End (A, B)/0./35.286 > 2/2/Drug B/ Begin (A, B), End (A, B)/0./35.286 > ") > > TestData <- data.frame(scan(connection, list(profile_key=0, line=0, drug="", > pattern="", start_drug=0, stop_drug=0), sep="/")) > TestData <- TestData[TestData$profile_key == 1 & TestData$line == 1,] > TestData > > require(reshape) > TestData <- melt(TestData, measure.vars = c("start_drug", "stop_drug")) > TestData$drug <- factor(TestData$drug, levels = c("Drug D", "Drug C", "Drug > B", "Drug A")) > TestData$key_line <- with(TestData,paste(profile_key, line, sep = "")) > TestData Useful trick: if you use dput() you can send this all in a much more concise fashion: structure(list(profile_key = c(1, 1, 1, 1), line = c(1, 1, 1, 1), drug = structure(c(4L, 3L, 4L, 3L), .Label = c("Drug D", "Drug C", "Drug B", "Drug A"), class = "factor"), pattern = structure(c(4L, 4L, 4L, 4L), .Label = c(" Begin (A, B, C), End (A, B), End (C)", " Begin (A, B), End (A, B)", " Begin (A, B), End (A, B), Begin (C), End (C), Begin (D), End (D)", " Begin (A), Begin (B), End (B), End (A)"), class = "factor"), variable = structure(c(1L, 1L, 2L, 2L), .Label = c("start_drug", "stop_drug"), class = "factor"), value = c(0, 0.7143, 21, 18), key_line = c("11", "11", "11", "11")), .Names = c("profile_key", "line", "drug", "pattern", "variable", "value", "key_line"), row.names = c(NA, -4L), class = "data.frame") > > require(ggplot2) > > png(filename = paste("plot", unique(TestData$key_line), ".png", sep = ""), > width=600, height=300) > > ggplot(TestData, aes(value, drug)) + geom_line(size = 6) + xlab("Time") + > ylab("") + theme_bw() + > opts(title = paste("Pattern = ", unique(TestData$pattern), " > \n (profile_key = ", unique(TestData$profile_key), ", line = ", > unique(TestData$line), ") \n", sep = "")) + > opts(axis.text.x = theme_blank() ) > > dev.off() > > If you want to loop over the different values of "key_line", I think it's pretty easy: TempData <- split(TestData, TestData$keyline) # List of data frames for(temp in TempData){ # Loop over the list ## Do all your stuff -- just change "TestData" to "temp" so you are using the right data.frame } Hope this helps, Michael __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] trouble for parsing HTML files
I just tried it on R. 2.14.1 and R 2.15.0 RC (r58802) and both worked with XML 3.9-4 on both 32 and 64-bit R on my Mac OS X 10.6.8 with the same locale setting so I can only guess it's one of three things: i) The website is generating different content for you than for Milan and me [wild guess] ii) Something in the OS 10.5 -> 10.6 difference [process of elimination] iii) Perhaps a shortlived bug in 2.14.2 -- can you update to 2.15 and see if it still throws that error? [the only one I know how to do anything for] Michael On Fri, Mar 23, 2012 at 3:10 AM, Julien Velcin wrote: > Here it is: > > R version 2.14.2 (2012-02-29) > Platform: i386-apple-darwin9.8.0/i386 (32-bit) > > locale: > [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 > > attached base packages: > [1] stats graphics grDevices utils datasets methods base > > other attached packages: > [1] XML_3.9-4 > > Thank you! > > Julien > > On Mar 22, 2012, at 10:12 PM, R. Michael Weylandt wrote: > >> Please give sessionInfo() so we can know your version of XML. >> >> Michael >> >> On Thu, Mar 22, 2012 at 2:04 PM, Julien Velcin >> wrote: >>> >>> I use mac OS 10.5.8 with this version of R: >>> >>> R version 2.14.1 (2011-12-22) >>> Platform: i386-apple-darwin9.8.0/i386 (32-bit) >>> >>> I've tried the command "RSiteSearch", but with no result. >>> >>> BTW, I recall that the code I've posted works for some websites. >>> >>> Julien >>> >>> >>> >>> >>> 2012/3/22, Milan Bouchet-Valat : Le jeudi 22 mars 2012 à 17:20 +0100, Julien Velcin a écrit : > > Hi all, > > Using the XML package, I'm not able to parse some html webpages. Here > is my code and the error message: > > library("XML") > url <- > "http://www.huffingtonpost.com/social/GraniteSkyline?action=fans"; > doc <- htmlParse(url) > > Error: Namespace prefix ꛀ of attribute (null) is not defined > > I've searched a lot on the Internet, but it's really difficult to find > something useful for R. What versions of R and XML are you using? The code you provided works fine here (R 2.14.1 x86_64 and XML 3.9-4 on Fedora 16). sessionInfo() will help us. BTW, see ?RSiteSearch to search for R content on the Web. Cheers >>> >>> __ >>> R-help@r-project.org mailing list >>> https://stat.ethz.ch/mailman/listinfo/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] Plotting patient drug timelines using ggplot2 (or some other means) -- Help!!!
Hi Michael, Added a little more to my code (see below). It now automatically sets the name of the file. It also does a better job of spacing the text for pattern and patient x line at the top of the graph. I really like the way this looks now. I just need to figure out how to loop through the data using my "key_line" (patient x line) variable. One of the things I've noticed while learning R is that things I think will be difficult often go surprisingly well. It's the things that I think will be easy that I wind up struggling with. Right now I'm struggling with figuring out how to loop through the data to produce plot11, plot 12, plot21, and plot22. Embarassing. But there it is. Can you show me how to do that? In the meantime, I keep working on it and may figure it out on my own. Thanks, Paul connection <- textConnection(" 1/1/Drug A/ Begin (A), Begin (B), End (B), End (A)/0./21.000 1/1/Drug B/ Begin (A), Begin (B), End (B), End (A)/0.7143/18.000 1/2/Drug A/ Begin (A, B, C), End (A, B), End (C)/0./20.000 1/2/Drug B/ Begin (A, B, C), End (A, B), End (C)/0./20.000 1/2/Drug C/ Begin (A, B, C), End (A, B), End (C)/0./36.000 2/1/Drug A/ Begin (A, B), End (A, B), Begin (C), End (C), Begin (D), End (D)/0./7.429 2/1/Drug B/ Begin (A, B), End (A, B), Begin (C), End (C), Begin (D), End (D)/ 0./7.429 2/1/Drug C/ Begin (A, B), End (A, B), Begin (C), End (C), Begin (D), End (D)/ 14.5714/21.857 2/1/Drug D/ Begin (A, B), End (A, B), Begin (C), End (C), Begin (D), End (D)/ 25.4286/231.286 2/2/Drug A/ Begin (A, B), End (A, B)/0./35.286 2/2/Drug B/ Begin (A, B), End (A, B)/0./35.286 ") TestData <- data.frame(scan(connection, list(profile_key=0, line=0, drug="", pattern="", start_drug=0, stop_drug=0), sep="/")) TestData <- TestData[TestData$profile_key == 1 & TestData$line == 1,] TestData require(reshape) TestData <- melt(TestData, measure.vars = c("start_drug", "stop_drug")) TestData$drug <- factor(TestData$drug, levels = c("Drug D", "Drug C", "Drug B", "Drug A")) TestData$key_line <- with(TestData,paste(profile_key, line, sep = "")) TestData require(ggplot2) png(filename = paste("plot", unique(TestData$key_line), ".png", sep = ""), width=600, height=300) ggplot(TestData, aes(value, drug)) + geom_line(size = 6) + xlab("Time") + ylab("") + theme_bw() + opts(title = paste("Pattern = ", unique(TestData$pattern), " \n (profile_key = ", unique(TestData$profile_key), ", line = ", unique(TestData$line), ") \n", sep = "")) + opts(axis.text.x = theme_blank() ) dev.off() __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Comples Boxplots in R . Resources
Take a look at example(boxplot) and example(bxp) I think the last one for boxplot (with the guinea pig teeth!) will work for you and I believe you can manipulate the linetype the same way they do color there. Though looking at your data, it seems problematic that your values are so differentif that's problematic of your real data, you'll need to scale them to match or use multiple facets / panels as the examples demonstrate. Michael On Fri, Mar 23, 2012 at 7:05 AM, Alaios wrote: > Dear all, > I want to have a box plot for 7 datasets I have. The different here is that > each of these 7 data sets has two status . The on and off. > > So I give a small example below with 2 data sets only > > List of 2 > $ :List of 2 > ..$ : num [1:3502, 1] 0 0 0 0 0 0 0 0 0 0 ... # On Status > ..$ : num [1:3502, 1] 102884 102884 102884 102884 102884 ... # Off status > $ :List of 2 > ..$ : num [1:3502, 1] 0 0 0 0 0 0 0 0 0 0 ... # On Status > ..$ : num [1:3502, 1] 102884 102884 102884 102884 102884 ... # Off status > > > I would like to print all these information in a same boxplot where in each > tick instead of having one box, I want it to have two boxes.. one for the on > status and one for the off status. Even better it would be great if the on > boxes will be plotted by solid lines and the off boxes with dashed lines. > > I understand that this is a bit complex, so do you know if there are few > references to read how I can do that in R? > > I would like to thank you in advance for your help > > B.R > Alex > > [[alternative HTML version deleted]] > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R Error : DATA to MATRIX
On Mar 23, 2012, at 2:53 AM, ritwi...@isical.ac.in wrote: Dear Sir/Madam, I'm getting a problem with a R-code which converts a data frame to a matrix. It first generate a (m^(n-m) * m) matrix A and then regenerate another matrix B having less dimension than A which satisfy some condition. Now I wish to assign each row of B to a vector as individual. My problem is when I set any choice of (n,m) except m=1 it works fine but setting m=1 I got the error : Error in B[i, ] : incorrect number of dimensions. Moreover if (n,m) is large (say, (20,8)) I got the error : Error: cannot allocate vector of size 3.0 Gb. I know this is due to large dimension of matrix A. How to solve this problem. My code is given below: ** n=5 m=3 R=numeric(0) # Generate all possible m-tuple ( variables having range 0 to n ) in a ( m^(n-m) * m ) matrix r = expand.grid(rep(list(0:(n-m)), m)) write.table(r,file="test.txt",row.names=FALSE,col.names=FALSE) a= read.table(file="test.txt",sep="",header=FALSE) A= data.matrix(a) #. # Generate matrix whose rowsum = n-m meet.crit = apply(A, 1, function(.row) any((sum(.row)) == n-m)) # criteron for being rowsum = n cbind(A, meet.crit) # Checking rowsum = n for each row -m B=A[meet.crit,] At this point the default behavior of the "[" function is to return a vector rather than a matrix. You need to add drop=FALSE as an additional argument. Read the help page for ?"[". # Generate matrix #. for(i in 1:choose(n-1,m-1)){ R=B[i,] } *** Can you please help me how to get rid of these errors. Thanking you in advance. Regards Ritwik Bhattacharya Senior Research Fellow SQC & OR UNIT, KOLKATA INDIAN STATISTICAL INSTITUTE -- 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] R Error : DATA to MATRIX
Hi See in text. > > Dear Sir/Madam, > > I'm getting a problem with a R-code which converts a data frame to a matrix. > > It first generate a (m^(n-m) * m) matrix A and then regenerate another > matrix B having less dimension than A which satisfy some condition. Now I > wish to assign each row of B to a vector as individual. > > My problem is when I set any choice of (n,m) except m=1 it works fine but > setting m=1 I got the error : Error in B[i, ] : incorrect number of > dimensions. > > Moreover if (n,m) is large (say, (20,8)) I got the error : Error: cannot > allocate vector of size 3.0 Gb. I know this is due to large dimension of > matrix A. How to solve this problem. > > My code is given below: > > ** > > n=5 > m=3 > R=numeric(0) > # Generate all possible m-tuple ( variables having range 0 to n ) in a ( > m^(n-m) * m ) matrix > > r = expand.grid(rep(list(0:(n-m)), m)) > > write.table(r,file="test.txt",row.names=FALSE,col.names=FALSE) > > a= read.table(file="test.txt",sep="",header=FALSE) Above lines do not do any sensible things. r shall be same as a. > > A= data.matrix(a) > > #. > > # Generate matrix whose rowsum = n-m > > meet.crit = apply(A, 1, function(.row) any((sum(.row)) == n-m)) # > criteron for being rowsum = n No error > > cbind(A, meet.crit) # > Checking rowsum = n for each row > -m > B=A[meet.crit,] # No error > Generate matrix > > #. > > > for(i in 1:choose(n-1,m-1)){ > R=B[i,] > } No error. However in each cycle only ith row is added to R and therefore only last row (in this case B[6,]) is added and stays in R. Either you need to use R <- c(R, B[i,]) in your construction or better as B is matrix > class(B) [1] "matrix" you can transform it to vector easily by stripping dimensions. R<-t(B) > dim(R) <-NULL > R [1] 2 0 0 1 1 0 0 2 0 1 0 1 0 1 1 0 0 2 Regards Petr > > *** > > Can you please help me how to get rid of these errors. Thanking you in > advance. > > Regards > > Ritwik Bhattacharya > > > Senior Research Fellow > SQC & OR UNIT, KOLKATA > INDIAN STATISTICAL INSTITUTE > > Voice : +91 9051253944 > > This mail is scanned by Ironport > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] Phylogenetics quartets distance
Hi all, I have a specific question about comparing phylogenies. Is there any function available to calculate quartets distance between a pair of trees? My apologies if it exists and I overlooked it. cheers __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Comples Boxplots in R . Resources
Dear all, I want to have a box plot for 7 datasets I have. The different here is that each of these 7 data sets has two status . The on and off. So I give a small example below with 2 data sets only List of 2 $ :List of 2 ..$ : num [1:3502, 1] 0 0 0 0 0 0 0 0 0 0 ... # On Status ..$ : num [1:3502, 1] 102884 102884 102884 102884 102884 ... # Off status $ :List of 2 ..$ : num [1:3502, 1] 0 0 0 0 0 0 0 0 0 0 ... # On Status ..$ : num [1:3502, 1] 102884 102884 102884 102884 102884 ... # Off status I would like to print all these information in a same boxplot where in each tick instead of having one box, I want it to have two boxes.. one for the on status and one for the off status. Even better it would be great if the on boxes will be plotted by solid lines and the off boxes with dashed lines. I understand that this is a bit complex, so do you know if there are few references to read how I can do that in R? I would like to thank you in advance for your help B.R Alex [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Read File for Matrix with rownames
first problem: the "blank" space in first position in the first line. Try removing it, so that the file looks like this: "1","2","3","4" "1",484,43,67,54 "2",54,35,67,34 "3",69,76,78,55 "4",67,86,44,34 Second: your colnames and rownames are numeric; R recognizes it but puts an X (but it recognizes the rownames and puts them correctly!). To see it try: test.csv: "23","3","33","31" "25",484,43,67,54 "54",54,35,67,34 "43",69,76,78,55 "34",67,86,44,34 > test <- read.table("test.csv", sep=",", header=T) Then you can remove the X in the colnames: > colnames(test) <- gsub("X", "", colnames(test)) 2012/3/23 MSousa > Good morning, > > Good morning, > >I'm trying to read the file into an array, with the following code. > > A<- as.matrix(read.csv("~/Desktop/Results/Cfile.csv", header = FALSE, > sep=",")) > > The content of the file > " ","1","2","3","4" > "1", 484,43,67,54 > "2",54,35,67,34 > "3",69,76,78,55 > "4",67,86,44,34 > > What I needed is that the first line was the name of the columns and the > first column was the name of the lines. > > Thanks > > > -- > View this message in context: > http://r.789695.n4.nabble.com/Read-File-for-Matrix-with-rownames-tp4498280p4498280.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. > [[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] [R-pkgs] New package cloudRmpi: Cloud-based parallel proccessing for R
cloudRmpi is means for doing parallel processing in R, using MPI on a cloud-based network. It currently supports the use of Amazon's EC2 cloud computer service. cloudRmpi provides a mechanism to launch and manage a cloud-based network and to access an R session on the network's master MPI node (using the rreval package). cloudRmpi should work with any MPI based R package (it has been tested with Rmpi, npRmpi, and snow). Barnet Wagman b...@norbl.com [[alternative HTML version deleted]] ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Randomly select elements based on criteria
On Fri, Mar 23, 2012 at 10:56:11AM +0100, Petr Savicky wrote: > On Thu, Mar 22, 2012 at 11:42:53AM -0700, aly wrote: [...] > > I want to randomly select two rows but they have to be from different fam. > > The fist part (random selection), I got it by doing: > > > > > ran <- sample(nrow (fish), size=2); ran > > > > [1] 9 12 > > > > > newfish <- fish [ran,]; newfish > > > > fam born spawn > > 103 136 4650 > > 106 142 4685 > > > > In this example I got two individuals from different families (good) but I > > will repeat the process many times and there's a chance that I get two fish > > from the same family (bad): > > > > > ran<-sample (nrow(fish), size=2);ran > > > > [1] 26 25 > > > > > newfish <-fish [ran,]; newfish > > > > fam born spawn > > 127 150 4685 > > 126 150 4678 > > > > I need a conditional but I have no clue on how to include it in the code. > > Hi. > > Try the following. > > ran1 <- sample(nrow(fish), 1) > ind <- which(fish$fam != fish$fam[ran1]) > ran2 <- ind[sample(length(ind), 1)] > fish[c(ran1, ran2), ] > > This generates the pairs from exactly the same distribution as > the rejection method suggested earlier, however, it does not > contain a loop. Hi. I am sorry for a wrong statement. If there are more than two families, then the distributions from the two methods are only approximately equal, not exactly. If the sizes of families are, say n <- c(20, 3, 3) p <- n/sum(n) then the probability to a get a pair from families (i, j) using the rejection method is p1[i, j], where p1 is p1 <- p %o% p diag(p1) <- 0 p1 <- p1/sum(p1) p1 <- p1 + t(p1) p1[row(p1) >= col(p1)] <- 0 p1 [,1] [,2] [,3] [1,]0 0.4651163 0.46511628 [2,]0 0.000 0.06976744 [3,]0 0.000 0. The above produces a pair from families (i, j) with probability p2[i, j], where p2 is p2 <- p %o% p diag(p2) <- 0 p2 <- p2/rep(rowSums(p2), times=nrow(p2))*p p2 <- p2 + t(p2) p2[row(p2) >= col(p2)] <- 0 p2 [,1] [,2] [,3] [1,]0 0.4849498 0.48494983 [2,]0 0.000 0.03010033 [3,]0 0.000 0. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Read File for Matrix with rownames
Good morning, Good morning, I'm trying to read the file into an array, with the following code. A<- as.matrix(read.csv("~/Desktop/Results/Cfile.csv", header = FALSE, sep=",")) The content of the file " ","1","2","3","4" "1", 484,43,67,54 "2",54,35,67,34 "3",69,76,78,55 "4",67,86,44,34 What I needed is that the first line was the name of the columns and the first column was the name of the lines. Thanks -- View this message in context: http://r.789695.n4.nabble.com/Read-File-for-Matrix-with-rownames-tp4498280p4498280.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 know perfect execution of function ? & if error occurred in execution, how to report it?
In addition, if you need to dig down why the error occurs: ?traceback ?recover HTH Claudia Am 23.03.2012 10:29, schrieb Jim Holtman: > ?try > > Sent from my iPad > > On Mar 23, 2012, at 3:32, sagarnikam123 wrote: > >> i have one for loop,in which i am dealing with time series & arima function, >> while iterating at some stage there is a error, like >> >> Error in arima(x, c(p, 0, q)) : non-stationary AR part from CSS >> >> i want to know at which step this error occurred & print that iterating >> number >> >> e.g. >> x<-c(1:10) >> for (i in 1:5 ){ >> z<-arima(x[i]) >> print(z) >> } >> >> if error occurred in arima function at i=3 step, it should report & execute >> complete loop until i=5 >> >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/how-to-know-perfect-execution-of-function-if-error-occurred-in-execution-how-to-report-it-tp4498037p4498037.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. -- 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.