[R] .::Gregory Gentlemen::.
http://www.rumipambadelzuro.com/waqztn/hyd.cn?gdqk Gregory Gentlemen [[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] ~3/30/2013 3:09:18 PM~
http://www.rideonthewaves.com/gtbzkeql/yi.mceeu?pihsc Gregory Gentlemen [[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] Is there a bisection method in R?
Now that is a more useful reply than Why do you assume there is one?. Thanks a lot Ravi! --- On Fri, 9/17/10, Ravi Varadhan rvarad...@jhmi.edu wrote: From: Ravi Varadhan rvarad...@jhmi.edu Subject: RE: [R] Is there a bisection method in R? To: 'Peter Dalgaard' pda...@gmail.com, 'Gregory Gentlemen' gregory_gentle...@yahoo.ca Cc: r-help@r-project.org Received: Friday, September 17, 2010, 5:44 PM Here is something simple (does not have any checks for bad input), yet should be adequate: bisect - function(fn, lower, upper, tol=1.e-07, ...) { f.lo - fn(lower, ...) f.hi - fn(upper, ...) feval - 2 if (f.lo * f.hi 0) stop(Root is not bracketed in the specified interval \n) chg - upper - lower while (abs(chg) tol) { x.new - (lower + upper) / 2 f.new - fn(x.new, ...) if (abs(f.new) = tol) break if (f.lo * f.new 0) upper - x.new if (f.hi * f.new 0) lower - x.new chg - upper - lower feval - feval + 1 } list(x = x.new, value = f.new, fevals=feval) } # An example fn1 - function(x, a) { exp(-x) - a*x } bisect(fn1, 0, 2, a=1) bisect(fn1, 0, 2, a=2) Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Peter Dalgaard Sent: Friday, September 17, 2010 4:16 PM To: Gregory Gentlemen Cc: r-help@r-project.org Subject: Re: [R] Is there a bisection method in R? On 09/17/2010 09:28 PM, Gregory Gentlemen wrote: If uniroot is not a bisection method, then what function in R does use bisection? Why do you assume that there is one? uniroot contains a better algorithm for finding bracketed roots. It shouldn't be too hard to roll your own if you need one for pedagogical purposes. -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Is there a bisection method in R?
Fair enough. I didn't intend to offend anyone. Please accept my apologies. Greg --- On Mon, 9/20/10, peter dalgaard pda...@gmail.com wrote: From: peter dalgaard pda...@gmail.com Subject: Re: [R] Is there a bisection method in R? To: Gregory Gentlemen gregory_gentle...@yahoo.ca Cc: Ravi Varadhan rvarad...@jhmi.edu, r-help@r-project.org Received: Monday, September 20, 2010, 12:46 PM On Sep 20, 2010, at 18:15 , Gregory Gentlemen wrote: Now that is a more useful reply than Why do you assume there is one?. Thanks a lot Ravi! Well, maybe, but you can NOT expect that someone will go out of THEIR way to solve YOUR problem every time. Sometimes they will and sometimes they won't. Complaining about having it pointed out that something might not actually exist just because you need it is downright offensive! --- On Fri, 9/17/10, Ravi Varadhan rvarad...@jhmi.edu wrote: From: Ravi Varadhan rvarad...@jhmi.edu Subject: RE: [R] Is there a bisection method in R? To: 'Peter Dalgaard' pda...@gmail.com, 'Gregory Gentlemen' gregory_gentle...@yahoo.ca Cc: r-help@r-project.org Received: Friday, September 17, 2010, 5:44 PM Here is something simple (does not have any checks for bad input), yet should be adequate: bisect - function(fn, lower, upper, tol=1.e-07, ...) { f.lo - fn(lower, ...) f.hi - fn(upper, ...) feval - 2 if (f.lo * f.hi 0) stop(Root is not bracketed in the specified interval \n) chg - upper - lower while (abs(chg) tol) { x.new - (lower + upper) / 2 f.new - fn(x.new, ...) if (abs(f.new) = tol) break if (f.lo * f.new 0) upper - x.new if (f.hi * f.new 0) lower - x.new chg - upper - lower feval - feval + 1 } list(x = x.new, value = f.new, fevals=feval) } # An example fn1 - function(x, a) { exp(-x) - a*x } bisect(fn1, 0, 2, a=1) bisect(fn1, 0, 2, a=2) Ravi. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Peter Dalgaard Sent: Friday, September 17, 2010 4:16 PM To: Gregory Gentlemen Cc: r-help@r-project.org Subject: Re: [R] Is there a bisection method in R? On 09/17/2010 09:28 PM, Gregory Gentlemen wrote: If uniroot is not a bisection method, then what function in R does use bisection? Why do you assume that there is one? uniroot contains a better algorithm for finding bracketed roots. It shouldn't be too hard to roll your own if you need one for pedagogical purposes. -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Peter Dalgaard Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Is there a bisection method in R?
If uniroot is not a bisection method, then what function in R does use bisection? Thanks. --- On Fri, 9/10/10, David Winsemius dwinsem...@comcast.net wrote: From: David Winsemius dwinsem...@comcast.net Subject: Re: [R] Is there a bisection method in R? To: huang min minhua...@gmail.com Cc: Gregory Gentlemen gregory_gentle...@yahoo.ca, r-help@r-project.org Received: Friday, September 10, 2010, 9:56 PM On Sep 10, 2010, at 8:35 PM, huang min wrote: uniroot ... is not a bisection method. On Sat, Sep 11, 2010 at 6:10 AM, Gregory Gentlemen gregory_gentle...@yahoo.ca wrote: Dear fellow R-users, Is there a function that does the bisection method? I was unable to find one. Thanks in advance. Gregory --David Winsemius, MD West Hartford, CT [[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] Is there a bisection method in R?
Dear fellow R-users, Is there a function that does the bisection method? I was unable to find one. Thanks in advance. Gregory [[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] Function to compute the multinomial beta function?
Dear R-users, Is there an R function to compute the multinomial beta function? That is, the normalizing constant that arises in a Dirichlet distribution. For example, with three parameters the beta function is Beta(n1,n2,n2) = Gamma(n1)*Gamma(n2)*Gamma(n3)/Gamma(n1+n2+n3) Thanks in advance for any assisstance. Regards, Greg [[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] Producing residual plots by time for lme object
Fellow R-users, I have a longitudinal data set with missing values in it. I would like to produce a residual plot for each time using panel.xyplot function but I get an error message. Here's a simple example, library(nlme) set.seed(1544) longdata - data.frame(ID=gl(10,1,50), y=rnorm(50), time = as.numeric(gl(5,10,50)), x = rnorm(50)) longdata$y[5] - NA longdata$x[35] - NA modlme- lme(fixed=y ~ time + x, random= ~ 1 | ID, na.action=na.exclude, data=longdata) plot( modlme, abs( resid(., type = 'p')) ~ fitted(.) | time, panel = function(x, y, ...) { panel.xyplot( x, y, ...) panel.loess( x, y,...) }) where the last call produces the error message Error in `[[-.data.frame`(`*tmp*`, j, value = c(1, 1, 1, 1, 1, 1, 1, : replacement has 48 rows, data has 50 How do I fix this? Any help would be greatly appreciated. Greg ps my sessioninfo is sessionInfo() R version 2.9.1 (2009-06-26) i386-pc-mingw32 locale: LC_COLLATE=English_Canada.1252;LC_CTYPE=English_Canada.1252;LC_MONETARY=English_Canada.1252;LC_NUMERIC=C;LC_TIME=English_Canada.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] nlme_3.1-96 loaded via a namespace (and not attached): [1] grid_2.9.1 lattice_0.17-25 [[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] Function for describing segements in sequential data
Dear R-users, Say that I have a sequence of zeroes and ones: x - c(1,1,1,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0) The sequences of ones represent segments and I want to report the starting and endpoints of these segments. For example, in 'x', the first segment starts at location 1 and ends at 3, and the second segment starts at location 8 and ends at location 10. Is there an efficient way of doing this in R without having to right a bunch of if-else conditions? I know the rle function will report the length of the segments but not the endpoints. Thanks in advance. Gregory Gentlemen __ [[elided Yahoo spam]] [[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] Text editors for Sweave (rnw) files
Hi fellow R-users, Are there any text editors that recognize sweave (.rnw) files? I am running Windows Vista and in the past I used Tinn-R for R files but it (surprisingly) doesn't recognize rnw files and does not do any syntax highlighting for them. Thanks in advance, Greg __ Make your browsing faster, safer, and easier with the new Internet Explorer[[elided Yahoo spam]] com/ca/internetexplorer/ [[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] matrix manipulation problem
Dear fellow R-users, Say we have a matrix x, defined as follows set.seed(50) x - matrix(rbinom(100*5,1, p=0.75),nrow=100, ncol=5) Now the interpretation of x is that each for of x is actually a sequence of length 5, and i would like to transform x in such a way that I can describe the frequencies of sequences observed among the 100. How can I do this efficiently? Thanks for any assistance! Greg __ [[elided Yahoo spam]] [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] using nrow to identify one row
Hi fellow R-users, I have run into a problem when trying to identify the number of rows in a matrix. Say we have an arbitrary 5 by 5 matrix called temp: temp - matrix(norm(25), nrow=5) The problem is that nrow(temp[1,]) returns NULL. I would like it to return 1 because in my larger program I am indexing the rows of large matrices according to another variable and I need to test when the resulting matrices have 0, 1 or more rows. Thanks in advance for any assistance. Best regards, Gregory Gentlemen - [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How can I sample from a two-dimensional grid of points
Hi everyone, My goal is to sample from a two-dimensional grid. Consider the following example of code: n.grid - 500 muA.grid - seq(-4,4, length=n.grid) muB.grid - seq(-4,4, length=n.grid) mu.p - matrix(NA, nrow=n.grid, ncol=n.grid) for(i in 1:n.grid){ for(j in 1:n.grid){ mu.p[i,j] - dnorm(muA.grid[i], 0, 1)*dnorm(muB.grid[j], 0, 0.5) } } mu.p - mu.p/sum(mu.p) I would now like to sample the grid of points from the probabilities in mu.p. Im using the multivariate normal here for illustration as my real problem is a more complicated probability density. If this problem were only one-dimensional, this is easy: n.samples - 1000 # assuming mu.p and muA.grid are now the appropriate vectors mu - sample(muA.grid, n.samples, replace=T, prob=mu.p) However, im not sure how to do this in two-dimensions in R. Thanks in advance for any help. All the best, Gregory Gentlemen - [[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] Listing the data contents of a package
Hi R users, Simply question: On the command line, how do I list the datasets contained within a package, e.g. MASS? I scanned the mailing list history but was unable to find the answer. Thanks in advance. Gregory - [[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] matrix elementwise average with NA's
Hello fellow R users, I have a matrix computation that I imagine should be relatively easy to do, however I cannot figure out a nice way to do it. I have two matrices, for example mat1 - matrix(c(1:5,rep(NA,5), 6:10), nrow=3, byrow=T) mat2 - matrix(c(2:6, 6:10, rep(NA,5)), nrow=3, byrow=T) I'd like to compute the element-wise average for non-NA entries. Of course (mat1+mat2)/2 does not work for the final two rows because of the NA's. Are there any elegant ways to accopmlish this without writing a loop with indices? Thanks in advance for any assistance. Greg - [[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] many zeroes in rgamma ... what's going on?
Hello fellow R users, I wanted to view the density on the standard deviation scale of a gamma(0.001, 0.001) prior for the precision. I did this as seen in the code below and found that for some reason rgamma is giving many values equal to zero, which is strange since a gamma distribution is continuous. What is going on here? Thanks for any help in advance. Greg x1 - rgamma(1, shape=0.001, scale=0.001) sd1 - 1/sqrt(x1) truehist(sd1, xlim=c(0, 1.5)) Error in truehist(sd1, xlim = c(0, 1.5)) : 'nbins' must result in a positive integer summary(sd1) Min.1st Qu. Median Mean3rd Qu. Max. 2.266e+01 9.311e+66 3.250e+153InfInfInf - [[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.