[R] Help required: binomial option pricing using package
I'm using the CRRBinomialTreeOption function (in package "fOptions") with a loop for pricing a large number of options. But I can't transfer the values obtained from this function to a "numeric" matrix as the outcome of this function is not a simple numeric. The following is the piece of code: # USING THE FUNCTION library(fOptions) option.price<-matrix(nrow=250,ncol=9) for(j in 1:9){for(i in 1:250) {option.price[i,j]=CRRBinomialTreeOption(TypeFlag="ca",S=data[(i+250),j],X=data[j,19],Time=T[i,j],r=data[i ,(9+j)],b=0,sigma=sig[i,j],n=5)}} R output: Error in option.price[i, j] = CRRBinomialTreeOption(TypeFlag = "ca", S = data[(i + : object of type 'S4' is not subsettable I'm very new to R and can't find a solution with my knowledge at this moment. Plz help. -- View this message in context: http://r.789695.n4.nabble.com/Help-required-binomial-option-pricing-using-package-tp3162935p3162935.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] dynamic model strategy
Hello, I'm hoping someone may know the most likely R package for a multivariate population model for comparing groups? That is, I'd like to estimate a (stochastic) model for one batch of experiments against a different batch growing under different conditions. I'm a bit familiar with grofit, but also reading about dse and dlm. Following Bolker's Ch. 11 it seems there are many paths open, and I add that with my data, collection of 5 time points(needed for grofit) is a gargantuan task. I'd be grateful for any advice- regards, shfets __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] lattice regression coefficients
Dear list I am sorry to have to ask this question, but I have not been able to find a solution to what seems a simple problem. I have created a lattice plot of a number of regression points and lines using a function containing panel.xyplot and panel.lmline. The result is what is expected , but I cannot figure out how to obtain the coefficients of each of the regression lines. Any help would be appreciated. thanks Art Tautz Science Advisor 2202 Main Mall UBC Ministry of Environment University of British Columbia Vancouver BC Canada V6T 1Z4 Phone 604-222-6763 [[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] initial values garchFit-formula
He guys, I'm trying to fit an arma(1,1)-garch(1,1) model with gaussian innovations, by manually implementing the likelihoodfunction, and subsequently using maxLik() to find the required estimates of the parameters. I know there is a garchFit()-command that does the same, and I use this command to check whether what I did manually is correct. However, I should use the same initial values for mu_0 and sigma_0^2 otherwise the comparison is meaningless. The problem is that I don't know what initial values are used in the garchFit()-function. I can't find it using the help(garchFit)-command, neither does google provide an answer. Does anyone of you guys know what initial values are used when one fits a arma(1,1)-garch(1,1) model with gaussian innovations by means of garchFit()? Kind regards, BabaSyb [[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] Non-uniformly distributed plot
On Dec 23, 2010, at 6:41 PM, David Winsemius wrote: On Dec 23, 2010, at 5:55 PM, Eric Hu wrote: Thanks David. I am reposting the data here. Jorge has already responded masterfully. He's apparently less lazy that I and did all the editing. A log transformation as he illustrated can be very useful with bivariate skewed distributions. The only variation I would have suggested would be to record the default par settings and restore them at the end. You could also repeat the plot an use abline to look at the predicted values plot(x,y, log="xy") lines( log(x), fit$predicted) It's complementary to the residual plot and the QQ plot in the plot.lm display for consideration of the possibility that this may not be a truly log-log-linear relationship. -- David Eric Hi, I would like to plot a linear relationship between variable x and y. Can anyone help me with scaled plotting and axes so that all data points can be visualized somehow evenly? Plaint plot(x,y) will generate condensed points near (0,0) due to several large data points. Thank you. Eric dput(x) c(0.349763, 3.39489, 1.52249, 0.269066, 0.107872, 0.0451689, 0.590268, 0.275755, 0.751845, 1.00599, 0.652409, 2.80664, 0.0269933, 0.137307, 0.282939, 1.23008, 0.436429, 0.0555626, 1.10624, 53, 1.30411, 1.29749, 53, 3.2552, 1.189, 2.23616, 1.13259, 0.505039, 1.05812, 1.18238, 0.500926, 1.0314, 0.733468, 3.13292, 1.26685, 3.10882, 1.01719, 0.13096, 0.0529692, 0.418408, 0.213299, 0.536631, 1.82336, 1.15287, 0.192519, 0.961295, 51, 0.470511, 4.05688, 1.78098, 0.364686, 1.24533) dput(y) c(0.423279, 0.473681, 0.629478, 1.09712, 0.396239, 0.273577, 0.303214, 0.628386, 0.465841, 0.687251, 0.544569, 0.635805, 0.358983, 0.16519, 0.366217, 1.08421, 0.668939, 0.181861, 0.782656, 13.3816, 1.15256, 0.965943, 20, 2.86051, 0.304939, 1.94654, 0.967576, 0.647599, 0.520811, 1.27434, 0.363666, 0.93621, 0.544573, 0.696733, 1.0031, 3.78895, 0.694053, 0.289111, 0.178439, 0.746576, 0.391725, 0.363901, 1.20297, 0.461934, 0.364011, 0.691368, 20, 0.81947, 1.69594, 1.56381, 0.900398, 0.960948) 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. 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] Non-uniformly distributed plot
On Dec 23, 2010, at 5:55 PM, Eric Hu wrote: Thanks David. I am reposting the data here. Jorge has already responded masterfully. He's apparently less lazy that I and did all the editing. A log transformation as he illustrated can be very useful with bivariate skewed distributions. The only variation I would have suggested would be to record the default par settings and restore them at the end. -- David Eric Hi, I would like to plot a linear relationship between variable x and y. Can anyone help me with scaled plotting and axes so that all data points can be visualized somehow evenly? Plaint plot(x,y) will generate condensed points near (0,0) due to several large data points. Thank you. Eric dput(x) c(0.349763, 3.39489, 1.52249, 0.269066, 0.107872, 0.0451689, 0.590268, 0.275755, 0.751845, 1.00599, 0.652409, 2.80664, 0.0269933, 0.137307, 0.282939, 1.23008, 0.436429, 0.0555626, 1.10624, 53, 1.30411, 1.29749, 53, 3.2552, 1.189, 2.23616, 1.13259, 0.505039, 1.05812, 1.18238, 0.500926, 1.0314, 0.733468, 3.13292, 1.26685, 3.10882, 1.01719, 0.13096, 0.0529692, 0.418408, 0.213299, 0.536631, 1.82336, 1.15287, 0.192519, 0.961295, 51, 0.470511, 4.05688, 1.78098, 0.364686, 1.24533) dput(y) c(0.423279, 0.473681, 0.629478, 1.09712, 0.396239, 0.273577, 0.303214, 0.628386, 0.465841, 0.687251, 0.544569, 0.635805, 0.358983, 0.16519, 0.366217, 1.08421, 0.668939, 0.181861, 0.782656, 13.3816, 1.15256, 0.965943, 20, 2.86051, 0.304939, 1.94654, 0.967576, 0.647599, 0.520811, 1.27434, 0.363666, 0.93621, 0.544573, 0.696733, 1.0031, 3.78895, 0.694053, 0.289111, 0.178439, 0.746576, 0.391725, 0.363901, 1.20297, 0.461934, 0.364011, 0.691368, 20, 0.81947, 1.69594, 1.56381, 0.900398, 0.960948) 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] Bayesian Belief Networks
Probability propragation is provided in the gRain package. Regards Søren Fra: r-help-boun...@r-project.org [r-help-boun...@r-project.org] På vegne af Michael Bedward [michael.bedw...@gmail.com] Sendt: 24. december 2010 00:01 Til: Data AnalyticsCorp. Cc: r-help@r-project.org Emne: Re: [R] Bayesian Belief Networks Hello Walt, Have a look at the bnlearn and deal packages. Michael On 24 December 2010 01:29, Data Analytics Corp. wrote: > Hi, > > Does anyone know of a package for or any implementation of a Bayesian Belief > Network in R? > > Thanks, > > Walt > > > > Walter R. Paczkowski, Ph.D. > Data Analytics Corp. > 44 Hamilton Lane > Plainsboro, NJ 08536 > > (V) 609-936-8999 > (F) 609-936-3733 > w...@dataanalyticscorp.com > www.dataanalyticscorp.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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Non-uniformly distributed plot
Hi Eric, You can try plot(x, y, log = 'xy') fit <- lm(log(y)~log(x)) abline(fit, col = 2, lty = 2) summary(fit) par(mfrow = c(2,2)) plot(fit) HTH, Jorge On Thu, Dec 23, 2010 at 5:55 PM, Eric Hu <> wrote: > Thanks David. I am reposting the data here. > > Eric > > > > Hi, > > > > I would like to plot a linear relationship between variable x and y. > > Can anyone help me with scaled plotting and axes so that all data > > points can be visualized somehow evenly? Plaint plot(x,y) will > > generate condensed points near (0,0) due to several large data > > points. Thank you. > > > > Eric > > > > > > dput(x) > c(0.349763, 3.39489, 1.52249, 0.269066, 0.107872, 0.0451689, > 0.590268, 0.275755, 0.751845, 1.00599, 0.652409, 2.80664, 0.0269933, > 0.137307, 0.282939, 1.23008, 0.436429, 0.0555626, 1.10624, 53, > 1.30411, 1.29749, 53, 3.2552, 1.189, 2.23616, 1.13259, 0.505039, > 1.05812, 1.18238, 0.500926, 1.0314, 0.733468, 3.13292, 1.26685, > 3.10882, 1.01719, 0.13096, 0.0529692, 0.418408, 0.213299, 0.536631, > 1.82336, 1.15287, 0.192519, 0.961295, 51, 0.470511, 4.05688, > 1.78098, 0.364686, 1.24533) > > dput(y) > c(0.423279, 0.473681, 0.629478, 1.09712, 0.396239, 0.273577, > 0.303214, 0.628386, 0.465841, 0.687251, 0.544569, 0.635805, 0.358983, > 0.16519, 0.366217, 1.08421, 0.668939, 0.181861, 0.782656, 13.3816, > 1.15256, 0.965943, 20, 2.86051, 0.304939, 1.94654, 0.967576, > 0.647599, 0.520811, 1.27434, 0.363666, 0.93621, 0.544573, 0.696733, > 1.0031, 3.78895, 0.694053, 0.289111, 0.178439, 0.746576, 0.391725, > 0.363901, 1.20297, 0.461934, 0.364011, 0.691368, 20, 0.81947, > 1.69594, 1.56381, 0.900398, 0.960948) > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] Bayesian Belief Networks
On Fri, Dec 24, 2010 at 12:01 AM, Michael Bedward wrote: > Hello Walt, > > Have a look at the bnlearn and deal packages. > > Michael Dear Walt, take a look also to the catnet/mugnet and pcalg packages, and if you have questions about bnlearn feel free to ask. Regards, Marco, author and maintainer of bnlearn. -- Marco Scutari, Ph.D. Student Department of Statistical Sciences University of Padova, Italy __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] data frame with nested data frame
On Thu, Dec 23, 2010 at 5:06 PM, Vadim Ogranovich wrote: > Dear R-users, > > I am somewhat puzzled by how R treats data frames with nested data frames. > Below are a couple of examples, maybe someone could help explain what the > guiding logic here is. > > ## construct plain data frame >> z <- data.frame(x=1) > > ## add a data frame member >> z$y <- data.frame(a=1,b=2) > > ## puzzle 1: z is apparently different from a straightforward construction of > the 'same' object >> all.equal(z, data.frame(x=1,y=data.frame(a=1,b=2))) > [1] "Names: 1 string mismatch" > "Length mismatch: comparison on first 2 components" > [3] "Component 2: Modes: list, numeric" > "Component 2: names for target but not for current" > [5] "Component 2: Attributes: < Modes: list, NULL >" > "Component 2: Attributes: < names for target but not for current >" > [7] "Component 2: Attributes: < Length mismatch: comparison on first 0 > components >" "Component 2: Length mismatch: comparison on first 1 components" > > ## puzzle 2: could not rbind z >> rbind.data.frame(z, z) > Error in `row.names<-.data.frame`(`*tmp*`, value = c("1", "1")) : > duplicate 'row.names' are not allowed > In addition: Warning message: > non-unique value when setting 'row.names': '1' > 1. If we strip out all data frames and leave them as lists then (a) z is basically a nested list list(x=1,y=list(a=1,b=2)) whereas (b) the construct data.frame(x=1,y=data.frame(a=1,b=2))) is interpreted to be a flat list, namely, the same as: data.frame(x = 1, y.a = 1, y.b = 2) and if we strip out data frames is basically list(x = 1, y.a = 1, y.b = 2) 2. Although this may be nothing more than stating the obvious, it seems its not necessarily true that operations that work in the normal cases also work in strange uncommon nested cases like this. -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] data frame with nested data frame
On Dec 23, 2010, at 5:06 PM, Vadim Ogranovich wrote: Dear R-users, I am somewhat puzzled by how R treats data frames with nested data frames. Speaking as a fellow user, why? Why would we want dataframes inside dataframes? Why wouldn't lists of dataframes be more appropriate if you were hoping to use apply or ? Below are a couple of examples, maybe someone could help explain what the guiding logic here is. ## construct plain data frame z <- data.frame(x=1) ## add a data frame member z$y <- data.frame(a=1,b=2) cbind.data.frame (dispatched if the first argument to cbind is a dataframe) would give you another dataframe without the mess of having nesting. > cbind(z, b=2) x b 1 1 2 This is also the time to ask what is it that you are _really_ trying to accomplish? ## puzzle 1: z is apparently different from a straightforward construction of the 'same' object all.equal(z, data.frame(x=1,y=data.frame(a=1,b=2))) [1] "Names: 1 string mismatch" "Length mismatch: comparison on first 2 components" [3] "Component 2: Modes: list, numeric" "Component 2: names for target but not for current" [5] "Component 2: Attributes: < Modes: list, NULL >" "Component 2: Attributes: < names for target but not for current >" [7] "Component 2: Attributes: < Length mismatch: comparison on first 0 components >" "Component 2: Length mismatch: comparison on first 1 components" Yes. the second one is equivalent to passing just the list portions of the nameless data.frame and ignoring attributes. ## puzzle 2: could not rbind z rbind.data.frame(z, z) Error in `row.names<-.data.frame`(`*tmp*`, value = c("1", "1")) : duplicate 'row.names' are not allowed In addition: Warning message: non-unique value when setting 'row.names': '1' That is a puzzle, I agree. This succeeds: z <- data.frame(x=1, y=2) rbind(z,z # x y 1 1 2 2 1 2 Perhaps a bug (... trying to add drop=FALSE had an amusing result: > rbind(z,z, drop=FALSE) x 11 21 drop 0 -- David version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 9.1 year 2009 month 06 day26 svn rev48839 language R version.string R version 2.9.1 (2009-06-26) Thanks, Vadim -- David Winsemius, MD West Hartford, CT > sessionInfo() R version 2.12.1 (2010-12-16) Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] splines stats graphics grDevices utils datasets methods base other attached packages: [1] sos_1.3-0 brew_1.0-4 lattice_0.19-13 loaded via a namespace (and not attached): [1] grid_2.12.1 tools_2.12.1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Bayesian Belief Networks
Hello Walt, Have a look at the bnlearn and deal packages. Michael On 24 December 2010 01:29, Data Analytics Corp. wrote: > Hi, > > Does anyone know of a package for or any implementation of a Bayesian Belief > Network in R? > > Thanks, > > Walt > > > > Walter R. Paczkowski, Ph.D. > Data Analytics Corp. > 44 Hamilton Lane > Plainsboro, NJ 08536 > > (V) 609-936-8999 > (F) 609-936-3733 > w...@dataanalyticscorp.com > www.dataanalyticscorp.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] Non-uniformly distributed plot
Thanks David. I am reposting the data here. Eric > Hi, > > I would like to plot a linear relationship between variable x and y. > Can anyone help me with scaled plotting and axes so that all data > points can be visualized somehow evenly? Plaint plot(x,y) will > generate condensed points near (0,0) due to several large data > points. Thank you. > > Eric > > > dput(x) c(0.349763, 3.39489, 1.52249, 0.269066, 0.107872, 0.0451689, 0.590268, 0.275755, 0.751845, 1.00599, 0.652409, 2.80664, 0.0269933, 0.137307, 0.282939, 1.23008, 0.436429, 0.0555626, 1.10624, 53, 1.30411, 1.29749, 53, 3.2552, 1.189, 2.23616, 1.13259, 0.505039, 1.05812, 1.18238, 0.500926, 1.0314, 0.733468, 3.13292, 1.26685, 3.10882, 1.01719, 0.13096, 0.0529692, 0.418408, 0.213299, 0.536631, 1.82336, 1.15287, 0.192519, 0.961295, 51, 0.470511, 4.05688, 1.78098, 0.364686, 1.24533) > dput(y) c(0.423279, 0.473681, 0.629478, 1.09712, 0.396239, 0.273577, 0.303214, 0.628386, 0.465841, 0.687251, 0.544569, 0.635805, 0.358983, 0.16519, 0.366217, 1.08421, 0.668939, 0.181861, 0.782656, 13.3816, 1.15256, 0.965943, 20, 2.86051, 0.304939, 1.94654, 0.967576, 0.647599, 0.520811, 1.27434, 0.363666, 0.93621, 0.544573, 0.696733, 1.0031, 3.78895, 0.694053, 0.289111, 0.178439, 0.746576, 0.391725, 0.363901, 1.20297, 0.461934, 0.364011, 0.691368, 20, 0.81947, 1.69594, 1.56381, 0.900398, 0.960948) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Non-uniformly distributed plot
On Dec 23, 2010, at 5:37 PM, Eric Hu wrote: Hi, I would like to plot a linear relationship between variable x and y. Can anyone help me with scaled plotting and axes so that all data points can be visualized somehow evenly? Plaint plot(x,y) will generate condensed points near (0,0) due to several large data points. Thank you. Eric x [1] 0.3497630 3.3948900 1.5224900 0.2690660 0.1078720 0.0451689 0.5902680 0.2757550 0.7518450 Rather than offering data in this format, which would require stripping out all of the element numbering at the margins, why not learn to post with dput values: dput(x) dput(y) # rather than #x #y -- David This message brought to you by the Committee for Better Posting Behavior. [10] 1.0059900 0.6524090 2.8066400 0.0269933 0.1373070 0.2829390 1.2300800 0.4364290 0.0555626 [19] 1.1062400 53.000 1.3041100 1.2974900 53.000 3.2552000 1.189 2.2361600 1.1325900 [28] 0.5050390 1.0581200 1.1823800 0.5009260 1.0314000 0.7334680 3.1329200 1.2668500 3.1088200 [37] 1.0171900 0.1309600 0.0529692 0.4184080 0.2132990 0.5366310 1.8233600 1.1528700 0.1925190 [46] 0.9612950 51.000 0.4705110 4.0568800 1.7809800 0.3646860 1.2453300 y [1] 0.423279 0.473681 0.629478 1.097120 0.396239 0.273577 0.303214 0.628386 0.465841 [10] 0.687251 0.544569 0.635805 0.358983 0.165190 0.366217 1.084210 0.668939 0.181861 [19] 0.782656 13.381600 1.152560 0.965943 20.00 2.860510 0.304939 1.946540 0.967576 [28] 0.647599 0.520811 1.274340 0.363666 0.936210 0.544573 0.696733 1.003100 3.788950 [37] 0.694053 0.289111 0.178439 0.746576 0.391725 0.363901 1.202970 0.461934 0.364011 [46] 0.691368 20.00 0.819470 1.695940 1.563810 0.900398 0.960948 [[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. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Non-uniformly distributed plot
Hi, I would like to plot a linear relationship between variable x and y. Can anyone help me with scaled plotting and axes so that all data points can be visualized somehow evenly? Plaint plot(x,y) will generate condensed points near (0,0) due to several large data points. Thank you. Eric > x [1] 0.3497630 3.3948900 1.5224900 0.2690660 0.1078720 0.0451689 0.5902680 0.2757550 0.7518450 [10] 1.0059900 0.6524090 2.8066400 0.0269933 0.1373070 0.2829390 1.2300800 0.4364290 0.0555626 [19] 1.1062400 53.000 1.3041100 1.2974900 53.000 3.2552000 1.189 2.2361600 1.1325900 [28] 0.5050390 1.0581200 1.1823800 0.5009260 1.0314000 0.7334680 3.1329200 1.2668500 3.1088200 [37] 1.0171900 0.1309600 0.0529692 0.4184080 0.2132990 0.5366310 1.8233600 1.1528700 0.1925190 [46] 0.9612950 51.000 0.4705110 4.0568800 1.7809800 0.3646860 1.2453300 > y [1] 0.423279 0.473681 0.629478 1.097120 0.396239 0.273577 0.303214 0.628386 0.465841 [10] 0.687251 0.544569 0.635805 0.358983 0.165190 0.366217 1.084210 0.668939 0.181861 [19] 0.782656 13.381600 1.152560 0.965943 20.00 2.860510 0.304939 1.946540 0.967576 [28] 0.647599 0.520811 1.274340 0.363666 0.936210 0.544573 0.696733 1.003100 3.788950 [37] 0.694053 0.289111 0.178439 0.746576 0.391725 0.363901 1.202970 0.461934 0.364011 [46] 0.691368 20.00 0.819470 1.695940 1.563810 0.900398 0.960948 [[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] data frame with nested data frame
Dear R-users, I am somewhat puzzled by how R treats data frames with nested data frames. Below are a couple of examples, maybe someone could help explain what the guiding logic here is. ## construct plain data frame > z <- data.frame(x=1) ## add a data frame member > z$y <- data.frame(a=1,b=2) ## puzzle 1: z is apparently different from a straightforward construction of the 'same' object > all.equal(z, data.frame(x=1,y=data.frame(a=1,b=2))) [1] "Names: 1 string mismatch" "Length mismatch: comparison on first 2 components" [3] "Component 2: Modes: list, numeric" "Component 2: names for target but not for current" [5] "Component 2: Attributes: < Modes: list, NULL >" "Component 2: Attributes: < names for target but not for current >" [7] "Component 2: Attributes: < Length mismatch: comparison on first 0 components >" "Component 2: Length mismatch: comparison on first 1 components" ## puzzle 2: could not rbind z > rbind.data.frame(z, z) Error in `row.names<-.data.frame`(`*tmp*`, value = c("1", "1")) : duplicate 'row.names' are not allowed In addition: Warning message: non-unique value when setting 'row.names': '1' > version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 9.1 year 2009 month 06 day26 svn rev48839 language R version.string R version 2.9.1 (2009-06-26) Thanks, Vadim Note: This email is for the confidential use of the named addressee(s) only and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you are hereby notified that any review, dissemination or copying of this email is strictly prohibited, and to please notify the sender immediately and destroy this email and any attachments. Email transmission cannot be guaranteed to be secure or error-free. Jump Trading, therefore, does not make any guarantees as to the completeness or accuracy of this email or any attachments. This email is for informational purposes only and does not constitute a recommendation, offer, request or solicitation of any kind to buy, sell, subscribe, redeem or perform any type of transaction of a financial product. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Reconcile Random Samples
> -Original Message- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] > On Behalf Of Mike Harwood > Sent: Thursday, December 23, 2010 9:19 AM > To: r-help@r-project.org > Subject: [R] Reconcile Random Samples > > Is there a way to generate identical random samples using R's runif > function and SAS's ranuni function? I have assigned the same seed > values in both software packages, but the following results show > different results. Thanks! > > R > === > > set.seed(6) > > random <- runif(10) > > random > [1] 0.6062683 0.9376420 0.2643521 0.3800939 0.8074834 0.9780757 > 0.9579337 > [8] 0.7627319 0.5096485 0.0644768 > > SAS (the log file) > === > 15 data _null_; > 16 do i=1 to 10; > 17random = ranuni(6); > 18put i= random=; > 19end; > 20 run; > > i=1 random=0.1097754189 > i=2 random=0.8205322939 > i=3 random=0.3989458365 > i=4 random=0.5563918723 > i=5 random=0.5296154672 > i=6 random=0.8156640985 > i=7 random=0.2578750389 > i=8 random=0.1901503369 > i=9 random=0.2987641572 > i=10 random=0.3993993096 > Yes, If you use the same pseudorandom number generator in both places. The ranuni() function in SAS uses a simple multiplicative generator SEED = mod( SEED * 397204094, 2**31-1 ) and then returns the value SEED / (2^31 - 1) as the random number. SAS also has a much better generator, rand(). I would instead generate a series of random number in one program and export the numbers to the other program. Hope this is helpful, Dan Daniel Nordlund Bothell, WA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Finding flat-topped "peaks" in simple data set
Hi. First, you might have more success with turnpoints() in the pastecs package. Next, consider an approach which makes your peaks truly flattopped. The sample dataset appears to show that the data on each side of your peaks are down by at least 6 counts or so, so try running the phase values thru a filter sort of like { R- pseudocode, so will need editing} phase[i] <- if (abs(phase[i+1]-phase[i])<6) phase[i+1] else phase[i] Then any peak-finder will find only one peak there, and you can select the center value if desired pretty easily. Or, if necessary, you could use instead the same if() condition but replace phase[i] with NA instead of phase[i+1] . Then there'd be a single phase value remaining at each peak. Carl * I have a new challenge. I often generate time-series data sets that look like the one below, with a variable ("Phase") which has a series of flat-topped peaks (sample data below with 5 "peaks"). I would like to calculate the phase value for each peak. It would be great to calculate the mean value for the peak (possibly using rollmean(), but given the low variability within the broad peak even just picking one value from the peak would be sufficient. I have tried using peaks() from the library(simecol), peaks(data$Time,data$phase, model="max"), but because of the flat nature of the peaks and the fact that peaks() looks for values with lower neighbors I am unable to find all the peaks (especially the one between time 0.762-0.897). For all my data files the maximum phase values will fall between 27 and 62 so adding a function which removes the values below 27 is reasonable and a technique I have used to eliminate some of the noise between the peaks. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problem installing R on ubuntu
On Thu, Dec 23, 2010 at 7:15 PM, Horace Tso wrote: > Barry, my reporting error, my ubuntu is 10.04, which is Hardy I believe. It > was a straight build from the source. No funny stuff done on it. My lsb_release says my 10.04 is Lucid. # lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description:Ubuntu 10.04.1 LTS Release:10.04 Codename: lucid https://wiki.ubuntu.com/DevelopmentCodeNames agrees! Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problem installing R on ubuntu
Barry, my reporting error, my ubuntu is 10.04, which is Hardy I believe. It was a straight build from the source. No funny stuff done on it. H -Original Message- From: b.rowling...@googlemail.com [mailto:b.rowling...@googlemail.com] On Behalf Of Barry Rowlingson Sent: Thursday, December 23, 2010 10:57 AM To: Horace Tso Cc: r-help Subject: Re: [R] problem installing R on ubuntu On Thu, Dec 23, 2010 at 6:30 PM, Horace Tso wrote: > Following the official instructions to install R on ubuntu 10.04, I issued > this command on the prompt, > > sudo apt-get install r-base > The following packages have unmet dependencies: > r-base: Depends: r-base-core (>= 2.12.1-1hardy0) but 2.10.1-2 is to be > installed > Depends: r-recommended (= 2.12.1-1hardy0) but 2.10.1-2 is to be > installed > E: Broken packages > > Note I already have 2.10.1 installed. Ubuntu 10.4 is Lucid Lynx, so I'm slightly worried why hardy is mentioned in the error. Is this a poorly upgraded machine from Hardy? Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] forcing evaluation of a char string argument
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Charles C. Berry > Sent: Thursday, December 23, 2010 9:39 AM > To: rballen > Cc: r-help@r-project.org > Subject: Re: [R] forcing evaluation of a char string argument > > On Wed, 22 Dec 2010, rballen wrote: > > > > > Why does x in "assign(x)" correctly evaluate to "rank" where > > UseMethod(func) does not get correctly evaluated? > > Because it is the body of a function definition. More generally, because it is in an expression and you need something like substitute() to change the expression. > > If you want to plug in the value of 'func' in the body of > that function, > you need to do something like this: > > toGeneric <- > function(func) { > env<-environment(get(func)) > > # default method of new generic = the original function > assign(paste(func,".default",sep=""),get(func),pos=env) > foo <- function(x,...) {} > lf <- list(x=func) > body.foo <- substitute(UseMethod(x),lf) > body(foo)<-body.foo > assign(func,foo,pos=env) > } > > BTW, are you sure you know what 'env' evaluates to?? (It is NOT the > environment of the object named by the value of func in the > parent.frame > of toGeneric.) Yes, environment(someFunction) gives you the environment in which the function was created (which controls where it looks up names of objects). It does not have much to do with the environment in which the name of the function is placed, which find("someFunction") gives you (roughly). local() can make a function in an arbitrary environment but you can put the name for that function in any other writable environment. > myEnv <- list2env(list(pi=3)) > f <- local(function(r) pi * r^2, envir=myEnv) > f(2) [1] 12 > environment(f) # where it looks up `pi` > objects(environment(f)) [1] "pi" > find("f") # where the name `f` is stashed [1] ".GlobalEnv" If you have a function that creates a new function (by calling the special function called "function") the new function's environment is the execution environment of the creator. This can lead to surprises like > makeFunc <- function(expr) { + func <- function(x){} + functionBody(func) <- substitute(expr) + func + } > f <- makeFunc(x+4) > f(10) # good, expected 14 [1] 14 > g <- makeFunc(func) > g(10) # bad, expected a 'func not found' error function (x) func See how g() got the symbol func's value from the execution environment of the call to makeFunc() in which g() was made. The following version of makeFunc creates the function in the desired environment so it looks things up there. > makeFunc2 <- function (expr, envir) { + eval(substitute(function(x) expr), envir = envir) + } > h <- makeFunc(func, environment()) > environment(h) > h(10) Error in h(10) : object 'func' not found toGeneric() really needs two environment-related arguments, one to say where the generic and default method should look things up and one to say where the the names of the new functions should be stored. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > > HTH, > > Chuck > > > > Can we use as.call(list(UseMethod,func))? > > > >>> assign(paste(func,".default",sep=""),get(func),pos=env) > >>> > >>> assign(func,function(x,...) UseMethod(func),pos=env) > > > > On Wed, Dec 22, 2010 at 9:03 PM, William Dunlap [via R] > > wrote: > >> Try the following, which I haven't tested much > >> and needs more error checking (e.g., to see that > >> the function is not already generic and that > >> its argument list is compatible with (x,...)). > >> I put in the print statements to show what > >> the calls to substitute() do. > >> > >> toGeneric <- function (funcName) { > >> Â Â stopifnot(is.character(funcName)) > >> Â Â funcItself <- get(funcName) > >> Â Â stopifnot(is.function(funcItself)) > >> Â Â envir <- environment(funcItself) > >> Â Â tmp <- substitute(funcSymbol <- function(x, ...) > >> UseMethod(funcName), > >> Â Â Â Â list(funcSymbol = as.symbol(funcName), > funcName = funcName)) > >> Â Â print(tmp) > >> Â Â eval(tmp, envir = envir) > >> Â Â tmp <- substitute(defaultSymbol <- funcItself, > list(defaultSymbol = > >> as.symbol(paste(sep = ".", > >> Â Â Â Â funcName, "default")), funcItself = funcItself)) > >> Â Â print(tmp) > >> Â Â eval(tmp, envir = envir) > >> } > >> > >> E.g., > >> > >> Â Â > wsx <- function(x, base=2)log(x, base=base) > >> Â Â > toGeneric("wsx") > >> Â Â wsx <- function(x, ...) UseMethod("wsx") > >> Â Â wsx.default <- function (x, base = 2) > >> Â Â log(x, base = base) > >> Â Â > wsx > >> Â Â function (x, ...) > >> Â Â UseMethod("wsx") > >> Â Â > wsx.default > >> Â Â function (x, base = 2) > >> Â Â log(x, base = base) > >> > >> Bill Dunlap > >> Spotfire, TIBCO Software > >> wdunlap tibco.com > >> > >>> -Original Message- > >>> From: [hidden email] >
Re: [R] problem installing R on ubuntu
On Thu, Dec 23, 2010 at 6:30 PM, Horace Tso wrote: > Following the official instructions to install R on ubuntu 10.04, I issued > this command on the prompt, > > sudo apt-get install r-base > The following packages have unmet dependencies: > r-base: Depends: r-base-core (>= 2.12.1-1hardy0) but 2.10.1-2 is to be > installed > Depends: r-recommended (= 2.12.1-1hardy0) but 2.10.1-2 is to be > installed > E: Broken packages > > Note I already have 2.10.1 installed. Ubuntu 10.4 is Lucid Lynx, so I'm slightly worried why hardy is mentioned in the error. Is this a poorly upgraded machine from Hardy? Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] problem installing R on ubuntu
Following the official instructions to install R on ubuntu 10.04, I issued this command on the prompt, sudo apt-get install r-base Here is the error msg, Reading package lists... Done Building dependency tree Reading state information... Done Some packages could not be installed. This may mean that you have requested an impossible situation or if you are using the unstable distribution that some required packages have not yet been created or been moved out of Incoming. The following information may help to resolve the situation: The following packages have unmet dependencies: r-base: Depends: r-base-core (>= 2.12.1-1hardy0) but 2.10.1-2 is to be installed Depends: r-recommended (= 2.12.1-1hardy0) but 2.10.1-2 is to be installed E: Broken packages Note I already have 2.10.1 installed. Any comments/advices appreciated. 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.
Re: [R] R-way to doing this?
Thanks Patrick for you input. That is what I wanted. I must have read the R-Inferno long time back. -Original Message- From: Patrick Burns [mailto:pbu...@pburns.seanet.com] Sent: 23 December 2010 15:01 To: r-help@r-project.org; bogaso.christofer Subject: Re: [R] R-way to doing this? If I understand your question properly, then you are looking for 'try' or 'tryCatch'. There is an example of using these on page 89 of 'The R Inferno'. On 23/12/2010 04:13, Bogaso Christofer wrote: > Dear friends, hope I could be able to explain my problem through > following example. Please consider this: > > > >> set.seed(1) > >> input<- rnorm(10) > >> input > > [1] -0.6264538 0.1836433 -0.8356286 1.5952808 0.3295078 -0.8204684 > 0.4874291 0.7383247 0.5757814 -0.3053884 > >> tag<- vector(length=10) > > > > for(i in 1:10) > > # if there is any error in evaluating "log(input[i])" > (or evaluating some function) then tag[i] = 1, otherwise tag[i] = 0 > > > > Therefore my "tag" vector should like: tag[1]=1, tag[2]=0, tag[3]=1, > tag[4]=0, tag[5]=0... > > > > Actually R returns logarithm of a negative number as NaN, however in > this example please consider R returns error when it encounters > logarithm of a negative number. > > > > Is there any way to do above task? > > > > Thanks and regards, > > > [[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. > -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Reconcile Random Samples
Is there a way to generate identical random samples using R's runif function and SAS's ranuni function? I have assigned the same seed values in both software packages, but the following results show different results. Thanks! R === > set.seed(6) > random <- runif(10) > random [1] 0.6062683 0.9376420 0.2643521 0.3800939 0.8074834 0.9780757 0.9579337 [8] 0.7627319 0.5096485 0.0644768 SAS (the log file) === 15 data _null_; 16 do i=1 to 10; 17 random = ranuni(6); 18 put i= random=; 19 end; 20 run; i=1 random=0.1097754189 i=2 random=0.8205322939 i=3 random=0.3989458365 i=4 random=0.5563918723 i=5 random=0.5296154672 i=6 random=0.8156640985 i=7 random=0.2578750389 i=8 random=0.1901503369 i=9 random=0.2987641572 i=10 random=0.3993993096 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] forcing evaluation of a char string argument
On Wed, 22 Dec 2010, rballen wrote: Why does x in "assign(x)" correctly evaluate to "rank" where UseMethod(func) does not get correctly evaluated? Because it is the body of a function definition. If you want to plug in the value of 'func' in the body of that function, you need to do something like this: toGeneric <- function(func) { env<-environment(get(func)) # default method of new generic = the original function assign(paste(func,".default",sep=""),get(func),pos=env) foo <- function(x,...) {} lf <- list(x=func) body.foo <- substitute(UseMethod(x),lf) body(foo)<-body.foo assign(func,foo,pos=env) } BTW, are you sure you know what 'env' evaluates to?? (It is NOT the environment of the object named by the value of func in the parent.frame of toGeneric.) HTH, Chuck Can we use as.call(list(UseMethod,func))? assign(paste(func,".default",sep=""),get(func),pos=env) assign(func,function(x,...) UseMethod(func),pos=env) On Wed, Dec 22, 2010 at 9:03 PM, William Dunlap [via R] wrote: Try the following, which I haven't tested much and needs more error checking (e.g., to see that the function is not already generic and that its argument list is compatible with (x,...)). I put in the print statements to show what the calls to substitute() do. toGeneric <- function (funcName) { ?? ?? stopifnot(is.character(funcName)) ?? ?? funcItself <- get(funcName) ?? ?? stopifnot(is.function(funcItself)) ?? ?? envir <- environment(funcItself) ?? ?? tmp <- substitute(funcSymbol <- function(x, ...) UseMethod(funcName), ?? ?? ?? ?? list(funcSymbol = as.symbol(funcName), funcName = funcName)) ?? ?? print(tmp) ?? ?? eval(tmp, envir = envir) ?? ?? tmp <- substitute(defaultSymbol <- funcItself, list(defaultSymbol = as.symbol(paste(sep = ".", ?? ?? ?? ?? funcName, "default")), funcItself = funcItself)) ?? ?? print(tmp) ?? ?? eval(tmp, envir = envir) } E.g., ?? ??> wsx <- function(x, base=2)log(x, base=base) ?? ??> toGeneric("wsx") ?? ??wsx <- function(x, ...) UseMethod("wsx") ?? ??wsx.default <- function (x, base = 2) ?? ??log(x, base = base) ?? ??> wsx ?? ??function (x, ...) ?? ??UseMethod("wsx") ?? ??> wsx.default ?? ??function (x, base = 2) ?? ??log(x, base = base) Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: [hidden email] [mailto:[hidden email]] On Behalf Of rballen Sent: Wednesday, December 22, 2010 2:42 PM To: [hidden email] Subject: [R] forcing evaluation of a char string argument I'm trying to make a function to turn a regular function into an S3 generic one. I want myMethod to be: function(x,...) UseMethod("myMethod") But I keep getting: function(x,...) UseMethod(func) Here's the function: toGeneric<-function(func) { env<-environment(get(func)) # default method of new generic = the original function assign(paste(func,".default",sep=""),get(func),pos=env) assign(func,function(x,...) UseMethod(func),pos=env) } toGeneric("myMethod") I messed around with force, substitute, and deparse, but I can't get any of those to help. Thanks. -- View this message in context: http://r.789695.n4.nabble.com/forcing-evaluation-of-a-char-str ing-argument-tp3161365p3161365.html Sent from the R help mailing list archive at Nabble.com. __ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ [hidden email] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. View message @ http://r.789695.n4.nabble.com/forcing-evaluation-of-a-char-string-argument-tp3161365p3161542.html To unsubscribe from forcing evaluation of a char string argument, click here. -- View this message in context: http://r.789695.n4.nabble.com/forcing-evaluation-of-a-char-string-argument-tp3161365p3161666.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] Charles C. BerryDept of Family/Preventive Medicine cbe...@tajo.ucsd.eduUC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Finding flat-topped "peaks" in simple data set
Hello, Thank you to all those great folks that have helped me in the past (especially Dennis Murphy). I have a new challenge. I often generate time-series data sets that look like the one below, with a variable ("Phase") which has a series of flat-topped peaks (sample data below with 5 "peaks"). I would like to calculate the phase value for each peak. It would be great to calculate the mean value for the peak (possibly using rollmean(), but given the low variability within the broad peak even just picking one value from the peak would be sufficient. I have tried using peaks() from the library(simecol), peaks(data$Time,data$phase, model="max"), but because of the flat nature of the peaks and the fact that peaks() looks for values with lower neighbors I am unable to find all the peaks (especially the one between time 0.762-0.897). For all my data files the maximum phase values will fall between 27 and 62 so adding a function which removes the values below 27 is reasonable and a technique I have used to eliminate some of the noise between the peaks. data= Time Phase 1 0.000 15.18 2 0.017 13.42 3 0.034 11.40 4 0.051 18.31 5 0.068 25.23 6 0.085 33.92 7 0.102 42.86 8 0.119 42.87 9 0.136 42.88 10 0.153 42.88 11 0.170 42.87 12 0.186 42.88 13 0.203 42.88 14 0.220 42.78 15 0.237 33.50 16 0.254 24.81 17 0.271 17.20 18 0.288 10.39 19 0.305 13.97 20 0.322 16.48 21 0.339 14.75 22 0.356 20.80 23 0.373 25.79 24 0.390 31.25 25 0.407 39.89 26 0.423 40.04 27 0.440 40.05 28 0.457 40.05 29 0.474 40.05 30 0.491 40.05 31 0.508 40.06 32 0.525 40.07 33 0.542 32.23 34 0.559 23.90 35 0.576 17.86 36 0.592 11.63 37 0.609 12.78 38 0.626 13.12 39 0.643 10.93 40 0.660 10.63 41 0.677 10.82 42 0.694 11.84 43 0.711 20.44 44 0.728 27.33 45 0.745 34.22 46 0.762 41.55 47 0.779 41.55 48 0.796 41.55 49 0.813 41.53 50 0.830 41.53 51 0.847 41.52 52 0.864 41.52 53 0.880 41.53 54 0.897 41.53 55 0.914 33.07 56 0.931 25.12 57 0.948 19.25 58 0.965 11.30 59 0.982 12.48 60 0.999 13.85 61 1.016 13.62 62 1.033 12.62 63 1.050 19.39 64 1.067 25.48 65 1.084 31.06 66 1.101 39.49 67 1.118 39.48 68 1.135 39.46 69 1.152 39.45 70 1.169 39.43 71 1.185 39.42 72 1.202 39.42 73 1.219 39.41 74 1.236 39.41 75 1.253 37.39 76 1.270 29.03 77 1.287 20.61 78 1.304 14.07 79 1.321 9.12 I have also tried using the peak finding code from Prof. Ripely, but it doesn't seem able to find all the peaks either even if I widen the "span." peaks<-function(series,span=3) { z <- embed(series, span) s <- span%/%2 v<- max.col(z) == 1 + s result <- c(rep(FALSE,s),v) result <- result[1:(length(result)-s)] result } Can anyone offer some advice on how to find a series of peaks in a data file when the peaks are flat-topped and actually less "peaked?" Thanks so much! Nate [[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] Removing elements of a list object
Thanks! On Thu, Dec 23, 2010 at 3:24 PM, Henrique Dallazuanna wrote: > Try this: > > x$second <- NULL > > > On Thu, Dec 23, 2010 at 3:21 PM, Eduardo de Oliveira Horta < > eduardo.oliveiraho...@gmail.com> wrote: > >> Hello, >> >> say I have an object >> >> > x = list(first = 10, second = 20, third = "Yeah!") >> >> and want to remove the $second element of that list. My first try was, of >> course, >> >> > rm(x$second) >> >> which gave me the following error message >> >> > Error in rm(x$second) : ... must contain names or character strings >> >> Any ideas here, folks? >> >> Best regards, and Merry Christmas! >> >> Eduardo Horta >> >>[[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. >> > > > > -- > Henrique Dallazuanna > Curitiba-Paraná-Brasil > 25° 25' 40" S 49° 16' 22" O > [[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] Integration with LaTex and LyX
Thanks! On Mon, Dec 13, 2010 at 7:10 PM, Yihui Xie wrote: > I tried hard to write an automagic script to configure LyX so that you > don't need to go to the instructions on CRAN > (http://cran.r-project.org/contrib/extra/lyx/): > > > http://yihui.name/en/2010/10/how-to-start-using-pgfsweave-in-lyx-in-one-minute/ > > This works for LyX 1.6.x and major OS'es with probability 95%. > > There will be substantial changes in LyX 2.0, and I will need to > modify my configurations after LyX 2.0 is out (hopefully early next > year). > > Regards, > Yihui > -- > Yihui Xie > Phone: 515-294-2465 Web: http://yihui.name > Department of Statistics, Iowa State University > 2215 Snedecor Hall, Ames, IA > > > > On Mon, Dec 13, 2010 at 9:27 AM, Eduardo de Oliveira Horta > wrote: > > Hello, > > > > Are there any packages which allow for a good integration between R and > > LaTex / LyX? I'm interested mainly in automatic (automagic?) imports of > > plots/graphics. > > > > Thanks in advance and best regards, > > > > Eduardo de Oliveira Horta > > > >[[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] Removing elements of a list object
Try this: x$second <- NULL On Thu, Dec 23, 2010 at 3:21 PM, Eduardo de Oliveira Horta < eduardo.oliveiraho...@gmail.com> wrote: > Hello, > > say I have an object > > > x = list(first = 10, second = 20, third = "Yeah!") > > and want to remove the $second element of that list. My first try was, of > course, > > > rm(x$second) > > which gave me the following error message > > > Error in rm(x$second) : ... must contain names or character strings > > Any ideas here, folks? > > Best regards, and Merry Christmas! > > Eduardo Horta > >[[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. > -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40" S 49° 16' 22" O [[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] Removing elements of a list object
Hello, say I have an object > x = list(first = 10, second = 20, third = "Yeah!") and want to remove the $second element of that list. My first try was, of course, > rm(x$second) which gave me the following error message > Error in rm(x$second) : ... must contain names or character strings Any ideas here, folks? Best regards, and Merry Christmas! Eduardo Horta [[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] Writing a single output file
On Thu, Dec 23, 2010 at 8:07 AM, Amy Milano wrote: > Dear R helpers! > > Let me first wish all of you "Merry Christmas and Very Happy New year 2011" > > "Christmas day is a day of Joy and Charity, > May God make you rich in both" - Phillips Brooks > > ## > > > I have a process which generates number of outputs. The R code for the same > is as given below. > > for(i in 1:n) > { > write.csv(output[i], file = paste("output", i, ".csv", sep = ""), row.names = > FALSE) > } > > Depending on value of 'n', I get different output files. > > Suppose n = 3, that means I am having three output csv files viz. > 'output1.csv', 'output2.csv' and 'output3.csv' > > output1.csv > date yield_rate > 12/23/2010 5.25 > 12/22/2010 5.19 > . > . > > > output2.csv > > date yield_rate > > 12/23/2010 4.16 > > 12/22/2010 4.59 > > . > > . > > output3.csv > > > date yield_rate > > > 12/23/2010 6.15 > > > 12/22/2010 6.41 > In the development version of zoo you can do all this in basically one read.zoo command producing the required zoo series: # chron's default date format is the same as in the output*.csv files library(chron) # pull in development version of read.zoo library(zoo) source("http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/zoo/R/read.zoo.R?revision=813&root=zoo";) # this does it z <- read.zoo(Sys.glob("output*.csv"), header = TRUE, FUN = as.chron) as.data.frame(z) or data.frame(Time = time(z), coredata(z)) can be used to convert z to a data frame with times as row names or a data frame with times in column respectively (although you may wish to just leave it as a zoo object so you can take advantage of zoo's other facilities too). -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Writing a single output file
>> input <- do.call(rbind, lapply(fileNames, function(.name){ > + .data <- read.table(.name, header = TRUE, as.is = TRUE) > + # add file name to the data > + .data$file <- .name > + .data > + })) You can simplify this a little with plyr: fileNames <- list.files(pattern = "file.*.csv") names(fileNames) <- fileNames input <- ldply(fileNames, read.table, header = TRUE, as.is = TRUE) Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Vioplot / list help
Hi: There appear to be several options, but it also seems that the amount of work required to achieve the goal varies among options. In situations like this, the sos package comes in handy. For example, it showed me that your vioplot() function was in package vioplot (unmentioned): library(sos) findFn('violin plot') The default output is sent to a created page in your web browser; I got 23 hits. At least seven packages might be relevant to your problem, including lattice, caroline and perhaps beanplot. In lattice, the operative panel function is panel.violin, which is meant to be used in conjunction with bwplot(). The following is a simplified version of the panel.violin() example using the singers data: library(lattice) bwplot(voice.part ~ height, data = singer, panel = function(...) panel.violin(...)) This is its most basic use; panel.violin() has its own set of customizable options. From a brief peek at the violin plot in the caroline package, it appears to take a grouping factor with its by = argument as well. It may also be advantageous to rearrange your data into a single data frame in long form; if you're pulling the same variable from multiple data sets or have the data from each year in separate columns, then it would be productive to reshape the data (e.g., with package reshape(2)) before sending it to the graphics function. Lattice may be a convenient way to go, especially if you want separate panels by year, for example. A data frame with columns response, year and whatever else you need for grouping should be enough to get the lattice version running. I haven't looked at the functions for violin plots in the caroline and beanplot packages, but you should also look at what they have to offer, as one or more of them may be suitable for your particular purposes. HTH, Dennis On Thu, Dec 23, 2010 at 5:10 AM, Matthew Vernon wrote: > Hi, > > I have some data (lots of year,distance pairs), which I can > straightforwardly boxplot: > > dists <- read.table("movedists.dat") > with(dists,plot(as.factor(V1),V2)) > > If I want to plot these data as violin plots using vioplot, this > approach doesn't work: > > > with(dists,vioplot(as.factor(V1),V2)) > Error in Summary.factor(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, : > min not meaningful for factors > > I tried making columns by year: > > ys=with(dists,by(V2,V1,function(x) x)) > > or even making that into a matrix: > > ysm<-as.matrix(ys,ncols=11) > > But still vioplot isn't happy. > > After a bit of faff, I end up with: > > with(dists,vioplot(dists[V1==1999,2],dists[V1==2000,2],dists[V1==2001,2], > dists[V1==2002,2],dists[V1==2003,2],dists[V1==2004,2],dists[V1==2005,2], > dists[V1==2006,2],dists[V1==2007,2],dists[V1==2008,2],dists[V1==2009,2], > names=1999:2009)) > > ...but this is clearly awful. Surely there's a better way of achieving > this? > > Thanks, > > Matthew > > -- > Matthew Vernon, Research Fellow > Ecology and Epidemiology Group, > University of Warwick > http://blogs.warwick.ac.uk/mcvernon > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] speed issues? read R_inferno by Patrick Burns: & a memory query
Actually the issue is not the size of memory that is consumed, but that memory allocation takes place and the object is copied in each iteration of the "bad" loop you have given below. This is not required for the second loop, where R can allocate the memory at once and does not need to copy the object around. Uwe Ligges On 23.12.2010 14:13, maddox wrote: Hi, I'm just starting out with R and came across R_inferno.pdf by Patrick Burns just yesterday - I recommend it! His description of how 'growing' objects (e.g. obj<- c(obj, additionalValue) eats up memory prompted me to rewrite a function (which made such calls ~210 times) so that it used indexing into a dimensioned object instead (i.e. obj[i, ]<- additionalValue). This transformed the process from old version: user system elapsed 133.436 14.257 155.807 new version: user system elapsed 16.041 1.180 18.535 To say I'm delighted is understatement. Thanks for putting the Inferno together, Patrick. However I'm misunderstanding the effect this has on memory use, (or misunderstanding the code I've highjacked to look at memory use). To look at virtual memory use I'm using the code below from this forum: cmd<- paste("ps -o vsz", Sys.getpid()) cat("\nVirtual size: ", system(cmd, intern = TRUE) [2], "\n", sep = "") I did three runs of the old version, and three with the new, preceding each with gc()& got the outputs below. In summary, the runs of old method required 17712, 17744& 17744& runs of new method required 13788, 15140& 13656. Two questions: 1. why does each run of the same process not make the same demand on memory? They're doing exactly the same work& creating exactly the same new objects. 2. is the modest decrease in memory consumed by new method expected? (having read R_Inferno I was, perhaps naively, expecting more of an improvement) ? or am I missing something (more than likely! ) Thanks M gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 786300 21.01265230 33.8 1166886 31.2 Vcells 948412 7.33244126 24.8 3766604 28.8 cat("old version") Virtual size before call: 881692 user system elapsed 131.872 14.417 159.653 Virtual size after call: 899404 899404-881692 [1] 17712 ## gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 786294 21.01265230 33.8 1166886 31.2 Vcells 948407 7.33244126 24.8 3766604 28.8 cat("old version") Virtual size before call: 881660 user system elapsed 133.281 14.473 159.661 Virtual size after call: 899440 899440-881660 [1] 17780 ## gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 786294 21.01265230 33.8 1166886 31.2 Vcells 948407 7.33244126 24.8 3766604 28.8 cat("old version") Virtual size before call: 881696 user system elapsed 133.436 14.257 155.807 Virtual size after call: 899440 899440-881696 [1] 17744 ## ## gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 786413 21.01265230 33.8 1166886 31.2 Vcells 948460 7.33244126 24.8 3766604 28.8 cat("new version") Virtual size before call: 881696 user system elapsed 16.041 1.180 18.535 Virtual size after call: 895484 895484-881696 [1] 13788 ## gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 786441 21.11265230 33.8 1166886 31.2 Vcells 948480 7.33244126 24.8 3766604 28.8 cat("new version") Virtual size before call: 882648 user system elapsed 16.321 1.068 18.136 Virtual size after call: 897788 897788- 882648 [1] 15140 ## gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 786441 21.11265230 33.8 1166886 31.2 Vcells 948480 7.33244126 24.8 3766604 28.8 cat("new version") Virtual size before call: 882648 user system elapsed 16.581 0.992 19.351 Virtual size after call: 896304 896304-882648 [1] 13656 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Forcing results from lm into datframe
Hi all, This subject treats exactly what I am looking for, thank you. Only I would like to include the p-values (or t-values) in the dataframe, like this: .id (Intercept) p-value(intercept) quartile p-value(intercept) 1 CBP090802020.92140 0.00 3.38546887 0.00 2 CBP090802129.31632 0.00 0.01372604 0.12 3 CBP090802239.1 0.00 3.3000 0.00 I have at most a lot of id's so a nice way to summarize the results is preferred. I tried a lot of thinks with apply, ldply, dlply, Lmlist, but I don't get the results that I wanted. Thanks a lot, With best regards -- View this message in context: http://r.789695.n4.nabble.com/Forcing-results-from-lm-into-datframe-tp3013889p3162235.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] make check from R2.12.0.exe installation
Looks liek there was no answer to this question. If you are installing R, you can select to install the tests directory in the installer (default is not to install the tests). Uwe Ligges On 06.12.2010 12:21, elliott harrison wrote: Hi, I typically install new versions of R on windows using the downloadable executable file rather than the full tar. I need to now document the success of the installation in addition to my preferred procedure of running an old dataset against the new build. I found quickly that this is all available to me but the tests directory I have does not contain the scripts that the tar file does. How do I check the installation when R is installed in this manner? Many thanks Elliott [[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] Fitting a Triangular Distribution to Bivariate Data
Dave, I am a little confused. You ask about a triangle distribution, but describe the situation as a relation between y and x. Do you really want a piecewise linear fit of y to x? That could be gotten using nonlinear least squares. Dave From: Jinsong Zhao To: r-help@r-project.org Date: 12/23/2010 07:53 AM Subject: Re: [R] Fitting a Triangular Distribution to Bivariate Data Sent by: r-help-boun...@r-project.org On 2010-12-23 2:19, David Bapst wrote: > Hello, > I have some xy data which clearly shows a non-monotonic, peaked > triangular trend. You can get an idea of what it looks like with: > > x<-1:20 > y<-c(2*x[1:10]+1,-2*x[11:20]+42) > > I've tried fitting a quadratic, but it just doesn't the data-structure > with the break point adequately. Is there anyway to fit a triangular > or 'tent' function to my data in R? > > Some sample code would be appreciated; I'm not new to R, but I > sometimes have difficulty understanding the model-fitting functions > (finally figured out how to extrapolate with predict() today!) > > Thanks! > -Dave Bapst, UChicago > Hi, you may try the following code: > library(triangle) > library(fitdistrplus) > summary(fitdist(y, "triangle", start = list(a = 1.9, b= 21.1, c = 11.5))) Fitting of the distribution ' triangle ' by maximum likelihood Parameters : estimate Std. Error a -1.47 2.3523724 b 23.627448 1.9804026 c 13.00 0.1107073 Loglikelihood: -62.41994 AIC: 130.8399 BIC: 133.8271 Correlation matrix: a b c a 1. -0.14537297 -0.01203898 b -0.14537297 1. -0.01439500 c -0.01203898 -0.01439500 1. HTH ... Jinsong Zhao __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] python-like dictionary for R
On Wed, Dec 22, 2010 at 7:05 PM, Martin Morgan wrote: > On 12/22/2010 05:49 PM, Paul Rigor wrote: >> Hi, >> >> I was wondering if anyone has played around this this package called >> "rdict"? It attempts to implement a hash table in R using skip lists. Just >> came across it while trying to look for simpler text manipulation methods: >> >> http://userprimary.net/posts/2010/05/29/rdict-skip-list-hash-table-for-R/ > > kind of an odd question, so kind of an odd answer. > > I'd say this was an implementation of skip lists in C with an R > interface. I had to play around with the rdict package in order to write it, but haven't used it much since :-P Be sure to look at R's native environment objects which provide a hash table structure and are suitable for many uses. + seth -- Seth Falcon | @sfalcon | http://userprimary.net/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Bayesian Belief Networks in R
Hi, Does anyone know of a package for or any implementation of a Bayesian Belief Network in R? Thanks, Walt Walter R. Paczkowski, Ph.D. Data Analytics Corp. 44 Hamilton Lane Plainsboro, NJ 08536 (V) 609-936-8999 (F) 609-936-3733 w...@dataanalyticscorp.com www.dataanalyticscorp.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] Bayesian Belief Networks
Hi, Does anyone know of a package for or any implementation of a Bayesian Belief Network in R? Thanks, Walt Walter R. Paczkowski, Ph.D. Data Analytics Corp. 44 Hamilton Lane Plainsboro, NJ 08536 (V) 609-936-8999 (F) 609-936-3733 w...@dataanalyticscorp.com www.dataanalyticscorp.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] Vioplot / list help
Hi, I have some data (lots of year,distance pairs), which I can straightforwardly boxplot: dists <- read.table("movedists.dat") with(dists,plot(as.factor(V1),V2)) If I want to plot these data as violin plots using vioplot, this approach doesn't work: > with(dists,vioplot(as.factor(V1),V2)) Error in Summary.factor(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, : min not meaningful for factors I tried making columns by year: ys=with(dists,by(V2,V1,function(x) x)) or even making that into a matrix: ysm<-as.matrix(ys,ncols=11) But still vioplot isn't happy. After a bit of faff, I end up with: with(dists,vioplot(dists[V1==1999,2],dists[V1==2000,2],dists[V1==2001,2], dists[V1==2002,2],dists[V1==2003,2],dists[V1==2004,2],dists[V1==2005,2], dists[V1==2006,2],dists[V1==2007,2],dists[V1==2008,2],dists[V1==2009,2], names=1999:2009)) ...but this is clearly awful. Surely there's a better way of achieving this? Thanks, Matthew -- Matthew Vernon, Research Fellow Ecology and Epidemiology Group, University of Warwick http://blogs.warwick.ac.uk/mcvernon __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] speed issues? read R_inferno by Patrick Burns: & a memory query
Hi, I'm just starting out with R and came across R_inferno.pdf by Patrick Burns just yesterday - I recommend it! His description of how 'growing' objects (e.g. obj <- c(obj, additionalValue) eats up memory prompted me to rewrite a function (which made such calls ~210 times) so that it used indexing into a dimensioned object instead (i.e. obj[i, ] <- additionalValue). This transformed the process from old version: user system elapsed 133.436 14.257 155.807 new version: user system elapsed 16.041 1.180 18.535 To say I'm delighted is understatement. Thanks for putting the Inferno together, Patrick. However I'm misunderstanding the effect this has on memory use, (or misunderstanding the code I've highjacked to look at memory use). To look at virtual memory use I'm using the code below from this forum: cmd <- paste("ps -o vsz", Sys.getpid()) cat("\nVirtual size: ", system(cmd, intern = TRUE) [2], "\n", sep = "") I did three runs of the old version, and three with the new, preceding each with gc() & got the outputs below. In summary, the runs of old method required 17712, 17744 & 17744 & runs of new method required 13788, 15140 & 13656. Two questions: 1. why does each run of the same process not make the same demand on memory? They're doing exactly the same work & creating exactly the same new objects. 2. is the modest decrease in memory consumed by new method expected? (having read R_Inferno I was, perhaps naively, expecting more of an improvement) ? or am I missing something (more than likely! ) Thanks M > gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 786300 21.01265230 33.8 1166886 31.2 Vcells 948412 7.33244126 24.8 3766604 28.8 > cat("old version") Virtual size before call: 881692 user system elapsed 131.872 14.417 159.653 Virtual size after call: 899404 > 899404-881692 [1] 17712 ## > gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 786294 21.01265230 33.8 1166886 31.2 Vcells 948407 7.33244126 24.8 3766604 28.8 > cat("old version") Virtual size before call: 881660 user system elapsed 133.281 14.473 159.661 Virtual size after call: 899440 > 899440-881660 [1] 17780 ## > gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 786294 21.01265230 33.8 1166886 31.2 Vcells 948407 7.33244126 24.8 3766604 28.8 > cat("old version") Virtual size before call: 881696 user system elapsed 133.436 14.257 155.807 Virtual size after call: 899440 > 899440-881696 [1] 17744 ## ## > gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 786413 21.01265230 33.8 1166886 31.2 Vcells 948460 7.33244126 24.8 3766604 28.8 > cat("new version") Virtual size before call: 881696 user system elapsed 16.041 1.180 18.535 Virtual size after call: 895484 > 895484-881696 [1] 13788 ## > gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 786441 21.11265230 33.8 1166886 31.2 Vcells 948480 7.33244126 24.8 3766604 28.8 > cat("new version") Virtual size before call: 882648 user system elapsed 16.321 1.068 18.136 Virtual size after call: 897788 > 897788- 882648 [1] 15140 ## > gc() used (Mb) gc trigger (Mb) max used (Mb) Ncells 786441 21.11265230 33.8 1166886 31.2 Vcells 948480 7.33244126 24.8 3766604 28.8 > cat("new version") Virtual size before call: 882648 user system elapsed 16.581 0.992 19.351 Virtual size after call: 896304 > 896304-882648 [1] 13656 -- View this message in context: http://r.789695.n4.nabble.com/speed-issues-read-R-inferno-by-Patrick-Burns-a-memory-query-tp3162032p3162032.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] Piece-wise continuous regression with one knot
On 23/12/2010 9:03 AM, John Sorkin wrote: Windows Vista R 2.10 - I know it is old, I will update later today. How might I perform a piece-wise linear regression where two linear segments are separated by a single knot? In addition to estimating the slopes of the two segments (or the slope in one segment and the difference between the slope of the first and second segment), I would like the analysis to select the optimum knot. My first analysis will contain a single dependent and a single independent variables. Subsequent analyses will add additional independent variables to determine the effect on the results of adjusting for potential confounding. Do you know the position of the knot? If so, it's simply linear regression with two predictors. One predictor could be the x variable, the other should be zero below the knot, x above it. (This corresponds to the formulation you list in parentheses; it's best if you want to test whether the knot is necessary or not). If you don't know the position of the knot it's a much harder problem. I don't know current recommended practice. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Piece-wise continuous regression with one knot
On Thu, 23 Dec 2010, John Sorkin wrote: Windows Vista R 2.10 - I know it is old, I will update later today. How might I perform a piece-wise linear regression where two linear segments are separated by a single knot? In addition to estimating the slopes of the two segments (or the slope in one segment and the difference between the slope of the first and second segment), I would like the analysis to select the optimum knot. My first analysis will contain a single dependent and a single independent variables. Subsequent analyses will add additional independent variables to determine the effect on the results of adjusting for potential confounding. Have a look at the "segmented" package, introduced in R News in http://www.R-project.org/doc/Rnews/Rnews_2008-1.pdf Best, Z Thank you, John John David Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for th...{{dropped:6}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Piece-wise continuous regression with one knot
Windows Vista R 2.10 - I know it is old, I will update later today. How might I perform a piece-wise linear regression where two linear segments are separated by a single knot? In addition to estimating the slopes of the two segments (or the slope in one segment and the difference between the slope of the first and second segment), I would like the analysis to select the optimum knot. My first analysis will contain a single dependent and a single independent variables. Subsequent analyses will add additional independent variables to determine the effect on the results of adjusting for potential confounding. Thank you, John John David Sorkin M.D., Ph.D. Chief, Biostatistics and Informatics University of Maryland School of Medicine Division of Gerontology Baltimore VA Medical Center 10 North Greene Street GRECC (BT/18/GR) Baltimore, MD 21201-1524 (Phone) 410-605-7119 (Fax) 410-605-7913 (Please call phone number above prior to faxing) Confidentiality Statement: This email message, including any attachments, is for th...{{dropped:6}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fitting a Triangular Distribution to Bivariate Data
On 2010-12-23 2:19, David Bapst wrote: Hello, I have some xy data which clearly shows a non-monotonic, peaked triangular trend. You can get an idea of what it looks like with: x<-1:20 y<-c(2*x[1:10]+1,-2*x[11:20]+42) I've tried fitting a quadratic, but it just doesn't the data-structure with the break point adequately. Is there anyway to fit a triangular or 'tent' function to my data in R? Some sample code would be appreciated; I'm not new to R, but I sometimes have difficulty understanding the model-fitting functions (finally figured out how to extrapolate with predict() today!) Thanks! -Dave Bapst, UChicago Hi, you may try the following code: > library(triangle) > library(fitdistrplus) > summary(fitdist(y, "triangle", start = list(a = 1.9, b= 21.1, c = 11.5))) Fitting of the distribution ' triangle ' by maximum likelihood Parameters : estimate Std. Error a -1.47 2.3523724 b 23.627448 1.9804026 c 13.00 0.1107073 Loglikelihood: -62.41994 AIC: 130.8399 BIC: 133.8271 Correlation matrix: a b c a 1. -0.14537297 -0.01203898 b -0.14537297 1. -0.01439500 c -0.01203898 -0.01439500 1. HTH ... Jinsong Zhao __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Writing a single output file
This should get you close: > # get file names > setwd('/temp') > fileNames <- list.files(pattern = "file.*.csv") > fileNames [1] "file1.csv" "file2.csv" "file3.csv" "file4.csv" > input <- do.call(rbind, lapply(fileNames, function(.name){ + .data <- read.table(.name, header = TRUE, as.is = TRUE) + # add file name to the data + .data$file <- .name + .data + })) > input date yield_rate file 1 12/23/2010 5.25 file1.csv 2 12/22/2010 5.19 file1.csv 3 12/23/2010 5.25 file2.csv 4 12/22/2010 5.19 file2.csv 5 12/23/2010 5.25 file3.csv 6 12/22/2010 5.19 file3.csv 7 12/23/2010 5.25 file4.csv 8 12/22/2010 5.19 file4.csv > require(reshape) > in.melt <- melt(input, measure = 'yield_rate') > cast(in.melt, date ~ file) date file1.csv file2.csv file3.csv file4.csv 1 12/22/2010 5.19 5.19 5.19 5.19 2 12/23/2010 5.25 5.25 5.25 5.25 > On Thu, Dec 23, 2010 at 8:07 AM, Amy Milano wrote: > Dear R helpers! > > Let me first wish all of you "Merry Christmas and Very Happy New year 2011" > > "Christmas day is a day of Joy and Charity, > May God make you rich in both" - Phillips Brooks > > ## > > > I have a process which generates number of outputs. The R code for the same > is as given below. > > for(i in 1:n) > { > write.csv(output[i], file = paste("output", i, ".csv", sep = ""), row.names = > FALSE) > } > > Depending on value of 'n', I get different output files. > > Suppose n = 3, that means I am having three output csv files viz. > 'output1.csv', 'output2.csv' and 'output3.csv' > > output1.csv > date yield_rate > 12/23/2010 5.25 > 12/22/2010 5.19 > . > . > > > output2.csv > > date yield_rate > > 12/23/2010 4.16 > > 12/22/2010 4.59 > > . > > . > > output3.csv > > > date yield_rate > > > 12/23/2010 6.15 > > > 12/22/2010 6.41 > > > . > > > . > > > > Thus all the output files have same column names viz. Date and yield_rate. > Also, I do need these files individually too. > > My further requirement is to have a single dataframe as given below. > > Date yield_rate1 yield_rate2 > yield_rate3 > 12/23/2010 5.25 4.16 > 6.15 > 12/22/2010 5.19 4.59 > 6.41 > ... > ... > > where yield_rate1 = output1$yield_rate and so on. > > One way is to simply create a dataframe as > > df = data.frame(Date = read.csv('output1.csv')$Date, yield_rate1 = > read.csv('output1.csv')$yield_rate, yield_rate2 = > read.csv('output2.csv')$yield_rate, > yield_rate3 = read.csv('output3.csv')$yield_rate) > > However, the problem arises when I am not aware how many output files are > there as n can be 5 or even 100. > > So is it possible to write some loop or some function which will enable me to > read 'n' files individually and then keeping "Date" common, only pickup the > yield_curve data from each output file. > > Thanking in advance for any guidance. > > Regards > > Amy > > > > > > [[alternative HTML version deleted]] > > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fitting a Triangular Distribution to Bivariate Data
I don't know if any specific package has a triangular distribution, but I know you can fit a model using first degree b-splines with a single knot. library(splines) ?bs x <- 1:100 y <- rnorm(100, ifelse(x <50, x, 100-x), 15) fit <- lm(y ~ bs(x, knots = 50, degree = 1)) -- Jonathan P. Daily Technician - USGS Leetown Science Center 11649 Leetown Road Kearneysville WV, 25430 (304) 724-4480 "Is the room still a room when its empty? Does the room, the thing itself have purpose? Or do we, what's the word... imbue it." - Jubal Early, Firefly r-help-boun...@r-project.org wrote on 12/22/2010 01:19:16 PM: > [image removed] > > [R] Fitting a Triangular Distribution to Bivariate Data > > David Bapst > > to: > > r-help > > 12/22/2010 04:04 PM > > Sent by: > > r-help-boun...@r-project.org > > Hello, > I have some xy data which clearly shows a non-monotonic, peaked > triangular trend. You can get an idea of what it looks like with: > > x<-1:20 > y<-c(2*x[1:10]+1,-2*x[11:20]+42) > > I've tried fitting a quadratic, but it just doesn't the data-structure > with the break point adequately. Is there anyway to fit a triangular > or 'tent' function to my data in R? > > Some sample code would be appreciated; I'm not new to R, but I > sometimes have difficulty understanding the model-fitting functions > (finally figured out how to extrapolate with predict() today!) > > Thanks! > -Dave Bapst, UChicago > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/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] Writing a single output file
Dear R helpers! Let me first wish all of you "Merry Christmas and Very Happy New year 2011" "Christmas day is a day of Joy and Charity, May God make you rich in both" - Phillips Brooks ## I have a process which generates number of outputs. The R code for the same is as given below. for(i in 1:n) { write.csv(output[i], file = paste("output", i, ".csv", sep = ""), row.names = FALSE) } Depending on value of 'n', I get different output files. Suppose n = 3, that means I am having three output csv files viz. 'output1.csv', 'output2.csv' and 'output3.csv' output1.csv date yield_rate 12/23/2010 5.25 12/22/2010 5.19 . . output2.csv date yield_rate 12/23/2010 4.16 12/22/2010 4.59 . . output3.csv date yield_rate 12/23/2010 6.15 12/22/2010 6.41 . . Thus all the output files have same column names viz. Date and yield_rate. Also, I do need these files individually too. My further requirement is to have a single dataframe as given below. Date yield_rate1 yield_rate2 yield_rate3 12/23/2010 5.25 4.16 6.15 12/22/2010 5.19 4.59 6.41 ... ... where yield_rate1 = output1$yield_rate and so on. One way is to simply create a dataframe as df = data.frame(Date = read.csv('output1.csv')$Date, yield_rate1 = read.csv('output1.csv')$yield_rate, yield_rate2 = read.csv('output2.csv')$yield_rate, yield_rate3 = read.csv('output3.csv')$yield_rate) However, the problem arises when I am not aware how many output files are there as n can be 5 or even 100. So is it possible to write some loop or some function which will enable me to read 'n' files individually and then keeping "Date" common, only pickup the yield_curve data from each output file. Thanking in advance for any guidance. Regards Amy [[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] epidemiology ode likelihood, hierarchical model
Hi all, I study epidemiology of soilborne disease. I have this ode model dS/dt = - (rp(t) X + rs(t) I) * S with X=1 ; rp(t) = ap exp( - bp*t) ; rs(t) = as exp (-0.5 ( ln (t/ds) / bs)² ) The data I have are not directly the infected individuals (which is a hidden state) but the Diseases ones (individuals who show aerial symptoms). I have studied with experiments the relationship between the infected I and the diseases D and I find a delay increasing linearly with a logNormal error. I would like to estimate the parameters of this model but as you can see using an ode solver package and the least square method to fit the model is not a good idea! Do you think it is possible to use a bayesian state space model with I as a Hidden state with this ode epidemiological model ? If not, it is at least possible to fit this ode model using a likelihood method instead of using least square ? Wich R package appears to be the most adapted ? Thank you! Melen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 CMD build/install: wrong Rtools include path is passed to g++
Actually, this is described in "R Installation and Administration". Best, Uwe Ligges On 21.12.2010 05:51, Andy Zhu wrote: Never mind. Found the solution: the package coded the rtools path in Makevars.win. So I was able to compile (but have another problem though). But not sure if there is an environment name for rtools, maybe RTOOLS_HOME ... Thanks. - Forwarded Message From: Andy Zhu Cc: r-help@r-project.org Sent: Mon, December 20, 2010 11:33:31 PM Subject: [R] R CMD build/install: wrong Rtools include path is passed to g++ Hi: I am trying to build/install rparallel source package in win32 using Rtools/R CMD. However, R CMD build or install fails. The R CMD build output shows that the path of Rtools/MinGW/include is wrong in g++ -I. How can I pass/configure the correct include path to R CMD? Tried this in both R 2.12 and 2.11 with compatible Rtools and Miktex/chm helper. Neither succeeded. Note, the R/Rtools/MinGW setting works fine if the package doesn't have C/C++ code. I was able to install my own R package which doesn't have C/C++ 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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] loading workspace- getting annoying
Thanks for your answers on R-help, although it is not very helpful - not to cite / quote the original question - not to answer to the questioner who may not be subscribed to the mailing list and hence may not recognize your answer at all. Best wishes, Uwe Ligges On 21.12.2010 10:42, Angel Salamanca wrote: Also, rm(list=ls()) will remove absolutely everything from your workspace. Next time you quit and save workspace you start with and empty workspace. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] monthly median in a daily dataset
On 21.12.2010 08:15, SNV Krishna wrote: Hi Dennis, I am looking for similar function and this post is useful. But a strange thing is happening when I try which I couldn't figure out (details below). Could you or anyone help me understand why this is so? df = data.frame(date = seq(as.Date("2010-1-1"), by = "days", length = 250)) df$value = cumsum(rnorm(1:250)) When I use the statement (as given in ?aggregate help file) the following error is displayed aggregate(df$value, by = months(df$date), FUN = median) Error in aggregate.data.frame(as.data.frame(x), ...) : 'by' must be a list The error message is quite helpful, you need a list of all the elements you'd have after the "~" in a formula, in this case only the date: aggregate(df$value, by = list(date = months(df$date)), FUN = median) But it works when I use as was suggested aggregate(value~months(date), data = df, FUN = median) months(date) value 1April 15.5721440 2 August -0.1261205 3 February -1.0230631 4 January -0.9277885 5 July -2.1890907 6 June 1.3045260 7March 11.4126371 8 May 2.1625091 The second question, is it possible to have the median across the months and years. Say I have daily data for last five years the above function will give me the median of Jan of all the five years, while I want Jan-2010, Jan-2009 and so... Wish my question is clear. Just use Year-Month as the grouping criterion as follows: aggregate(x=df$value, by = list(date = format(df$date, "%Y-%m")), FUN = median) Uwe Ligges Any assistance will be greatly appreciated and many thanks for the same. Regards, Krishna Date: Sun, 19 Dec 2010 15:42:15 -0800 From: Dennis Murphy To: HUXTERE Cc: r-help@r-project.org Subject: Re: [R] monthly median in a daily dataset Message-ID: Content-Type: text/plain Hi: There is a months() function associated with Date objects, so you should be able to do something like aggregate(value ~ months(date), data = data$flow$daily, FUN = median) Here's a toy example because your data are not in a ready form: df<- data.frame(date = seq(as.Date('2010-01-01'), by = 'days', length = 250), val = rnorm(250)) aggregate(val ~ months(date), data = df, FUN = median) months(date) val 1April -0.18864817 2 August -0.16203705 3 February 0.03671700 4 January 0.04500988 5 July -0.12753151 6 June 0.09864811 7March 0.23652105 8 May 0.25879994 9September 0.53570764 HTH, Dennis On Sun, Dec 19, 2010 at 2:31 PM, HUXTERE wrote: Hello, I have a multi-year dataset (see below) with date, a data value and a flag for the data value. I want to find the monthly median for each month in this dataset and then plot it. If anyone has suggestions they would be greatly apperciated. It should be noted that there are some dates with no values and they should be removed. Thanks Emily print ( str(data$flow$daily) ) 'data.frame': 16071 obs. of 3 variables: $ date :Class 'Date' num [1:16071] -1826 -1825 -1824 -1823 -1822 ... $ value: num NA NA NA NA NA NA NA NA NA NA ... $ flag : chr "" "" "" "" ... NULL 5202008-11-01 0.034 1041 2008-11-02 0.034 1562 2008-11-03 0.034 2083 2008-11-04 0.038 2604 2008-11-05 0.036 3125 2008-11-06 0.035 3646 2008-11-07 0.036 4167 2008-11-08 0.039 4688 2008-11-09 0.039 5209 2008-11-10 0.039 5730 2008-11-11 0.038 6251 2008-11-12 0.039 6772 2008-11-13 0.039 7293 2008-11-14 0.038 7814 2008-11-15 0.037 8335 2008-11-16 0.037 8855 2008-11-17 0.037 9375 2008-11-18 0.037 9895 2008-11-19 0.034B 10415 2008-11-20 0.034B 10935 2008-11-21 0.033B 11455 2008-11-22 0.034B 11975 2008-11-23 0.034B 12495 2008-11-24 0.034B 13016 2008-11-25 0.034B 13537 2008-11-26 0.033B 14058 2008-11-27 0.033B 14579 2008-11-28 0.033B 15068 2008-11-29 0.034B 15546 2008-11-30 0.035B 5212008-12-01 0.035B 1042 2008-12-02 0.034B 1563 2008-12-03 0.033B 2084 2008-12-04 0.031B 2605 2008-12-05 0.031B 3126 2008-12-06 0.031B 3647 2008-12-07 0.032B 4168 2008-12-08 0.032B 4689 2008-12-09 0.032B 5210 2008-12-10 0.033B 5731 2008-12-11 0.033B 6252 2008-12-12 0.032B 6773 2008-12-13 0.031B 7294 2008-12-14 0.030B 7815 2008-12-15 0.030B 8336 2008-12-16 0.029B 8856 2008-12-17 0.028B 9376 2008-12-18 0.028B 9896 2008-12-19 0.028B 10416 2008-12-20 0.027B 10936 2008-12-21 0.027B 11456 2008-12-22 0.028B 11976 2008-12-23 0.028B 12496 2008-12-24 0.029B 13017 2008-12-25 0.029B 13538 2008-12-26 0.029B 14059 2008-12-27 0.030B 14580 2008-12-28 0.030B 15069 2008-12-29 0.030B 15547 2008-12-30 0.031B 15851 2008-12-31 0.031B -- View this message in context: http://r.789695.n4.nabble.com/monthly-median-in-a-daily-dataset-tp3094917p30
Re: [R] Running sweave automatically using cygwin
On 23.12.2010 02:17, Raquel Rangel de Meireles Guimarães wrote: Hi all, Hope someone could help me. I am trying to run automatically the conversion of an Rwn file to a tex file. I am using windows 7, and cygwin. I tried to run automatically the Sweave.sh script, in its the most recent version available at R webpage: http://cran.r-project.org/contrib/extra/scripts/Sweave.sh Unfortunately, I got this error message: === raq...@dell-raquel-pc ~ $ cd /cygdrive/c/Users/Raquel/Desktop/test_max_planck/test-raquel raq...@dell-raquel-pc /cygdrive/c/Users/Raquel/Desktop/test_max_planck/test-raquel $ chmod +x Sweave.sh raq...@dell-raquel-pc /cygdrive/c/Users/Raquel/Desktop/test_max_planck/test-raquel $ ./Sweave.sh test-raquel.Rnw Run Sweave and postprocess with LaTeX directly from the command line ./Sweave.sh: line 657: R: command not found Then R is not in your PATH, obviously. On the other hand, why don't you simply use R CMD Sweave yourFIle.Rnw from your favorite shell (for which you need R in the PATH environment variable as well). Best, Uwe Ligges An error occured after the use of 'R'! Quiting. = I don't know what is the problem. Could you please help me? Below you find my Rnw code and the data for running sweave. Best regards, Raquel Rnw file \documentclass[12pt,oneside,a4paper]{article} \usepackage[latin1]{inputenc} \usepackage[brazil]{babel} \usepackage{amsthm,amsfonts,bm} \usepackage{graphicx} \usepackage[T1]{fontenc} \usepackage{ae} \usepackage[alf,bibjustif,recuo=1cm]{abntcite} %bibliografia da ABNT \usepackage{setspace} \usepackage[charter]{mathdesign} \usepackage{graphicx} \usepackage{Sweave} \bibliographystyle{abnt-alf} \onehalfspacing \setlength\parskip{0.5cm} % espaçamento entre parágrafos \title{MP 187: Statistical Models with missing values \\Final Test} \author{Raquel Rangel de Meireles Guimarães} \date{December, 2010} \begin{document} \maketitle <>= if (require(xtable) == FALSE) stop("Pacote xtable() necessário para rodar essa análise.") options(digits=3) @ In this test we were required to analyse data from IQ scores of 250 subjects, repeated after one month. A large part of the sample dropped the second visit. Using only the complete cases, estimate the parameters of the regression line: <<>>= setwd("C:\\Users\\Raquel\\Desktop\\test_max_planck") data<-read.table("IQ.txt") attach(data) @ I start here with a scatterplot of the two variables. It is easy to see from the figure \ref{fig:scatter} that we have a censored \begin{figure}[ht!] \centering <>= plot(data$IQ1,data$IQ2) @ \caption{Scatterplot of the two measurements of the IQ score, in the first and second visit.} \label{fig:scatter} \end{figure} \end{document} = Data file: IQ.txt "IQ1" "IQ2" "1" 114.71 NA "2" 112.84 NA "3" 184.88 NA "4" 120.03 NA "5" 67 85.28 "6" 75.12 64.24 "7" 104.87 NA "8" 73.07 67.34 "9" 100.7 NA "10" 129.79 NA "11" 11.83 109.91 "12" 139.52 NA "13" 130.74 NA "14" 111.92 NA "15" 83.45 106.15 "16" 80.33 19.14 "17" 80.85 146.93 "18" 65.63 89.09 "19" 152.95 NA "20" 9.84 104.58 "21" 112.47 NA "22" 92.14 NA "23" 151.66 NA "24" 168.06 NA "25" 34.6 47.21 "26" 120.65 NA "27" 112.47 NA "28" 80.5 109.71 "29" 58.46 52.5 "30" 112.97 NA "31" 75.95 55.53 "32" 58.59 123.95 "33" 147.19 NA "34" 38.98 90.26 "35" 115.18 NA "36" 98.93 NA "37" 113.2 NA "38" 144.42 NA "39" 145.52 NA "40" 134.97 NA "41" 98.61 NA "42" 98.23 NA "43" 166.18 NA "44" 43.75 95.76 "45" 77.07 99.5 "46" 112.2 NA "47" -0.03 13.23 "48" 102.19 NA "49" 70.98 74.52 "50" 80.48 26.61 "51" 102.87 NA "52" 94.22 NA "53" 60.33 52.95 "54" 54.09 95.25 "55" 60.81 87.87 "56" 106.98 NA "57" 71.18 112.27 "58" 80.95 53 "59" 122.56 NA "60" 74.22 41.55 "61" 109.73 NA "62" 142.66 NA "63" 95.39 NA "64" 97.68 NA "65" 114.37 NA "66" 114.02 NA "67" 87.39 NA "68" 183.12 NA "69" 88.39 NA "70" 57.81 99.84 "71" 133.65 NA "72" 78.16 30.84 "73" 80.52 82.42 "74" 107.02 NA "75" 85.35 NA "76" 84.35 NA "77" 92.62 NA "78" 45.62 100.89 "79" 79.53 102.13 "80" 85.11 NA "81" 108.72 NA "82" 95.55 NA "83" 57.17 52.48 "84" 106.16 NA "85" 72.3 109.69 "86" 88.13 NA "87" 117.57 NA "88" 86.59 NA "89" 65.56 71.14 "90" 97.76 NA "91" 81.91 85.55 "92" 65.58 78.26 "93" 109.13 NA "94" 92.55 NA "95" 112.54 NA "96" 66.77 106.92 "97" 106.69 NA "98" 43.65 56.27 "99" 13.29 14.43 "100" 108.6 NA "101" 111.95 NA "102" 62.04 25.49 "103" 113.79 NA "104" 125.43 NA "105" 68.13 85.19 "106" 112.13 NA "107" 21.61 83.67 "108" 49.13 132.66 "109" 104.61 NA "110" 105.9 NA "111" 107.7 NA "112" 157.83 NA "113" 20.3 41.49 "114" 43.87 -7.62 "115" 130.19 NA "116" 137.28 NA "117" 62.99 128.23 "118" 97.71 NA "119" 103.46 NA "120" 90.81 NA "121" 40.89 51 "122" 146.28 NA "123" 136.18 NA "124" 111.93 NA "125" 84.19 51.3 "126" 105.01 NA "127" 78.28 44.44 "128" 74.54 67.52 "129" 80.92 152.09 "130" 151.56 NA "131" 30.4 147.39 "132" 62.99 97.48 "133" 111.86 NA "1
Re: [R] randomForest: tuneRF error
Since we do not have the data, it is hard for us to reproduce and debug. Uwe Ligges On 21.12.2010 23:48, Dennis wrote: Just curious if anyone else has got this error before, and if so, would know what I could do (if anything) to get past it: mtry<- tuneRF(training, trainingdata$class, ntreeTry = 500, stepFactor = 2, improve = 0.05, trace = TRUE, plot = TRUE, doBest = FALSE) mtry = 13 OOB error = 0.62% Searching left ... mtry = 7OOB error = 1.38% -1.22 0.05 Searching right ... mtry = 26 OOB error = 0.24% 0.611 0.05 mtry = 52 OOB error = 0.07% 0.7142857 0.05 mtry = 104 OOB error = 0% 1 0.05 mtry = 173 OOB error = 0% NaN 0.05 Error in if (Improve> improve) { : missing value where TRUE/FALSE needed I've used tuneRF successfully before, but in this instance, no matter what I change in the parameters, I still get the error above (last line). The data has no NAs in it. I'm using R 2.12.0 (64bit-M$ Windows 7). Thanks in advance! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 more plots from one matrix
On 21.12.2010 00:25, AlexZolot wrote: See library(reshape) Thanks for your answers on R-help, although it is not very helpful - not to cite / quote the original question - not to answer to the questioner who may not be subscribed to the mailing list and hence may not recognize your answer at all. Best wishes, Uwe Ligges __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to suppress plotting for "xyplot(zoo(x))"?
On Tue, Dec 21, 2010 at 8:40 AM, Gabor Grothendieck wrote: > On Tue, Dec 21, 2010 at 7:53 AM, Marius Hofert wrote: >> Hi, >> >> I found the thread >> http://r.789695.n4.nabble.com/Matrix-as-input-to-xyplot-lattice-proper-extended-formula-syntax-td896948.html >> I used Gabor's approach and then tried to assign the plot to a variable (see >> below). But a Quartz device is opened... why? I don't want to have anything >> plot/printed, I just would like to store the plot object. Is there something >> like "plot = FALSE"? >> >> Cheers, >> >> Marius >> >> library(lattice) >> library(zoo) >> >> df <- data.frame(y = matrix(rnorm(24), nrow = 6), x = 1:6) >> xyplot(zoo(df[1:4], df$x), type = "p") >> >> plot.object <- xyplot(zoo(df[1:4], df$x), type = "p") # problem: a Quartz >> device is opened (on Mac OS X 10.6) > > This also opens up a window on Windows. It occurs within lattice > when lattice issues a trellis.par.get . A workaround would be to open > a device directed to null. On Windows this would work. I assume if > you use "/dev/null" it would work on your machine. > > png("NUL") > plot.object <- ... > dev.off() Also Yihui Xie found an undocumented NULL device which you could try See: http://yihui.name/en/2010/12/a-special-graphics-device-in-r-the-null-device/ -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] vectorised recovery of strsplit value ??
Thanks Jorge, for your reply. In the end I changed my approach and used a sub() strategy I found on this forum to recover the prefixes as below. IDs.prefix <- sub("([^*])(_.*)", "\\1" , sampleIDs ) IDs.split <- cbind(sampleIDs , IDs.prefix) Regards M -- View this message in context: http://r.789695.n4.nabble.com/vectorised-recovery-of-strsplit-value-tp3161254p3161806.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] recovering names of factor levels ??
Thanks Peter, for your succinctly helpful reply The way R works is still a learning experience for me. I hope I'll be asking fewer of these type of questions as I get to grips with R. In the meantime, thanks for the help (and patience) regards M -- View this message in context: http://r.789695.n4.nabble.com/recovering-names-of-factor-levels-tp3161388p3161797.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] R-way to doing this?
If I understand your question properly, then you are looking for 'try' or 'tryCatch'. There is an example of using these on page 89 of 'The R Inferno'. On 23/12/2010 04:13, Bogaso Christofer wrote: Dear friends, hope I could be able to explain my problem through following example. Please consider this: set.seed(1) input<- rnorm(10) input [1] -0.6264538 0.1836433 -0.8356286 1.5952808 0.3295078 -0.8204684 0.4874291 0.7383247 0.5757814 -0.3053884 tag<- vector(length=10) for(i in 1:10) # if there is any error in evaluating "log(input[i])" (or evaluating some function) then tag[i] = 1, otherwise tag[i] = 0 Therefore my "tag" vector should like: tag[1]=1, tag[2]=0, tag[3]=1, tag[4]=0, tag[5]=0... Actually R returns logarithm of a negative number as NaN, however in this example please consider R returns error when it encounters logarithm of a negative number. Is there any way to do above task? Thanks and regards, [[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. -- Patrick Burns pbu...@pburns.seanet.com twitter: @portfolioprobe http://www.portfolioprobe.com/blog http://www.burns-stat.com (home of 'Some hints for the R beginner' and 'The R Inferno') __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] force tree to use certain attributes
Hi, I'm currently using the 'rpart' package, and curious on whether we can enforce the package to utilize some specified attributes, rather than having it choose on its own. Thanks. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.