Re: [R] python
On 11/21/2009 11:32 PM, Stefan Evert wrote: My hunch is that Python and R run at about the same speed, and both use C libraries for speedups (Python primarily via the numpy package). That's not necessarily true. There can be enormous differences between interpreted languages, and R appears to be a particularly slow one (which doesn't usually matter, as well-written code will mostly perform matrix operations). I did run some simple benchmarks with naive loops such as this one for (x in 1:N) { sum - sum + x } Sure, badly written R code does not perform as well as well written python code or C code. On the other hand badly written python code does not perform as well as well written R code. What happens when you try one of these : sum - sum( 1:N ) sum - sum( seq_len(N) ) sum - N * (N + 1L) / 2L # ;-) A lot can be done by just rewriting some of the R code. as well as function calls. I haven't tested Python yet, but in generally it is considered to be roughly on par with Perl. Here are results for the loop above: R/simple_count.R 0.82 Mops/s (200 ops in 2.43 s) perl/simple_count.perl 8.32 Mops/s (1000 ops in 1.20 s) (where Mops = million operations per second treats one loop iteration as a single operation here). As you can see, Perl is about 10 times as fast as R. The point is, however, that this difference may not be worth the effort you spend re-implementing your algorithms in Python or Perl and getting the Python/Perl interface for R up and running (I've just about given up on RSPerl, since I simply can't get it to install on my Mac in the way I need it). The difference between R and Perl appears much less important if you compare it to compiled C code: C/simple_count.exe 820.86 Mops/s (5 ops in 0.61 s) If you really need speed from an interpreted language, you could try Lua: lua/simple_count.lua 65.78 Mops/s (1 ops in 1.52 s) (though you're going to lose much of this advantage as soon as you include function calls, which have a lot of overhead in every interpreted language. Hope this helps, Stefan -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://tr.im/EAD5 : LondonR slides |- http://tr.im/BcPw : celebrating R commit #5 `- http://tr.im/ztCu : RGG #158:161: examples of package IDPmisc __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Define return values of a function
I have created a function to do something: i - factor(sample(c(A, B, C, NA), 793, rep=T, prob=c(8, 7, 5, 1))) k - factor(sample(c(X, Y, Z, NA), 793, rep=T, prob=c(12, 7, 9, 1))) mytable - function(x){ xtb - x btx - x # do more with x, not relevant here cat(The table has been created, see here:\n) print(xtb) list(table=xtb, elbat=btx) } tbl - table(i, k) mytable(tbl) # (1) z - mytable(tbl) # (2) str(z) # (3) (1) Wanted: outputs the string and the table properly. *Unwanted*: outputs the list elements. (2) and (3) Wanted: outputs the string properly. Wanted: assigns the list properly. How can I get rid of the *unwanted* part? That is, how do I define what the functions prints and -- on the other hand -- what it returns without printing? Thanks Sören -- Sören Vogel, Dipl.-Psych. (Univ.), PhD-Student, Eawag, Dept. SIAM http://www.eawag.ch, http://sozmod.eawag.ch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Define return values of a function
hi, Try making your last line invisible( list(table=xtb, elbat=btx) ) HTH, baptiste 2009/11/22 Soeren.Vogel soeren.vo...@eawag.ch: I have created a function to do something: i - factor(sample(c(A, B, C, NA), 793, rep=T, prob=c(8, 7, 5, 1))) k - factor(sample(c(X, Y, Z, NA), 793, rep=T, prob=c(12, 7, 9, 1))) mytable - function(x){ xtb - x btx - x # do more with x, not relevant here cat(The table has been created, see here:\n) print(xtb) list(table=xtb, elbat=btx) } tbl - table(i, k) mytable(tbl) # (1) z - mytable(tbl) # (2) str(z) # (3) (1) Wanted: outputs the string and the table properly. *Unwanted*: outputs the list elements. (2) and (3) Wanted: outputs the string properly. Wanted: assigns the list properly. How can I get rid of the *unwanted* part? That is, how do I define what the functions prints and -- on the other hand -- what it returns without printing? Thanks Sören -- Sören Vogel, Dipl.-Psych. (Univ.), PhD-Student, Eawag, Dept. SIAM http://www.eawag.ch, http://sozmod.eawag.ch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] python
Sure, badly written R code does not perform as well as well written python code or C code. On the other hand badly written python code does not perform as well as well written R code. What happens when you try one of these : sum - sum( 1:N ) R runs out of memory and crashes. :-) I didn't tell you how big N is, did I? But this is exactly the point I was trying to make (but perhaps not prominently enough). In many cases, you can vectorize at least parts of your code or find a more efficient algorithm, which may be faster in R than a brute-force solution in C. But sometimes, you just cannot avoid loops (let's not forget that all the forms of apply() are just loops and don't give much of a speed benefit over a for-loop), function calls, etc.; in this case, performance differences between interpreted languages can matter. Personally, I'd never switch from R to Perl just for speed, though. BTW, I also tried a vectorised algorithm in R, which calculates the sum above in a small number of chunks: N1 - 50 N2 - 100 N - N1 * N2 sum - 0 for (i in 1:N1) { x - as.numeric(i-1) * N2 + 1:N2 sum - sum + sum(x) } which gives R/simple_count_vec.R 31.30 Mops/s (5000 ops in 1.60 s) So an interpreted loop in Lua is still faster than this partially vectorized code in R: lua/simple_count.lua 65.78 Mops/s (1 ops in 1.52 s) As people on the SQLite mailing list always say: there's no general answer as to which language/implementation/query/... is faster and better. You just have to test the different options for your specific application setting, and be prepared for one or two surprises. Just in case this isn't obvious: If I rewrote matrix multiplication in C and linked this code into R, it would run much slower than if I just typed A %*% B. All the best, Stefan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] other decriptive stats packages
On Sat, Nov 21, 2009 at 02:01:07PM -0800, frenchcr wrote: i just found the following list, i wondered if anybody could add to this as i have to characterize a large data set and am new to R...the list below was so helpfulcan you add to this??? Just to forestall confusion amongst those who would like to use one of the functions called describe... Hmisc package - describe [...] psych package - describe [...] prettyR package - describe [...] the above are the defaults - the user can specify the name(s) of any function(s) as an argument to the function to customize the display. [...] are there any more packages that help decribe and explore data sets I maintain the package descr, which has the following descriptive functions (in addition to a few others): freq : frequency table crosstab : cross tabulation compmeans : means comparison The three functions accept weights among their arguments. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] python
Thank you Gabor, Romain and Stefan. Gabor this looks like really interesting for speeding up loops. I just have to install it and add jit(1) before a loop ! Is the result faster than Python ? I have seen the name of L. Tierney among the contributors. I guess it is good for MCMC :-) Best, Jean 2009/11/22 Stefan Evert stefan.ev...@uos.de Sure, badly written R code does not perform as well as well written python code or C code. On the other hand badly written python code does not perform as well as well written R code. What happens when you try one of these : sum - sum( 1:N ) R runs out of memory and crashes. :-) I didn't tell you how big N is, did I? But this is exactly the point I was trying to make (but perhaps not prominently enough). In many cases, you can vectorize at least parts of your code or find a more efficient algorithm, which may be faster in R than a brute-force solution in C. But sometimes, you just cannot avoid loops (let's not forget that all the forms of apply() are just loops and don't give much of a speed benefit over a for-loop), function calls, etc.; in this case, performance differences between interpreted languages can matter. Personally, I'd never switch from R to Perl just for speed, though. BTW, I also tried a vectorised algorithm in R, which calculates the sum above in a small number of chunks: N1 - 50 N2 - 100 N - N1 * N2 sum - 0 for (i in 1:N1) { x - as.numeric(i-1) * N2 + 1:N2 sum - sum + sum(x) } which gives R/simple_count_vec.R 31.30 Mops/s (5000 ops in 1.60 s) So an interpreted loop in Lua is still faster than this partially vectorized code in R: lua/simple_count.lua 65.78 Mops/s (1 ops in 1.52 s) As people on the SQLite mailing list always say: there's no general answer as to which language/implementation/query/... is faster and better. You just have to test the different options for your specific application setting, and be prepared for one or two surprises. Just in case this isn't obvious: If I rewrote matrix multiplication in C and linked this code into R, it would run much slower than if I just typed A %*% B. All the best, Stefan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Over-coloring facets on persp() plot
On 22/11/2009 1:07 AM, Marc Chiarini (Tufts) wrote: Dear R Community: Recently, I have managed to plot some really useful graphs of my research data using persp(). I have even figured out how to overplot rectangular regions (corresponding to submatrices) with a different color. This is accomplished by using par(new=T). I am now searching for a way to highlight a set of (possibly non-contiguous) facets with a specific color, e.g., the facet between each set of four points whose values are all above a certain threshold. An example would be coloring the raised corners of the classic sombrero (found in example(persp)) differently from the rest of the sombrero. I feel like the last example in persp() is pointing me in the right direction, but I'm not quite getting it. Any help is much appreciated. Think of the facets as an nx-1 by ny-1 matrix. Pass the col arg by creating a matrix of this shape. (A vector version of the data in the matrix would also be good enough.) If you pass something shorter, it will be recycled to that length. You could also use persp3d from the rgl package, but an important difference is that it colours all nx by ny vertices, and interpolates colours on the facets. So you can't use the same colour matrix as in persp. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] other decriptive stats packages
Here is one more function for the list: whatis from the package: YaleToolkit See: http://cran.r-project.org/web/packages/YaleToolkit/ I also like using: ls() ls.str() And sometimes (for just one variable): stem (which can be viewd as an ascii histogram) Wonderful question and list, I hope for more answers. 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) -- On Sun, Nov 22, 2009 at 12:01 AM, frenchcr frenc...@btinternet.com wrote: i just found the following list, i wondered if anybody could add to this as i have to characterize a large data set and am new to R...the list below was so helpfulcan you add to this??? Just to forestall confusion amongst those who would like to use one of the functions called describe... Hmisc package - describe numeric name count of observations count of missing values count of unique values mean seven quantiles five lowest and highest values discrete (factor or numeric with = 10 unique values) - as for numeric, but no mean, quantiles or low/high values and including a frequency/percent display for each value. psych package - describe item name item number number of valid cases mean standard deviation median mad: median absolute deviation (from the median) minimum maximum skew (optional) kurtosis (optional) standard error prettyR package - describe numeric name mean median var sd valid.n the above are the defaults - the user can specify the name(s) of any function(s) as an argument to the function to customize the display. factor name count for each value percent for each value modal value count of missing values logical name count of FALSE count of TRUE percent of TRUE count of missing values are there any more packages that help decribe and explore data sets -- View this message in context: http://old.nabble.com/other-decriptive-stats-packages-tp26460757p26460757.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] other decriptive stats packages
A few more came to mind: VIM package (for exploring missing data): http://cran.r-project.org/web/packages/VIM/index.html http://bm2.genes.nig.ac.jp/RGM2/index.php?scope=namequery=VIM And the basic commands: * edit (for seeing the dataframe as in a spreadsheet) And the commands: * head (and) tail 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) -- On Sun, Nov 22, 2009 at 3:15 PM, Tal Galili tal.gal...@gmail.com wrote: Here is one more function for the list: whatis from the package: YaleToolkit See: http://cran.r-project.org/web/packages/YaleToolkit/ I also like using: ls() ls.str() And sometimes (for just one variable): stem (which can be viewd as an ascii histogram) Wonderful question and list, I hope for more answers. 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) -- On Sun, Nov 22, 2009 at 12:01 AM, frenchcr frenc...@btinternet.comwrote: i just found the following list, i wondered if anybody could add to this as i have to characterize a large data set and am new to R...the list below was so helpfulcan you add to this??? Just to forestall confusion amongst those who would like to use one of the functions called describe... Hmisc package - describe numeric name count of observations count of missing values count of unique values mean seven quantiles five lowest and highest values discrete (factor or numeric with = 10 unique values) - as for numeric, but no mean, quantiles or low/high values and including a frequency/percent display for each value. psych package - describe item name item number number of valid cases mean standard deviation median mad: median absolute deviation (from the median) minimum maximum skew (optional) kurtosis (optional) standard error prettyR package - describe numeric name mean median var sd valid.n the above are the defaults - the user can specify the name(s) of any function(s) as an argument to the function to customize the display. factor name count for each value percent for each value modal value count of missing values logical name count of FALSE count of TRUE percent of TRUE count of missing values are there any more packages that help decribe and explore data sets -- View this message in context: http://old.nabble.com/other-decriptive-stats-packages-tp26460757p26460757.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Define return values of a function
On Nov 22, 2009, at 6:26 AM, soeren.vo...@eawag.ch wrote: I have created a function to do something: i - factor(sample(c(A, B, C, NA), 793, rep=T, prob=c(8, 7, 5, 1))) k - factor(sample(c(X, Y, Z, NA), 793, rep=T, prob=c(12, 7, 9, 1))) mytable - function(x){ xtb - x btx - x # do more with x, not relevant here cat(The table has been created, see here:\n) print(xtb) list(table=xtb, elbat=btx) } tbl - table(i, k) mytable(tbl) # (1) z - mytable(tbl) # (2) str(z) # (3) (1) Wanted: outputs the string and the table properly. *Unwanted*: outputs the list elements. Whet the author of a function wants a particular object that exists insode a function to be returned they may warp it in the function return(). Otherwise R returns the result of the last evaluation which in this case was list(table=xtb, elbat=btx). If you want the function to return something else. then you could put something else last in the sequence. If you want it to return nothing than put this at the end: return() If you want the results to not be printed the use invisible() Perhaps: invisible(list( elbat=btx)) #substituted for list(table=xtb, elbat=btx) after the print line tbl - table(i, k) mytable(tbl) # (1) The table has been created, see here: k i X Y Z A 119 69 89 B 116 70 97 C 80 36 52 z - mytable(tbl) # (2) The table has been created, see here: k i X Y Z A 119 69 89 B 116 70 97 C 80 36 52 str(z) # (3) List of 1 $ elbat: 'table' int [1:3, 1:3] 119 116 80 69 70 36 89 97 52 ..- attr(*, dimnames)=List of 2 .. ..$ i: chr [1:3] A B C .. ..$ k: chr [1:3] X Y Z (2) and (3) Wanted: outputs the string properly. Wanted: assigns the list properly. If you want to return the list, elbat, then just put the name of the list last in your case inside invisible or put it inside return(). How can I get rid of the *unwanted* part? That is, how do I define what the functions prints That set by cat and print in your case. and -- on the other hand -- what it returns without printing? By return() or the order of evaluation -- 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] other decriptive stats packages
On 11/21/09, frenchcr frenc...@btinternet.com wrote: are there any more packages that help decribe and explore data sets See numSummary() in Rcmdr. Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Over-coloring facets on persp() plot
On Nov 22, 2009, at 7:07 AM, Duncan Murdoch wrote: On 22/11/2009 1:07 AM, Marc Chiarini (Tufts) wrote: Dear R Community: Recently, I have managed to plot some really useful graphs of my research data using persp(). I have even figured out how to overplot rectangular regions (corresponding to submatrices) with a different color. This is accomplished by using par(new=T). I am now searching for a way to highlight a set of (possibly non- contiguous) facets with a specific color, e.g., the facet between each set of four points whose values are all above a certain threshold. An example would be coloring the raised corners of the classic sombrero (found in example(persp)) differently from the rest of the sombrero. I feel like the last example in persp() is pointing me in the right direction, but I'm not quite getting it. Any help is much appreciated. Think of the facets as an nx-1 by ny-1 matrix. Pass the col arg by creating a matrix of this shape. (A vector version of the data in the matrix would also be good enough.) I came close to coloring the top facet, but did not quite get there with: x - seq(-10, 10, length= 30) y - x f - function(x,y) { r - sqrt(x^2+y^2); 10 * sin(r)/r } z - outer(x, y, f) z[is.na(z)] - 1 op - par(bg = white) zcol - as.vector( z[-1,-1] == max(z) ) # Need to exclude two sides, I think persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = ifelse(zcol , red, lightblue), ltheta = 120, shade = 0.75, ticktype = detailed, xlab = X, ylab = Y, zlab = Sinc( r ) ) par(op) I did not get precisely the top facet in part, because there are 4 z elements at the max. -- David. If you pass something shorter, it will be recycled to that length. You could also use persp3d from the rgl package, but an important difference is that it colours all nx by ny vertices, and interpolates colours on the facets. So you can't use the same colour matrix as in persp. 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. 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] Over-coloring facets on persp() plot
On Nov 22, 2009, at 9:18 AM, David Winsemius wrote: On Nov 22, 2009, at 7:07 AM, Duncan Murdoch wrote: On 22/11/2009 1:07 AM, Marc Chiarini (Tufts) wrote: Dear R Community: Recently, I have managed to plot some really useful graphs of my research data using persp(). I have even figured out how to overplot rectangular regions (corresponding to submatrices) with a different color. This is accomplished by using par(new=T). I am now searching for a way to highlight a set of (possibly non- contiguous) facets with a specific color, e.g., the facet between each set of four points whose values are all above a certain threshold. An example would be coloring the raised corners of the classic sombrero (found in example(persp)) differently from the rest of the sombrero. I feel like the last example in persp() is pointing me in the right direction, but I'm not quite getting it. Any help is much appreciated. Think of the facets as an nx-1 by ny-1 matrix. Pass the col arg by creating a matrix of this shape. (A vector version of the data in the matrix would also be good enough.) I came close to coloring the top facet, but did not quite get there with: x - seq(-10, 10, length= 30) y - x f - function(x,y) { r - sqrt(x^2+y^2); 10 * sin(r)/r } z - outer(x, y, f) z[is.na(z)] - 1 op - par(bg = white) zcol - as.vector( z[-1,-1] == max(z) ) # Need to exclude two side edges, I think persp(x, y, z, theta = 30, phi = 30, expand = 0.5, col = ifelse(zcol , red, lightblue), ltheta = 120, shade = 0.75, ticktype = detailed, xlab = X, ylab = Y, zlab = Sinc( r ) ) par(op) I did not get precisely the top facet in part, because there are 4 z elements at the max. Specifying row and column == 15 for z[-1,-1] does color just the top facet. Conditional level coloring can be achieved as above with suitable limits on the z values: zcol - as.vector( z[-1,-1] 1 z[-1,-1] 3 ) -- David. If you pass something shorter, it will be recycled to that length. You could also use persp3d from the rgl package, but an important difference is that it colours all nx by ny vertices, and interpolates colours on the facets. So you can't use the same colour matrix as in persp. 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. 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. 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.
[R] How to make a matrix of a number of factors?
I use the following code to generate a matrix of factors. I'm wondering if there is a way to make it more general so that I can have any number of factors (not necessarily 5). a=3 b=4 c=5 d=6 e=7 A=1:a B=1:b C=1:c D=1:d E=1:e X=matrix(nr=a*b*c*d*e,nc=5) for(i_a in 1:a-1) { for(i_b in 1:b-1) { for(i_c in 1:c-1) { for(i_d in 1:d-1) { for(i_e in 1:e-1) { X[(((i_a * b + i_b) * c + i_c) * d + i_d) * e + i_e + 1, ] = c(i_a+1, i_b+1, i_c+1, i_d+1, i_e+1) } } } } } print(X) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Repeated measures unbalanced in a split-split design
Hi, I have a experiment with block, plots, sub-plots, and sub-sub-plots with repeated measures and 3 factors (factorial design) when we have been observed diameter (mm), high (cm) and leaves number (count). However, we don't have one treatment in one factor, so, my design is unbalanced. On a previous message here, a friend tell me that It appears to me that your design is a split-split plot with repeated measures at the split-split plot level. Because you have multiple sizes of experimental unit (blocks, plots and sub-plots), you have a different random error term at each size of unit, so you have to analyze it as a mixed-effects model. For the diameter and height measurements, you can probably get away with using normal errors, but for the counts, you may well have to use a generalized linear mixed model. So, I am trying to analyze my data with car package. I have: time (days after germination) - 4 levels (38, 53, 73, 85) Hormone - 2 levels (SH, CH) on sub-plots Block - 4 blocks Treatment - 6 levels (1, 2, 3, 4, 5, and 6) on sub-sub-plots Plant - subjects I measured Diameter (mm), Height (cm), HD (height/diameter), and Number of Leaves (count) at each time point. But, plant can be died and I got NAs. However, Treatment 6 (control) is only present on SH sub-plots. It isn't present on CH sub-plots. I try this model: idata.Cana - data.frame(Time=factor(c(38,53,73,85))) idata.Cana mod.Cana - lm(cbind(Diameter.38, Diameter.53, Diameter.73, Diameter.85) ~ Treatment*Hormone, data=marcelo.subset) mod.Cana Call: lm(formula = cbind(Diameter.38, Diameter.53, Diameter.73, Diameter.85) ~ Treatment * Hormone, data = marcelo.subset) Coefficients: Diameter.38 Diameter.53 Diameter.73 Diameter.85 (Intercept)1.24000 1.35750 1.99375 2.31000 Treatment2-0.31625 -0.14250 0.07500 -0.13875 Treatment3-0.19250 -0.01500 -0.20875 -0.36875 Treatment4-0.35375 -0.08500 -0.22750 -0.27125 Treatment5-0.29125 0.04875 -0.14375 -0.26375 Treatment6-0.00125 -0.25750 -0.81125 -0.77750 HormoneSH -0.30875 -0.08875 0.31500 0.07000 Treatment2:HormoneSH 0.19875 0.11250 -0.44500 -0.24875 Treatment3:HormoneSH 0.15375 0.01875 -0.12125 0.07000 Treatment4:HormoneSH 0.28000 -0.04250 -0.41750 -0.38750 Treatment5:HormoneSH 0.40875 -0.11125 -0.17750 -0.05125 Treatment6:HormoneSHNA NA NA NA av.Cana - Anova(mod.Cana, idata=idata.Cana, idesign= ~ as.factor(Idade)) Erro em solve.default(crossprod(model.matrix(mod))) : rotina Lapack dgesv: sistema é exatamente singular How I model my data to analyze it with this unbalanced design? How I could use the block factor on model? Or it is not necessary? And sub-plots? Please, here you could find my design http://www.divshare.com/download/9431636-e0c and here you could find a subset of my data http://www.divshare.com/download/9456640-fd7 Thank you very much! -- Marcelo Luiz de Laia Universidade do Estado de Santa Catarina UDESC - www.cav.udesc.br Lages - SC - Brazil Linux user number 487797 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] MASS loading error
Erin Hodgess wrote: Dear R People: I just installed R-2.10.0 on Karmic Koala Ubuntu, via the sudo apt-get install r-base, etc. However, when I try to install an Rcmdr Plugin package, I get the following: install.packages(RcmdrPlugin.qual,depen=TRUE) Warning in install.packages(RcmdrPlugin.qual, depen = TRUE) : argument 'lib' is missing: using '/usr/local/lib/R/site-library' Warning in install.packages(RcmdrPlugin.qual, depen = TRUE) : 'lib = /usr/local/lib/R/site-library' is not writable Would you like to create a personal library '~/R/i486-pc-linux-gnu-library/2.10' to install packages into? (y/n) y --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done also installing the dependency ‘qcc’ trying URL 'http://cran.opensourceresources.org/src/contrib/qcc_2.0.tar.gz' Content type 'application/x-gzip' length 163556 bytes (159 Kb) opened URL == downloaded 159 Kb trying URL 'http://cran.opensourceresources.org/src/contrib/RcmdrPlugin.qual_0.4.0.tar.gz' Content type 'application/x-gzip' length 3545 bytes opened URL == downloaded 3545 bytes * installing *source* package ‘qcc’ ... ** R ** data ** demo ** inst ** preparing package for lazy loading ** help *** installing help indices ** building package indices ... * DONE (qcc) * installing *source* package ‘RcmdrPlugin.qual’ ... ** R ** inst ** preparing package for lazy loading Warning: package 'Rcmdr' was built under R version 2.8.1 and help may not work correctly Loading required package: tcltk Loading Tcl/Tk interface ... done The Commander GUI is launched only in interactive sessions Attaching package: 'Rcmdr' The following object(s) are masked from package:tcltk : tclvalue Warning: package 'rgl' was built under R version 2.8.1 and help may not work correctly Warning: package 'abind' was built under R version 2.8.1 and help may not work correctly Error : This is R 2.10.0, package 'MASS' needs = 2.9.2 ERROR: lazy loading failed for package ‘RcmdrPlugin.qual’ * removing ‘/home/erin/R/i486-pc-linux-gnu-library/2.10/RcmdrPlugin.qual’ The downloaded packages are in ‘/tmp/RtmpioC2DR/downloaded_packages’ Warning message: In install.packages(RcmdrPlugin.qual, depen = TRUE) : installation of package 'RcmdrPlugin.qual' had non-zero exit status The line that looks particularly strange is the 'MASS needs = 2.9.2. Erin, the MASS you have installed in one of your current libraries needs R = 2.9.2 (perhaps in /usr/local/lib/R/site-library ?) Please run update.packages(checkBuilt=TRUE) and packages in your library will be updated. If the one in /usr/local/lib/R/site-library can't be updated, because you do not have write permissions there, please remove it from the library path. Best, Uwe Ligges Could that be the problem, please? Thank you in advance for any help. Sincerely, Erin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to make the assignment in a for-loop not affect variables outside the loop?
I know that R is a dynamic programming language. But I'm wondering if there is a way to make the assignment in a for-loop not affect variables outside the loop. n=10 for(i in 1:n){ + n=3 + print(n) + } [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 print(n) [1] 3 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to make a matrix of a number of factors?
Hi, Try this, do.call(expand.grid, lapply(7:3, seq, from=1)) HTH, baptiste 2009/11/22 Peng Yu pengyu...@gmail.com: I use the following code to generate a matrix of factors. I'm wondering if there is a way to make it more general so that I can have any number of factors (not necessarily 5). a=3 b=4 c=5 d=6 e=7 A=1:a B=1:b C=1:c D=1:d E=1:e X=matrix(nr=a*b*c*d*e,nc=5) for(i_a in 1:a-1) { for(i_b in 1:b-1) { for(i_c in 1:c-1) { for(i_d in 1:d-1) { for(i_e in 1:e-1) { X[(((i_a * b + i_b) * c + i_c) * d + i_d) * e + i_e + 1, ] = c(i_a+1, i_b+1, i_c+1, i_d+1, i_e+1) } } } } } print(X) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Metaplot Axis Annotation
Ishwar Bridgelal wrote: Hello, We are looking to adjust the font size of the axis annotation on the graph that results from use of the metaplot() function. Metaplot seems to respond to cex and cex.lab to change those graphical parameters, but it doesn't respond to cex.axis. Is there a way to work around this by creating a customized x-axis, and if so, how? Set the axis' character expansion for the whole device using par() as in: par(cex.axis=2) metaplot() And for you next post: Please provide reproducible code and tell us which package you are talking about (here rmeta, I guess). Best, Uwe Ligges Thanks for all your help. Syntax is below. Best, Dawn McDaniel Ishwar Bridgelal University of Southern California local({pkg - select.list(sort(.packages(all.available = TRUE))) + if(nchar(pkg)) library(pkg, character.only=TRUE)}) Loading required package: grid m1=matrix(scan(file=C:/Users/Roymohan/Desktop/meta.txt), ncol=4, byrow=TRUE) Read 208 items oddsratio=m1[,2] seinor=m1[,3] inw=m1[,4] c1=c(Cross-Drew (1974), Ahlstrom Havighurst (1982), Litton Marye (1981), Gold Mattick (1974), Willman Snortum (1982), Leiber Mawhorr (1995), Hackler Hagan (1974), Sadd, Kotkin, Freidman (1983), New York State Division for Youth (1972), Spergel (2005), Bloom et al. (1997), Quigley et al. (1999), Thambidurai (1980, Schochet et al. (2001), Gruenewald, Laurence, West (1985), Cave et al. (1993), Elliot Knowles (1976), Elliot Knowles (1976), Porter (1967), Kawaguchi (1975), Minnesota Governor’s Commission (1973), Youth Opportunities Upheld (1978), Maynard (1980), Baker Sadd (1979), Goldberg Johnson (1972),Roth (1983),Seckel Turner (1967),Zimring (1973),Randall (1973),Anderson Schumacker (1986),Lattimore, Witte, Baker (1990),Weisz, Walter, Weiss (1990),Greenwood Turner (1993),Johnson Goldberg (1982), Kovacs (1967),Auerbach (1978),Guthmann (1981),Sullivan Mandall (1967),Blew, McGillis, Bryant (1970) + , Custer (1981), Goldberg (1978), Bowker (1977), Zivan (1966), Massimo Shore (1966), Killinger (1974), Morris (1970), Bernardo (1973), Mann Pratt (1978), Goodwill Industries Vocational Service (1971), Springfield Massachusetts Goodwill Industries, Inc. (1966), Walter Mills (1980), Odell (1974)) metaplot(mn=oddsratio, se=seinor, labels=c1, cex=.65, lwd=2, cex.lab=.65) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to make the assignment in a for-loop not affect variables outside the loop?
Either use local as in: n=10 local(for(i in 1:n){ n=3 print(n) }) print(n) or write a function that is evaluated in its own environment: n=10 MyLoopFoo - function(){ for(i in 1:n){ n - 3 print(n) } } MyLoopFoo() print(n) Uwe Ligges Peng Yu wrote: I know that R is a dynamic programming language. But I'm wondering if there is a way to make the assignment in a for-loop not affect variables outside the loop. n=10 for(i in 1:n){ + n=3 + print(n) + } [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 [1] 3 print(n) [1] 3 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Why F value and Pr are not show in summary() of an aov() result?
I have the following code. I'm wondering why summary() doesn't show F value and Pr? Rscript multi_factor.R a=3 b=4 c=5 d=6 e=7 A=1:a B=1:b C=1:c D=1:d E=1:e X=matrix(nr=a*b*c*d*e,nc=5) colnames(X)=LETTERS[1:5] for(i_a in 1:a-1) { + for(i_b in 1:b-1) { + for(i_c in 1:c-1) { + for(i_d in 1:d-1) { + for(i_e in 1:e-1) { + X[(((i_a * b + i_b) * c + i_c) * d + i_d) * e + i_e + 1, ] = c(i_a+1, i_b+1, i_c+1, i_d+1, i_e+1) + } + } + } + } + } Y=matrix(nr=a*b*c*d*e,nc=1) for(i in 1:(a*b*c*d*e)) { + fa=X[i,'A'] + fb=X[i,'B'] + fc=X[i,'C'] + fd=X[i,'D'] + fe=X[i,'E'] + + Y[i,1]= fa +fb +fc +fe +fa*fb +fa*fc +fb*fc +fa*fe +fc*fe +fa*fb*fc +fa*fc*fe + rnorm(1) + } aframe = data.frame( + A=as.factor(X[,'A']) + , B=as.factor(X[,'B']) + , C=as.factor(X[,'C']) + , D=as.factor(X[,'D']) + , E=as.factor(X[,'E']) + ,Y) afit=aov(Y ~ A * B * C * D * E, aframe) summary(afit) Df Sum Sq Mean Sq A 2 1512240 756120 B 3 453324 151108 C 4 2549895 637474 D 5 2 0.3693 E 6 1451057 241843 A:B 6 338755646 A:C 8 189839 23730 B:C 12 560244669 A:D 10 7 1 B:D 15 25 2 C:D 20 18 1 A:E 12 1075748964 B:E 18 21 1 C:E 24 1804137517 D:E 30 16 1 A:B:C244167 174 A:B:D30 37 1 A:C:D40 42 1 B:C:D60 63 1 A:B:E36 30 1 A:C:E48 13298 277 B:C:E72 62 1 A:D:E60 79 1 B:D:E90 87 1 C:D:E 120 122 1 A:B:C:D 120 140 1 A:B:C:E 144 131 1 A:B:D:E 180 145 1 A:C:D:E 240 225 1 B:C:D:E 360 398 1 A:B:C:D:E 720 713 1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to tell if its better to standardize your data matrix first when you do principal
masterinex wrote: Hi guys , Im trying to do principal component analysis in R . There is 2 ways of doing it , I believe. One is doing principal component analysis right away the other way is standardizing the matrix first using s = scale(m)and then apply principal component analysis. How do I tell what result is better ? What values in particular should i look at . I already managed to find the eigenvalues and eigenvectors , the proportion of variance for each eigenvector using both methods. Generally, it is better to standardize. But in some cases, e.g. for the same units in your variables indicating also the importance, it might make sense not to do so. You should think about the analysis, you cannot know which result is `better' unless you know an interpretation. I noticed that the proportion of the variance for the first pca without standardizing had a larger value . Is there a meaning to it ? Isnt this always the case? At last , if I am supposed to predict a variable ie weight should I drop the variable ie weight from my data matrix when I do principal component analysis ? This sounds a bit like homework. If that is the case, please ask your teacher rather than this list. Anyway, it does not make sense to predict weight using a linear combination (principle component) that contains weight, does it? Uwe Ligges __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how do i persuade IT to install R on PCs ?? ...and should I ??
Please help me persuade IT to install R on my computer! All suggestions welcome. Our IT department run scared when you mention software that they have no working experience of. I need to know the pros and cons of having R on corporate desktops. Please no funny stuff, this is quite a serious issue for us. Pros and cons would be good. Thanks. -- View this message in context: http://old.nabble.com/how-do-i-persuade-IT-to-install-R-on-PCs...and-should-Itp26464163p26464163.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] Computing multivariate normal probabilities. Was: Re: Problem with Numerical derivatives (numDeriv) and mvtnorm
Hi Torsten, It would be useful to warn the users that the multivariate normal probability calculated by pmvnorm using the GenzBretz algorithm is random, i.e. the result can vary between repeated executions of the function. This would prevent inappropriate use of pmvnorm such as computing derivatives of it (see this email thread). It seems that the other algorithm Miwa is deterministic, but not sure how reliable it is (I had some trouble with it). It would also be useful in the help page to provide a link to two other functions for evaluating multivariate normal probabilities: mnormt::sadmvn mprobit::mvnapp In particular, the `mvnapp' function of Harry Joe in mprobit package seems to be very interesting as it provides very accurate results using asymptotic expansions. Best, 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: Ravi Varadhan rvarad...@jhmi.edu Date: Saturday, November 21, 2009 8:15 pm Subject: Re: [R] Problem with Numerical derivatives (numDeriv) and mvtnorm To: SL sl...@yahoo.fr Cc: r-help@r-project.org Go back to your calculus text and review the definition of derivative: f'(x) = lim h - 0 [f(x+h) - f(x)] / h when f(x) and f(x + h) are random variables, the above limit does not exist. In fact, f'(x) is also a random variable. Now, if you want the derivative you have to use a multivariate integration algorithm that yields a deterministic value. The function `sadmvn' in the package mnormt can do this: require(mnormt) PP2 - function(p){ thetac - p thetae - 0.323340333 thetab - -0.280970036 thetao - 0.770768082 ssigma - diag(4) ssigma[1,2] - 0.229502120 ssigma[1,3] - 0.677949335 ssigma[1,4] - 0.552907745 ssigma[2,3] - 0.784263100 ssigma[2,4] - 0.374065025 ssigma[3,4] - 0.799238700 ssigma[2,1] - ssigma[1,2] ssigma[3,1] - ssigma[1,3] ssigma[4,1] - ssigma[1,4] ssigma[3,2] - ssigma[2,3] ssigma[4,2] - ssigma[2,4] ssigma[4,3] - ssigma[3,4] pp - sadmvn(lower=rep(-Inf, 4), upper=c(thetac,thetae,thetab,thetao), mean=rep(0,4), varcov=ssigma, maxpt=10) return(pp) } xx - -0.6675762 P2(xx) require(numDeriv) grad(x=xx, func=PP2) I hope this helps, 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: SL sl...@yahoo.fr Date: Saturday, November 21, 2009 2:42 pm Subject: Re: [R] Problem with Numerical derivatives (numDeriv) and mvtnorm To: r-help@r-project.org Thanks for you comment. There is certainly some Monte Carlo sampling involved in mvtnorm but why derivatives could not be computed? In theory, the derivatives exist (eg. bivariate probit). Moreover, when used with optim, there are some numerical derivatives computed... does it mean that mvtnorm cannot be used in an optimisation problem? I think it hard to believe. One possibility would be to use the analytical derivatives and then a do-it-yourself integration but i was looking for something a bit more comprehensive. The mvtnorm package uses a specific way to compute pmvnorm and I'm far to do a good enough job so that derivatives can compare with what mvtnorm can do. Stef __ R-help@r-project.org mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list PLEASE do read the posting guide 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] consecutive numbering of elements in a matrix
Many thanks to Dimitris, William and David for very helpful answers which solved my problem. Being a relatve newb, I am confused by something in the solutions by Dimitris and David. #Create a matrix A as follows: A - matrix(sample(50, 21), 7, 3) A[sample(21, 5)] - NA;A [,1] [,2] [,3] [1,] 36 38 24 [2,]6 33 13 [3,] 12 42 10 [4,]7 NA NA [5,] 48 NA NA [6,]3 NA 47 [7,] 29 234 B = row(A) - apply(is.na(A), 2, cumsum);B [,1] [,2] [,3] [1,]111 [2,]222 [3,]333 [4,]433 [5,]533 [6,]634 [7,]745 #But: B = row(A) - apply(!is.na(A), 2, cumsum);B [,1] [,2] [,3] [1,]000 [2,]000 [3,]000 [4,]011 [5,]022 [6,]032 [7,]032 This seems exactly backwards to me. The is.na(A) command should be cumulatively summing the NA values and !is.na(A) should be doing so on the non-NA values. But the opposite is the case. I'm glad I have a solution but this apparent backwardness of expected logic has me worried. I do have another, tougher question if anyone has the time, which is, given a resulting matrix like B below: is.na(B) - is.na(A);B [,1] [,2] [,3] [1,]111 [2,]222 [3,]333 [4,]4 NA NA [5,]5 NA NA [6,]6 NA4 [7,]745 how can I rearrange all the columns so that equal values are in the same row, i.e. in the case above, the NA values are removed from columns 2 and 3 and all non-NA values that had been below them are moved up to replace them. Thanks again for your help. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Why F value and Pr are not show in summary() of an aov() result?
It's hard to read your code, so I won't comment on your specific example. So when all else fails read the documentation for ?summary.aov: They have columns ‘Df’, ‘Sum Sq’, ‘Mean Sq’, as well as ‘F value’ and ‘Pr(F)’ if there are non-zero residual degrees of freedom. So if you do df.residual(afit), is it 0? --sundar On Sun, Nov 22, 2009 at 7:19 AM, Peng Yu pengyu...@gmail.com wrote: I have the following code. I'm wondering why summary() doesn't show F value and Pr? Rscript multi_factor.R a=3 b=4 c=5 d=6 e=7 A=1:a B=1:b C=1:c D=1:d E=1:e X=matrix(nr=a*b*c*d*e,nc=5) colnames(X)=LETTERS[1:5] for(i_a in 1:a-1) { + for(i_b in 1:b-1) { + for(i_c in 1:c-1) { + for(i_d in 1:d-1) { + for(i_e in 1:e-1) { + X[(((i_a * b + i_b) * c + i_c) * d + i_d) * e + i_e + 1, ] = c(i_a+1, i_b+1, i_c+1, i_d+1, i_e+1) + } + } + } + } + } Y=matrix(nr=a*b*c*d*e,nc=1) for(i in 1:(a*b*c*d*e)) { + fa=X[i,'A'] + fb=X[i,'B'] + fc=X[i,'C'] + fd=X[i,'D'] + fe=X[i,'E'] + + Y[i,1]= fa +fb +fc +fe +fa*fb +fa*fc +fb*fc +fa*fe +fc*fe +fa*fb*fc +fa*fc*fe + rnorm(1) + } aframe = data.frame( + A=as.factor(X[,'A']) + , B=as.factor(X[,'B']) + , C=as.factor(X[,'C']) + , D=as.factor(X[,'D']) + , E=as.factor(X[,'E']) + ,Y) afit=aov(Y ~ A * B * C * D * E, aframe) summary(afit) Df Sum Sq Mean Sq A 2 1512240 756120 B 3 453324 151108 C 4 2549895 637474 D 5 2 0.3693 E 6 1451057 241843 A:B 6 33875 5646 A:C 8 189839 23730 B:C 12 56024 4669 A:D 10 7 1 B:D 15 25 2 C:D 20 18 1 A:E 12 107574 8964 B:E 18 21 1 C:E 24 180413 7517 D:E 30 16 1 A:B:C 24 4167 174 A:B:D 30 37 1 A:C:D 40 42 1 B:C:D 60 63 1 A:B:E 36 30 1 A:C:E 48 13298 277 B:C:E 72 62 1 A:D:E 60 79 1 B:D:E 90 87 1 C:D:E 120 122 1 A:B:C:D 120 140 1 A:B:C:E 144 131 1 A:B:D:E 180 145 1 A:C:D:E 240 225 1 B:C:D:E 360 398 1 A:B:C:D:E 720 713 1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] scatter plot equation
Hi, If I have 2D data set say (x,y) and I can do scatter plot by using plot(x,y) command. How can I add in this scatter plot the equations curve say 2X2 + 3Y2 6X 7Y + 9 = 0. Regards Rofizah [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] python
Stefan Evert wrote: Sure, badly written R code does not perform as well as well written python code or C code. On the other hand badly written python code does not perform as well as well written R code. What happens when you try one of these : sum - sum( 1:N ) R runs out of memory and crashes. :-) I didn't tell you how big N is, did I? Really? N - 1e30 sum( 1:N ) Error in 1:N : result would be too long a vector -Peter Ehlers But this is exactly the point I was trying to make (but perhaps not prominently enough). In many cases, you can vectorize at least parts of your code or find a more efficient algorithm, which may be faster in R than a brute-force solution in C. But sometimes, you just cannot avoid loops (let's not forget that all the forms of apply() are just loops and don't give much of a speed benefit over a for-loop), function calls, etc.; in this case, performance differences between interpreted languages can matter. Personally, I'd never switch from R to Perl just for speed, though. BTW, I also tried a vectorised algorithm in R, which calculates the sum above in a small number of chunks: N1 - 50 N2 - 100 N - N1 * N2 sum - 0 for (i in 1:N1) { x - as.numeric(i-1) * N2 + 1:N2 sum - sum + sum(x) } which gives R/simple_count_vec.R 31.30 Mops/s (5000 ops in 1.60 s) So an interpreted loop in Lua is still faster than this partially vectorized code in R: lua/simple_count.lua 65.78 Mops/s (1 ops in 1.52 s) As people on the SQLite mailing list always say: there's no general answer as to which language/implementation/query/... is faster and better. You just have to test the different options for your specific application setting, and be prepared for one or two surprises. Just in case this isn't obvious: If I rewrote matrix multiplication in C and linked this code into R, it would run much slower than if I just typed A %*% B. All the best, Stefan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] scatter plot equation
On 22/11/2009 11:27 AM, Rofizah Mohammad wrote: Hi, If I have 2D data set say (x,y) and I can do scatter plot by using plot(x,y) command. How can I add in this scatter plot the equations curve say 2X2 + 3Y2 – 6X – 7Y + 9 = 0. You could do it using contour(), but you should use an equation that has some real solutions. For example, using a different equation than yours: x - rnorm(100, sd=1) y - rnorm(100, sd=1) xgrid - seq(min(x), max(x), len=100) ygrid - seq(min(y), max(y), len=120) grid - expand.grid(x=xgrid, y=ygrid) LHS - function(x, y) x^2 + y^2 - x - y - 1 z - apply(grid, 1, function(x) LHS(x[1], x[2]) ) z - matrix(z, 100, 120) plot(x,y) contour(xgrid, ygrid, z, levels=0, add=TRUE) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] consecutive numbering of elements in a matrix
On Nov 22, 2009, at 11:11 AM, Jim Bouldin wrote: Many thanks to Dimitris, William and David for very helpful answers which solved my problem. Being a relatve newb, I am confused by something in the solutions by Dimitris and David. #Create a matrix A as follows: A - matrix(sample(50, 21), 7, 3) A[sample(21, 5)] - NA;A [,1] [,2] [,3] [1,] 36 38 24 [2,]6 33 13 [3,] 12 42 10 [4,]7 NA NA [5,] 48 NA NA [6,]3 NA 47 [7,] 29 234 B = row(A) - apply(is.na(A), 2, cumsum);B [,1] [,2] [,3] [1,]111 [2,]222 [3,]333 [4,]433 [5,]533 [6,]634 [7,]745 #But: B = row(A) - apply(!is.na(A), 2, cumsum);B [,1] [,2] [,3] [1,]000 [2,]000 [3,]000 [4,]011 [5,]022 [6,]032 [7,]032 This seems exactly backwards to me. Put the individual components together side by side with cbind and it will make more sense: cbind( row(A), apply(is.na(A), 2, cumsum) ) And think about the fact that row(A) and apply(is.na(A), 2, cumsum) will be identical in the case where there are no NAs, so their difference would be a zero matrix. Double negativism strikes again not(is.na) == is The is.na(A) command should be cumulatively summing the NA values and !is.na(A) should be doing so on the non-NA values. But the opposite is the case. I'm glad I have a solution but this apparent backwardness of expected logic has me worried. I do have another, tougher question if anyone has the time, which is, given a resulting matrix like B below: is.na(B) - is.na(A);B [,1] [,2] [,3] [1,]111 [2,]222 [3,]333 [4,]4 NA NA [5,]5 NA NA [6,]6 NA4 [7,]745 how can I rearrange all the columns so that equal values are in the same row, i.e. in the case above, the NA values are removed from columns 2 and 3 and all non-NA values that had been below them are moved up to replace them. You cannot have unequal length columns in a matrix. Only a list is able to handle that task. So we need a more clear description of what you expect, preferably typed out in full so we can see it. -- David. Thanks again for your help. Jim 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] scatter plot equation
On Nov 22, 2009, at 11:27 AM, Rofizah Mohammad wrote: Hi, If I have 2D data set say (x,y) and I can do scatter plot by using plot(x,y) command. How can I add in this scatter plot the equations curve say 2X2 + 3Y2 6X 7Y + 9 = 0. No executable example... so if you are too lazy to construct one, then I would suggest looking for worked examples at one of the graphics galleries. Perhaps: http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=44 Regards Rofizah [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD 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.
[R] Do you keep an archive of useful R code? and if so - how?
Hello all, When using R for some time, one comes across more and more useful functions. But naturally we can't remember all of them, so I imagine some of you save these snippets of code. My question to you is how do you manage that code? Do you use special software, or archiving system? Any advice is welcomed. 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.
Re: [R] python
Anyway I think it was just a toy example. Any additionnal information is welcome. Best, Jean 2009/11/22 Peter Ehlers ehl...@ucalgary.ca Stefan Evert wrote: Sure, badly written R code does not perform as well as well written python code or C code. On the other hand badly written python code does not perform as well as well written R code. What happens when you try one of these : sum - sum( 1:N ) R runs out of memory and crashes. :-) I didn't tell you how big N is, did I? Really? N - 1e30 sum( 1:N ) Error in 1:N : result would be too long a vector -Peter Ehlers But this is exactly the point I was trying to make (but perhaps not prominently enough). In many cases, you can vectorize at least parts of your code or find a more efficient algorithm, which may be faster in R than a brute-force solution in C. But sometimes, you just cannot avoid loops (let's not forget that all the forms of apply() are just loops and don't give much of a speed benefit over a for-loop), function calls, etc.; in this case, performance differences between interpreted languages can matter. Personally, I'd never switch from R to Perl just for speed, though. BTW, I also tried a vectorised algorithm in R, which calculates the sum above in a small number of chunks: N1 - 50 N2 - 100 N - N1 * N2 sum - 0 for (i in 1:N1) { x - as.numeric(i-1) * N2 + 1:N2 sum - sum + sum(x) } which gives R/simple_count_vec.R 31.30 Mops/s (5000 ops in 1.60 s) So an interpreted loop in Lua is still faster than this partially vectorized code in R: lua/simple_count.lua 65.78 Mops/s (1 ops in 1.52 s) As people on the SQLite mailing list always say: there's no general answer as to which language/implementation/query/... is faster and better. You just have to test the different options for your specific application setting, and be prepared for one or two surprises. Just in case this isn't obvious: If I rewrote matrix multiplication in C and linked this code into R, it would run much slower than if I just typed A %*% B. All the best, Stefan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how do i persuade IT to install R on PCs ?? ...and should I ??
On Nov 22, 2009, at 5:14 AM, frenchcr wrote: Please help me persuade IT to install R on my computer! All suggestions welcome. Our IT department run scared when you mention software that they have no working experience of. I need to know the pros and cons of having R on corporate desktops. Please no funny stuff, this is quite a serious issue for us. Pros and cons would be good. Thanks. You need to define how R will meet and preferably enhance whatever functional requirements you have as compared to alternatives that are either already installed or that your IT folks are considering. How will R enhance your ability to meet the needs of the internal and/or external consumers of your analytic services? Typically, arguments based solely on costs (eg. R is free) will fall on deaf ears in IT, since there is the likelihood that your R installations will require some level of support from them, thus having a real cost in time and money. Are your R installations going to need to interface with other platforms such as database servers, etc? What security and server/network access implications will it have? What other supporting applications will you require to use with R (eg. editors, Perl, LaTeX, C/FORTAN compilers and related tools, etc.) that will increase support and maintenance requirements? Who is going to support R as problems occur and updates are needed? Most IT departments are used to paying for support to a commercial vendor. Somebody that they can call when things go wrong. They may not be used to getting support from mailing lists. Yes, there are commercial variants of R that address that issue and that may be something to consider depending upon the specifics of your situation. What knowledge does your IT department have of open source development and support? Is Linux being used on servers or workstations? Even if they are using a commercial Linux installation (eg. Red Hat), they may be more comfortable with the general concept of open source, which may be part of the battle that you are facing. Is there an alternative to installing on local desktops versus considering a central installation on a server? The former magnifies the time and workload requirements to IT for installing and maintaining over a larger number of computers. The latter enables a more centralized and possibly more efficient IT approach to this. What, if any, issues are there in converting existing code and processes that are implemented using other applications to R? What if any code reviews and functional validations will be required, resulting in real costs associated with those processes? There are not only direct costs, but indirect costs and opportunity costs associated with moving to and using R. You are going to require some level of support from them for R, which means they will have less time and resources for other activities. This becomes a control, political, economic and potentially even a legal issue. Over the years, as desktop PC's became common, there was a decentralization and dilution of IT involvement from the old mainframe/minicomputer days. That trend has been reversing for some time in most corporate environments, such that IT is taking a much more proactive role in controlling technology decision making, support and access across the IT spectrum. That includes driving corporate policies regarding applications, hardware, security, mobile platforms (laptops, smart phones, etc.) and is influenced by a variety of factors, not the least of which can be risk management, regulatory and related issues. An incremental approach is something to consider. Install R on one desktop machine or a server and let your IT folks become comfortable with it, before moving to a larger scale implementation if you are looking beyond just your one desktop. In addition, sell your manager(s) on R to gain their support and influence on the decision making process, therefore helping to politically bolster your arguments. It is known as managing up and can be an important part of the strategy in gaining IT's support, presuming that your managers are in a position of influence with IT. It would be difficult to provide detailed guidance to you without more information on your specific environment, but hopefully the above provides food for thought, at least in the abstract. Cheers, 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.
[R] contour(): lines labels in different colours?
Greetings, All! I want to draw contour lines in red, using contour(), but also have the contour labels (for the level-values) in black so that they will stand out against a coloured background already generated using filled.contour() (the background shades from green at low levels of risk to red at high levels). In any case, contour labels in red are already somewhat inconspicuous with contour lines in red, regardless of background. I see nothing in ?contour nor in ?par about this. One way to approach it could be to first draw the labelled contours in black, and then overlay by re-drawing (with out labels) in red. This would sort-of work, but the red contour lines would then cut through the black numbers, which is somewhat undesirable. Also (I've tried it) you can get show-through along the contour lines from the black layer, which is nasty. Any suggestions? With thanks, Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 22-Nov-09 Time: 17:06:08 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Do you keep an archive of useful R code? and if so - how?
On Nov 22, 2009, at 10:53 AM, Tal Galili wrote: Hello all, When using R for some time, one comes across more and more useful functions. But naturally we can't remember all of them, so I imagine some of you save these snippets of code. My question to you is how do you manage that code? Do you use special software, or archiving system? Any advice is welcomed. Tal One word: Subversion (http://subversion.tigris.org/) A version control system is a critical part of any code management process. If you or other users may not be comfortable at the command line using it, there are a plethora of GUI based clients for Subversion available depending upon the operating systems you are using. 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] how do i persuade IT to install R on PCs ?? ...and should I ??
frenchcr frenchcr at btinternet.com writes: Please help me persuade IT to install R on my computer! All suggestions welcome. Our IT department run scared when you mention software that they have no working experience of. I need to know the pros and cons of having R on corporate desktops. Please no funny stuff, this is quite a serious issue for us. Pros and cons would be good. Thanks. You can probably expect to get some funny stuff along with any useful advice you do get. It is almost impossible to answer this question without knowing what you want to use R for! You could tell your IT department that R is easy to install and well-behaved (i.e. it is self-contained and doesn't do nasty things to system libraries etc.), that it doesn't phone home or need to talk to servers outside your environment (unless you program it to, or unless you try to download install additional packages), that it is used by a very wide range of reputable companies (see a variety of discussions on this list, or see http://www.r-project.org/foundation/memberlist.html ), ... but the most important thing should presumably be whether it helps you do your job ... The license is unrestrictive, unless you want to redistribute a modified version, in which case it requires you to provide source code and allow redistribution ... Cons: like any software, it takes time and space to install (although not very much). R develops rapidly and there is little support for obsolete versions. The software comes without support, but you can pay for third-party support. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] scatter plot equation
Many thanks Duncan. I got the plot even I don't really understand the whole command.. I will study that later.. :-) Regards On Sun, Nov 22, 2009 at 4:44 PM, Duncan Murdoch murd...@stats.uwo.cawrote: On 22/11/2009 11:27 AM, Rofizah Mohammad wrote: Hi, If I have 2D data set say (x,y) and I can do scatter plot by using plot(x,y) command. How can I add in this scatter plot the equations curve say 2X2 + 3Y2 6X 7Y + 9 = 0. You could do it using contour(), but you should use an equation that has some real solutions. For example, using a different equation than yours: x - rnorm(100, sd=1) y - rnorm(100, sd=1) xgrid - seq(min(x), max(x), len=100) ygrid - seq(min(y), max(y), len=120) grid - expand.grid(x=xgrid, y=ygrid) LHS - function(x, y) x^2 + y^2 - x - y - 1 z - apply(grid, 1, function(x) LHS(x[1], x[2]) ) z - matrix(z, 100, 120) plot(x,y) contour(xgrid, ygrid, z, levels=0, add=TRUE) [[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] AKIMA: z values at a set coordinate
Dear Dr Hiemstra Thank you for taking the time to reply to my request. You are a very big help. regards and many thanks Sylvestre On Sat, Nov 21, 2009 at 10:57 AM, Paul Hiemstra p.hiems...@geo.uu.nlwrote: Hi Anonymous, (Maybe next time include your name) There are data objects in R that are designed for spatial data, look at the sp package. Casting them into this format gives you an enormous increase in flexibility with analyzing spatial data. See the example below using your example: library(akima) library(sp) data(akima) akima.li - interp(akima$x, akima$y, akima$z) # Change to sp object # Note that we swap the x and y column [1] y = rep(akima.li$x, each = length(akima.li$y)) x = rep(akima.li$y, length(akima.li$x)) z = as.numeric(akima.li$z) akima.sp = data.frame(x, y, z) # sp-function, which columns are the coordinates coordinates(akima.sp) = ~x+y # Tell sp that it is a grid gridded(akima.sp) = TRUE # Plot and compare image (akima.li) spplot(akima.sp) # Use overlay from sp to get the value # at a specific location pt = data.frame(x = 11.25, y = 6.5) coordinates(pt) = ~x+y val = akima...@data[overlay(akima.sp, pt),] val # [1] 19.14752 Learning to use sp-objects is really worthwhile. See the spatial Task view for more information, or check out the R-wiki [2]. With these kind of geographic questions you might want to use the r-sig-geo mailing list instead of R-help. cheers, Paul [1] We do this because (from details section of Image): Notice that image interprets the z matrix as a table of f(x[i], y[j]) values, so that the x axis corresponds to row number and the y axis to column number, with column 1 at the bottom, i.e. a 90 degree counter-clockwise rotation of the conventional printed layout of a matrix. [2] http://wiki.r-project.org/rwiki/doku.php?id=tips:spatial-data Rhelp wanted wrote: Dear all. I am using the akima function to produce 3d contour plots using interp based on irregular data. using the eg in the akima manual library(akima) data(akima) plot(y ~ x, data = akima, main = akima example data) with(akima, text(x, y, formatC(z,dig=2), adj = -0.1)) ## linear interpolation akima.li - interp(akima$x, akima$y, akima$z) image (akima.li, add=TRUE) contour(akima.li, add=TRUE) points (akima, pch = 3) so with this in mind is there a way of obtaining the interpolated value at a particular coordinate eg at (11.25,6.5) I can see that it as an orange and should I look at the contour lines I can see what value it produces. However Is there a way of saying function[11.25,6.5] which provides a value for that coordinate. Hope someone can help [[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. -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +3130 274 3113 Mon-Tue Phone: +3130 253 5773 Wed-Fri http://intamap.geo.uu.nl/~paul http://intamap.geo.uu.nl/%7Epaul [[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] Do you keep an archive of useful R code? and if so - how?
Hello Marc and Jeff, Thank you for replying. I am using winXP, and any recommendation for GUI based system will be welcomed. However, my initial question was not how to maintain code that I write and develop, but rather how to keep a filing system for other peoples code that I find useful. Here are some simple examples: - A code to allow me to start a window with history recording turned on. - A code to have wider margins so to allow more space for the plot labels. - A code for creating an ellipse plot of a matrix of correlations. All of these example are things I wouldn't put into a Subversion system or a new package. I hope my question was made more clear, and your answer will be much appreciated. Best, 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) -- On Sun, Nov 22, 2009 at 7:13 PM, Marc Schwartz marc_schwa...@me.com wrote: On Nov 22, 2009, at 10:53 AM, Tal Galili wrote: Hello all, When using R for some time, one comes across more and more useful functions. But naturally we can't remember all of them, so I imagine some of you save these snippets of code. My question to you is how do you manage that code? Do you use special software, or archiving system? Any advice is welcomed. Tal One word: Subversion (http://subversion.tigris.org/) A version control system is a critical part of any code management process. If you or other users may not be comfortable at the command line using it, there are a plethora of GUI based clients for Subversion available depending upon the operating systems you are using. HTH, Marc Schwartz [[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] Do you keep an archive of useful R code? and if so - how?
On Sun, Nov 22, 2009 at 5:45 PM, Tal Galili tal.gal...@gmail.com wrote: Hello Marc and Jeff, Thank you for replying. I am using winXP, and any recommendation for GUI based system will be welcomed. However, my initial question was not how to maintain code that I write and develop, but rather how to keep a filing system for other peoples code that I find useful. Here are some simple examples: - A code to allow me to start a window with history recording turned on. - A code to have wider margins so to allow more space for the plot labels. - A code for creating an ellipse plot of a matrix of correlations. All of these example are things I wouldn't put into a Subversion system or a new package. I just use plain text files for keeping notes - generally each project directory I work on has a 'notes.txt' file which is a working log of what I'm doing. If I think 'how did I do that the other day?' I can search my text files. Recently I've been experimenting with using 'personal' or 'desktop' wiki systems for this. Like Wikipedia but just for you, and stored as files on your PC, and edited with a local client program instead of over the web (although some personal wikis work over the web). I've found 'zim' to be pretty good for this. It organises notes, lets you link pages, timestamps things, has various plugins and MOST importantly it's Open Source so you won't ever have your notes locked up in a proprietary format that you need to keep paying a license fee for. Not sure if there's a Windows port of it, but I'm certain similar systems exist for Windows. Another idea is to have a public blog for R tips and tricks. That way not only do you get free storage (from blogspot.com or some other blog provider) but also it's searchable and other people can find it and comment and improve on it. Or you could contribute to the R-wiki: http://wiki.r-project.org/rwiki/doku.php?id=tips:tips Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Do you keep an archive of useful R code? and if so - how?
Tal, I would still use Subversion. Think of Subversion as as an electronic filing system. You can organize code into project trees, with sub-folders and so forth. As you come across code snippets that you want to save, copy them to a file and commit the file to a project tree or sub-folder, based upon the domain of functionality. Add related code snippets to the same domains. That way, you have related code snippets in a common area, making recall easier. The advantage of using a VCS is that you can make trackable modifications to the code over time, as your functional requirements change or as you discover bugs, etc. to existing code. In terms of a GUI, for Windows, it seems that most use Tortoise SVN: http://tortoisesvn.net/ There are cross-platform GUIs such as RapidSVN (http://rapidsvn.tigris.org/ ), but it all depends upon personal preferences. More links here: http://subversion.tigris.org/links.html#all-clients There are also Subversion extensions for editors, such as Emacs, like psvn.el (http://www.xsteve.at/prg/vc_svn/) which enable a blending of functionality into environments that you may already be using, such as ESS. Last but not least, there are also commercial variants of Subversion clients, which of course have a cost associated with them. These are also listed on the clients link above. An alternative would be to create a local wiki, the implementation details, as with a Subversion repo, would be dependent upon whether or not you are the only person that needs access or if access and/or content modification are to be shared. HTH, Marc On Nov 22, 2009, at 11:45 AM, Tal Galili wrote: Hello Marc and Jeff, Thank you for replying. I am using winXP, and any recommendation for GUI based system will be welcomed. However, my initial question was not how to maintain code that I write and develop, but rather how to keep a filing system for other peoples code that I find useful. Here are some simple examples: A code to allow me to start a window with history recording turned on. A code to have wider margins so to allow more space for the plot labels. A code for creating an ellipse plot of a matrix of correlations. All of these example are things I wouldn't put into a Subversion system or a new package. I hope my question was made more clear, and your answer will be much appreciated. Best, Tal On Sun, Nov 22, 2009 at 7:13 PM, Marc Schwartz marc_schwa...@me.com wrote: On Nov 22, 2009, at 10:53 AM, Tal Galili wrote: Hello all, When using R for some time, one comes across more and more useful functions. But naturally we can't remember all of them, so I imagine some of you save these snippets of code. My question to you is how do you manage that code? Do you use special software, or archiving system? Any advice is welcomed. Tal One word: Subversion (http://subversion.tigris.org/) A version control system is a critical part of any code management process. If you or other users may not be comfortable at the command line using it, there are a plethora of GUI based clients for Subversion available depending upon the operating systems you are using. HTH, Marc Schwartz [[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] Do you keep an archive of useful R code? and if so - how?
Marc and Barry, many thanks for your detailed answers. Marc - I thank you for the links and ideas. Thanks to your advice I will look more into SVN in the future, although it sounds on the surface to require some learning curve, so It could take me some time to start using it. Barry - I am actually a blog builder in my side profession, I already built myself a blog called: r-statistics.com On which I intend to put up good code I will come across. The problem with it though is that I don't see blogs as a good information management system. Since on a blog one is open to the public and doesn't want to leave half scribles of thoughts (which IS what ends up happening when managing snippets of code). Also, blogging is not build for easy hierarchical ordering. The idea of a wiki is more appealing. BTW - another suggestion I got was using MS onenote. Although it is not open source (which is my preference as well), I understood it offers a powerful solution. I hope more people will share how they manage their snippets of code. Best to all of you, 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) -- On Sun, Nov 22, 2009 at 8:09 PM, Marc Schwartz marc_schwa...@me.com wrote: Tal, I would still use Subversion. Think of Subversion as as an electronic filing system. You can organize code into project trees, with sub-folders and so forth. As you come across code snippets that you want to save, copy them to a file and commit the file to a project tree or sub-folder, based upon the domain of functionality. Add related code snippets to the same domains. That way, you have related code snippets in a common area, making recall easier. The advantage of using a VCS is that you can make trackable modifications to the code over time, as your functional requirements change or as you discover bugs, etc. to existing code. In terms of a GUI, for Windows, it seems that most use Tortoise SVN: http://tortoisesvn.net/ There are cross-platform GUIs such as RapidSVN ( http://rapidsvn.tigris.org/), but it all depends upon personal preferences. More links here: http://subversion.tigris.org/links.html#all-clients There are also Subversion extensions for editors, such as Emacs, like psvn.el (http://www.xsteve.at/prg/vc_svn/) which enable a blending of functionality into environments that you may already be using, such as ESS. Last but not least, there are also commercial variants of Subversion clients, which of course have a cost associated with them. These are also listed on the clients link above. An alternative would be to create a local wiki, the implementation details, as with a Subversion repo, would be dependent upon whether or not you are the only person that needs access or if access and/or content modification are to be shared. HTH, Marc On Nov 22, 2009, at 11:45 AM, Tal Galili wrote: Hello Marc and Jeff, Thank you for replying. I am using winXP, and any recommendation for GUI based system will be welcomed. However, my initial question was not how to maintain code that I write and develop, but rather how to keep a filing system for other peoples code that I find useful. Here are some simple examples: - A code to allow me to start a window with history recording turned on. - A code to have wider margins so to allow more space for the plot labels. - A code for creating an ellipse plot of a matrix of correlations. All of these example are things I wouldn't put into a Subversion system or a new package. I hope my question was made more clear, and your answer will be much appreciated. Best, Tal On Sun, Nov 22, 2009 at 7:13 PM, Marc Schwartz marc_schwa...@me.comwrote: On Nov 22, 2009, at 10:53 AM, Tal Galili wrote: Hello all, When using R for some time, one comes across more and more useful functions. But naturally we can't remember all of them, so I imagine some of you save these snippets of code. My question to you is how do you manage that code? Do you use special software, or archiving system? Any advice is welcomed. Tal One word: Subversion (http://subversion.tigris.org/) A version control system is a critical part of any code management process. If you or other users may not be comfortable at the command line using it, there are a plethora of GUI based clients for Subversion available depending upon the operating systems you are using. HTH, Marc Schwartz [[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
[R] serialized plot object (2 years later)
About 2 years ago, Tobias Verbeke asked: I am looking for a way to capture the binary string that in normal use of graphics devices will bewritten to (most commonly) a file connection... Is there a way of capturing the binary `jpeg string' [generated by jpeg()]? http://tolstoy.newcastle.edu.au/R/e2/devel/07/09/4276.html Brian Ripley's answer was Nope, unfortunately, they write to files not connections and no R object is involved. Is this still the case? _ Hotmail: Trusted email with powerful SPAM protection. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] consecutive numbering of elements in a matrix
one approach is the following: B - cbind(c(1:6, NA), c(1:3, NA,NA,NA, 4), c(1:3, NA,NA, 4,5)) matrix(B[order(col(B), B)], nrow(B), ncol(B)) I hope it helps. Best, Dimitris Jim Bouldin wrote: And think about the fact that row(A) and apply(is.na(A), 2, cumsum) will be identical in the case where there are no NAs, so their difference would be a zero matrix. Double negativism strikes again not(is.na) == is OK I see it now--thanks. I was interpreting the apply function incorrectly in terms of what it was summing. You cannot have unequal length columns in a matrix. Only a list is able to handle that task. So we need a more clear description of what you expect, preferably typed out in full so we can see it. Given a matrix B like before, which has NAs mixed with integers in all columns, where those NAs may occur anywhere within the columns, and where the integers within a column are always consecutive and increasing: B [,1] [,2] [,3] ...etc [1,]111 [2,]222 [3,]333 [4,]4 NA NA [5,]5 NA NA [6,]6 NA4 [7,]NA 45 etc I would like to create a new matrix, in which all NAs that occur BETWEEN consecutive integers are removed, and the integers which follow such NAs are moved up in the column to replace them. NAs which occur near the bottom of each column, and are NOT followed by more integers can be retained without problem. Empty spaces that might result from this process, near the column bottoms as the integers are moved up, would need to be replaced by NAs so that equal numbers of entries are maintained in each row, hence still allowing a matrix to exist: If B above were in fact the complete matrix, the desired result would thus be: [,1] [,2] [,3] etc [1,]111 [2,]222 [3,]333 [4,]444 [5,]5 NA5 [6,]6 NA NA [7,]NA NA NA etc In other words, all integers of a particular value in the original matrix need to be placed on the same row of a new matrix, and all empty values replaced with NA. I hope that explains it well enough, but will try again if not. Thanks again for any help. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Do you keep an archive of useful R code? and if so - how?
Marc - I thank you for the links and ideas. Thanks to your advice I will look more into SVN in the future, although it sounds on the surface to require some learning curve, so It could take me some time to start using it. If you consider investing time to learn a version control system, I would recommend looking into a distributed one. - Personally I use git. http://git-scm.com/ is a good start, http://www.github.com can be used to store code 'in the cloud'. Cheers, Hans-Peter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Computing multivariate normal probabilities. Was: Re: Problem with Numerical derivatives (numDeriv) and mvtnorm
I'm now making some trials with sadmvn which provides results similar to pmvnorm for optimization but I know compute my OPG estimator of the covariance matrix with sadmvn (by the way Ravi, when I was refering to exist in theory I was refering to the theory not to the computation - would an appropriate random computation of partial derivative work?). Interestingly, mprobit also provides derivatives, exactly what I need. Unfortunatly it fails to install on mac os X! (I don't want to install windows in my system and my linux server is off for the moment). Stephane 2009/11/22 Ravi Varadhan rvarad...@jhmi.edu: Hi Torsten, It would be useful to warn the users that the multivariate normal probability calculated by pmvnorm using the GenzBretz algorithm is random, i.e. the result can vary between repeated executions of the function. This would prevent inappropriate use of pmvnorm such as computing derivatives of it (see this email thread). It seems that the other algorithm Miwa is deterministic, but not sure how reliable it is (I had some trouble with it). It would also be useful in the help page to provide a link to two other functions for evaluating multivariate normal probabilities: mnormt::sadmvn mprobit::mvnapp In particular, the `mvnapp' function of Harry Joe in mprobit package seems to be very interesting as it provides very accurate results using asymptotic expansions. Best, 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: Ravi Varadhan rvarad...@jhmi.edu Date: Saturday, November 21, 2009 8:15 pm Subject: Re: [R] Problem with Numerical derivatives (numDeriv) and mvtnorm To: SL sl...@yahoo.fr Cc: r-help@r-project.org Go back to your calculus text and review the definition of derivative: f'(x) = lim h - 0 [f(x+h) - f(x)] / h when f(x) and f(x + h) are random variables, the above limit does not exist. In fact, f'(x) is also a random variable. Now, if you want the derivative you have to use a multivariate integration algorithm that yields a deterministic value. The function `sadmvn' in the package mnormt can do this: require(mnormt) PP2 - function(p){ thetac - p thetae - 0.323340333 thetab - -0.280970036 thetao - 0.770768082 ssigma - diag(4) ssigma[1,2] - 0.229502120 ssigma[1,3] - 0.677949335 ssigma[1,4] - 0.552907745 ssigma[2,3] - 0.784263100 ssigma[2,4] - 0.374065025 ssigma[3,4] - 0.799238700 ssigma[2,1] - ssigma[1,2] ssigma[3,1] - ssigma[1,3] ssigma[4,1] - ssigma[1,4] ssigma[3,2] - ssigma[2,3] ssigma[4,2] - ssigma[2,4] ssigma[4,3] - ssigma[3,4] pp - sadmvn(lower=rep(-Inf, 4), upper=c(thetac,thetae,thetab,thetao), mean=rep(0,4), varcov=ssigma, maxpt=10) return(pp) } xx - -0.6675762 P2(xx) require(numDeriv) grad(x=xx, func=PP2) I hope this helps, 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: SL sl...@yahoo.fr Date: Saturday, November 21, 2009 2:42 pm Subject: Re: [R] Problem with Numerical derivatives (numDeriv) and mvtnorm To: r-help@r-project.org Thanks for you comment. There is certainly some Monte Carlo sampling involved in mvtnorm but why derivatives could not be computed? In theory, the derivatives exist (eg. bivariate probit). Moreover, when used with optim, there are some numerical derivatives computed... does it mean that mvtnorm cannot be used in an optimisation problem? I think it hard to believe. One possibility would be to use the analytical derivatives and then a do-it-yourself integration but i was looking for something a bit more comprehensive. The mvtnorm package uses a specific way to compute pmvnorm and I'm far to do a good enough job so that derivatives can compare with what mvtnorm can do. Stef __ R-help@r-project.org mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list PLEASE do read the posting guide 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] mac os X: mprobit fails to install
Hi all, any chance that someone got through the installation problem of mprobit on mac os X? Stephane __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Do you keep an archive of useful R code? and if so - how?
I accidentally sent this directly to the author and didn't reply to the whole list, I am sorry, I need to remember to hit reply all instead of reply to the R help list, heres my message: I keep a separate R file of code I commonly use but more generic. So if I am making contingency tables I say: ftable(category, category[top]) or if I am wanting to subset data: subset2$X5-recode(subset2$X5, 6:10=1:5) things like that, generic code that I can refer to and include my variables in as necessary (as you can tell the top mark I made in ftable isn't in the code but reminds me how the table structures itself. Since I am a newbie at R I am still keeping notes, I do this for importing things, also graphics: xyplot(value~X1,data=subset1,groups=factor(X2), type=c(b,g),ylim=c(0,1),xlim=c(1,5),lwd=1,cex = 1, plot.points = TRUE,auto.key = list(points = TRUE,lines = TRUE, space = inside), label.curves=FALSE,xlab = x axis title, ylab = y axis title ) so it just lets me organize my codes on my local system. R wiki is ok, but will be much better as people expand it, I am sure very soon it will grow exponentially as a good resource. (as you can tell some of the code I save includes old variable names instead of neutral ones, but easy enough to change). Joe King 206-913-2912 j...@joepking.com Never throughout history has a man who lived a life of ease left a name worth remembering. --Theodore Roosevelt -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Tal Galili Sent: Sunday, November 22, 2009 10:31 AM To: Marc Schwartz Cc: r-help@r-project.org; Barry Rowlingson; jeff.la...@noaa.gov Subject: Re: [R] Do you keep an archive of useful R code? and if so - how? Marc and Barry, many thanks for your detailed answers. Marc - I thank you for the links and ideas. Thanks to your advice I will look more into SVN in the future, although it sounds on the surface to require some learning curve, so It could take me some time to start using it. Barry - I am actually a blog builder in my side profession, I already built myself a blog called: r-statistics.com On which I intend to put up good code I will come across. The problem with it though is that I don't see blogs as a good information management system. Since on a blog one is open to the public and doesn't want to leave half scribles of thoughts (which IS what ends up happening when managing snippets of code). Also, blogging is not build for easy hierarchical ordering. The idea of a wiki is more appealing. BTW - another suggestion I got was using MS onenote. Although it is not open source (which is my preference as well), I understood it offers a powerful solution. I hope more people will share how they manage their snippets of code. Best to all of you, 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) -- On Sun, Nov 22, 2009 at 8:09 PM, Marc Schwartz marc_schwa...@me.com wrote: Tal, I would still use Subversion. Think of Subversion as as an electronic filing system. You can organize code into project trees, with sub-folders and so forth. As you come across code snippets that you want to save, copy them to a file and commit the file to a project tree or sub-folder, based upon the domain of functionality. Add related code snippets to the same domains. That way, you have related code snippets in a common area, making recall easier. The advantage of using a VCS is that you can make trackable modifications to the code over time, as your functional requirements change or as you discover bugs, etc. to existing code. In terms of a GUI, for Windows, it seems that most use Tortoise SVN: http://tortoisesvn.net/ There are cross-platform GUIs such as RapidSVN ( http://rapidsvn.tigris.org/), but it all depends upon personal preferences. More links here: http://subversion.tigris.org/links.html#all-clients There are also Subversion extensions for editors, such as Emacs, like psvn.el (http://www.xsteve.at/prg/vc_svn/) which enable a blending of functionality into environments that you may already be using, such as ESS. Last but not least, there are also commercial variants of Subversion clients, which of course have a cost associated with them. These are also listed on the clients link above. An alternative would be to create a local wiki, the implementation details, as with a Subversion repo, would be dependent upon whether or not you are the only person that needs access or if access and/or content modification are to be shared. HTH, Marc On Nov 22, 2009, at 11:45 AM, Tal Galili wrote: Hello Marc and Jeff, Thank you for replying. I am using winXP, and any
Re: [R] Do you keep an archive of useful R code? and if so - how?
Hello, I do keep a blog with R and non R related snippets of code. Besides that, something like Alfresco, Plone or other document management systems could be useful. Maybe the solution is too complex for a single user, but you can keep tags and other kind of metadata attached to your code and you would have an integrated search engine. Best regards, Carlos J. Gil Bellosta http://www.datanalytics.com Tal Galili wrote: Hello all, When using R for some time, one comes across more and more useful functions. But naturally we can't remember all of them, so I imagine some of you save these snippets of code. My question to you is how do you manage that code? Do you use special software, or archiving system? Any advice is welcomed. 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] mac os X: mprobit fails to install
Stephane - The check log indicated that malloc.h couldn't be found. Since that header file is located in /usr/include/sys on Macs, you could do the following: 1. Download mprobit_0.9-2.tar.gz from your local CRAN mirror. 2. At a terminal, type PKG_CFLAGS=-I/usr/include/sys R CMD INSTALL mprobit_0.9-2.tar.gz They'll be some warning messages, but the package should get built. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Sun, 22 Nov 2009, stephane Luchini wrote: Hi all, any chance that someone got through the installation problem of mprobit on mac os X? Stephane __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to tell if its better to standardize your data matrix first when you do principal
so under which cases is it better to standardize the data matrix first ? also is PCA generally used to predict the response variable , should I keep that variable in my data matrix ? Uwe Ligges-3 wrote: masterinex wrote: Hi guys , Im trying to do principal component analysis in R . There is 2 ways of doing it , I believe. One is doing principal component analysis right away the other way is standardizing the matrix first using s = scale(m)and then apply principal component analysis. How do I tell what result is better ? What values in particular should i look at . I already managed to find the eigenvalues and eigenvectors , the proportion of variance for each eigenvector using both methods. Generally, it is better to standardize. But in some cases, e.g. for the same units in your variables indicating also the importance, it might make sense not to do so. You should think about the analysis, you cannot know which result is `better' unless you know an interpretation. I noticed that the proportion of the variance for the first pca without standardizing had a larger value . Is there a meaning to it ? Isnt this always the case? At last , if I am supposed to predict a variable ie weight should I drop the variable ie weight from my data matrix when I do principal component analysis ? This sounds a bit like homework. If that is the case, please ask your teacher rather than this list. Anyway, it does not make sense to predict weight using a linear combination (principle component) that contains weight, does it? Uwe Ligges __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://old.nabble.com/how-to-tell-if-its-better-to-standardize-your-data-matrix-first-when-you-do-principal-tp26462070p26466400.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] consecutive numbering of elements in a matrix
Thank you Dimitris, that solves it exactly! I continue to be amazed at how a single line of code can be so powerful in R, containing so much information. Hard as hell to interpret though (for me). Jim one approach is the following: B - cbind(c(1:6, NA), c(1:3, NA,NA,NA, 4), c(1:3, NA,NA, 4,5)) matrix(B[order(col(B), B)], nrow(B), ncol(B)) I hope it helps. Best, Dimitris Jim Bouldin, PhD Research Ecologist Department of Plant Sciences, UC Davis Davis CA, 95616 530-554-1740 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] mac os X: mprobit fails to install
I have tried your command but without success. Any idea? Here is my log: Macbook:$ PKG_CFLAGS=-I/usr/include/sys R CMD INSTALL mprobit_0.9-2.tar.gz * Installing to library ‘/Users/stephaneluchini/Library/R/2.9/library’ * Installing *source* package ‘mprobit’ ... ** libs ** arch - i386 sh: make: command not found ERREUR : compilation failed pour le package ‘mprobit’ * Removing ‘/Users/stephaneluchini/Library/R/2.9/library/mprobit’ 2009/11/22 Phil Spector spec...@stat.berkeley.edu: Stephane - The check log indicated that malloc.h couldn't be found. Since that header file is located in /usr/include/sys on Macs, you could do the following: 1. Download mprobit_0.9-2.tar.gz from your local CRAN mirror. 2. At a terminal, type PKG_CFLAGS=-I/usr/include/sys R CMD INSTALL mprobit_0.9-2.tar.gz They'll be some warning messages, but the package should get built. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Sun, 22 Nov 2009, stephane Luchini wrote: Hi all, any chance that someone got through the installation problem of mprobit on mac os X? Stephane __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] How to get the factor level means with interaction term?
I thought that the last two statements in the following code should give me the same results (what I want are the factor level means for factor 'A'). But they don't. I think that the last statement should give me the correct factor level means for 'A'. Could somebody let me know what the problems are with 'afit$coefficients[1:3]'? set.seed(0) a=3 b=4 A=1:a B=1:b n=4 X=matrix(nr=a*b*n,nc=2) colnames(X)=LETTERS[1:2] for(i_a in 1:a-1) { for(i_b in 1:b-1) { for(i_n in 1:n-1) { X[(i_a * b + i_b) * n + i_n + 1, ] = c(i_a+1, i_b+1) } } } Y=matrix(nr=a*b*n,nc=1) for(i in 1:(a*b)) { for(i_n in 1:n-1) { print((i-1)*n+i_n+1,1) Y[(i-1)*n+i_n+1,1]= rnorm(1) } } aframe = data.frame( A=as.factor(X[,'A']) , B=as.factor(X[,'B']) , Y) afit=aov(Y ~ A * B - 1, aframe) summary(afit) afit$coefficients[1:3] lapply(split(aframe$Y, aframe$A),mean) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Do you keep an archive of useful R code? and if so - how?
I 've used tiddlywiki a personal notebook for other things but not for R. It may be useful to write a css that separates out code from description. http://www.tiddlywiki.com/ On 22 Nov 2009, at 11:53AM, Tal Galili wrote: Hello all, When using R for some time, one comes across more and more useful functions. But naturally we can't remember all of them, so I imagine some of you save these snippets of code. My question to you is how do you manage that code? Do you use special software, or archiving system? Any advice is welcomed. 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.
[R] where is lme() that is referred by aov() help page?
The help page of aov() mentions lme(). Does it refer to lme() in package nlme? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] where is lme() that is referred by aov() help page?
On 22/11/2009 3:38 PM, Peng Yu wrote: The help page of aov() mentions lme(). Does it refer to lme() in package nlme? Yes, that's where the link takes you. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] mac os X: mprobit fails to install
There were quite a few implicit declaration warning messages when I followed Phil's advice, but I do seem to get a complete build on a Mac 10.5.8 running 64 bit R 2.10.0. Have you installed the Xcode package? The gcc-4.2? -- David. On Nov 22, 2009, at 3:15 PM, SL wrote: I have tried your command but without success. Any idea? Here is my log: Macbook:$ PKG_CFLAGS=-I/usr/include/sys R CMD INSTALL mprobit_0.9-2.tar.gz * Installing to library ‘/Users/stephaneluchini/Library/R/2.9/library’ * Installing *source* package ‘mprobit’ ... ** libs ** arch - i386 sh: make: command not found ERREUR : compilation failed pour le package ‘mprobit’ * Removing ‘/Users/stephaneluchini/Library/R/2.9/library/mprobit’ 2009/11/22 Phil Spector spec...@stat.berkeley.edu: Stephane - The check log indicated that malloc.h couldn't be found. Since that header file is located in /usr/include/sys on Macs, you could do the following: 1. Download mprobit_0.9-2.tar.gz from your local CRAN mirror. 2. At a terminal, type PKG_CFLAGS=-I/usr/include/sys R CMD INSTALL mprobit_0.9-2.tar.gz They'll be some warning messages, but the package should get built. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Sun, 22 Nov 2009, stephane Luchini wrote: Hi all, any chance that someone got through the installation problem of mprobit on mac os X? Stephane __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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] where is lme() that is referred by aov() help page?
On Sun, Nov 22, 2009 at 2:42 PM, Duncan Murdoch murd...@stats.uwo.ca wrote: On 22/11/2009 3:38 PM, Peng Yu wrote: The help page of aov() mentions lme(). Does it refer to lme() in package nlme? Yes, that's where the link takes you. Should this information be mentioned in aov() help page? Because ?lme does not return anything in my system, I think it is better to mention where lme is from in aov help page. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Spatstat, markcorr, max. radius limited??
On 21/11/2009, at 12:01 AM, rudi1...@gmx.de wrote: Hello, could please somebody help me. I want to apply the mark correlation function but for radii up to 75 meters (in 75 individual 1m steps). Unfortunately, There is a sensible default for the values of the argument r at which the mark correlation function kf (r) should be evaluated, so that I do not get results for r 25m. Can I change something in the function to get the required values as written above? Questions about contributed packages should be addressed, in the first instance, to the maintainer(s) of the package rather than to the R-help list. I am one of the maintainers, but I'm afraid that I don't know/ understand a lot about the mark correlation function, and Adrian --- the other maintainer, who does know a lot --- is off on holidays, and won't be back till 7 December. In the mean time let me just say that ``There is a sensible default'' is probably an understatement. The default is what you ***should*** use. Trying to set your own value of ``r'' will probably give you nonsense. This is my understanding of the situation, anyway. That being said --- how do you *know* that you do not get results for r 25? Did you just plot the output from markcorr()? There is also a ``sensible default'' for the x-axis limits, which is used *unless xlim is specified* in your call to plot(). Did you try specifying xlim to extend to something about r = 25? And ***that*** being said, you probably shouldn't! Given that the ``sensible default'' for xlim is c(0,25) then it seems to me very likely that ***it is simply not meaningful*** to consider the mark correlation function for r 25. I cannot explain to you *why* it is not meaningful, but I'm sure that were this not the case Adrian would not have written the function this way. When he gets back from hols Adrian may be able to explain to you just why it is not meaningful to consider r 25 in your setting. Finally let me draw to your attention a quote from the late great John Tukey: The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from the given body of data. The fact that you have an aching desire to know the value of the mark correlation function at values of r 25 does not guarantee that reasonable estimates of these values can be found from the data that you have available. cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] mac os X: mprobit fails to install
Thanks. I have 10.5.8 with R 2.10.0 now (i still had 2.9 in my previous messages). I also have gcc-4.2 installed but no Xcode package. It still fails to install - can it be the Xcode package? Where can I find it - I don't have my install CDs with me and will not get them soon? Stephane 2009/11/22 David Winsemius dwinsem...@comcast.net: There were quite a few implicit declaration warning messages when I followed Phil's advice, but I do seem to get a complete build on a Mac 10.5.8 running 64 bit R 2.10.0. Have you installed the Xcode package? The gcc-4.2? -- David. On Nov 22, 2009, at 3:15 PM, SL wrote: I have tried your command but without success. Any idea? Here is my log: Macbook:$ PKG_CFLAGS=-I/usr/include/sys R CMD INSTALL mprobit_0.9-2.tar.gz * Installing to library ‘/Users/stephaneluchini/Library/R/2.9/library’ * Installing *source* package ‘mprobit’ ... ** libs ** arch - i386 sh: make: command not found ERREUR : compilation failed pour le package ‘mprobit’ * Removing ‘/Users/stephaneluchini/Library/R/2.9/library/mprobit’ 2009/11/22 Phil Spector spec...@stat.berkeley.edu: Stephane - The check log indicated that malloc.h couldn't be found. Since that header file is located in /usr/include/sys on Macs, you could do the following: 1. Download mprobit_0.9-2.tar.gz from your local CRAN mirror. 2. At a terminal, type PKG_CFLAGS=-I/usr/include/sys R CMD INSTALL mprobit_0.9-2.tar.gz They'll be some warning messages, but the package should get built. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Sun, 22 Nov 2009, stephane Luchini wrote: Hi all, any chance that someone got through the installation problem of mprobit on mac os X? Stephane __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] where is lme() that is referred by aov() help page?
On 22/11/2009 3:44 PM, Peng Yu wrote: On Sun, Nov 22, 2009 at 2:42 PM, Duncan Murdoch murd...@stats.uwo.ca wrote: On 22/11/2009 3:38 PM, Peng Yu wrote: The help page of aov() mentions lme(). Does it refer to lme() in package nlme? Yes, that's where the link takes you. Should this information be mentioned in aov() help page? Because ?lme does not return anything in my system, I think it is better to mention where lme is from in aov help page. It links to the right page. 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] any equivalent SUM IF statement in R
for example, i want to sum all the row entries if column 1 takes the value boy. anyone knows ? -- View this message in context: http://old.nabble.com/any-equivalent-SUM-IF-statement-in-R-tp26467889p26467889.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] mac os X: mprobit fails to install
On Nov 22, 2009, at 4:00 PM, stephane Luchini wrote: Thanks. I have 10.5.8 with R 2.10.0 now (i still had 2.9 in my previous messages). I also have gcc-4.2 installed but no Xcode package. It still fails to install - can it be the Xcode package? Where can I find it - I don't have my install CDs with me and will not get them soon? Xcode is distributed free by Apple through its developer program. All you need to do is register, again, free, or at least it used to be so. You could also check the tools section of CRAN. I am not sufficient UNIXified to be an authoritative source on these issues. -- David Stephane 2009/11/22 David Winsemius dwinsem...@comcast.net: There were quite a few implicit declaration warning messages when I followed Phil's advice, but I do seem to get a complete build on a Mac 10.5.8 running 64 bit R 2.10.0. Have you installed the Xcode package? The gcc-4.2? -- David. On Nov 22, 2009, at 3:15 PM, SL wrote: I have tried your command but without success. Any idea? Here is my log: Macbook:$ PKG_CFLAGS=-I/usr/include/sys R CMD INSTALL mprobit_0.9-2.tar.gz * Installing to library ‘/Users/stephaneluchini/Library/R/2.9/ library’ * Installing *source* package ‘mprobit’ ... ** libs ** arch - i386 sh: make: command not found ERREUR : compilation failed pour le package ‘mprobit’ * Removing ‘/Users/stephaneluchini/Library/R/2.9/library/mprobit’ 2009/11/22 Phil Spector spec...@stat.berkeley.edu: Stephane - The check log indicated that malloc.h couldn't be found. Since that header file is located in /usr/include/sys on Macs, you could do the following: 1. Download mprobit_0.9-2.tar.gz from your local CRAN mirror. 2. At a terminal, type PKG_CFLAGS=-I/usr/include/sys R CMD INSTALL mprobit_0.9-2.tar.gz They'll be some warning messages, but the package should get built. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Sun, 22 Nov 2009, stephane Luchini wrote: Hi all, any chance that someone got through the installation problem of mprobit on mac os X? Stephane __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] any equivalent SUM IF statement in R
On 22/11/2009 3:44 PM, ychu066 wrote: for example, i want to sum all the row entries if column 1 takes the value boy. anyone knows ? Subset then sum: sum(M[M[,1] == boy, ]) Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] any equivalent SUM IF statement in R
Presumably you want all the columns _except_ column 1, right? Perhaps (no code, no test) : sum( dta[ dta[,1]==boy , -1 ] ) -- David. On Nov 22, 2009, at 3:44 PM, ychu066 wrote: for example, i want to sum all the row entries if column 1 takes the value boy. anyone knows ? -- View this message in context: http://old.nabble.com/any-equivalent-SUM-IF-statement-in-R-tp26467889p26467889.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. 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] contour(): lines labels in different colours?
Hi Ted, This won't solve your problem, but a small improvement might be to place the labels over the lines rather than the other way around. It will definitely avoid putting red lines over black ones: x - -6:16 z - outer(x,x) contour(z, labels=, col=2) contour(z, lty=0, labcex=1, add=TRUE) Cheers, Peter (Ted Harding) wrote: Greetings, All! I want to draw contour lines in red, using contour(), but also have the contour labels (for the level-values) in black so that they will stand out against a coloured background already generated using filled.contour() (the background shades from green at low levels of risk to red at high levels). In any case, contour labels in red are already somewhat inconspicuous with contour lines in red, regardless of background. I see nothing in ?contour nor in ?par about this. One way to approach it could be to first draw the labelled contours in black, and then overlay by re-drawing (with out labels) in red. This would sort-of work, but the red contour lines would then cut through the black numbers, which is somewhat undesirable. Also (I've tried it) you can get show-through along the contour lines from the black layer, which is nasty. Any suggestions? With thanks, Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 22-Nov-09 Time: 17:06:08 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how do i persuade IT to install R on PCs ?? ...and should I ??
Please also look at the R document http://www.r-project.org/doc/R-FDA.pdf and ask your IT department to read this document Rich __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to tell if its better to standardize your data matrix first when you do principal
You've asked the same question on stackoverflow.com and received the same answer. This is rude because it duplicates effort. If you urgently need a response to a question, perhaps you should consider paying for it. Hadley On Sun, Nov 22, 2009 at 12:04 PM, masterinex xevilgan...@hotmail.com wrote: so under which cases is it better to standardize the data matrix first ? also is PCA generally used to predict the response variable , should I keep that variable in my data matrix ? Uwe Ligges-3 wrote: masterinex wrote: Hi guys , Im trying to do principal component analysis in R . There is 2 ways of doing it , I believe. One is doing principal component analysis right away the other way is standardizing the matrix first using s = scale(m)and then apply principal component analysis. How do I tell what result is better ? What values in particular should i look at . I already managed to find the eigenvalues and eigenvectors , the proportion of variance for each eigenvector using both methods. Generally, it is better to standardize. But in some cases, e.g. for the same units in your variables indicating also the importance, it might make sense not to do so. You should think about the analysis, you cannot know which result is `better' unless you know an interpretation. I noticed that the proportion of the variance for the first pca without standardizing had a larger value . Is there a meaning to it ? Isnt this always the case? At last , if I am supposed to predict a variable ie weight should I drop the variable ie weight from my data matrix when I do principal component analysis ? This sounds a bit like homework. If that is the case, please ask your teacher rather than this list. Anyway, it does not make sense to predict weight using a linear combination (principle component) that contains weight, does it? Uwe Ligges __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://old.nabble.com/how-to-tell-if-its-better-to-standardize-your-data-matrix-first-when-you-do-principal-tp26462070p26466400.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. -- 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] contour(): lines labels in different colours?
On Nov 22, 2009, at 4:57 PM, Peter Ehlers wrote: Hi Ted, This won't solve your problem, but a small improvement might be to place the labels over the lines rather than the other way around. It will definitely avoid putting red lines over black ones: x - -6:16 z - outer(x,x) contour(z, labels=, col=2) contour(z, lty=0, labcex=1, add=TRUE) I played around a bit with you example, and can get almost the desired color and lack of cutting through labels. There is the possibility of plotting empty labels that create a space in the curves for the later labels-without-lines overlay: x - -6:16 z - outer(x,x) contour(z, labels=, col=2, labcex=1.5, drawlabels=TRUE) contour(z, lty=0, labcex=1.5, add=TRUE) Cheers, Peter (Ted Harding) wrote: Greetings, All! I want to draw contour lines in red, using contour(), but also have the contour labels (for the level-values) in black so that they will stand out against a coloured background already generated using filled.contour() (the background shades from green at low levels of risk to red at high levels). In any case, contour labels in red are already somewhat inconspicuous with contour lines in red, regardless of background. I see nothing in ?contour nor in ?par about this. One way to approach it could be to first draw the labelled contours in black, and then overlay by re-drawing (with out labels) in red. This would sort-of work, but the red contour lines would then cut through the black numbers, which is somewhat undesirable. Also (I've tried it) you can get show-through along the contour lines from the black layer, which is nasty. Any suggestions? With thanks, Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 22-Nov-09 Time: 17:06:08 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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.
[R] how to generate balanced sample from two normal distribution
Good afternoon, I have a question on generating simple randomization data. Thanks for any suggestions. Two normal distribution N(0,1) and N(1,1) A: I want to generate 20 data, 10 from N(0,1) and 10 from (1,1). each observation's indicator (either is from N(0,1) or N(1,1) ) is randomized. I need use the frist 10 data from the generated 20 dataset. (it is not necessary 5 from N(0,1) and 5 from N(1,1) for these 10 data, since the indicator for the 20 data is randomized) . For example, the 10 data's indicator could be 0 0 0 1 0 1 1 0 0 0 (0 means the observation is from N(0,1) and 1 indicates the observations is from N(1,1)) B: still the same 20 data generate data above. I want the indictor is forced to be balanced in the first 10 data. That is, if I use the first 10 data, 5 are from N(0,1) and 5 are from (1,1). For example, the 10 data's indicator could be 0 1 1 0 0 1 0 1 1 0 How can I generate the 20 data . Sorry it is a little confusing. I want to generate the data not the indicator. The dataset I want to generated in A is not balanced for the frist 10, in B it is balanced in the first 10. I want to use the same dataset, how can I use to method to randomize it. Thanks -- View this message in context: http://old.nabble.com/how-to-generate-balanced-sample-from-two-normal-distribution-tp26467900p26467900.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] mac os X: mprobit fails to install
Xcode is available for download here: http://developer.apple.com/technology/xcode.html As David noted, you do need to register, but it is free. Note also that it is a 750 Mb download. HTH, Marc Schwartz On Nov 22, 2009, at 3:11 PM, David Winsemius wrote: On Nov 22, 2009, at 4:00 PM, stephane Luchini wrote: Thanks. I have 10.5.8 with R 2.10.0 now (i still had 2.9 in my previous messages). I also have gcc-4.2 installed but no Xcode package. It still fails to install - can it be the Xcode package? Where can I find it - I don't have my install CDs with me and will not get them soon? Xcode is distributed free by Apple through its developer program. All you need to do is register, again, free, or at least it used to be so. You could also check the tools section of CRAN. I am not sufficient UNIXified to be an authoritative source on these issues. -- David Stephane 2009/11/22 David Winsemius dwinsem...@comcast.net: There were quite a few implicit declaration warning messages when I followed Phil's advice, but I do seem to get a complete build on a Mac 10.5.8 running 64 bit R 2.10.0. Have you installed the Xcode package? The gcc-4.2? -- David. On Nov 22, 2009, at 3:15 PM, SL wrote: I have tried your command but without success. Any idea? Here is my log: Macbook:$ PKG_CFLAGS=-I/usr/include/sys R CMD INSTALL mprobit_0.9-2.tar.gz * Installing to library ‘/Users/stephaneluchini/Library/R/2.9/ library’ * Installing *source* package ‘mprobit’ ... ** libs ** arch - i386 sh: make: command not found ERREUR : compilation failed pour le package ‘mprobit’ * Removing ‘/Users/stephaneluchini/Library/R/2.9/library/mprobit’ 2009/11/22 Phil Spector spec...@stat.berkeley.edu: Stephane - The check log indicated that malloc.h couldn't be found. Since that header file is located in /usr/include/sys on Macs, you could do the following: 1. Download mprobit_0.9-2.tar.gz from your local CRAN mirror. 2. At a terminal, type PKG_CFLAGS=-I/usr/include/sys R CMD INSTALL mprobit_0.9-2.tar.gz They'll be some warning messages, but the package should get built. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Sun, 22 Nov 2009, stephane Luchini wrote: Hi all, any chance that someone got through the installation problem of mprobit on mac os X? Stephane __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] mac os X: mprobit fails to install
Thanks to all, that was it! Xcode needed to be installed. For those who did not update to snow Leopard, things could be a bit tricky because apple did delete links to previous versions in search engines. On their site, one has to search through their download section. For snow leopard: version 3.2.1 For leopard : version 3.1.4 did the trick for me. I now can load mprobit in R - I still have to do some testing. Thanks again. Stephane 2009/11/22 Marc Schwartz marc_schwa...@me.com: Xcode is available for download here: http://developer.apple.com/technology/xcode.html As David noted, you do need to register, but it is free. Note also that it is a 750 Mb download. HTH, Marc Schwartz On Nov 22, 2009, at 3:11 PM, David Winsemius wrote: On Nov 22, 2009, at 4:00 PM, stephane Luchini wrote: Thanks. I have 10.5.8 with R 2.10.0 now (i still had 2.9 in my previous messages). I also have gcc-4.2 installed but no Xcode package. It still fails to install - can it be the Xcode package? Where can I find it - I don't have my install CDs with me and will not get them soon? Xcode is distributed free by Apple through its developer program. All you need to do is register, again, free, or at least it used to be so. You could also check the tools section of CRAN. I am not sufficient UNIXified to be an authoritative source on these issues. -- David Stephane 2009/11/22 David Winsemius dwinsem...@comcast.net: There were quite a few implicit declaration warning messages when I followed Phil's advice, but I do seem to get a complete build on a Mac 10.5.8 running 64 bit R 2.10.0. Have you installed the Xcode package? The gcc-4.2? -- David. On Nov 22, 2009, at 3:15 PM, SL wrote: I have tried your command but without success. Any idea? Here is my log: Macbook:$ PKG_CFLAGS=-I/usr/include/sys R CMD INSTALL mprobit_0.9-2.tar.gz * Installing to library ‘/Users/stephaneluchini/Library/R/2.9/library’ * Installing *source* package ‘mprobit’ ... ** libs ** arch - i386 sh: make: command not found ERREUR : compilation failed pour le package ‘mprobit’ * Removing ‘/Users/stephaneluchini/Library/R/2.9/library/mprobit’ 2009/11/22 Phil Spector spec...@stat.berkeley.edu: Stephane - The check log indicated that malloc.h couldn't be found. Since that header file is located in /usr/include/sys on Macs, you could do the following: 1. Download mprobit_0.9-2.tar.gz from your local CRAN mirror. 2. At a terminal, type PKG_CFLAGS=-I/usr/include/sys R CMD INSTALL mprobit_0.9-2.tar.gz They'll be some warning messages, but the package should get built. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Sun, 22 Nov 2009, stephane Luchini wrote: Hi all, any chance that someone got through the installation problem of mprobit on mac os X? Stephane __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how do i persuade IT to install R on PCs ?? ...and should I ??
On Sun, Nov 22, 2009 at 11:14 AM, frenchcr frenc...@btinternet.com wrote: Please help me persuade IT to install R on my computer! All suggestions welcome. Our IT department run scared when you mention software that they have no working experience of. I need to know the pros and cons of having R on corporate desktops. Please no funny stuff, this is quite a serious issue for us. Pros and cons would be good. Thanks. -- View this message in context: http://old.nabble.com/how-do-i-persuade-IT-to-install-R-on-PCs...and-should-Itp26464163p26464163.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. I requested to have R installed at work. For me it helped that I have a lot of non-standard technical packages anyway that are off radar for support from the IT department anyway - they only support for original install rights anyway. They wanted to know what the licence was - GPL is recognised and they don't run a mile. I did my homework and found some other people on a company research site were already using R so I could use that as justification. I had some code ready to run that could produce graphs easily that are very hard to do in Excel and require a lot of custom code (and even then aren't good). We do use some other stats packages anyway and are being encouraged to use proper packages rather than kludging through in Excel References like this (below) have been circulated at work which adds weight to arguments that we should not just accept the 'standard' Office install. Although I did not use this in my justification. @ARTICLE{, author = {B.D. McCullough and David A. Heiser}, title = {On the accuracy of statistical procedures in Microsoft Excel 2007}, journal = {Computational Statistics \ Data Analysis}, year = {2008}, volume = {52}, pages = {4570--4578}, number = {10} } ( http://dx.doi.org/10.1016/j.csda.2008.03.004) I use R via TINN-R (http://www.sciviews.org/Tinn-R/) on a Windows desktop. Stephen [[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] contour(): lines labels in different colours?
On 22/11/2009 5:21 PM, David Winsemius wrote: On Nov 22, 2009, at 4:57 PM, Peter Ehlers wrote: Hi Ted, This won't solve your problem, but a small improvement might be to place the labels over the lines rather than the other way around. It will definitely avoid putting red lines over black ones: x - -6:16 z - outer(x,x) contour(z, labels=, col=2) contour(z, lty=0, labcex=1, add=TRUE) I played around a bit with you example, and can get almost the desired color and lack of cutting through labels. There is the possibility of plotting empty labels that create a space in the curves for the later labels-without-lines overlay: x - -6:16 z - outer(x,x) contour(z, labels=, col=2, labcex=1.5, drawlabels=TRUE) contour(z, lty=0, labcex=1.5, add=TRUE) That's a nice solution. You could probably do a bit better in a couple of steps: 1st, figure out what the level labels will be (by default, pretty(range(z, finite=TRUE), 10) ), then compute an equivalent number of spaces, e.g. levels - pretty(range(z, finite=TRUE), 10) strwidth(levels, cex=1.5) / strwidth( , cex=0.5) Then use the appropriate number of spaces as the labels in the first plot, and the numbers in the second one. Do we have a simple function to take input like c(10, 12) and produce two character strings containing 10 and 12 spaces? Duncan Murdoch Cheers, Peter (Ted Harding) wrote: Greetings, All! I want to draw contour lines in red, using contour(), but also have the contour labels (for the level-values) in black so that they will stand out against a coloured background already generated using filled.contour() (the background shades from green at low levels of risk to red at high levels). In any case, contour labels in red are already somewhat inconspicuous with contour lines in red, regardless of background. I see nothing in ?contour nor in ?par about this. One way to approach it could be to first draw the labelled contours in black, and then overlay by re-drawing (with out labels) in red. This would sort-of work, but the red contour lines would then cut through the black numbers, which is somewhat undesirable. Also (I've tried it) you can get show-through along the contour lines from the black layer, which is nasty. Any suggestions? With thanks, Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 22-Nov-09 Time: 17:06:08 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] contour(): lines labels in different colours?
On 22/11/2009 5:35 PM, Duncan Murdoch wrote: On 22/11/2009 5:21 PM, David Winsemius wrote: On Nov 22, 2009, at 4:57 PM, Peter Ehlers wrote: Hi Ted, This won't solve your problem, but a small improvement might be to place the labels over the lines rather than the other way around. It will definitely avoid putting red lines over black ones: x - -6:16 z - outer(x,x) contour(z, labels=, col=2) contour(z, lty=0, labcex=1, add=TRUE) I played around a bit with you example, and can get almost the desired color and lack of cutting through labels. There is the possibility of plotting empty labels that create a space in the curves for the later labels-without-lines overlay: x - -6:16 z - outer(x,x) contour(z, labels=, col=2, labcex=1.5, drawlabels=TRUE) contour(z, lty=0, labcex=1.5, add=TRUE) That's a nice solution. You could probably do a bit better in a couple of steps: 1st, figure out what the level labels will be (by default, pretty(range(z, finite=TRUE), 10) ), then compute an equivalent number of spaces, e.g. levels - pretty(range(z, finite=TRUE), 10) strwidth(levels, cex=1.5) / strwidth( , cex=0.5) Then use the appropriate number of spaces as the labels in the first plot, and the numbers in the second one. Do we have a simple function to take input like c(10, 12) and produce two character strings containing 10 and 12 spaces? Here's a little implementation. It didn't work using different cex values for the spaces and the levels, but this seems okay: x - -6:16 z - outer(x,x) levels - pretty(range(z, finite=TRUE), 10) plot.new() # Might want a throwaway plot instead reps - round(strwidth(levels, cex=1.5) / strwidth( , cex=1.5)) spaces - sapply(reps, function(x) paste(rep( , round(x)), collapse=)) contour(z, labels=spaces, levels=levels, col=2, labcex=1.5, drawlabels=TRUE) contour(z, lty=0, labcex=1.5, add=TRUE) Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] contour(): lines labels in different colours?
On Nov 22, 2009, at 5:35 PM, Duncan Murdoch wrote: On 22/11/2009 5:21 PM, David Winsemius wrote: On Nov 22, 2009, at 4:57 PM, Peter Ehlers wrote: Hi Ted, This won't solve your problem, but a small improvement might be to place the labels over the lines rather than the other way around. It will definitely avoid putting red lines over black ones: x - -6:16 z - outer(x,x) contour(z, labels=, col=2) contour(z, lty=0, labcex=1, add=TRUE) I played around a bit with you example, and can get almost the desired color and lack of cutting through labels. There is the possibility of plotting empty labels that create a space in the curves for the later labels-without-lines overlay: x - -6:16 z - outer(x,x) contour(z, labels=, col=2, labcex=1.5, drawlabels=TRUE) contour(z, lty=0, labcex=1.5, add=TRUE) That's a nice solution. You could probably do a bit better in a couple of steps: 1st, figure out what the level labels will be (by default, pretty(range(z, finite=TRUE), 10) ), then compute an equivalent number of spaces, e.g. levels - pretty(range(z, finite=TRUE), 10) strwidth(levels, cex=1.5) / strwidth( , cex=0.5) Then use the appropriate number of spaces as the labels in the first plot, and the numbers in the second one. Do we have a simple function to take input like c(10, 12) and produce two character strings containing 10 and 12 spaces? Not sure it is simple but this (after more playing around) did the trick: library(R.oo) vecspaces - function(n) sapply(n, function(x) paste(rep(intToChar(32), x), sep=, collapse=) ) vecspaces(c(10,12) ) [1] vecspaces(1:10) [1] [8] -- David Duncan Murdoch Cheers, Peter (Ted Harding) wrote: Greetings, All! I want to draw contour lines in red, using contour(), but also have the contour labels (for the level-values) in black so that they will stand out against a coloured background already generated using filled.contour() (the background shades from green at low levels of risk to red at high levels). In any case, contour labels in red are already somewhat inconspicuous with contour lines in red, regardless of background. I see nothing in ?contour nor in ?par about this. One way to approach it could be to first draw the labelled contours in black, and then overlay by re-drawing (with out labels) in red. This would sort-of work, but the red contour lines would then cut through the black numbers, which is somewhat undesirable. Also (I've tried it) you can get show-through along the contour lines from the black layer, which is nasty. Any suggestions? With thanks, Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 22-Nov-09 Time: 17:06:08 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. 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. 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.
[R] optim(,SANN...)
Hi, Can anyone please tell me is there a way to view the annealing schedule when using SANN is optim. I have tried setting report=1 in the control list, but cannot seem to get it to work? Ant help or suggestions would be appreciated! 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] Removing + and ? signs
Hi all, I get an error message when trying to replace *+* or *?* signs (with empty space) from a string. x - asdf+,jkl? gsub(?, , x) Error message: Error in gsub(?, , x) : invalid regular expression '?' In addition: Warning message: In gsub(?, , x) : regcomp error: 'Invalid preceding regular expression' Your expertise in resolving this issue would be appreciated. Thanks. Steven [[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] Missing/Incomplete Data Study
Hi, I have a project where unsupervised learning failed to produce rules using Weka. I wanted to know if there are any tools in R that can be used to assess how well timestamps of event, task, load, and hardware logs for completeness or missing and incomplete data to be able to know whether it impacted our unsupervised approach. Please advise. [[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] contour(): lines labels in different colours?
Wow! (Top-posting for once, since there's no natural other place ...) Thanks Peter, David and Duuncan for the suggestions. I'll look at the later ones from David Duncan later (it's getting late here). However, as something to work on if you want to, here is a toy example, based on the same overall methodology as I'm using for my real plot (though the real one looks quite different): # library(MASS) set.seed(54321) X - rnorm(100) ; Y - rnorm(100) h0 - 2.0 W - kde2d(x=X,y=Y,n=100,h=c(h0,h0),lims=c(-3,3,-3,3)) Wmax - max(W$z) W$z - 10*(W$z/Wmax) Palette - colorRampPalette(c(lightgreen,red), interpolate=spline ) Levels - (1.0*(0:10)) filled.contour(x=W$x,y=W$y,z=W$z,levels=Levels, xlim=c(-3,3),ylim=c(-3,3), color.palette=Palette, plot.axes={axis(1);axis(2);points(X,Y,pch=+,col=blue); points(X,Y,pch=+,col=blue); contour(x=W$x,y=W$y,z=W$z,levels=Levels,labcex=1.5, col=red,add=TRUE, labels= , method=flattest ); contour(x=W$x,y=W$y,z=W$z,levels=Levels,labcex=1.5, lty=0,col=black,add=TRUE, method=flattest ); } ) # I've incorporated here the first two suggestiong from Peter and David, though not (yet) any of the later ones. One thing that emerges is that the two contour() plots don't quite match up as to where (or whether) the space from 'labels= ' in the first are made, and the placing of the labels in the second. I'll try the other suggestions and see what happens -- but I may end up doing the first plot (red) without labels, so that there's no break in the contours. Better, I think, to have the black labels simply stuck onto the red contours, than have some of them misaligned with bvreaks in the contours. Thank you all! Ted. On 22-Nov-09 22:53:03, David Winsemius wrote: On Nov 22, 2009, at 5:35 PM, Duncan Murdoch wrote: On 22/11/2009 5:21 PM, David Winsemius wrote: On Nov 22, 2009, at 4:57 PM, Peter Ehlers wrote: Hi Ted, This won't solve your problem, but a small improvement might be to place the labels over the lines rather than the other way around. It will definitely avoid putting red lines over black ones: x - -6:16 z - outer(x,x) contour(z, labels=, col=2) contour(z, lty=0, labcex=1, add=TRUE) I played around a bit with you example, and can get almost the desired color and lack of cutting through labels. There is the possibility of plotting empty labels that create a space in the curves for the later labels-without-lines overlay: x - -6:16 z - outer(x,x) contour(z, labels=, col=2, labcex=1.5, drawlabels=TRUE) contour(z, lty=0, labcex=1.5, add=TRUE) That's a nice solution. You could probably do a bit better in a couple of steps: 1st, figure out what the level labels will be (by default, pretty(range(z, finite=TRUE), 10) ), then compute an equivalent number of spaces, e.g. levels - pretty(range(z, finite=TRUE), 10) strwidth(levels, cex=1.5) / strwidth( , cex=0.5) Then use the appropriate number of spaces as the labels in the first plot, and the numbers in the second one. Do we have a simple function to take input like c(10, 12) and produce two character strings containing 10 and 12 spaces? Not sure it is simple but this (after more playing around) did the trick: library(R.oo) vecspaces - function(n) sapply(n, function(x) paste(rep(intToChar(32), x), sep=, collapse=) ) vecspaces(c(10,12) ) [1] vecspaces(1:10) [1] [8] -- David Duncan Murdoch Cheers, Peter (Ted Harding) wrote: Greetings, All! I want to draw contour lines in red, using contour(), but also have the contour labels (for the level-values) in black so that they will stand out against a coloured background already generated using filled.contour() (the background shades from green at low levels of risk to red at high levels). In any case, contour labels in red are already somewhat inconspicuous with contour lines in red, regardless of background. I see nothing in ?contour nor in ?par about this. One way to approach it could be to first draw the labelled contours in black, and then overlay by re-drawing (with out labels) in red. This would sort-of work, but the red contour lines would then cut through the black numbers, which is somewhat undesirable. Also (I've tried it) you can get show-through along the contour lines from the black layer, which is nasty. Any suggestions? With thanks, Ted. E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk Fax-to-email: +44 (0)870 094 0861 Date: 22-Nov-09 Time: 17:06:08 -- XFMail
Re: [R] how do i persuade IT to install R on PCs ?? ...and should I ??
On Nov 22, 2009, at 4:45 PM, stephen's mailinglist account wrote: On Sun, Nov 22, 2009 at 11:14 AM, frenchcr frenc...@btinternet.com wrote: Please help me persuade IT to install R on my computer! All suggestions welcome. Our IT department run scared when you mention software that they have no working experience of. I need to know the pros and cons of having R on corporate desktops. Please no funny stuff, this is quite a serious issue for us. Pros and cons would be good. Thanks. -- View this message in context: http://old.nabble.com/how-do-i-persuade-IT-to-install-R-on-PCs...and-should-Itp26464163p26464163.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. I requested to have R installed at work. For me it helped that I have a lot of non-standard technical packages anyway that are off radar for support from the IT department anyway - they only support for original install rights anyway. They wanted to know what the licence was - GPL is recognised and they don't run a mile. I did my homework and found some other people on a company research site were already using R so I could use that as justification. I had some code ready to run that could produce graphs easily that are very hard to do in Excel and require a lot of custom code (and even then aren't good). We do use some other stats packages anyway and are being encouraged to use proper packages rather than kludging through in Excel References like this (below) have been circulated at work which adds weight to arguments that we should not just accept the 'standard' Office install. Although I did not use this in my justification. @ARTICLE{, author = {B.D. McCullough and David A. Heiser}, I'm not surprised to see McCollough and Heiser's names on such an article. They have both a long track record of pointing out Excel's statistical deficiencies. (I don't they did so together in the past.) MS has turned a deaf ear to their efforts to point the way to correct methods. It is truly amazing that MS continues to ignore constrictive criticism and that such arrogance is compounded by corporate policies encouraging reliance on demonstrably faulty tools. The full list of articles documenting MS's resistance to statistical corrections would be much longer that just this one article and extends back more than a decade. title = {On the accuracy of statistical procedures in Microsoft Excel 2007}, journal = {Computational Statistics \ Data Analysis}, year = {2008}, volume = {52}, pages = {4570--4578}, number = {10} } ( http://dx.doi.org/10.1016/j.csda.2008.03.004) I use R via TINN-R (http://www.sciviews.org/Tinn-R/) on a Windows desktop. Stephen -- 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] Removing + and ? signs
'?' is a metacharacter in a regular expression. You have to escape it: x - asdf+,jkl? gsub(?, , x) Error in gsub(?, , x) : invalid regular expression '?' In addition: Warning message: In gsub(?, , x) : regcomp error: 'Invalid preceding regular expression' # escape it gsub(\\?, , x) [1] asdf+,jkl On Sun, Nov 22, 2009 at 6:01 PM, Steven Kang stochastick...@gmail.com wrote: Hi all, I get an error message when trying to replace *+* or *?* signs (with empty space) from a string. x - asdf+,jkl? gsub(?, , x) Error message: Error in gsub(?, , x) : invalid regular expression '?' In addition: Warning message: In gsub(?, , x) : regcomp error: 'Invalid preceding regular expression' Your expertise in resolving this issue would be appreciated. Thanks. Steven [[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? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Removing + and ? signs
Try this: gsub([?], , x) On Mon, Nov 23, 2009 at 7:01 AM, Steven Kang stochastick...@gmail.com wrote: Hi all, I get an error message when trying to replace *+* or *?* signs (with empty space) from a string. x - asdf+,jkl? gsub(?, , x) Error message: Error in gsub(?, , x) : invalid regular expression '?' In addition: Warning message: In gsub(?, , x) : regcomp error: 'Invalid preceding regular expression' Your expertise in resolving this issue would be appreciated. Thanks. Steven [[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] Removing + and ? signs
Dear Steven, You were almost there: x - asdf+,jkl? gsub(\\?, , x) [1] asdf+,jkl gsub(\\+, , x) [1] asdf,jkl? Take a look at the Basic Regular Expressions section in ?regex for more details. HTH, Jorge On Sun, Nov 22, 2009 at 6:01 PM, Steven Kang wrote: Hi all, I get an error message when trying to replace *+* or *?* signs (with empty space) from a string. x - asdf+,jkl? gsub(?, , x) Error message: Error in gsub(?, , x) : invalid regular expression '?' In addition: Warning message: In gsub(?, , x) : regcomp error: 'Invalid preceding regular expression' Your expertise in resolving this issue would be appreciated. Thanks. Steven [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Removing + and ? signs
On 23/11/2009, at 12:01 PM, Steven Kang wrote: Hi all, I get an error message when trying to replace *+* or *?* signs (with empty space) from a string. x - asdf+,jkl? gsub(?, , x) Error message: Error in gsub(?, , x) : invalid regular expression '?' In addition: Warning message: In gsub(?, , x) : regcomp error: 'Invalid preceding regular expression' Your expertise in resolving this issue would be appreciated. (a) That's funny. I don't get an error message when I try your example. I get [1] a s d f + , j k l ? Of course that's not what you want, though. (b) You need to escape the question mark: gsub(\\?, , x) yields [1] asdf+,jkl which I think *is* what you want. cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Removing + and ? signs
And if you want to replace both + and ?, here is a suggestion: x - asdf+,jkl? gsub([?]|[+], , x) # [1] asdf,jkl HTH, Jorge On Sun, Nov 22, 2009 at 6:46 PM, Jorge Ivan Velez wrote: Dear Steven, You were almost there: x - asdf+,jkl? gsub(\\?, , x) [1] asdf+,jkl gsub(\\+, , x) [1] asdf,jkl? Take a look at the Basic Regular Expressions section in ?regex for more details. HTH, Jorge On Sun, Nov 22, 2009 at 6:01 PM, Steven Kang wrote: Hi all, I get an error message when trying to replace *+* or *?* signs (with empty space) from a string. x - asdf+,jkl? gsub(?, , x) Error message: Error in gsub(?, , x) : invalid regular expression '?' In addition: Warning message: In gsub(?, , x) : regcomp error: 'Invalid preceding regular expression' Your expertise in resolving this issue would be appreciated. Thanks. Steven [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Removing + and ? signs
On Nov 22, 2009, at 6:01 PM, Steven Kang wrote: Hi all, I get an error message when trying to replace *+* or *?* signs (with empty space) from a string. x - asdf+,jkl? gsub(?, , x) Since both ? and + are special regex characters, to do both the substitutions at once you need to use double backslashes and an or gsub(\\?|\\+, , x) [1] asdf ,jkl -- David Error message: Error in gsub(?, , x) : invalid regular expression '?' In addition: Warning message: In gsub(?, , x) : regcomp error: 'Invalid preceding regular expression' Your expertise in resolving this issue would be appreciated. Thanks. Steven [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD 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.
[R] How to change line width in heatmap.2()?
I don't see an option to tune linewdith in heatmap.2(). Could somebody let me know how to tune the dendrogram line width? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to prevent lattic barchart from drawing bar completely to the bottom/left of the chart
?panel.barchart use the argument origin=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.
Re: [R] contour(): lines labels in different colours?
On 22/11/2009 6:28 PM, (Ted Harding) wrote: Wow! (Top-posting for once, since there's no natural other place ...) Thanks Peter, David and Duuncan for the suggestions. I'll look at the later ones from David Duncan later (it's getting late here). However, as something to work on if you want to, here is a toy example, based on the same overall methodology as I'm using for my real plot (though the real one looks quite different): # library(MASS) set.seed(54321) X - rnorm(100) ; Y - rnorm(100) h0 - 2.0 W - kde2d(x=X,y=Y,n=100,h=c(h0,h0),lims=c(-3,3,-3,3)) Wmax - max(W$z) W$z - 10*(W$z/Wmax) Palette - colorRampPalette(c(lightgreen,red), interpolate=spline ) Levels - (1.0*(0:10)) filled.contour(x=W$x,y=W$y,z=W$z,levels=Levels, xlim=c(-3,3),ylim=c(-3,3), color.palette=Palette, plot.axes={axis(1);axis(2);points(X,Y,pch=+,col=blue); points(X,Y,pch=+,col=blue); contour(x=W$x,y=W$y,z=W$z,levels=Levels,labcex=1.5, col=red,add=TRUE, labels= , method=flattest ); contour(x=W$x,y=W$y,z=W$z,levels=Levels,labcex=1.5, lty=0,col=black,add=TRUE, method=flattest ); } ) # I've incorporated here the first two suggestiong from Peter and David, though not (yet) any of the later ones. One thing that emerges is that the two contour() plots don't quite match up as to where (or whether) the space from 'labels= ' in the first are made, and the placing of the labels in the second. I'll try the other suggestions and see what happens -- but I may end up doing the first plot (red) without labels, so that there's no break in the contours. Better, I think, to have the black labels simply stuck onto the red contours, than have some of them misaligned with bvreaks in the contours. Here's a version of the last one I posted: filled.contour(x=W$x,y=W$y,z=W$z,levels=Levels, xlim=c(-3,3),ylim=c(-3,3), color.palette=Palette, plot.axes={axis(1);axis(2);points(X,Y,pch=+,col=blue); points(X,Y,pch=+,col=blue); reps - round(strwidth(Levels, cex=1.5) / strwidth( , cex=1.5)) spaces - sapply(reps, function(x) paste(rep( , round(x)), collapse=)) contour(x=W$x,y=W$y,z=W$z,labels=spaces,levels=Levels,labcex=1.5, col=red,add=TRUE, method=flattest, drawlabels=TRUE ); contour(x=W$x,y=W$y,z=W$z,levels=Levels,labcex=1.5, lty=0,col=black,add=TRUE, method=flattest ); } ) Duncan Murdoch Thank you all! Ted. On 22-Nov-09 22:53:03, David Winsemius wrote: On Nov 22, 2009, at 5:35 PM, Duncan Murdoch wrote: On 22/11/2009 5:21 PM, David Winsemius wrote: On Nov 22, 2009, at 4:57 PM, Peter Ehlers wrote: Hi Ted, This won't solve your problem, but a small improvement might be to place the labels over the lines rather than the other way around. It will definitely avoid putting red lines over black ones: x - -6:16 z - outer(x,x) contour(z, labels=, col=2) contour(z, lty=0, labcex=1, add=TRUE) I played around a bit with you example, and can get almost the desired color and lack of cutting through labels. There is the possibility of plotting empty labels that create a space in the curves for the later labels-without-lines overlay: x - -6:16 z - outer(x,x) contour(z, labels=, col=2, labcex=1.5, drawlabels=TRUE) contour(z, lty=0, labcex=1.5, add=TRUE) That's a nice solution. You could probably do a bit better in a couple of steps: 1st, figure out what the level labels will be (by default, pretty(range(z, finite=TRUE), 10) ), then compute an equivalent number of spaces, e.g. levels - pretty(range(z, finite=TRUE), 10) strwidth(levels, cex=1.5) / strwidth( , cex=0.5) Then use the appropriate number of spaces as the labels in the first plot, and the numbers in the second one. Do we have a simple function to take input like c(10, 12) and produce two character strings containing 10 and 12 spaces? Not sure it is simple but this (after more playing around) did the trick: library(R.oo) vecspaces - function(n) sapply(n, function(x) paste(rep(intToChar(32), x), sep=, collapse=) ) vecspaces(c(10,12) ) [1] vecspaces(1:10) [1] [8] -- David Duncan Murdoch Cheers, Peter (Ted Harding) wrote: Greetings, All! I want to draw contour lines in red, using contour(), but also have the contour labels (for the level-values) in black so that they will stand out against a coloured background already generated using filled.contour() (the background shades from green at low levels of risk to red at high levels). In any case, contour labels in red are already somewhat inconspicuous with contour lines in red,
[R] Help about stability analysis in R software!!!
 Hello people!! I'm trying to make a statistical analysis of stability through to package 'Agricolae', and procedure 'stability.par', but I don't get conclude the analysis. The problem is in my data set, that have missing value, and I didn't manage interpret the 'NA' used to assign missing value. Someone have any suggestion to solve the problem? I thank from now on! Regards, LuÃce. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] contour(): lines labels in different colours?
On Nov 22, 2009, at 8:01 PM, Duncan Murdoch wrote: On 22/11/2009 6:28 PM, (Ted Harding) wrote: Wow! (Top-posting for once, since there's no natural other place ...) Thanks Peter, David and Duuncan for the suggestions. I'll look at the later ones from David Duncan later (it's getting late here). However, as something to work on if you want to, here is a toy example, based on the same overall methodology as I'm using for my real plot (though the real one looks quite different): # library(MASS) set.seed(54321) X - rnorm(100) ; Y - rnorm(100) h0 - 2.0 W - kde2d(x=X,y=Y,n=100,h=c(h0,h0),lims=c(-3,3,-3,3)) Wmax - max(W$z) W$z - 10*(W$z/Wmax) Palette - colorRampPalette(c(lightgreen,red), interpolate=spline ) Levels - (1.0*(0:10)) filled.contour(x=W$x,y=W$y,z=W$z,levels=Levels, xlim=c(-3,3),ylim=c(-3,3), color.palette=Palette, plot.axes={axis(1);axis(2);points(X,Y,pch=+,col=blue); points(X,Y,pch=+,col=blue); contour(x=W$x,y=W$y,z=W$z,levels=Levels,labcex=1.5, col=red,add=TRUE, labels= , method=flattest ); contour(x=W$x,y=W$y,z=W$z,levels=Levels,labcex=1.5, lty=0,col=black,add=TRUE, method=flattest ); } ) # I've incorporated here the first two suggestiong from Peter and David, though not (yet) any of the later ones. One thing that emerges is that the two contour() plots don't quite match up as to where (or whether) the space from 'labels= ' in the first are made, and the placing of the labels in the second. I'll try the other suggestions and see what happens -- but I may end up doing the first plot (red) without labels, so that there's no break in the contours. Better, I think, to have the black labels simply stuck onto the red contours, than have some of them misaligned with bvreaks in the contours. Here's a version of the last one I posted: filled.contour(x=W$x,y=W$y,z=W$z,levels=Levels, xlim=c(-3,3),ylim=c(-3,3), color.palette=Palette, plot.axes={axis(1);axis(2);points(X,Y,pch=+,col=blue); points(X,Y,pch=+,col=blue); reps - round(strwidth(Levels, cex=1.5) / strwidth( , cex=1.5)) spaces - sapply(reps, function(x) paste(rep( , round(x)), collapse=)) contour(x=W$x,y=W$y,z=W$z,labels=spaces,levels=Levels,labcex=1.5, col=red,add=TRUE, method=flattest, drawlabels=TRUE ); contour(x=W$x,y=W$y,z=W$z,levels=Levels,labcex=1.5, lty=0,col=black,add=TRUE, method=flattest ); } ) I thought the code was good, although there is a duplicated points () call, but the offered colorPallete would be improved by going to lightyellow to blue and the points to orange. Also got bold labels to work. Still takes a bit of experimentation with the width of the space string when you vary the number of points for some reason: library(MASS) set.seed(54321) X - rnorm(500) ; Y - rnorm(500) h0 - 2.0 W - kde2d(x=X,y=Y,n=100,h=c(h0,h0),lims=c(-3,3,-3,3)) Wmax - max(W$z) W$z - 10*(W$z/Wmax) Palette - colorRampPalette(c(lightyellow,blue), interpolate=spline ) Levels - (1.0*(0:10)) filled.contour(x=W$x,y=W$y,z=W$z,levels=Levels, xlim=c(-3,3),ylim=c(-3,3), color.palette=Palette, plot.axes={axis(1);axis(2); points(X,Y,pch=+,col=orange, cex=.8); contour(x=W$x,y=W$y,z=W$z,levels=Levels,labcex=1.5, col=red,add=TRUE, labels= , method=flattest ); contour(x=W$x,y=W$y,z=W$z,levels=Levels,labcex=1.5, lty=0,col=black,vfont=c(sans serif, bold), add=TRUE, method=flattest ); } ) Duncan Murdoch Thank you all! Ted. On 22-Nov-09 22:53:03, David Winsemius wrote: On Nov 22, 2009, at 5:35 PM, Duncan Murdoch wrote: On 22/11/2009 5:21 PM, David Winsemius wrote: On Nov 22, 2009, at 4:57 PM, Peter Ehlers wrote: Hi Ted, This won't solve your problem, but a small improvement might be to place the labels over the lines rather than the other way around. It will definitely avoid putting red lines over black ones: x - -6:16 z - outer(x,x) contour(z, labels=, col=2) contour(z, lty=0, labcex=1, add=TRUE) I played around a bit with you example, and can get almost the desired color and lack of cutting through labels. There is the possibility of plotting empty labels that create a space in the curves for the later labels-without-lines overlay: x - -6:16 z - outer(x,x) contour(z, labels=, col=2, labcex=1.5, drawlabels=TRUE) contour(z, lty=0, labcex=1.5, add=TRUE) That's a nice solution. You could probably do a bit better in a couple of steps: 1st, figure out what the level labels will be (by default, pretty(range(z, finite=TRUE), 10) ), then compute an equivalent number of
Re: [R] how to tell if its better to standardize your data matrix first when you do principal
Hi Hadley , I really apreciate the suggestions you gave, It was helpful , but I still didnt quite get it all. and I really want to do a good job , so any comments would sure come helpful, please understand me . hadley wrote: You've asked the same question on stackoverflow.com and received the same answer. This is rude because it duplicates effort. If you urgently need a response to a question, perhaps you should consider paying for it. Hadley On Sun, Nov 22, 2009 at 12:04 PM, masterinex xevilgan...@hotmail.com wrote: so under which cases is it better to standardize the data matrix first ? also is PCA generally used to predict the response variable , should I keep that variable in my data matrix ? Uwe Ligges-3 wrote: masterinex wrote: Hi guys , Im trying to do principal component analysis in R . There is 2 ways of doing it , I believe. One is doing principal component analysis right away the other way is standardizing the matrix first using s = scale(m)and then apply principal component analysis. How do I tell what result is better ? What values in particular should i look at . I already managed to find the eigenvalues and eigenvectors , the proportion of variance for each eigenvector using both methods. Generally, it is better to standardize. But in some cases, e.g. for the same units in your variables indicating also the importance, it might make sense not to do so. You should think about the analysis, you cannot know which result is `better' unless you know an interpretation. I noticed that the proportion of the variance for the first pca without standardizing had a larger value . Is there a meaning to it ? Isnt this always the case? At last , if I am supposed to predict a variable ie weight should I drop the variable ie weight from my data matrix when I do principal component analysis ? This sounds a bit like homework. If that is the case, please ask your teacher rather than this list. Anyway, it does not make sense to predict weight using a linear combination (principle component) that contains weight, does it? Uwe Ligges __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://old.nabble.com/how-to-tell-if-its-better-to-standardize-your-data-matrix-first-when-you-do-principal-tp26462070p26466400.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. -- 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. -- View this message in context: http://old.nabble.com/how-to-tell-if-its-better-to-standardize-your-data-matrix-first-when-you-do-principal-tp26462070p26471673.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to generate balanced sample from two normal distribution
Thank you, Dennis. It really helps. That is what I want, for the first 10 obs in A, it is not necessary balanced. for the first 10 obs in B, it is balanced. But there is one thing I need maybe I didn't say it clear. I generate 20 observations first, I want permutation in these 20 then select the first ten. For the SAME 20 observation, I want permutation happens among the first ten and also the second ten. How can I use the same dataset (generated 20 observations) to do two kinds of permutations? Thanks a lot. gcheer3 wrote: Good afternoon, I have a question on generating simple randomization data. Thanks for any suggestions. Two normal distribution N(0,1) and N(1,1) A: I want to generate 20 data, 10 from N(0,1) and 10 from (1,1). each observation's indicator (either is from N(0,1) or N(1,1) ) is randomized. I need use the frist 10 data from the generated 20 dataset. (it is not necessary 5 from N(0,1) and 5 from N(1,1) for these 10 data, since the indicator for the 20 data is randomized) . For example, the 10 data's indicator could be 0 0 0 1 0 1 1 0 0 0 (0 means the observation is from N(0,1) and 1 indicates the observations is from N(1,1)) B: still the same 20 data generate data above. I want the indictor is forced to be balanced in the first 10 data. That is, if I use the first 10 data, 5 are from N(0,1) and 5 are from (1,1). For example, the 10 data's indicator could be 0 1 1 0 0 1 0 1 1 0 How can I generate the 20 data . Sorry it is a little confusing. I want to generate the data not the indicator. The dataset I want to generated in A is not balanced for the frist 10, in B it is balanced in the first 10. I want to use the same dataset, how can I use to method to randomize it. Thanks -- View this message in context: http://old.nabble.com/how-to-generate-balanced-sample-from-two-normal-distribution-tp26467900p26471382.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How do I change the colour and format for the trelli plot ?
NICE!!! thanks Deepayan Sarkar wrote: On Thu, Nov 19, 2009 at 6:03 AM, ychu066 ychu...@aucklanduni.ac.nz wrote: http://old.nabble.com/file/p26418382/hist1.png hist1.png i want three plots along on the side , how to i do that ? and I also want to change the colour of the bars for each plot, how do i do that ? i got the code here to draw that .. This code did not produce the plot you have linked to. The answer to your question depends on how you created the plot, so you have to tell us that. Changing the color in all panels is easy: histogram(rnorm(100), col = goldenrod) Different colors in different panels is a little more work: histogram(~rnorm(100) | gl(3, 1, 100), mycolors = sample(colors(), 3), panel = function(..., col, mycolors) { panel.histogram(..., col = mycolors[panel.number()]) }) -Deepayan columns - 8:153 plots - vector(list, length(columns)) j - 0 for (i in columns) { plots[[ j - j+1 ]] - histogram( ~ data[,i], ylab = Frequency, xlab = Score, xlim = c(1,5), ylim = c(0,100), main = colnames(data)[i] ) } print(plots[[1]]) # or export for (i in seq_along(plots)) { png(paste(hist, i, .png, sep = )) print(plots[[i]]) dev.off() } -- View this message in context: http://old.nabble.com/How-do-I-change-the-colour-and-format-for-the-trelli-plot---tp26418382p26418382.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://old.nabble.com/How-do-I-change-the-colour-and-format-for-the-trelli-plot---tp26418382p26471627.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How do I change the colour and format for the trelli plot ?
anyone know how to add some text on the panel ??? for example 2.5, 50 and 1000 are mearsured in Litre, and i want to put the units beside the measurements. How could i do that? ychu066 wrote: NICE!!! thanks Deepayan Sarkar wrote: On Thu, Nov 19, 2009 at 6:03 AM, ychu066 ychu...@aucklanduni.ac.nz wrote: http://old.nabble.com/file/p26418382/hist1.png hist1.png i want three plots along on the side , how to i do that ? and I also want to change the colour of the bars for each plot, how do i do that ? i got the code here to draw that .. This code did not produce the plot you have linked to. The answer to your question depends on how you created the plot, so you have to tell us that. Changing the color in all panels is easy: histogram(rnorm(100), col = goldenrod) Different colors in different panels is a little more work: histogram(~rnorm(100) | gl(3, 1, 100), mycolors = sample(colors(), 3), panel = function(..., col, mycolors) { panel.histogram(..., col = mycolors[panel.number()]) }) -Deepayan columns - 8:153 plots - vector(list, length(columns)) j - 0 for (i in columns) { plots[[ j - j+1 ]] - histogram( ~ data[,i], ylab = Frequency, xlab = Score, xlim = c(1,5), ylim = c(0,100), main = colnames(data)[i] ) } print(plots[[1]]) # or export for (i in seq_along(plots)) { png(paste(hist, i, .png, sep = )) print(plots[[i]]) dev.off() } -- View this message in context: http://old.nabble.com/How-do-I-change-the-colour-and-format-for-the-trelli-plot---tp26418382p26418382.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. http://old.nabble.com/file/p26471713/hist1.png hist1.png -- View this message in context: http://old.nabble.com/How-do-I-change-the-colour-and-format-for-the-trelli-plot---tp26418382p26471713.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] Help about stability analysis in R software!!!
On Nov 22, 2009, at 8:19 PM, lugobueno wrote: Â Hello people!! I'm trying to make a statistical analysis of stability through to package 'Agricolae', and procedure 'stability.par', but I don't get conclude the analysis. The problem is in my data set, that have missing value, and I didn't manage interpret the 'NA' used to assign missing value. Someone have any suggestion to solve the problem? It's a bit hard to tell from what you have offered, but perhaps you should be looking at ?is.na ...and making sure you understand that is.na is capable of doing more than returning logical vectors. I thank from now on! Regards, LuÃce. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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.
[R] dynlm predict with newdata?
Hello, can one use predict, as you can with other model objects like lm, with dynlm to predict a new data set that is identical in field names, just a different time period. Be nice if you could, I don't really want to create a new data set with all the lags, hoping it would generate dynamically. Does not seem to work, get a # of column error. Any suggestions? R str(dfz) An 'xts' object from 2009-09-25 09:45:06 to 2009-10-19 15:00:57 containing: Data: num [1:28232, 1:8] 0.54771 -0.00825 1.27406 0.69705 1.08107 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:8] PC1 PC2 PC3 PC4 ... Indexed by objects of class: [POSIXt,POSIXct] TZ: GMT xts Attributes: NULL R str(z) An 'xts' object from 2009-10-21 09:45:04 to 2009-10-21 15:00:56 containing: Data: num [1:2304, 1:8] -0.5044 1.237 -0.7764 0.3931 0.0629 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:8] PC1 PC2 PC3 PC4 ... Indexed by objects of class: [POSIXt,POSIXct] TZ: GMT xts Attributes: NULL dols = dynlm(FAS0 ~ L(FAS0,1:10) + L(PC1,0:10) + L(PC2,0:10) + L(PC3,0:10) + L(PC4,0:10) + L(PC5,0:10) + L(PC6,0:10) + L(PC7,0:10), data=dfz) R predict(dols,newdata=z) /*Error in fix.by(by.x, x) : 'by' must match numbers of columns*/ [[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.