Re: [R] Adding variables
Jim, Both my emails contained reproducible code (the first one wasn't completely reproducible - it required one to know that attenu is a base R dataset). Anyway, thanks for your help. On Sat, Sep 26, 2009 at 8:11 PM, jim holtman jholt...@gmail.com wrote: I assumed (since you did not provide reproducible code) that 'mag' was a matrix. If 'station' is a matrix, then mag + rowSums(station) will work. If that does not work, then you need to tell us what your data objects are. On Sat, Sep 26, 2009 at 11:39 AM, tzygmund mcfarlane tzygm...@googlemail.com wrote: Hi Jim, I might be missing something but your command gives the error: Error in rowSums(mag) : 'x' must be an array of at least two dimensions # data(attenu) attach(attenu) rowSums(mag) + rowSums(station) attenu$new-rowSums(cbind(mag, station)) # Thanks On Sat, Sep 26, 2009 at 4:30 PM, jim holtman jholt...@gmail.com wrote: Probably more efficient if you remove the 'cbind' which would create a combined matrix. Use the following: rowSums(mag) + rowSums(station) On Sat, Sep 26, 2009 at 11:16 AM, tzygmund mcfarlane tzygm...@googlemail.com wrote: Hi, For very large matrices, is this the most efficient way to add two variables together? # attach(attenu) new-rowSums(cbind(mag, station)) # Also, could I be directed to some resources for working with very large datasets? Thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? -- 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] Adding variables
So why were you trying to add a factor variable to a numeric, anyway? For no other reason than to illustrate the task of addition. It is, admittedly, meaningless. Well, I had never seen any help pages use attenu as an example. I literally went to: http://stat.ethz.ch/R-manual/R-patched/library/datasets/html/00Index.html and picked a random dataset. I haven't enough R experience to know which datasets are more commonly used to illustrate issues than others. My original question was about the efficiency of simple arithmetic for large datasets and managing them. While the advice I have received so far is very good for my R style, I was wondering if you might add something regarding this. PS. Thanks Henrique, but again the example was chosen completely at random to provide reproducible code I wasn't thinking about numeric and factor variables. On Sun, Sep 27, 2009 at 3:14 PM, David Winsemius dwinsem...@comcast.net wrote: Well, I had never seen any help pages use attenu as an example. Like Jim I assumed that you were offering code that was operating on some private copy of data, If you look at the number of datasets, I think it unreasonable to expect the great majority of potentially helpful persons to know all of them either. So why were you trying to add a factor variable to a numeric, anyway? If your hope was to convert those codes to numeric then it's a FAQ: http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f If the problem were more basic, and you did not know what was in that dataset then the answer might have bee: str(attenu) -- David On Sep 27, 2009, at 7:47 AM, tzygmund mcfarlane wrote: Jim, Both my emails contained reproducible code (the first one wasn't completely reproducible - it required one to know that attenu is a base R dataset). Anyway, thanks for your help. On Sat, Sep 26, 2009 at 8:11 PM, jim holtman jholt...@gmail.com wrote: I assumed (since you did not provide reproducible code) that 'mag' was a matrix. If 'station' is a matrix, then mag + rowSums(station) will work. If that does not work, then you need to tell us what your data objects are. On Sat, Sep 26, 2009 at 11:39 AM, tzygmund mcfarlane tzygm...@googlemail.com wrote: Hi Jim, I might be missing something but your command gives the error: Error in rowSums(mag) : 'x' must be an array of at least two dimensions # data(attenu) attach(attenu) rowSums(mag) + rowSums(station) attenu$new-rowSums(cbind(mag, station)) # Thanks On Sat, Sep 26, 2009 at 4:30 PM, jim holtman jholt...@gmail.com wrote: Probably more efficient if you remove the 'cbind' which would create a combined matrix. Use the following: rowSums(mag) + rowSums(station) On Sat, Sep 26, 2009 at 11:16 AM, tzygmund mcfarlane tzygm...@googlemail.com wrote: Hi, For very large matrices, is this the most efficient way to add two variables together? # attach(attenu) new-rowSums(cbind(mag, station)) # Also, could I be directed to some resources for working with very large datasets? Thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? -- 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. David Winsemius, MD Heritage Laboratories 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] Adding variables
Thank you Gabor ( Henrique)! On Sun, Sep 27, 2009 at 3:26 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: with(attenu, mag + as.numeric(station)) is nearly twice as fast: system.time(for(i in 1:1000) with(attenu, mag + as.numeric(station))) user system elapsed 0.05 0.02 0.06 system.time(for(i in 1:1000) rowSums(cbind(mag, station))) user system elapsed 0.09 0.00 0.10 See ?system.time, ?Rprof and http://code.google.com/p/rbenchmark/ for timing commands. On Sat, Sep 26, 2009 at 11:16 AM, tzygmund mcfarlane tzygm...@googlemail.com wrote: Hi, For very large matrices, is this the most efficient way to add two variables together? # attach(attenu) new-rowSums(cbind(mag, station)) # Also, could I be directed to some resources for working with very large datasets? Thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Adding variables
Hi, For very large matrices, is this the most efficient way to add two variables together? # attach(attenu) new-rowSums(cbind(mag, station)) # Also, could I be directed to some resources for working with very large datasets? Thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Adding variables
Hi Jim, I might be missing something but your command gives the error: Error in rowSums(mag) : 'x' must be an array of at least two dimensions # data(attenu) attach(attenu) rowSums(mag) + rowSums(station) attenu$new-rowSums(cbind(mag, station)) # Thanks On Sat, Sep 26, 2009 at 4:30 PM, jim holtman jholt...@gmail.com wrote: Probably more efficient if you remove the 'cbind' which would create a combined matrix. Use the following: rowSums(mag) + rowSums(station) On Sat, Sep 26, 2009 at 11:16 AM, tzygmund mcfarlane tzygm...@googlemail.com wrote: Hi, For very large matrices, is this the most efficient way to add two variables together? # attach(attenu) new-rowSums(cbind(mag, station)) # Also, could I be directed to some resources for working with very large datasets? Thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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.
[R] Processing strings
Hi, I am unable to do something fairly simple. I have matrices called Table1,..., Table10. I want to be able to print them using a loop. So I wrote: ## for (i in 1:10){ disp-paste(Table, i, sep=) eval(parse(text=disp)) } ## but this produces no output. Any ideas? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Processing strings
Jorge, Your suggestions produce the names of the matrices and not the contents. Sorry if this was not clear in the question. On Sat, Sep 19, 2009 at 11:46 PM, Jorge Ivan Velez jorgeivanve...@gmail.com wrote: Dear tzygmund, Here are two suggestions: # Suggestion 1 for (i in 1:10){ disp-paste(Table, i, sep=) print(get(disp)) } # Suggestion 2 disp - paste(Table, 1:10, sep=) sapply(disp, function(x) print( get(x) ) ) See ?print and ?get for more information. HTH, Jorge On Sat, Sep 19, 2009 at 6:40 PM, tzygmund mcfarlane wrote: Hi, I am unable to do something fairly simple. I have matrices called Table1,..., Table10. I want to be able to print them using a loop. So I wrote: ## for (i in 1:10){ disp-paste(Table, i, sep=) eval(parse(text=disp)) } ## but this produces no output. Any ideas? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Processing strings
Ah, apologies. In the backing and forthing, I assigned the names to the matrices. All sorted. Thanks! On Sat, Sep 19, 2009 at 11:55 PM, Duncan Murdoch murd...@stats.uwo.ca wrote: On 19/09/2009 6:51 PM, tzygmund mcfarlane wrote: Jorge, Your suggestions produce the names of the matrices and not the contents. Sorry if this was not clear in the question. You must not have entered them correctly. His answer is fine. Duncan Murdoch On Sat, Sep 19, 2009 at 11:46 PM, Jorge Ivan Velez jorgeivanve...@gmail.com wrote: Dear tzygmund, Here are two suggestions: # Suggestion 1 for (i in 1:10){ disp-paste(Table, i, sep=) print(get(disp)) } # Suggestion 2 disp - paste(Table, 1:10, sep=) sapply(disp, function(x) print( get(x) ) ) See ?print and ?get for more information. HTH, Jorge On Sat, Sep 19, 2009 at 6:40 PM, tzygmund mcfarlane wrote: Hi, I am unable to do something fairly simple. I have matrices called Table1,..., Table10. I want to be able to print them using a loop. So I wrote: ## for (i in 1:10){ disp-paste(Table, i, sep=) eval(parse(text=disp)) } ## but this produces no output. Any ideas? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Processing strings
Thanks again! On Sun, Sep 20, 2009 at 12:04 AM, Jorge Ivan Velez jorgeivanve...@gmail.com wrote: Hi tzygmund, You can avoid the print() part and the result would be pretty much the same: # Data x1 - x2- x3 - matrix( rnorm(20), ncol = 5) # Names to print Names - paste('x', 1:3, sep=) # New suggestion sapply( Names, function( y ) list( get( y ) ) ) Best, Jorge On Sat, Sep 19, 2009 at 6:51 PM, tzygmund mcfarlane wrote: Jorge, Your suggestions produce the names of the matrices and not the contents. Sorry if this was not clear in the question. On Sat, Sep 19, 2009 at 11:46 PM, Jorge Ivan Velez jorgeivanve...@gmail.com wrote: Dear tzygmund, Here are two suggestions: # Suggestion 1 for (i in 1:10){ disp-paste(Table, i, sep=) print(get(disp)) } # Suggestion 2 disp - paste(Table, 1:10, sep=) sapply(disp, function(x) print( get(x) ) ) See ?print and ?get for more information. HTH, Jorge On Sat, Sep 19, 2009 at 6:40 PM, tzygmund mcfarlane wrote: Hi, I am unable to do something fairly simple. I have matrices called Table1,..., Table10. I want to be able to print them using a loop. So I wrote: ## for (i in 1:10){ disp-paste(Table, i, sep=) eval(parse(text=disp)) } ## but this produces no output. Any ideas? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] stableFit
A quick question about stableFit() in the fBasics package. Is it possible to constrain the gamma and delta parameters and only estimate the alpha and beta parameters? I tried: ## set.seed(1953) r = rstable(n = 1000, alpha = 1.9, beta = 0.3) stableFit(r, gamma=1, delta=0, type=c(q, mle), doplot=TRUE, trace=TRUE) ## but that seems to estimate the gamma and delta as well. Thanks __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Anderson-Darling (one sample)
Hi, I would like to compute a goodness-of-fit statistic for one data series against a t-distribution, and obtain the quantiles of the distribution of the statistic with given degrees of freedom. I wonder if this is implemented in a package. I know that the critical values have to be computed for every distribution, and this requires numerical integration typically. I would prefer if I could get script or code implementing this rather than published critical values. Thanks, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R formula
You got the order of the arguments wrong: ## library(systemfit) eqDemand - consump ~ price + income eqSupply - consump ~ price + farmPrice + trend fitsur - systemfit(list(demand=eqDemand, supply=eqSupply), SUR, data=Kmenta) summary(fitsur) ## On Tue, Aug 18, 2009 at 9:48 AM, Anwesha Chakrabartic.anwe...@gmail.com wrote: Hi I was trying to estimate simultaneous equation system in R using systemfit. I used the following commands library(systemfit) data(Kmenta) attach(Kmenta) eqDemand-consump~price+income eqSupply-consump~price+farmprice+trend fitsur-systemfit(SUR,list(demand=eqDemand, supply=eqSupply)) and got the following error messege Error in systemfit(SUR, list(demand = eqDemand, supply = eqSupply)) : argument 'formula' must be an object of class 'formula' or a list of objects of class 'formula' Can anyone tell me how to overcome this problem? regards Anwesha [[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] Whittle estimation for ARMA models
Hi, Does anyone know of a package/script that will implement the Whittle (1953) estimator for the parameters of an invertible stationary ARMA time series model? The estimator is defined on, for example, pg. 378 of Brockwell Davis (1991). I assume that the internal call .whittle in this code due to Diethelm Wuertz can be used, but I am unsure how: http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/*checkout*/pkg/fArma/R/whittle.R?rev=2307root=rmetrics Thanks @article{whittle1953estimation, title={{Estimation and information in stationary time series}}, author={Whittle, P.}, journal={Arkiv f{\\o}r Matematik}, volume={2}, number={5}, pages={423--434}, year={1953}, publisher={Springer} } @book{brockwell1991time, title={{Time series: theory and methods}}, author={Brockwell, P.J. and Davis, R.A.}, year={1991}, publisher={Springer} } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Dantzig Selector
Hi, I was wondering if there was an R package or routines for the Dantzig Selector (Candes Tao, 2007). I know Emmanuel Candes has Matlab routines to do this but I was wondering if someone had ported those to R. Thanks, T ---Reference--- @article{candes2007dantzig, title={{The Dantzig selector: statistical estimation when p is much larger than n}}, author={Candes, E. and Tao, T.}, journal={Annals of Statistics}, volume={35}, number={6}, pages={2313--2351}, year={2007}, publisher={Hayward, Calif.[etc] Institute of Mathematical Statistics [etc]} } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.