[R] simple apply syntax
I know this is a simple question, but I have yet to master the apply statements. Any help would be appreciated. I have a column of probabilities and sample sizes, I would like to create a column of binomial random variables using those corresponding probabilities. Eg. mat = as.matrix(cbind(p=runif(10,0,1), n=rep(1:5))) p n [1,] 0.5093493 1 [2,] 0.4947375 2 [3,] 0.6753015 3 [4,] 0.8595729 4 [5,] 0.1004739 5 [6,] 0.6292883 1 [7,] 0.3752004 2 [8,] 0.6889157 3 [9,] 0.2435880 4 [10,] 0.9619128 5 I want to create mat$x as binomial(n, p) Thanks, Robin [[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] simple apply syntax
Hello Robin, I cannot quite figure out what your final goal is (it's late and I'm low on caffeine so if I missed the obvious, bear with me). I think you may mean the rbinom() function rather than the binomial() function (see ?rbinom and ?binomial, respectively). At any rate, this should get you there except for deciding what arguments of what function you want to pass the values from your matrix to. set.seed(1) mat - as.matrix(cbind(p=runif(10,0,1), n=rep(1:5))) #demonstrating what 'x' is apply(X = mat, MARGIN = 1, FUN = function(x) {return(x)}) #the function I imagine you might pass x to apply(X = mat, MARGIN = 1, FUN = function(x) {rbinom(n = 1, size = x[2], prob = x[1])}) what I did was just create an anonymous function, with a single argument, (x). 'x' becomes the values of each row in 'mat'. So all you have to do then, is specify what function (e.g., rbinom() ) you want to use, and then which arguments are set to what element of 'x' (here 1 or 2, but there could be more if you had more columns in your matrix). HTH, Josh On Sun, Jul 11, 2010 at 12:27 AM, Robin Jeffries rjeffr...@ucla.edu wrote: I know this is a simple question, but I have yet to master the apply statements. Any help would be appreciated. I have a column of probabilities and sample sizes, I would like to create a column of binomial random variables using those corresponding probabilities. Eg. mat = as.matrix(cbind(p=runif(10,0,1), n=rep(1:5))) p n [1,] 0.5093493 1 [2,] 0.4947375 2 [3,] 0.6753015 3 [4,] 0.8595729 4 [5,] 0.1004739 5 [6,] 0.6292883 1 [7,] 0.3752004 2 [8,] 0.6889157 3 [9,] 0.2435880 4 [10,] 0.9619128 5 I want to create mat$x as binomial(n, p) Thanks, Robin [[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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] simple apply syntax
On Sun, 11 Jul 2010, Robin Jeffries wrote: I know this is a simple question, but I have yet to master the apply statements. Any help would be appreciated. You don't want to use apply() here: rbinom is vectorized. However, you cannot use mat$x on a matrix, and the cbind() gave you a matrix anyway. So something like mat - data.frame(p=runif(10,0,1), n=rep(1:5)) mat$x - with(mat, rbinom(10, n, p)) is the idiomatic way to do it. As an example of using apply and a matrix: mat - cbind(p=runif(10,0,1), n=rep(1:5)) x - apply(mat, 1, function(z) rbinom(1, z['n'], z['p'])) mat - cbind(mat, x=x) I have a column of probabilities and sample sizes, I would like to create a column of binomial random variables using those corresponding probabilities. Eg. mat = as.matrix(cbind(p=runif(10,0,1), n=rep(1:5))) p n [1,] 0.5093493 1 [2,] 0.4947375 2 [3,] 0.6753015 3 [4,] 0.8595729 4 [5,] 0.1004739 5 [6,] 0.6292883 1 [7,] 0.3752004 2 [8,] 0.6889157 3 [9,] 0.2435880 4 [10,] 0.9619128 5 I want to create mat$x as binomial(n, p) Thanks, Robin [[alternative HTML version deleted]] Please so as we ask, and don't send HTML but rather properly formatted plain text (without all these blank lines). __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using Ubuntu as a Server
Hi Leandro, On 07/10/2010 08:46 PM, Leandro Marino wrote: I want to know how can I configure R in a Ubuntu to be a server. I am planning to use R in a Windows machine with Tinn-R, but I want R running at an Ubuntu Lucid machine. How can i do this? One possibility is to use Eclipse/StatET on the Windows machine and configure a remote console (to be running on your GNU/Linux server). The StatET user list has posts with explanations on how to achieve this. http://lists.r-forge.r-project.org/mailman/listinfo/statet-user http://lists.r-forge.r-project.org/mailman/swish.cgi?query=listname%3D%22statet-user%22 Best, Tobias __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] getting data from table command
Thanks very much :). On Sat, Jul 10, 2010 at 10:02 PM, jim holtman jholt...@gmail.com wrote: Is this what you want: x - c(1,2,2,2,3,3,3,4,4,5) z - table(x) z x 1 2 3 4 5 1 3 3 2 1 as.integer(rep(names(z), z)) [1] 1 2 2 2 3 3 3 4 4 5 On Sat, Jul 10, 2010 at 10:55 AM, nn roh nn.r...@gmail.com wrote: Hi, I have a question relating to R package If i have the frequencies of data how i can get the data as following : 1 2 3 4 data 2 3 3 1 frequency Which command i can use to get the data set in the above example should be 1 1 2 2 2 3 3 3 4 Thanks Nada [[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 Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[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] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)
Thanks. Seems to me the easiest sensible fix might be to change the default abs.tol=0 in R and add a warning in the help files? Matt On 11 July 2010 01:41, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/07/2010 7:32 PM, Ravi Varadhan wrote: Hi, The best solution would be to identify where the problem is in the FORTRAN code and correct it. However, this problem of premature termination due to absolute function convergence is highly unlikely to occur in practice. As John Nash noted, this is going to be highly unlikely for multi-dimensional parameters (it is also unlikely for one-dimensional problem). However, unless we understand the source of the problem, we cannot feel comfortable in saying with absolute certainty that this will not occur for n 1. Therefore, I would suggest that either we fix the problem at its source or we set abs.tol=0, since there is little harm in doing so. Just for future reference: that's not the kind of answer that leads to anything getting done. So I'll leave it to the authors of nlminb. Duncan Murdoch Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Duncan Murdoch murdoch.dun...@gmail.com Date: Saturday, July 10, 2010 7:32 am Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1) To: Ravi Varadhan rvarad...@jhmi.edu Cc: Matthew Killeya matthewkill...@googlemail.com, Peter Ehlers ehl...@ucalgary.ca, r-help@r-project.org, ba...@stat.wisc.edu Ravi Varadhan wrote: Hi, The absolute function stopping criterion is not meant for any positive objective function. It is meant for functions whose minimum is 0. Here is what David Gay's documentation from PORT says: 6 - absolute function convergence: |f (x)| V(AFCTOL) = V(31). This test is only of interest in problems where f (x) = 0 means a perfect fit, such as nonlinear least-squares problems. Okay, I've taken a more careful look at the docs, and they do say that the return code 6 does not necessarily indicate convergence: The desirable return codes are 3, 4, 5, and sometimes 6. So we shouldn't by default terminate on it, we should allow users to choose that if they want faster convergence to perfect fits. Would changing the default for abs.tol to zero be a reasonable solution? Duncan Murdoch For example, let us try a positive objective function: nlminb( obj = function(x) x^2 + 1, start=1, lower=-Inf, upper=Inf, control=list(trace=TRUE))0: 2.000: 1.0 1: 1.000: 0.0 2: 1.000: 0.0 $par [1] 0 $objective [1] 1 $convergence [1] 0 $message [1] relative convergence (4) $iterations [1] 2 $evaluations function gradient32 Here the absolute function criterion does not kicks in. Now let us try a function whose minimum value is 0. nlminb( obj = function(x) x^2, start=6, grad=function(x) 2*x, lower=-Inf, upper=Inf, control=list(trace=TRUE) ) 0: 36.00: 6.0 1: 4.000: 2.0 2: 4.9303807e-32: 2.22045e-16 $par [1] 2.220446e-16 $objective [1] 4.930381e-32 $convergence [1] 0 $message [1] absolute function convergence (6) $iterations [1] 2 $evaluations function gradient43 We see that convergence is attained and that the stoppage is due to absolute function criterion. Suppose, we now set abs.tol=0: nlminb( obj = function(x) x^2, start=6, grad=function(x) 2*x, lower=-Inf, upper=Inf, control=list(trace=TRUE, abs.tol=0) ) 0: 36.00: 6.0 1: 4.000: 2.0 2: 4.9303807e-32: 2.22045e-16 3: 2.4308653e-63: -4.93038e-32 4: 2.9962729e-95: -5.47382e-48 5:1.4772766e-126: 1.21543e-63 6:1.8208840e-158: 1.34940e-79 7:8.9776511e-190: -2.99627e-95 8:1.1065809e-221: -3.32653e-111 9:5.4558652e-253: 7.38638e-127 10:6.7248731e-285: 8.20053e-143 11:3.3156184e-316: -1.82088e-158 12: 0.000: -2.02159e-174 13: 0.000: -2.02159e-174 $par [1] -2.021587e-174 $objective [1] 0 $convergence [1] 0 $message [1] X-convergence (3) $iterations [1] 13 $evaluations function gradient 15 13Now, we see that it takes a while to stop, eventhough it is clear that convergence has been attained after 2 iterations. This demonstrates the need for the absolute function criterion for obj functions whose minimum is exactly 0. Although, there is nothing wrong with setting abs.tol=0, except for some loss of computational efficiency. Now, let us get back to Matthew' example: nlminb( obj = function(x) x, start=1, lower=-2, upper=2,
Re: [R] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)
On 11/07/2010 5:00 AM, Matthew Killeya wrote: Thanks. Seems to me the easiest sensible fix might be to change the default abs.tol=0 in R and add a warning in the help files? That was exactly my suggestion in the message to which Ravi was replying, but he apparently has doubts. Duncan Murdoch Matt On 11 July 2010 01:41, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/07/2010 7:32 PM, Ravi Varadhan wrote: Hi, The best solution would be to identify where the problem is in the FORTRAN code and correct it. However, this problem of premature termination due to absolute function convergence is highly unlikely to occur in practice. As John Nash noted, this is going to be highly unlikely for multi-dimensional parameters (it is also unlikely for one-dimensional problem). However, unless we understand the source of the problem, we cannot feel comfortable in saying with absolute certainty that this will not occur for n 1. Therefore, I would suggest that either we fix the problem at its source or we set abs.tol=0, since there is little harm in doing so. Just for future reference: that's not the kind of answer that leads to anything getting done. So I'll leave it to the authors of nlminb. Duncan Murdoch Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Duncan Murdoch murdoch.dun...@gmail.com Date: Saturday, July 10, 2010 7:32 am Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1) To: Ravi Varadhan rvarad...@jhmi.edu Cc: Matthew Killeya matthewkill...@googlemail.com, Peter Ehlers ehl...@ucalgary.ca, r-help@r-project.org, ba...@stat.wisc.edu Ravi Varadhan wrote: Hi, The absolute function stopping criterion is not meant for any positive objective function. It is meant for functions whose minimum is 0. Here is what David Gay's documentation from PORT says: 6 - absolute function convergence: |f (x)| V(AFCTOL) = V(31). This test is only of interest in problems where f (x) = 0 means a ‘‘perfect fit’’, such as nonlinear least-squares problems. Okay, I've taken a more careful look at the docs, and they do say that the return code 6 does not necessarily indicate convergence: The desirable return codes are 3, 4, 5, and sometimes 6. So we shouldn't by default terminate on it, we should allow users to choose that if they want faster convergence to perfect fits. Would changing the default for abs.tol to zero be a reasonable solution? Duncan Murdoch For example, let us try a positive objective function: nlminb( obj = function(x) x^2 + 1, start=1, lower=-Inf, upper=Inf, control=list(trace=TRUE))0: 2.000: 1.0 1: 1.000: 0.0 2: 1.000: 0.0 $par [1] 0 $objective [1] 1 $convergence [1] 0 $message [1] relative convergence (4) $iterations [1] 2 $evaluations function gradient32 Here the absolute function criterion does not kicks in. Now let us try a function whose minimum value is 0. nlminb( obj = function(x) x^2, start=6, grad=function(x) 2*x, lower=-Inf, upper=Inf, control=list(trace=TRUE) ) 0: 36.00: 6.0 1: 4.000: 2.0 2: 4.9303807e-32: 2.22045e-16 $par [1] 2.220446e-16 $objective [1] 4.930381e-32 $convergence [1] 0 $message [1] absolute function convergence (6) $iterations [1] 2 $evaluations function gradient43 We see that convergence is attained and that the stoppage is due to absolute function criterion. Suppose, we now set abs.tol=0: nlminb( obj = function(x) x^2, start=6, grad=function(x) 2*x, lower=-Inf, upper=Inf, control=list(trace=TRUE, abs.tol=0) ) 0: 36.00: 6.0 1: 4.000: 2.0 2: 4.9303807e-32: 2.22045e-16 3: 2.4308653e-63: -4.93038e-32 4: 2.9962729e-95: -5.47382e-48 5:1.4772766e-126: 1.21543e-63 6:1.8208840e-158: 1.34940e-79 7:8.9776511e-190: -2.99627e-95 8:1.1065809e-221: -3.32653e-111 9:5.4558652e-253: 7.38638e-127 10:6.7248731e-285: 8.20053e-143 11:3.3156184e-316: -1.82088e-158 12: 0.000: -2.02159e-174 13: 0.000: -2.02159e-174 $par [1] -2.021587e-174 $objective [1] 0 $convergence [1] 0 $message [1] X-convergence (3) $iterations [1] 13 $evaluations function gradient 15 13Now, we see that it takes a while to stop, eventhough it is clear that convergence has been attained after 2 iterations. This demonstrates the need for the absolute function criterion for obj functions whose minimum is exactly 0. Although, there is nothing wrong with setting abs.tol=0, except for some loss of computational efficiency. Now, let us get back to Matthew'
Re: [R] Not nice behaviour of nlminb (windows 32 bit, version, 2.11.1)
On 10/07/2010 9:48 AM, Prof. John C Nash wrote: I won't add to the quite long discussion about the vagaries of nlminb, but will note that over a long period of software work in this optimization area I've found a number of programs and packages that do strange things when the objective is a function of a single parameter. Some methods quite explicitly throw an error when n2. It seems nlminb does not, but that does not mean that the authors ever thought anyone would use their large package to solve a small 1D problem, or if they did, whether they seriously tested for the awkward things that happen when one only has one parameter. I've seen similar things go wrong with matrix packages e.g., eigensolutions of 1 by 1 matrices. So this msg is to watch carefully when problems are n=1 and put in some checks that answers make sense. This has nothing to do with n=1. nlminb(obj = function(x) sum(x^2)-25, start = c(0,6)) fails as badly as all the other examples. The problem is the (unintended?) assumption in nlminb, and possibly in the PORT library it uses, that f(x) is non-negative, so a vector x where f(x) = 0 is guaranteed to be a solution. 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.
[R] Fast string comparison
What is the fastest way to compare two strings in R? Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fast string comparison
== ? Hadley On Sun, Jul 11, 2010 at 2:08 PM, Ralf B ralf.bie...@gmail.com wrote: What is the fastest way to compare two strings in R? Ralf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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] a very particular plot
Hi Ian, Have a look at the examples in http://had.co.nz/ggplot2/geom_tile.html for some ideas on how to do this with ggplot2. Hadley On Sat, Jul 10, 2010 at 8:10 PM, Ian Bentley ian.bent...@gmail.com wrote: Hi all, Thanks for the really great help I've received on this board in the past. I have a very particular graph that I'm trying to plot, and I'm not really sure how to do it. I think I should be able to use ggplot for this, but I'm not really sure how. I have a data.frame which contains fifty sub frames containing one hundred data points each. I can do a histogram of each of these sub frames individually, and see the distribution. I can also plot the mean standard deviation of the fifty together in one plot, where the x axis identifies the subframe to which it refers. What I'd like to do is combine these two things, so that I have a 2 -d graph. The x axis specifies the sub-frame. The y axis is just the data. Each x column plots the minimum of the data in the sub frame, the maximum, and the median, as points. AND each x column also displays histogram data, so that the y values which have more density in the subframe are darker, and the ones with less density are lighter. I know this is fairly particular, and may not be possible, but it would be really great for me! If anyone can help - thanks! -- Ian Bentley M.Sc. Candidate Queen's University Kingston, Ontario [[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. -- 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] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)
Hi, I am ok with setting abs.tol=0. Here is an nlminb.patch that has this. There is just one line of code that has been added: control$abs.tol - 0 I have commented where this change happens. I am sorry if I was not being clear. I just wanted to have the authors to also have a look at the source of the problem. Regards, Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Duncan Murdoch murdoch.dun...@gmail.com Date: Sunday, July 11, 2010 7:49 am Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1) To: Matthew Killeya matthewkill...@googlemail.com Cc: Ravi Varadhan rvarad...@jhmi.edu, Peter Ehlers ehl...@ucalgary.ca, r-help@r-project.org, ba...@stat.wisc.edu On 11/07/2010 5:00 AM, Matthew Killeya wrote: Thanks. Seems to me the easiest sensible fix might be to change the default abs.tol=0 in R and add a warning in the help files? That was exactly my suggestion in the message to which Ravi was replying, but he apparently has doubts. Duncan Murdoch Matt On 11 July 2010 01:41, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/07/2010 7:32 PM, Ravi Varadhan wrote: Hi, The best solution would be to identify where the problem is in the FORTRAN code and correct it. However, this problem of premature termination due to absolute function convergence is highly unlikely to occur in practice. As John Nash noted, this is going to be highly unlikely for multi-dimensional parameters (it is also unlikely for one-dimensional problem). However, unless we understand the source of the problem, we cannot feel comfortable in saying with absolute certainty that this will not occur for n 1. Therefore, I would suggest that either we fix the problem at its source or we set abs.tol=0, since there is little harm in doing so. Just for future reference: that's not the kind of answer that leads to anything getting done. So I'll leave it to the authors of nlminb. Duncan Murdoch Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Duncan Murdoch murdoch.dun...@gmail.com Date: Saturday, July 10, 2010 7:32 am Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1) To: Ravi Varadhan rvarad...@jhmi.edu Cc: Matthew Killeya matthewkill...@googlemail.com, Peter Ehlers ehl...@ucalgary.ca, r-help@r-project.org, ba...@stat.wisc.edu Ravi Varadhan wrote: Hi, The absolute function stopping criterion is not meant for any positive objective function. It is meant for functions whose minimum is 0. Here is what David Gay's documentation from PORT says: 6 - absolute function convergence: |f (x)| V(AFCTOL) = V(31). This test is only of interest in problems where f (x) = 0 means a ‘‘perfect fit’’, such as nonlinear least-squares problems. Okay, I've taken a more careful look at the docs, and they do say that the return code 6 does not necessarily indicate convergence: The desirable return codes are 3, 4, 5, and sometimes 6. So we shouldn't by default terminate on it, we should allow users to choose that if they want faster convergence to perfect fits. Would changing the default for abs.tol to zero be a reasonable solution? Duncan Murdoch For example, let us try a positive objective function: nlminb( obj = function(x) x^2 + 1, start=1, lower=-Inf, upper=Inf, control=list(trace=TRUE))0: 2.000: 1.0 1: 1.000: 0.0 2: 1.000: 0.0 $par [1] 0 $objective [1] 1 $convergence [1] 0 $message [1] relative convergence (4) $iterations [1] 2 $evaluations function gradient32 Here the absolute function criterion does not kicks in. Now let us try a function whose minimum value is 0. nlminb( obj = function(x) x^2, start=6, grad=function(x) 2*x, lower=-Inf, upper=Inf, control=list(trace=TRUE) ) 0: 36.00: 6.0 1: 4.000: 2.0 2: 4.9303807e-32: 2.22045e-16 $par [1] 2.220446e-16 $objective [1] 4.930381e-32 $convergence [1] 0 $message [1] absolute function convergence (6) $iterations [1] 2 $evaluations function gradient43 We see that convergence is attained and that the stoppage is due to absolute function
[R] Inserting an image into a PDF file
Colleagues, I am creating a PDF document from R using pdf(), the document contains text / images created with R. I also have an image in either PDF / TIFF / JPEG format (in this case, a scanned image saved as a file). I would like to insert the image into the PDF file. Any ideas on how to accomplish this? (OS X, R 2.11.1) Dennis Dennis Fisher MD P (The P Less Than Company) Phone: 1-866-PLessThan (1-866-753-7784) Fax: 1-866-PLessThan (1-866-753-7784) www.PLessThan.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] Durban Watson statistics
I would like to do the Durban-Watson test on a time series of log returns. 2 questions: 1) If I am just trying to find out if there is serial correlation, what do I do for the residuals? there is no model, so do I just use the log returns (time series) itself? 2) what is the code in R to accomplish this? 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.
Re: [R] Inserting an image into a PDF file
On Jul 11, 2010, at 11:06 AM, Dennis Fisher wrote: Colleagues, I am creating a PDF document from R using pdf(), the document contains text / images created with R. I also have an image in either PDF / TIFF / JPEG format (in this case, a scanned image saved as a file). I would like to insert the image into the PDF file. Any ideas on how to accomplish this? http://www.stat.auckland.ac.nz/~paul/Talks/import.pdf (OS X, R 2.11.1) -- 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] F# vs. R
On Wed, 07 Jul 2010 14:34:05 -0300 Bernardo Rangel Tura t...@centroin.com.br wrote: F# is public, but is not open source. F# run in windows but run in AIX, linux, MAC, UNIX etc? Compiled code should run faster than R, but is precise? Compiled code should run faster than R, but is reliable? Compiled code should run faster than R, but have 2.440 packages for extend your capacities? Compiled code should run faster than R, but critical code is in C o FORTRAN So I think the F# is not a good alternative, if your concern is velocity dou you look Littler There is noguarantee that F# would be faster than R even if it is compiled. R is not -- so far as I can see -- interpreted: the source code is compiled on input to an intermediate format and executed via a bytecode engine. Hmmm... sounds familliar, kinda like Perl and Java and Phytnon and C. C? Yes. Kindly recall that C ocmpilers output assembly code -- the *.a files that gcc gracefully removes for you since few people bother to hand-craft their assy any more. The object files are the result of feeding C's assembly output through an assembler. Unless you can really describe the registers, L1 L2 locations of every piece of text, BSS, and stack/heap you are the mercy of whomever wrote the C compiler and data handling libraries you link with. Net result: C is not guaranteed to run any faster than native R code. Also recall that most of the code today runs on # x86-lineage equipment, where CPU is free to # replace some portions of the assembly with # microcode, execute computations out of order, # and use branch prediction to try and # accelerate execution. Net result: CPU's look kinda like bytecode engines these days. It is worth remembering in any time comparison that R, C, assembly, and well-optimized machine code all block at exactly the same rate: zero. Much of the time in many R programs is spend idle waiting for I/O to disks, memory, and screens. Yup: memory. Intel still uses the IBM 360 motherboard layout; even the AMD's end up blocking for memory I/O since the on-board controller has to wait for signals from sticks that run at a fraction of CPU clock speed. Unless you can pre-load the entire execution cycle into L1 L2 there is no way to avoid blocking. Java also introduces the downside of depending on the JVM authors to properly control the performance for your application. In my -- rather limited -- exposure to the beastie, it hasn't handled heavy-duty number crunching or really large I/O all that well. Net result is that the time you save writing code in R will probably outweigh any differences in computation speed between R and even well-written Fortran, probably C, and certianly almost any other language. Happy hacking. -- Steven Lembark 85-09 90th St. Workhorse Computing Woodhaven, NY, 11421 lemb...@wrkhors.com+1 888 359 3508 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Inserting an image into a PDF file
On Jul 11, 2010, at 10:51 AM, David Winsemius wrote: On Jul 11, 2010, at 11:06 AM, Dennis Fisher wrote: Colleagues, I am creating a PDF document from R using pdf(), the document contains text / images created with R. I also have an image in either PDF / TIFF / JPEG format (in this case, a scanned image saved as a file). I would like to insert the image into the PDF file. Any ideas on how to accomplish this? http://www.stat.auckland.ac.nz/~paul/Talks/import.pdf (OS X, R 2.11.1) Just to offer an additional option since Dennis is on OSX, if you are on 10.6.x (Snow Leopard), you can view this YouTube video: http://www.youtube.com/watch?v=zF_WgXAfMP0 which describes how to combine/insert pages from multiple document types that OSX' Preview can open. If you are on Leopard (10.5.x), the drag and drop behavior, as noted in the above video, is somewhat different and you may wish to view this page: http://macintoshhowto.com/leopard/how-to-merge-pdf-files-with-preview-in-leopard.html This presumes that you want the scanned image on a separate page, rather than combined on the same page as your pdf() output. Since PDF is a native format on OSX, you can take advantage of built-in functionality to manipulate these files. Of course using Sweave is yet another option. HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Durban Watson statistics
On Sun, 11 Jul 2010, Leigh E. Lommen wrote: I would like to do the Durban-Watson test on a time series of log returns. 2 questions: 1) If I am just trying to find out if there is serial correlation, what do I do for the residuals? there is no model, so do I just use the log returns (time series) itself? Test a regression model with an intercept only. 2) what is the code in R to accomplish this? There is dwtest() in the lmtest package which employs the exact or asymptotic distribution for computing the p-value (both under normality) or durbin.watson() in car which employs a bootstrap approach. Note that there are also various other tests for serial correlation around, e.g., the Breusch-Pagan test in bptest() from lmtest among many others. Best, Z 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Interrupt R?
How can one interrupt the following gracefully: while(TRUE){ Sys.sleep(1) } In R2.11.1 under Emacs+ESS, some sequence of ctrl-g, ctrl-c eventually worked for me. Under Rgui 2.11.1, the only way I've found was to kill R. Suggestions on something more graceful? Beyond this, what would you suggest to update a real-time report when new data arrives in a certain directory? A generalization of the above works, but I'd like something more graceful. Thanks, Spencer Graves sessionInfo() R version 2.11.1 (2010-05-31) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] SIM_0.5-0 RCurl_1.4-2bitops_1.0-4.1 R2HTML_2.1 oce_0.1-80 -- Spencer Graves, PE, PhD President and Chief Operating Officer Structure Inspection and Monitoring, Inc. 751 Emerson Ct. San José, CA 95126 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Compress string memCompress/Decompress
On Fri, 2010-07-09 at 20:02 -0400, Erik Wright wrote: Hi Matt, This works great, thanks! At first I got an error message saying BLOB is not implemented in RSQLite. When I updated to the latest version it worked. SQLite began to support BLOBs from version 3.0. Is there any reason the string needs to be stored as type BLOB? It seems to work the same when I swap BLOB with TEXT in the CREATE TABLE command. SQLite has a dynamic-type system. That is, data types are associated with values rather than with their container (column). This means that most columns in a table can store more than just the type (or 'affinity') it is declared with. I think that's what happens when you use TEXT rather than BLOB. If you use something like x'A9' to insert data into a column with TEXT affinity, I believe it is stored as a BLOB regardless. -Matt Thanks again!, Erik On Jul 9, 2010, at 3:21 PM, Matt Shotwell wrote: Erik, Can you store the data as a blob? For example: #create string, compress with gzip, convert to SQLite blob string string - gzip this string, store as blob in SQLite database string.gz - memCompress(string, type=gzip) string.sqlite - paste(x',paste(string.gz,collapse=),',sep=) #create database and table with a BLOB column library(RSQLite) Loading required package: DBI con - dbConnect(dbDriver(SQLite), compress.sqlite) dbGetQuery(con, CREATE TABLE Compress (id INTEGER, data BLOB);) NULL #insert the string as a blob query - paste(INSERT INTO Compress (id, data) VALUES (1, , + string.sqlite, );, sep=) dbGetQuery(con, query) NULL #recover the blob, decompress, and convert back to a string result - dbGetQuery(con, SELECT data FROM Compress;) string.gz - result[[1]][[1]] string - memDecompress(string.gz, type=gzip) rawToChar(string) [1] gzip this string, store as blob in SQLite database -Matt On Fri, 2010-07-09 at 12:51 -0400, Erik Wright wrote: Hello, I would like to compress a long string (character vector), store the compressed string in the text field of a SQLite database (using RSQLite), and then load the text back into memory and decompress it back into the the original string. My character vector can be compressed considerably using standard gzip/bzip2 compression. In theory it should be much faster for me to compress/decompress a long string than to write the whole string to the hard drive and then read it back (not to mention the saved hard drive space). I have tried accomplishing this task using memCompress() and memDecompress() without success. It seems memCompress can only convert a character vector to raw type which cannot be treated as a string. Does anyone have ideas on how I can go about doing this, especially using the standard base packages? Thanks!, Erik sessionInfo() R version 2.11.0 (2010-04-22) x86_64-apple-darwin9.8.0 locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.11.0 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Matthew S. Shotwell Graduate Student Division of Biostatistics and Epidemiology Medical University of South Carolina http://biostatmatt.com -- Matthew S. Shotwell Graduate Student Division of Biostatistics and Epidemiology Medical University of South Carolina http://biostatmatt.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] F# vs. R
Sergey Goriatchev wrote: Hello, Marc No, I do not want to validate Cox PH. :-) I do use R daily, though right now I do not use the statistical part that much. I just generally wonder if any R-user tried F# and his/her opinions. Regards, Sergey In my work as a programmer- this line of thinking usually leads to one set of questions: What problem am I really trying to solve? Am a using the right tools to attack that problem? Mulling over the above questions usually presents a choice: 1. Learn and deploy a new tool that is better suited at attacking the problem than the tools I am currently comfortable with. 2. Stick with one of my better-known tools because it is stronger across a wider class of problems due to factors such as language flexibility, available libraries, widespread adoption, etc. So, if you feel in your gut that F# is better suited to your current or future programming problems than R, it may be worthwhile to invest some time learning the language. If you have the time, it can also be extremely valuable to learn a different language just to try a different approach to solving problems. Personally, I have done very little programming in functional languages- a little bit of Erlang and the tiniest amount of Haskell. But the week or two I have spend on those languages profoundly changed the way I program in R. I discovered a whole bunch of functional programming constructs in R that I feel have made my code smaller and cleaner. In the end I stick with R due to the wealth of libraries available on CRAN, the ease at which the language can be extended via packaging, and the fact that it allows for a variety of approaches to problems. However, it never hurts to have more tools in the toolbox. -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://r.789695.n4.nabble.com/F-vs-R-tp2281084p2285402.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] Fast string comparison
Ralf B wrote: What is the fastest way to compare two strings in R? Ralf Which way is not fast enough? In other words, are you asking this question because profiling showed one of R's string comparison operations is causing a massive bottleneck in your code? If so, which one and how are you using it? -Charlie - Charlie Sharpsteen Undergraduate-- Environmental Resources Engineering Humboldt State University -- View this message in context: http://r.789695.n4.nabble.com/Fast-string-comparison-tp2285156p2285409.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] Interrupt R?
Use the timer in tcl. See this email from Phillipe Grosjean with details. https://stat.ethz.ch/pipermail/r-help/2009-July/203151.html Rich [[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] Interrupt R?
On 11/07/2010 2:29 PM, Spencer Graves wrote: How can one interrupt the following gracefully: while(TRUE){ Sys.sleep(1) } In R2.11.1 under Emacs+ESS, some sequence of ctrl-g, ctrl-c eventually worked for me. Under Rgui 2.11.1, the only way I've found was to kill R. Suggestions on something more graceful? This is an Emacs+ESS bug. In the Windows GUI or using Rterm, the standard methods (ESC or Ctrl-C resp.) work fine. Duncan Murdoch Beyond this, what would you suggest to update a real-time report when new data arrives in a certain directory? A generalization of the above works, but I'd like something more graceful. Thanks, Spencer Graves sessionInfo() R version 2.11.1 (2010-05-31) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] SIM_0.5-0 RCurl_1.4-2bitops_1.0-4.1 R2HTML_2.1 oce_0.1-80 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] RSQLite install R x86_64 fail
Hi, On a fresh install of R on mac os x 10.6.4 (snow leopard) RSQLite did not install while running biocLite() $ R R version 2.11.1 (2010-05-31) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 [...] Loading required package: utils BioC_mirror = http://www.bioconductor.org Change using chooseBioCmirror(). [Previously saved workspace restored] biocLite(RSQLite) Using R version 2.11.1, biocinstall version 2.6.7. Installing Bioconductor version 2.6 packages: [1] RSQLite Please wait... Warning in install.packages(pkgs = pkgs, repos = repos, ...) : argument 'lib' is missing: using '/Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11' trying URL 'http://cran.fhcrc.org/src/contrib/RSQLite_0.9-1.tar.gz' Content type 'application/x-gzip' length 1402602 bytes (1.3 Mb) opened URL == downloaded 1.3 Mb * installing *source* package ‘RSQLite’ ... checking for gcc... /opt/local/bin/gcc-mp-4.4 -std=gnu99 checking for C compiler default output file name... rm: a.out.dSYM: is a directory a.out checking whether the C compiler works... yes checking whether we are cross compiling... no checking for suffix of executables... checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether /opt/local/bin/gcc-mp-4.4 -std=gnu99 accepts -g... yes checking for /opt/local/bin/gcc-mp-4.4 -std=gnu99 option to accept ISO C89... none needed checking how to run the C preprocessor... /opt/local/bin/gcc-mp-4.4 -std=gnu99 -E checking for gcc... (cached) /opt/local/bin/gcc-mp-4.4 -std=gnu99 checking whether we are using the GNU C compiler... (cached) yes checking whether /opt/local/bin/gcc-mp-4.4 -std=gnu99 accepts -g... (cached) yes checking for /opt/local/bin/gcc-mp-4.4 -std=gnu99 option to accept ISO C89... (cached) none needed configure: creating ./config.status config.status: creating src/Makevars ** libs /opt/local/bin/gcc-mp-4.4 -std=gnu99 -I/opt/local/lib/R/include -I/usr/local/mysql/include -DTHREADSAFE=0 -I/opt/local/include-fPIC -pipe -O2 -m64 -c RS-DBI.c -o RS-DBI.o /opt/local/bin/gcc-mp-4.4 -std=gnu99 -I/opt/local/lib/R/include -I/usr/local/mysql/include -DTHREADSAFE=0 -I/opt/local/include-fPIC -pipe -O2 -m64 -c RS-SQLite.c -o RS-SQLite.o /opt/local/bin/gcc-mp-4.4 -std=gnu99 -I/opt/local/lib/R/include -I/usr/local/mysql/include -DTHREADSAFE=0 -I/opt/local/include-fPIC -pipe -O2 -m64 -c param_binding.c -o param_binding.o /opt/local/bin/gcc-mp-4.4 -std=gnu99 -I/opt/local/lib/R/include -I/usr/local/mysql/include -DTHREADSAFE=0 -I/opt/local/include-fPIC -pipe -O2 -m64 -c sqlite-all.c -o sqlite-all.o sqlite-all.c:1:35: warning: extra tokens at end of #ifdef directive mkdir -p ../inst/include cp sqlite/sqlite3.h ../inst/include cp sqlite/sqlite3ext.h ../inst/include /opt/local/bin/gcc-mp-4.4 -std=gnu99 -dynamiclib -Wl,-headerpad_max_install_names -undefined dynamic_lookup -single_module -multiply_defined suppress -L/opt/local/lib -o RSQLite.so RS-DBI.o RS-SQLite.o param_binding.o sqlite-all.o -L/usr/local/mysql/lib -lmysqlclient -L/opt/local/lib/R/lib -lR installing to /Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs ** R ** inst ** preparing package for lazy loading ** help *** installing help indices ** building package indices ... ** testing if installed package can be loaded Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared library '/Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/RSQLite.so': dlopen(/Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/RSQLite.so, 6): Symbol not found: _sqlite3_backup_finish Referenced from: /Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/RSQLite.so Expected in: flat namespace in /Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/RSQLite.so ERROR: loading failed * removing ‘/Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite’ * restoring previous ‘/Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite’ The downloaded packages are in ‘/private/var/folders/e9/e9-5zLVqFgGBR2S8qU74+U+++TM/-Tmp-/RtmpBgST91/downloaded_packages’ Warning message: In install.packages(pkgs = pkgs, repos = repos, ...) : installation of package 'RSQLite' had non-zero exit status # # The binary install work with install.packages(RSQLite, type='mac.binary') or 'mac.binary.leopard' but the package does not load properly. library('RSQLite') Error: package 'RSQLite' was built for universal-apple-darwin9.8.0 The RSQLite.so file is not in libs/RSQLite.so but in libs/x86_64/RSQLite.so sessionInfo() R version 2.11.1 (2010-05-31) x86_64-apple-darwin10.4.0 locale: [1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/C attached base packages: [1] stats graphics grDevices datasets utils methods base loaded via a namespace (and not attached): [1] tools_2.11.1 Thanks,
[R] data export HELP!
Hello! So, this is going to seem like a very simple question - I am quite new to R and am having some trouble figuring out little nuances: I am running a loop that goes through my data and performs a nls parameter estimation on each data set. At the end of the loop, I would like to collect the parameter estimates in ONE SINGLE DATA FRAME or WRITE.TABLE that I can import into excel. Here is my code: for(j in 1:dim(r)[2]){ indiv=r[,j][which(r[,j]-1)] #removes -1 growth data age.1=age[1:length(indiv)] length.ind=data.frame(age.1,indiv, row.names=TRUE) #data frame of ages and length est.ind=nls(indiv~Linf*(1-exp(-K*(age.1-to))),start=lkt.A,data=length.ind) # von b growth estimate summary=summary(est.ind, correlation=TRUE) #gives parameter estimate values parameters=data.frame(Linf=coef(est.ind)[1],K=coef(est.ind)[2]) #data frame of parameter estimates } if I just type parameters I only get the parameter estimates for the LAST individual that was in the loop. How can i combine EVERY SINGLE parameter estimate into a data.frame or something of the sort and then export this set of data into ONE csv file. I can do it using write.table within my loop, but then I get 52 csv files - I would like to avoid this. I hope this makes sense - any help would be GREATLY APPRECIATED thanks! -- View this message in context: http://r.789695.n4.nabble.com/data-export-HELP-tp2285445p2285445.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] eval and assign in loop problem
On Fri, 09-Jul-2010 at 08:25AM -0700, S.Nicholas wrote: | deaR useRs, | | I am trying to assign different values to different objects in a for loop. | The following is a toy example of the part that has been giving me a hard | time. | | The first for loop generates four objects, b0, b1, b2, b3 with random | numbers. | And, the second for loop is equivalent to | b1 = b0 | b2 = b1 | b3 = b2 | b4 = b3 I don't quite get the idea, but would you be able to simply reverse the order of those last 4 (for i in 3:0)? That way, they won't all be overwritten with b0. HTH | | But, when I run this code, the result is equivalent to | b1 = b0 | b2 = b0 | b3 = b0 | b4 = b0 | | So, the increment does not seem to be properly working for the second part | of the assign function. | Why would this be? | | for (i in 0:3) |{ |r = runif(1) |assign(paste('b',i,sep=''),r) |} | | | for (i in 1:4) |{ | | assign(paste('b',i,sep=''),eval(parse(text=paste('b',i-1,sep='' |} | | Thank you. | | Nic | | [[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 Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 export HELP!
Not necessarily the best way if your dataframe will get large, but it should work: parameters - NULL # where you will collect the result for(j in 1:dim(r)[2]){ indiv=r[,j][which(r[,j]-1)] #removes -1 growth data age.1=age[1:length(indiv)] length.ind=data.frame(age.1,indiv, row.names=TRUE) #data frame of ages and length est.ind=nls(indiv~Linf*(1-exp(-K*(age.1-to))),start=lkt.A,data=length.ind) # von b growth estimate summary=summary(est.ind, correlation=TRUE) #gives parameter estimate values parameters - rbind(parameters, data.frame(Linf=coef(est.ind)[1],K=coef(est.ind)[2])) #data frame of parameter estimates } On Sun, Jul 11, 2010 at 3:54 PM, adriana1986 adriana.olij...@queensu.ca wrote: Hello! So, this is going to seem like a very simple question - I am quite new to R and am having some trouble figuring out little nuances: I am running a loop that goes through my data and performs a nls parameter estimation on each data set. At the end of the loop, I would like to collect the parameter estimates in ONE SINGLE DATA FRAME or WRITE.TABLE that I can import into excel. Here is my code: for(j in 1:dim(r)[2]){ indiv=r[,j][which(r[,j]-1)] #removes -1 growth data age.1=age[1:length(indiv)] length.ind=data.frame(age.1,indiv, row.names=TRUE) #data frame of ages and length est.ind=nls(indiv~Linf*(1-exp(-K*(age.1-to))),start=lkt.A,data=length.ind) # von b growth estimate summary=summary(est.ind, correlation=TRUE) #gives parameter estimate values parameters=data.frame(Linf=coef(est.ind)[1],K=coef(est.ind)[2]) #data frame of parameter estimates } if I just type parameters I only get the parameter estimates for the LAST individual that was in the loop. How can i combine EVERY SINGLE parameter estimate into a data.frame or something of the sort and then export this set of data into ONE csv file. I can do it using write.table within my loop, but then I get 52 csv files - I would like to avoid this. I hope this makes sense - any help would be GREATLY APPRECIATED thanks! -- View this message in context: http://r.789695.n4.nabble.com/data-export-HELP-tp2285445p2285445.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 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] Interrupt R?
Hi, Richard and Duncan: Thank you both very much. You provided different but workable solutions. 1. With Rgui 2.11.1 on Vista x64, the escape worked, but neither ctrl-c nor ctrl-C worked for me. 2. The TCLTK version works but seems to require either more skill from the programmer or more user training than using escape under Rgui or ctrl-g/c under Emacs. Best Wishes, Spencer On 7/11/2010 12:02 PM, Duncan Murdoch wrote: On 11/07/2010 2:29 PM, Spencer Graves wrote: How can one interrupt the following gracefully: while(TRUE){ Sys.sleep(1) } In R2.11.1 under Emacs+ESS, some sequence of ctrl-g, ctrl-c eventually worked for me. Under Rgui 2.11.1, the only way I've found was to kill R. Suggestions on something more graceful? This is an Emacs+ESS bug. In the Windows GUI or using Rterm, the standard methods (ESC or Ctrl-C resp.) work fine. Duncan Murdoch Beyond this, what would you suggest to update a real-time report when new data arrives in a certain directory? A generalization of the above works, but I'd like something more graceful. Thanks, Spencer Graves sessionInfo() R version 2.11.1 (2010-05-31) i386-pc-mingw32 locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] SIM_0.5-0 RCurl_1.4-2bitops_1.0-4.1 R2HTML_2.1 oce_0.1-80 -- Spencer Graves, PE, PhD President and Chief Operating Officer Structure Inspection and Monitoring, Inc. 751 Emerson Ct. San José, CA 95126 ph: 408-655-4567 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Mixed effect model for regression/classification trees?
Hello all, This is more a statistical question then an R question, but I am sure it will have an R interpretation to it. If I wish to predict an outcome based on some potential features, I could (in some cases) use either regression or regression-tree. However, if my observations are divided to groups (for example by subject), I might then want to model that using a random effect for the subject and a fixed effect for the other features I wish to model for the prediction. My question is what (if exist) is the parallel of this in regression trees ? Is it simply like adding the subject classifier to the tree? or is this leading to a different model scheme all together? (and if so - what is it) Thanks, Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- [[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] make an model object (e.g. nlme) available in a user defined function (xyplot related)
Dear all, When I construct an nlme model object by calling nlme(...)-mod.nlme, this object can be used in xyplot(). Something like xyplot(x,y,.. .. ind.predict-predict(mod.nlme) .. ) is working fine in console environment. But the same structure is not working in a user defined function. It seems the mod.nlme created in a user defined function can not be called in xyplot(). Why is that? Appreciate any comment. (The error message says Error in using packet 1, object model not found) Thanks. Jun Shen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Mixed effect model for regression/classification trees?
On Sun, 11 Jul 2010, Tal Galili wrote: Hello all, This is more a statistical question then an R question, but I am sure it will have an R interpretation to it. If I wish to predict an outcome based on some potential features, I could (in some cases) use either regression or regression-tree. However, if my observations are divided to groups (for example by subject), I might then want to model that using a random effect for the subject and a fixed effect for the other features I wish to model for the prediction. My question is what (if exist) is the parallel of this in regression trees ? Is it simply like adding the subject classifier to the tree? or is this leading to a different model scheme all together? (and if so - what is it) We had thought about doing something in this direction in the model-based recursive partitioning framework (MOB) in the party package but never pulled it off. However, I've seen various other ideas at conferences for trees with random intercepts etc. One CRAN package that provides infracstructure for this is REEMtree which is probably worth a look. hth, Z Thanks, Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- [[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] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)
On 11/07/2010 10:22 AM, Ravi Varadhan wrote: Hi, I am ok with setting abs.tol=0. Here is an nlminb.patch that has this. There is just one line of code that has been added: control$abs.tol - 0 I have commented where this change happens. I am sorry if I was not being clear. I just wanted to have the authors to also have a look at the source of the problem. I've put in a different patch that sets the default value of abs.tol to zero, rather than forcing it to zero in all calls. Duncan Murdoch Regards, Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Duncan Murdoch murdoch.dun...@gmail.com Date: Sunday, July 11, 2010 7:49 am Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1) To: Matthew Killeya matthewkill...@googlemail.com Cc: Ravi Varadhan rvarad...@jhmi.edu, Peter Ehlers ehl...@ucalgary.ca, r-help@r-project.org, ba...@stat.wisc.edu On 11/07/2010 5:00 AM, Matthew Killeya wrote: Thanks. Seems to me the easiest sensible fix might be to change the default abs.tol=0 in R and add a warning in the help files? That was exactly my suggestion in the message to which Ravi was replying, but he apparently has doubts. Duncan Murdoch Matt On 11 July 2010 01:41, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/07/2010 7:32 PM, Ravi Varadhan wrote: Hi, The best solution would be to identify where the problem is in the FORTRAN code and correct it. However, this problem of premature termination due to absolute function convergence is highly unlikely to occur in practice. As John Nash noted, this is going to be highly unlikely for multi-dimensional parameters (it is also unlikely for one-dimensional problem). However, unless we understand the source of the problem, we cannot feel comfortable in saying with absolute certainty that this will not occur for n 1. Therefore, I would suggest that either we fix the problem at its source or we set abs.tol=0, since there is little harm in doing so. Just for future reference: that's not the kind of answer that leads to anything getting done. So I'll leave it to the authors of nlminb. Duncan Murdoch Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Duncan Murdoch murdoch.dun...@gmail.com Date: Saturday, July 10, 2010 7:32 am Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1) To: Ravi Varadhan rvarad...@jhmi.edu Cc: Matthew Killeya matthewkill...@googlemail.com, Peter Ehlers ehl...@ucalgary.ca, r-help@r-project.org, ba...@stat.wisc.edu Ravi Varadhan wrote: Hi, The absolute function stopping criterion is not meant for any positive objective function. It is meant for functions whose minimum is 0. Here is what David Gay's documentation from PORT says: 6 - absolute function convergence: |f (x)| V(AFCTOL) = V(31). This test is only of interest in problems where f (x) = 0 means a ‘‘perfect fit’’, such as nonlinear least-squares problems. Okay, I've taken a more careful look at the docs, and they do say that the return code 6 does not necessarily indicate convergence: The desirable return codes are 3, 4, 5, and sometimes 6. So we shouldn't by default terminate on it, we should allow users to choose that if they want faster convergence to perfect fits. Would changing the default for abs.tol to zero be a reasonable solution? Duncan Murdoch For example, let us try a positive objective function: nlminb( obj = function(x) x^2 + 1, start=1, lower=-Inf, upper=Inf, control=list(trace=TRUE))0: 2.000: 1.0 1: 1.000: 0.0 2: 1.000: 0.0 $par [1] 0 $objective [1] 1 $convergence [1] 0 $message [1] relative convergence (4) $iterations [1] 2 $evaluations function gradient32 Here the absolute function criterion does not kicks in. Now let us try a function whose minimum value is 0. nlminb( obj = function(x) x^2, start=6, grad=function(x) 2*x, lower=-Inf, upper=Inf, control=list(trace=TRUE) ) 0: 36.00: 6.0 1: 4.000: 2.0 2: 4.9303807e-32: 2.22045e-16 $par [1] 2.220446e-16 $objective [1] 4.930381e-32 $convergence [1] 0 $message [1] absolute function convergence (6) $iterations [1] 2 $evaluations function gradient43 We see that convergence is
Re: [R] RSQLite install R x86_64 fail
Hi David, On Sun, Jul 11, 2010 at 12:27 PM, David Ruau dr...@stanford.edu wrote: On a fresh install of R on mac os x 10.6.4 (snow leopard) RSQLite did not install while running biocLite() How did you install R? $ R biocLite(RSQLite) Using R version 2.11.1, biocinstall version 2.6.7. Installing Bioconductor version 2.6 packages: [1] RSQLite Please wait... Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared library '/Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/RSQLite.so': dlopen(/Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/RSQLite.so, 6): Symbol not found: _sqlite3_backup_finish Referenced from: /Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/RSQLite.so Expected in: flat namespace in /Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/RSQLite.so ERROR: loading failed * removing ‘/Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite’ * restoring previous ‘/Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite’ What version of XCode do you have? I have 3.2.1 and can build RSQLite from source from an R that I have compiled from source. If you have an earlier version, please try upgrading and repeating the install. The binary install work with install.packages(RSQLite, type='mac.binary') or 'mac.binary.leopard' but the package does not load properly. library('RSQLite') Error: package 'RSQLite' was built for universal-apple-darwin9.8.0 The mac binary package is intended to work with the R binary installer for OS X. So if you want to use it, you need to install R that way. Hope that helps some. + 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.
Re: [R] Compress string memCompress/Decompress
On Sun, Jul 11, 2010 at 11:31 AM, Matt Shotwell shotw...@musc.edu wrote: On Fri, 2010-07-09 at 20:02 -0400, Erik Wright wrote: Hi Matt, This works great, thanks! At first I got an error message saying BLOB is not implemented in RSQLite. When I updated to the latest version it worked. SQLite began to support BLOBs from version 3.0. And RSQLite began supporting BLOBs only just recently :-) See the NEWS file for details. Below is a minimal example of how you might use BLOBs: db - dbConnect(SQLite(), dbname = :memory:) dbGetQuery(db, CREATE TABLE t1 (name TEXT, data BLOB)) z - paste(hello, 1:10) df - data.frame(a = letters[1:10], z = I(lapply(z, charToRaw))) dbGetPreparedQuery(db, insert into t1 values (:a, :z), df) a - dbGetQuery(db, select name from t1) checkEquals(10, nrow(a)) a - dbGetQuery(db, select data from t1) checkEquals(10, nrow(a)) a - dbGetQuery(db, select * from t1) checkEquals(10, nrow(a)) checkEquals(2, ncol(a)) checkEquals(z, sapply(a$data, rawToChar)) dbDisconnect(db) -- 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.
Re: [R] RSQLite install R x86_64 fail
Hi Seth, Thanks for the answer. I have install R using macport (since many years now). It compile R from source using gcc 4.4 by default. But I don't think this is the problem because I manage to install many other package that do not need RSQLite. The configure options for the macport port are at: http://trac.macports.org/browser/trunk/dports/math/R/Portfile I have Xcode 3.2.3 downloaded yesterday. The thing is that it compile correctly but the RSQLite.so is not at the place specified. Instead of being at ~/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/ it is in a subfolder ~/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/x86_64/ I could create a symbolic link only if biocLite would not erase the folder at the end of the failed install. David On Jul 11, 2010, at 4:09 PM, Seth Falcon wrote: Hi David, On Sun, Jul 11, 2010 at 12:27 PM, David Ruau dr...@stanford.edu wrote: On a fresh install of R on mac os x 10.6.4 (snow leopard) RSQLite did not install while running biocLite() How did you install R? $ R biocLite(RSQLite) Using R version 2.11.1, biocinstall version 2.6.7. Installing Bioconductor version 2.6 packages: [1] RSQLite Please wait... Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared library '/Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/RSQLite.so': dlopen(/Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/RSQLite.so, 6): Symbol not found: _sqlite3_backup_finish Referenced from: /Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/RSQLite.so Expected in: flat namespace in /Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/RSQLite.so ERROR: loading failed * removing ‘/Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite’ * restoring previous ‘/Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite’ What version of XCode do you have? I have 3.2.1 and can build RSQLite from source from an R that I have compiled from source. If you have an earlier version, please try upgrading and repeating the install. The binary install work with install.packages(RSQLite, type='mac.binary') or 'mac.binary.leopard' but the package does not load properly. library('RSQLite') Error: package 'RSQLite' was built for universal-apple-darwin9.8.0 The mac binary package is intended to work with the R binary installer for OS X. So if you want to use it, you need to install R that way. Hope that helps some. + 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.
Re: [R] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1)
I guess it is ok, but then a warning should be added, when describing the `abs.tol' parameter in the help file to state that changing it may result in premature stopping when f(x*) = 0. Regards, Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Duncan Murdoch murdoch.dun...@gmail.com Date: Sunday, July 11, 2010 7:05 pm Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1) To: Ravi Varadhan rvarad...@jhmi.edu Cc: Matthew Killeya matthewkill...@googlemail.com, Peter Ehlers ehl...@ucalgary.ca, r-help@r-project.org, ba...@stat.wisc.edu On 11/07/2010 10:22 AM, Ravi Varadhan wrote: Hi, I am ok with setting abs.tol=0. Here is an nlminb.patch that has this. There is just one line of code that has been added: control$abs.tol - 0 I have commented where this change happens. I am sorry if I was not being clear. I just wanted to have the authors to also have a look at the source of the problem. I've put in a different patch that sets the default value of abs.tol to zero, rather than forcing it to zero in all calls. Duncan Murdoch Regards, Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Duncan Murdoch murdoch.dun...@gmail.com Date: Sunday, July 11, 2010 7:49 am Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1) To: Matthew Killeya matthewkill...@googlemail.com Cc: Ravi Varadhan rvarad...@jhmi.edu, Peter Ehlers ehl...@ucalgary.ca, r-help@r-project.org, ba...@stat.wisc.edu On 11/07/2010 5:00 AM, Matthew Killeya wrote: Thanks. Seems to me the easiest sensible fix might be to change the default abs.tol=0 in R and add a warning in the help files? That was exactly my suggestion in the message to which Ravi was replying, but he apparently has doubts. Duncan Murdoch Matt On 11 July 2010 01:41, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 10/07/2010 7:32 PM, Ravi Varadhan wrote: Hi, The best solution would be to identify where the problem is in the FORTRAN code and correct it. However, this problem of premature termination due to absolute function convergence is highly unlikely to occur in practice. As John Nash noted, this is going to be highly unlikely for multi-dimensional parameters (it is also unlikely for one-dimensional problem). However, unless we understand the source of the problem, we cannot feel comfortable in saying with absolute certainty that this will not occur for n 1. Therefore, I would suggest that either we fix the problem at its source or we set abs.tol=0, since there is little harm in doing so. Just for future reference: that's not the kind of answer that leads to anything getting done. So I'll leave it to the authors of nlminb. Duncan Murdoch Ravi. Ravi Varadhan, Ph.D. Assistant Professor, Division of Geriatric Medicine and Gerontology School of Medicine Johns Hopkins University Ph. (410) 502-2619 email: rvarad...@jhmi.edu - Original Message - From: Duncan Murdoch murdoch.dun...@gmail.com Date: Saturday, July 10, 2010 7:32 am Subject: Re: [R] Not nice behaviour of nlminb (windows 32 bit, version 2.11.1) To: Ravi Varadhan rvarad...@jhmi.edu Cc: Matthew Killeya matthewkill...@googlemail.com, Peter Ehlers ehl...@ucalgary.ca, r-help@r-project.org, ba...@stat.wisc.edu Ravi Varadhan wrote: Hi, The absolute function stopping criterion is not meant for any positive objective function. It is meant for functions whose minimum is 0. Here is what David Gay's documentation from PORT says: 6 - absolute function convergence: |f (x)| V(AFCTOL) = V(31). This test is only of interest in problems where f (x) = 0 means a ‘‘perfect fit’’, such as nonlinear least-squares problems. Okay, I've taken a more careful look at the docs, and they do say that the return code 6 does not necessarily indicate convergence: The desirable return codes are 3, 4, 5, and sometimes 6. So we shouldn't by default terminate on it, we should allow users to choose that if they want faster convergence to perfect fits. Would changing the default for abs.tol to zero be a reasonable solution? Duncan
[R] The formula interface of SVM
Hi Could you please explain the line that I got from the documentation of R? does it mean that there is a difference between using and not using the formula interface with SVM ?: If the predictor variables include factors, the formula interface must be used to get a correct model matrix. Cheers, Amy _ View photos of singles in your area! Looking for a hot date? [[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] (no subject)
Hi all, I want to add the red color under the standard normal curve to the right of 1.96. Can anyone give me a hand? Please see the code below. Thank you. x - seq(-4, 4, length=100) hx - dnorm(x) par(pty=s) plot(x, hx, type=l, xlab=z value, ylab=Density, main=density of N(0,1)) abline(v=1.96, col=red) [[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] The formula interface of SVM
Hi, On Sun, Jul 11, 2010 at 7:11 PM, Amy Hessen amy_4_5...@hotmail.com wrote: Hi Could you please explain the line that I got from the documentation of R? does it mean that there is a difference between using and not using the formula interface with SVM ?: If the predictor variables include factors, the formula interface must be used to get a correct model matrix. It might have something to do with the fact that one would expand factors into a set of dummy variables (that can take either a 1, or 0 value) in order to encode all of the levels of the factors into different variables. You could do this yourself without using the formula, but you would then have to manually expand (column wise) your data to encode the vars yourself where as the formula interface does this for you? (I don't know that for sure, I'm just guessing from that sentence you mention -- look at the source code of the function in order verify this for yourself) Here's a ref: http://dss.princeton.edu/online_help/analysis/dummy_variables.htm You can google about using nominal/categorical variables to learn more. -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] (no subject)
On Sun, 11 Jul 2010, li li wrote: Hi all, I want to add the red color under the standard normal curve to the right of 1.96. Can anyone give me a hand? Please see the code below. Thank you. x - seq(-4, 4, length=100) hx - dnorm(x) par(pty=s) plot(x, hx, type=l, xlab=z value, ylab=Density, main=density of N(0,1)) abline(v=1.96, col=red) ?polygon example(polygon) [[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. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC 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.
Re: [R] (no subject)
You need three more lines of code abline(h=0) xx - seq(1.96, 4, length=25) polygon(x=c(xx[1],xx,xx[25]), y=c(0,dnorm(xx),0), col='red') Please see the normal.and.t.dist function in the HH package for more detailed control of the graph. ## install.packages(HH) ## if you don't have it yet. library(HH) normal.and.t.dist(alpha.right=.025) [[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] problem with comparisons for vectors
I don't know the real reason, but help(==) gives some clues. For numerical and complex values, remember == and != do not allow for the finite representation of fractions, nor for rounding error. Using all.equal with identical is almost always preferable. See the examples. x1 - 0.5 - 0.3 x2 - 0.3 - 0.1 x1 == x2 # FALSE on most machines identical(all.equal(x1, x2), TRUE) # TRUE everywhere - A R learner. -- View this message in context: http://r.789695.n4.nabble.com/problem-with-comparisons-for-vectors-tp2285557p2285685.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] Marking the tail of a distribution (was (no subject))
Here is a way: ### x - sort(c(seq(-4, 4, length=100), 1.96)) hx - dnorm(x) par(pty=s) plot(x, hx, type=l, xlab=z value, ylab=Density, main=density of N(0,1)) abline(v=1.96, col=red) abline(h = 0) top - x = 1.96 tail - rbind(cbind(x[top], hx[top]), c(4, 0), c(1.96, 0)) polygon(tail, col = red) ### As the guidelines say, please put a suitable subject line on your queries. These messages are archived for future reference by others. It makes it impossible to find appropriate messages if there is no subject to give a clue on what it is all about. -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of li li Sent: Monday, 12 July 2010 1:22 PM To: r-help Subject: [R] (no subject) Hi all, I want to add the red color under the standard normal curve to the right of 1.96. Can anyone give me a hand? Please see the code below. Thank you. x - seq(-4, 4, length=100) hx - dnorm(x) par(pty=s) plot(x, hx, type=l, xlab=z value, ylab=Density, main=density of N(0,1)) abline(v=1.96, col=red) [[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] RSQLite install R x86_64 fail
On Sun, Jul 11, 2010 at 4:25 PM, David Ruau dr...@stanford.edu wrote: Hi Seth, Thanks for the answer. I have install R using macport (since many years now). It compile R from source using gcc 4.4 by default. But I don't think this is the problem because I manage to install many other package that do not need RSQLite. The configure options for the macport port are at: http://trac.macports.org/browser/trunk/dports/math/R/Portfile I have Xcode 3.2.3 downloaded yesterday. The thing is that it compile correctly but the RSQLite.so is not at the place specified. Instead of being at ~/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/ it is in a subfolder ~/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/x86_64/ I could create a symbolic link only if biocLite would not erase the folder at the end of the failed install. I don't use macports so I'm afraid I can't be of much help. I suspect that something isn't getting configured properly for 64bit R in macports. When I build R from source on OS X and install RSQLite, I see the package in .../libs/x86_64 and this works. Maybe it will be useful to review the advice here: http://r.research.att.com/building.html + seth David On Jul 11, 2010, at 4:09 PM, Seth Falcon wrote: Hi David, On Sun, Jul 11, 2010 at 12:27 PM, David Ruau dr...@stanford.edu wrote: On a fresh install of R on mac os x 10.6.4 (snow leopard) RSQLite did not install while running biocLite() How did you install R? $ R biocLite(RSQLite) Using R version 2.11.1, biocinstall version 2.6.7. Installing Bioconductor version 2.6 packages: [1] RSQLite Please wait... Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared library '/Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/RSQLite.so': dlopen(/Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/RSQLite.so, 6): Symbol not found: _sqlite3_backup_finish Referenced from: /Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/RSQLite.so Expected in: flat namespace in /Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite/libs/RSQLite.so ERROR: loading failed * removing ‘/Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite’ * restoring previous ‘/Users/druau/R/x86_64-apple-darwin10.4.0-library/2.11/RSQLite’ What version of XCode do you have? I have 3.2.1 and can build RSQLite from source from an R that I have compiled from source. If you have an earlier version, please try upgrading and repeating the install. The binary install work with install.packages(RSQLite, type='mac.binary') or 'mac.binary.leopard' but the package does not load properly. library('RSQLite') Error: package 'RSQLite' was built for universal-apple-darwin9.8.0 The mac binary package is intended to work with the R binary installer for OS X. So if you want to use it, you need to install R that way. Hope that helps some. + seth -- Seth Falcon | @sfalcon | http://userprimary.net/ -- 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] long to wide on larger data set
I have a data set that has 4 columns and 53860858 rows. I was able to read this into R with: cc - rep(character,4) myData - read.table(myData.csv,header=FALSE,skip=1,colClasses=cc,nrow=53860858,sep=,) I need to reshape this data from long to wide. On a small data set the following lines work. But on the real data set, it didn't finish even when I took a sample of two (rows in new data). I didn't receive an error. I just stopped it because it was taking too long. Any suggestions for improvements? Thanks. # start example # i have commented out the write.table statement below testData - read.table(textConnection(rs853,cv0084,A,A rs86,cv0084,C,B rs883,cv0084,E,F rs853,cv0085,G,H rs86,cv0085,I,J rs883,cv0085,K,L),header=FALSE,sep=,) closeAllConnections() mysamples - unique(testData$V2) for (one_ind in mysamples) { one_sample - testData[testData$V2==one_ind,] mywide - reshape(one_sample, timevar = V1, idvar = V2,direction = wide) # write.table(mywide,file =newdata.txt,append=TRUE,row.names=FALSE,col.names=FALSE,quote=FALSE) } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.