Re: [R] list.files recursively to find files in a specific way...
But using the approproate tool, Sys.glob, whould be much simpler. Note that 'pattern' in list.files is - a regexp, and '.' is a special character in a regexp: Phil's solution also needs to escape it or use fixed = TRUE - it is documented to match file *names*, not file paths. One of the authors of list.files and the author of Sys.glob On Tue, 19 Jul 2011, Phil Spector wrote: Pei - A file pattern can't contain a directory separator, but it's easy to search for one outside the context of list.files. I think grep('B/file2.txt',list.files(path = routeStr, all.files = TRUE, full.names = TRUE, recursive = TRUE),value=TRUE) should give you what you want. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Tue, 19 Jul 2011, JIA Pei wrote: Hi, all: My folders are organized in such a way: root branch1 ---A ---file1.txt ---file2.txt ---B ---file1.txt ---file2.txt branch2 ---A ---file1.txt ---file2.txt ---B ---file1.txt ---file2.txt ... branch100 ---A ---file1.txt ---file2.txt ---B ---file1.txt ---file2.txt I'd love to list all file2.txt from all subdirectories Bs but not from As, how to do that? I tried the following two a) allResults - list.files(path = routeStr, pattern = file2.txt, all.files = TRUE, full.names = TRUE, recursive = TRUE); gives me 200 files in allResults, which is wrong. There should be only 100 files in allResults. b) allResults - list.files(path = routeStr, pattern = B/file2.txt, all.files = TRUE, full.names = TRUE, recursive = TRUE); still wrong. It give me nothing, namely, 0 file(s) in allResults. Can anybody help to solve this problem? Best Regards Pei -- Pei JIA Email: jp4w...@gmail.com cell:+1 604-362-5816 Welcome to Vision Open http://www.visionopen.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with RODBC
David Scott-6 wrote: I have been trying to read some data from an Excel workbook without success. ... faults - sqlFetch(channel, sqtable = 'Data', +colnames = FALSE, as.is = TRUE) faults [1] HY001 -1040 [Microsoft][ODBC Excel Driver] Too many fields defined. [2] [RODBC] ERROR: Could not SQLExecDirect 'SELECT * FROM [Data$]' I have given up using odbc/Excel without named ranges, but I know it works sometimes. xlsReadWrite works well for whole sheets, while the gdata/Perl solutions can be terribly slow (minutes instead of seconds) with large files. I had seen the message above before, and it had to do with some invisible characters in the fields. I managed to get it to work by exporting value of the sheet, which seems to do a cleanup. Alternatively, a Copy/PasteValue. After that, my curiosity was satisfied, and I returned to named ranges or xlsReadWrite. Dieter -- View this message in context: http://r.789695.n4.nabble.com/Problem-with-RODBC-tp3680047p3680108.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] grouping data
adolfpf wrote: How do I group my data in dolf the same way the data Orthodont are grouped. show(dolf) distance age Subjectt Sex 16.83679 22.01 F1 F 26.63245 23.04 F1 F 3 11.58730 39.26 M2 M I know that many sample in that excellent book use grouped data, but the concept of grouped data is more confusing than helpful. I only got started using nlme/lme when I realized that everything could be done without grouped data. Too bad, many examples in Pinheiro/Bates rely on the concept (but no longer do in the coing lme4). So I suggest that you try to solve the problem with vanilla data frames instead of grouped ones. In most cases, it only means that you have to put the formula into the lme(..) call instead of relying on some hidden defaults. Dieter -- View this message in context: http://r.789695.n4.nabble.com/grouping-data-tp3679803p3680115.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] Setting packet order and display order in lattice barchat
Greetings In a lattice barchart (lattice_0.19-26, R 2.12.1), I am trying to control the order in which packets are displayed (in other words, which packet goes in which panel), and the order in which bars are displayed in each panel. I tried the simple idea of changing the levels of the relevant variables but found that this changes the panel and bar labels, but not the data. I've tried many more complicated ideas, too, also to no avail. I've attached a little test program, along with input data, and output images. I appreciate the help! Many thanks, Nat Goodman Nathan (Nat) Goodman Senior Research Scientist Institute for Systems Biology 401 Terry Avenue North Seattle, WA 98109-5234 206-331-0077 206-363-0431 (fax) n...@shore.net or ngood...@systemsbiology.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] bar chart issue
Hi everyone, I determined the presence of three types parasites in a passerine bird over two years. I would like to create a bar chart that shows the proportion infected on the y and year/parasite on the x such that each type of parasite is grouped together (single label) and a bar for each year . This would show if there have been changes in the prevalence of a the parasite over two years. This is the summary data: ParasiteYear Infected Leukocytozoon 2009 0.2564 Plasmodium 2009 0.3846 Hemoproteus2009 0.0769 Leukocytozoon 2010 0.0562 Plasmodium 2010 0.7079 Hemoproteus2010 0.3034 Any2009 0.5128 Any2010 0.7753 Here are rows 86 to 92. Band and site were recorded differently each year but these are not part of any calculation. Year band site Plasmodium Hemoproteus Leukocytozoon Any 86 2010 2341-06597 1041 1 1 1 1 87 2010 2341-06598 1041 0 0 0 0 88 2010 2341-06599 1042 1 1 0 1 89 2010 2341-06600 1042 0 1 0 1 90 2009 6443 SOSP0901 0 0 1 1 91 2009 6444 SOSP0902 0 1 0 1 92 2009 6445 SOSP0903 0 0 0 0 Any suggestions on how to create this plot would be greatly appreciated. Many thanks, Jeff * Jeffrey A. Stratford, Ph.D. Department of Health and Biological Sciences 84 W. South St. Wilkes Univertsity, PA 18766 570-332-2942 http://web.wilkes.edu/jeffrey.stratford/ * [[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] Hardy Weinberg Case Control Test in gap R package
As an alternative, you could try the HWExact function in the GWASExactHW package. (Haven't tried it myself though ...). Brad - Original Message - From: Jim Silverton jim.silver...@gmail.com To: r-help@r-project.org Sent: Tuesday, 12 July, 2011 8:33:54 PM Subject: Re: [R] Hardy Weinberg Case Control Test in gap R package Hi, I am using the gap R package to do the Hardy Weinberg Case Control test for many SNP. I am not sure what the values initial1 and initial2 should be for the test. I tried values but they failed. I emailed the author but to no avail. There seems to be some documentation that is deleted at the top, if anyone can direct me how to get this I will be grateful. -- Thanks, Jim. [[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] multiple plots in single frame: 2 upper, 1 lower
Hi, par(mfrow = c(2,2)) will create a 2x2 window that I can use to plot 4 diferent figures in: [plot1 plot2] [plot3 plot4] But how can do 3 so that the bottom spans the width of the upper two: [plot1 plot1] [p l o t 3] Is this possible in R? -- View this message in context: http://r.789695.n4.nabble.com/multiple-plots-in-single-frame-2-upper-1-lower-tp3679574p3679574.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] Deviance of zeroinfl/hurdle models
bbolker wrote: What about library(pscl) example(hurdle) -2*logLik(fm_hnb2) ? Should this not be -2*(logLik(M) - logLik(S)) where M is the current model and S is the saturated or full model? In which case, is it safe to assume that L(S) = 0? Or have I got my deviances crossed? Carson - Carson J. Q. Farmer Doctoral Fellow National Centre for Geocomputation National University of Ireland, Maynooth -- View this message in context: http://r.789695.n4.nabble.com/Deviance-of-zeroinfl-hurdle-models-tp3663196p3679780.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] Different result of multiple regression in R and SPSS
@Dimitri: I tried to enter it as numeric and still got the same outcome. I still wonder if there is any way to get the same result from both programs. @David, Bert: Yes, I found that the gender coefficient is R is exactly twice that of the one from SPSS. Need to study on parametrization. Thanks, Jay -- View this message in context: http://r.789695.n4.nabble.com/Different-result-of-multiple-regression-in-R-and-SPSS-tp3679423p3679590.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] grouping data
All the examples in 'nlme' are in Grouped Data: distance ~ age | Subject format. How do I group my data in dolf the same way the data Orthodont are grouped. show(dolf) distance age Subjectt Sex 16.83679 22.01 F1 F 26.63245 23.04 F1 F 3 11.58730 39.26 M2 M show(Orthodont) Grouped Data: distance ~ age | Subject distance age SubjectSex 1 26.0 8 M01 Male 2 25.0 10 M01 Male 3 29.0 12 M01 Male -- View this message in context: http://r.789695.n4.nabble.com/grouping-data-tp3679803p3679803.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] Different result of multiple regression in R and SPSS
I finally got the same result by converting gender variable as numeric, and standardize it. I guess SPSS automatically doing the same thing when doing analysis. But, it still is not clear to me how I can interpret standardized categorical (dummy coded) variable. I'd rather stick to use R. Thanks for all the comments and advice. Jay -- View this message in context: http://r.789695.n4.nabble.com/Different-result-of-multiple-regression-in-R-and-SPSS-tp3679423p3679835.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] multiple plots in single frame: 2 upper, 1 lower
Hi, Try looking at ?layout. Here is a simple example: layout(matrix(c(1, 2, 3, 3), 2, byrow = TRUE)) plot(1:10); plot(11:20); plot(21:40) Cheers, Josh On Tue, Jul 19, 2011 at 4:07 PM, DrCJones matthias.godd...@gmail.com wrote: Hi, par(mfrow = c(2,2)) will create a 2x2 window that I can use to plot 4 diferent figures in: [plot1 plot2] [plot3 plot4] But how can do 3 so that the bottom spans the width of the upper two: [plot1 plot1] [p l o t 3] Is this possible in R? -- View this message in context: http://r.789695.n4.nabble.com/multiple-plots-in-single-frame-2-upper-1-lower-tp3679574p3679574.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. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles https://joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] multiple plots in single frame: 2 upper, 1 lower
DrCJones wrote: But how can do 3 so that the bottom spans the width of the upper two: [plot1 plot1] [p l o t 3] ?layout for standard graphics (plot..), but that's what you are referring to. For trellis, you must use other methods. Dieter -- View this message in context: http://r.789695.n4.nabble.com/multiple-plots-in-single-frame-2-upper-1-lower-tp3679574p3680128.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] Is it possible to save raster data as a bitmap?
Hi all, I intend to use R for some image manipulations/analysis. It's relatively straightforward to read and manipulate image files in R, but I also would like to store the resulting image (after manipulation) as a bitmap image with the same resolution as the original image. Here is a simplified version of what I'm working on: # Start example require(RImageJ) # first open image and store as raster logo - system.file(images, R.jpg, package = RImageJ) img - as.raster(IJ$openImage(logo)) # do some modifications modify - as.raster(matrix(hsv(1, 1, 0.5 * rgb2hsv(col2rgb(img))[3,]), nrow(img), ncol(img))) # End example The next step in the example would be to store the raster data 'modify' as a bitmap image. I know that the 'image' function of the 'graphics' library might be usable for this purpose. However, I'm at a loss on how to maintain the exact RGB-information of each pixel using the 'image' function. Any suggestions on this issue would be most welcome. Thanks in advance! Cheers, Pepijn de Vries M.Sc. Research Scientist Institute for Marine Resources and Ecosystem Studies (IMARES) www.imares.nl __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] cforest - keep.forest = false option? (fwd)
-- Forwarded message -- Date: Mon, 18 Jul 2011 10:17:00 -0700 (PDT) From: KHOFF kuph...@gmail.com To: r-help@r-project.org Subject: [R] cforest - keep.forest = false option? Hi, I'm very new to R. I am most interested in the variable importance measures that result from randomForest, but many of my predictors are highly correlated. My first question is: 1. do highly correlated variables render variable importance measures in randomForest invalid? that depends on your idea of valid. A number of papers published over the last years explore this question and you should read the relevant literature first. and 2. I know that cforest is robust to highly correlated variables, however, I do not have enough space on my machine to run cforest. I used the keep.forest = false option when using randomForest and that solved my space issue. Is there a similar option for cforest (besides savesplitstats = FALSE, which isn't helping) no. party was designed as a flexible research tool and is not optimized wrt speed or memory consumption. Best, Torsten below is my code and error message Thanks in advance! fit - cforest(formula = y ~ x1 + x2+ x3+ x4+ x5+ + x6+ x7+ x8+ x9+ x10, data=data, control= cforest_unbiased(savesplitstats = FALSE, ntree = 50, mtry = 5) 1: In mf$data - data : Reached total allocation of 3955Mb: see help(memory.size) 2: In mf$data - data : Reached total allocation of 3955Mb: see help(memory.size) -- View this message in context: http://r.789695.n4.nabble.com/cforest-keep-forest-false-option-tp3675921p3675921.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.
Re: [R] Doesnt' winedt 6 version work as Rwinedt?
You may want to try out the beta (!!!) version of a new RWinEdt available from http://www.statistik.tu-dortmund.de/~ligges/RWinEdt Please use R-2.13.1 or later to try it out (2.13.0 won't work with Windows 7 and RWinEdt). Best, Uwe Ligges On 18.07.2011 23:16, Soyeon Kim wrote: Dear All, I've tried install Rwinedt using my Winedt 6. I cannot see R tab in Rwinedt even though I followed the instruction. (Installed RWinEdt and called the library) Version 6 doesn't work? If not, if would you recommend an R editor for window user?(Except for Emacs) Thanks, [[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] Fwd: Help please
Hi All, This is not really an R question but a statistical one. If someone could either give me the brief explanation or point me to a reference that might help, I'd appreciate it. I want to estimate the mean of a log-normal distribution, given the (log scale normal) parameters mu and sigma squared (sigma2). I understood this should simply be: exp(mu + sigma2) ... but I the following code gives me something strange: R - 1000 mu - -400 sigma2 - 200 tmp - rlnorm(R, mu, sqrt(sigma2)) # a sample from the desired log-normal distribution muh - mean(log(tmp)) sigma2h - var(log(tmp)) #by my understanding, all of the the following vectors should then contain very similar numbers c(mu, muh) c(sigma2, sigma2h) c(exp(mu + sigma2/2), exp(muh + sigma2h/2), mean(tmp)) I get the following (for one sample): c(mu, muh) [1] -400. -400.0231 c(sigma2, sigma2h) [1] 200. 199.5895 c(exp(mu + sigma2/2), exp(muh + sigma2h/2), mean(tmp)) [1] 5.148200e-131 4.097249e-131 5.095888e-150 so they do all contain similar numbers, with the exception of the last vector, which is out by a factor of 10^19. Is this likely to be because one needs **very** large samples to get a reasonable estimate of the mean... or am I missing something? Regards, Simon [[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] Incorrect degrees of freedom for splines using GAMM4?
Melinda, Any chance you could send me the data that goes with this, offline, (if you can, I'll only use the data for investigating this issue, of course)? I can reproduce something going wrong with the edf computation for fixed smooths in gamm4, when there are random effects, but I can't get anywhere near as extreme a discrepancy as you are seeing. Also, I can't get anything to go wrong in mgcv, (actually you didn't paste the mgcv code, but rather another gamm4 call? could you send the mgcv code too?). Also, could you send me gamm4, mgcv and R version numbers, please? best, Simon On 19/07/11 22:16, Melinda Power wrote: Hello, I'm running mixed models in GAMM4 with 2 (non-nested) random intercepts and I want to include a spline term for one of my exposure variables. However, when I include a spline term, I always get reported degrees of freedom of less than 1, even when I know that my spline is using more than 1 degree of freedom. For example, here is the code for my model: global.gamm4-gamm4(zcog~s(adjpatx, fx=TRUE, k=5)+int234+cogagec+cogagesq + + + oldfran +newus +alc2 +alc3 +alc4 +alcmiss +smk2 +smk3 + +mdinc10c +mdinc10sq+ pwhtc +pwhtsq +edu2+ edu3 +husbgs +husbcol+ husbmiss + +currpmh +pastpmh +neverpmh, random= ~(1|id) +(1|cogtest), data=global) Using summary(global.gamm4$mer), I get the following output for my spline term, indicating that I use the expected 4 degrees of freedom. Xs(adjpatx)Fx1 0.1018943 0.1073225 0.949 Xs(adjpatx)Fx2 -0.0708114 0.1123845 -0.630 Xs(adjpatx)Fx3 0.7459511 0.6836413 1.091 Xs(adjpatx)Fx4 -0.2062321 0.0923569 -2.233 However, when I use summary(global.gamm4$gam). I get an estimate of degrees of freedom that is not 4: Approximate significance of smooth terms: edf Ref.df F p-value s(adjpatx) 0.7588 0.7588 1.346 0.234 This degree of freedom = 0.76 also shows up on my plot. Ultimately, I would like to use a cubic regression penalized spline, allowing R to choose the degrees of freedom for me using GCV. However, when I use the correct code for this or variants of it using mgcv, I also get degrees of freedom less than 1. For example, in the following code provides a degree of freedom of less than 1 as well: global.gamm4-gamm4(zcog~s(adjpatx, fx=FALSE)+int234+cogagec+cogagesq + + + oldfran +newus +alc2 +alc3 +alc4 +alcmiss +smk2 +smk3 + +mdinc10c +mdinc10sq+ pwhtc +pwhtsq +edu2+ edu3 +husbgs +husbcol+ husbmiss + +currpmh +pastpmh +neverpmh, random= ~(1|id) +(1|cogtest), data=global) Output indicating that this spline should probably look linear: summary(global.gamm4$mer) Random effects: Groups NameVariance Std.Dev. id (Intercept) 0.1823454 0.427019 cogtest (Intercept) 0.0025498 0.050496 Xr.1 s(adjtibx) 0.000 0.00 Residual 0.7782969 0.882211 Xs(adjtibx)Fx1 -0.0387360 0.0215596 -1.797 Output getting a df for this spline of 0.20. summary(global.gamm4$gam) Approximate significance of smooth terms: edf Ref.df F p-value s(adjtibx) 0.2009 0.2009 16.07 NA The plot looks linear, but reports a df =0.20. So...to summarize my questions: 1. Are the splines produced by s(exp, fx=FALSE) or s(exp, fx=TRUE, k=k) correct even though the reported degrees of freedom appears to be wrong? 2. Can I believe my plot? 3. How can I get the true df used when I use s(exp, fx=FALSE)? Thanks for any and all help you can provide! Melinda [[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. -- Simon Wood, Mathematical Science, University of Bath BA2 7AY UK +44 (0)1225 386603 http://people.bath.ac.uk/sw283 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Warning in ansari.test
Dear list, When I try to run the Ansari-Bradley test on two long vectors I obtain a warning and the p-value is NA: set.seed(12) x - rnorm(10) y - rnorm(10) ansari.test(x,y) Ansari-Bradley test data: x and y AB = 5002890779, p-value = NA alternative hypothesis: true ratio of scales is not equal to 1 Warning message: In m * n : NAs produced by integer overflow This operation occurs inside a function named normalize(): normalize - function(s, r, TIES, m = length(x), n = length(y)) { } If I add these two lines to the beginning of the function: m - as.double(m) n - as.double(n) Then I obtain the following: Myansari.test(x,y) Ansari-Bradley test data: x and y AB = 5002890779, p-value = 0.6599 alternative hypothesis: true ratio of scales is not equal to 1 Is this a proper fix for the problem? PS: I'm running 2.13.1 Cheers, Oscar Oscar M. Rueda, PhD. Postdoctoral Research Fellow, Breast Cancer Functional Genomics. Cancer Research UK Cambridge Research Institute. Li Ka Shing Centre, Robinson Way. Cambridge CB2 0RE England NOTICE AND DISCLAIMER This e-mail (including any attachments) is intended for ...{{dropped:16}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Latex Table for means and standard deviations in brackets
Hello all, I am new to xtable. I have several datasets in the form of matrices. Consider the following two simple datasets which are 2 x 3 matrices. The rows in both matrices have the same meaning. For example the first row of both matrices are variable 1 and the second row of both matrices are variable 2. dataset1 = matrix( c(1,2,3,4, 5, 6 ), 2 , 3) dataset2 = matrix( c(4,3,5,10, 1, 0), 2, 3) I would like to find the means and standard deviations in brackets for each data set in the form of a table that looks like: dataset1 dataset2 var1 2 3 (1.3) (2.5) var2 410 (2.3) (1.2) ( I used the wrong numbers). But does anyone has any idea how Xtable or some other R package can automatically create the latex table? -- Thanks, Jim. [[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] Calculating mean from wit mice (multiple imputation)
Hi all, How can I calculate the mean from several imputed data sets with the package mice? I know you can estimate regression parameters with, for example, lm and subsequently pool those parameters to get a point estimate using functions included in mice. But if I want to calculate the mean value of a variable over my multiple imputed data sets with fit - with(data=imp, expr=mean(y)) and pool(fit), I get the warning: Error in pool(fit) : Object has no coef() method. Does anyone know what is happening, and is there another way of calculating means? Thanks. -- View this message in context: http://r.789695.n4.nabble.com/Calculating-mean-from-wit-mice-multiple-imputation-tp3680347p3680347.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] bar chart issue
Hi Jeff, One way to graph the differences between the two years for the first set of data is via barchart(), a function equivalent to barplot in the lattice package. Please check if with this portion of code (and with your data) the graph you get is quite self-explanatory. ### require(lattice) Lines-Parasite Year Infected Leukocytozoon 2009 0.2564 Plasmodium 2009 0.3846 Hemoproteus 2009 0.0769 Leukocytozoon 2010 0.0562 Plasmodium 2010 0.7079 Hemoproteus 2010 0.3034 Any 2009 0.5128 Any 2010 0.7753 DF - read.table(textConnection(Lines), skip=1, as.is = TRUE, col.names=c(Parasite, Year, Infected) ) barchart( Infected ~ Parasite, data=DF, groups=as.factor(Year), auto.key = list(space = bottom), origin=0 ) ## Regards, Carlos Ortega www.qualityexcellence.es On Wed, Jul 20, 2011 at 5:56 AM, Stratford, Jeffrey jeffrey.stratf...@wilkes.edu wrote: Hi everyone, I determined the presence of three types parasites in a passerine bird over two years. I would like to create a bar chart that shows the proportion infected on the y and year/parasite on the x such that each type of parasite is grouped together (single label) and a bar for each year . This would show if there have been changes in the prevalence of a the parasite over two years. This is the summary data: ParasiteYear Infected Leukocytozoon 2009 0.2564 Plasmodium 2009 0.3846 Hemoproteus2009 0.0769 Leukocytozoon 2010 0.0562 Plasmodium 2010 0.7079 Hemoproteus2010 0.3034 Any2009 0.5128 Any2010 0.7753 Here are rows 86 to 92. Band and site were recorded differently each year but these are not part of any calculation. Year band site Plasmodium Hemoproteus Leukocytozoon Any 86 2010 2341-06597 1041 1 1 1 1 87 2010 2341-06598 1041 0 0 0 0 88 2010 2341-06599 1042 1 1 0 1 89 2010 2341-06600 1042 0 1 0 1 90 2009 6443 SOSP0901 0 0 1 1 91 2009 6444 SOSP0902 0 1 0 1 92 2009 6445 SOSP0903 0 0 0 0 Any suggestions on how to create this plot would be greatly appreciated. Many thanks, Jeff * Jeffrey A. Stratford, Ph.D. Department of Health and Biological Sciences 84 W. South St. Wilkes Univertsity, PA 18766 570-332-2942 http://web.wilkes.edu/jeffrey.stratford/ * [[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] list.files recursively to find files in a specific way...
I don't think the OP specified an operating system, but... A few weeks ago I had a closely analogous problem, seeking files 'menus.txt' in subdirectories 'etc' but not from other subdirectories; '/etc/menus.txt'. I made this post http://tolstoy.newcastle.edu.au/R/e14/help/11/06/5685.html, but it was unanswered - I tend to ramble :-( An appropriate Sys.glob construction was: Sys.glob(file.path(.libPaths(), */etc/menus.txt)) I suggested that under MS Windows Sys.glob() cannot handle a UNC path beginning with backslashes. Was I correct? If so, I suggested an equivalent list.files construction (where I did escape '.') as: list.files(path=file.path(list.files(path=.libPaths(), full.names=TRUE), etc), pattern=^menus\\.txt$, full.names=TRUE) Does that look OK? Best regards, Keith Jewell Prof Brian Ripley rip...@stats.ox.ac.uk wrote in message news:alpine.lfd.2.02.1107200711180.30...@gannet.stats.ox.ac.uk... But using the approproate tool, Sys.glob, whould be much simpler. Note that 'pattern' in list.files is - a regexp, and '.' is a special character in a regexp: Phil's solution also needs to escape it or use fixed = TRUE - it is documented to match file *names*, not file paths. One of the authors of list.files and the author of Sys.glob On Tue, 19 Jul 2011, Phil Spector wrote: Pei - A file pattern can't contain a directory separator, but it's easy to search for one outside the context of list.files. I think grep('B/file2.txt',list.files(path = routeStr, all.files = TRUE, full.names = TRUE, recursive = TRUE),value=TRUE) should give you what you want. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Tue, 19 Jul 2011, JIA Pei wrote: Hi, all: My folders are organized in such a way: root branch1 ---A ---file1.txt ---file2.txt ---B ---file1.txt ---file2.txt branch2 ---A ---file1.txt ---file2.txt ---B ---file1.txt ---file2.txt ... branch100 ---A ---file1.txt ---file2.txt ---B ---file1.txt ---file2.txt I'd love to list all file2.txt from all subdirectories Bs but not from As, how to do that? I tried the following two a) allResults - list.files(path = routeStr, pattern = file2.txt, all.files = TRUE, full.names = TRUE, recursive = TRUE); gives me 200 files in allResults, which is wrong. There should be only 100 files in allResults. b) allResults - list.files(path = routeStr, pattern = B/file2.txt, all.files = TRUE, full.names = TRUE, recursive = TRUE); still wrong. It give me nothing, namely, 0 file(s) in allResults. Can anybody help to solve this problem? Best Regards Pei -- Pei JIA Email: jp4w...@gmail.com cell:+1 604-362-5816 Welcome to Vision Open http://www.visionopen.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] PCA - princomp can only be used with more units than variables
At 03:56 20/07/2011, Joshua Wiley wrote: On Mon, Jul 18, 2011 at 10:48 AM, a.me...@yahoo.co.uk a.me...@yahoo.co.uk wrote: Ok thank you Josh. Basically I have a matrix A with 7 rows and 18 columns. If i j (where i is the number of rows in your matrix and j is the number of columns), then the determinant of the covariance (or correlation) matrix |Sigma_A| will be 0 (or very near zero, you can easily convince yourself of this by running det(cov(matrix(rnorm(90), 9))) as many times as you need). From Cramer's Rule, if the determinant of the matrix is 0, there is not a unique solution (clarifications/corrections are welcome if any of this is wrong). What I am told is I need the 'varimax rotated scores from the PCA analysis of matrix A' You should be able to get scores on the first 7 components from prcomp surely? Is that not what it returns in x or am I misreading the documentation? Whether it is sensible to do this with such a small dataset and in particular whether rotating principal components is illogical I would not comment on. Who told you that? Is this homework? You could look at the ?principal function in package psych. That said, if this is homework I would talk with your instructor more, and if this is anything beyond an exercise (i.e., has real world implications), I would seek the advice/help of a local statistician. I can choose from 3 up to 7 components. My problem is how to carry out the above. Have you any ideas? Would appreciate your help! Armin On 18/07/2011 18:07, Joshua Wiley wrote: Hi, You need to explain what you want to do.  This is not a software issue, you simply cannot create more uncorrelated variables than you have observations. Josh On Mon, Jul 18, 2011 at 8:53 AM, a.me...@yahoo.co.uk a.me...@yahoo.co.uk  wrote: Hi, May I ask a question about a thread https://stat.ethz.ch/pipermail/r-help/2005-March/068365.html? I understand I need to use prcomp instead of princomp when i have less units than variables. However, when I use prcomp the scores is NULL. How can I overcome this? Regards, Armin -- Kind Regards, Armin Mewes Groundesign 10 Jerusalem street Belfast BT7 1QN Tel.   (0044)(0)2890280887 Email.  enquir...@groundesign.net www.   www.groundesign.net     [[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. -- Kind Regards, Armin Mewes Groundesign 10 Jerusalem street Belfast BT7 1QN Tel.   (0044)(0)2890280887 Email.  enquir...@groundesign.net www.   www.groundesign.net -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles https://joshuawiley.com/ Michael Dewey i...@aghmed.fsnet.co.uk http://www.aghmed.fsnet.co.uk/home.html __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Different result of multiple regression in R and SPSS
At 19.07.2011 18:50 -0700, Spencer Graves wrote: On 7/19/2011 4:04 PM, Bert Gunter wrote: On Tue, Jul 19, 2011 at 3:45 PM, David Winsemiusdwinsem...@comcast.net wrote: On Jul 19, 2011, at 6:29 PM, J. wrote: Thanks for the answer. # However, I am still curious about which result I should use? The result from R or the one from SPSS? It is becoming apparent that you do not know how to use the results from either system. The progress of science would be safer if you get some advice from a person that knows what they are doing. ## I nominate this for an R fortune. -- Bert None of us ever know what we're doing at some level. We often think we do, and sometimes we get results more in spite of what we've done than because of it. That of course increases our confidence and encourages us to repeat mistakes in contexts where we might not be so lucky. Spencer Wise! Heinz Why the results from two programs are different? Different parametrizations. If I had to guess I would bet that the gender coefficient is R is exactly twice that of the one from SPSS. They are probably both correct in the context of their respective codings. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Spencer Graves, PE, PhD President and Chief Technology Officer Structure Inspection and Monitoring, Inc. 751 Emerson Ct. San José, CA 95126 ph: 408-655-4567 web: www.structuremonitoring.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plotting groups via density and different colors
Hi, Instead of hist you can use functions histogram() or densityplot() in lattice package: require(lattice) histogram( ~ length | factor(sex), data=dene ) densityplot( ~ length, data=dene, groups=factor(sex), auto.key = list(space = bottom) ) Regards, Carlos Ortega www.qualityexcellence.es On Mon, Jul 18, 2011 at 3:50 PM, Jacob Kasper jacobkas...@gmail.com wrote: I have a data set that looks like this: dene - data.frame(length = c(35,32,33,34,41,40,46,35,41,40,45,36,38,37,39,40,42,42,42,43,44), sex=c(1,1,1,1,2,2,2,1,2,2,2,1,2,2,2,2,2,2,2,2,2)) I would like to plot the density (frequency of occurrence) of each length class but I want to have different colors for sex. I used the following: library(sm) sex.f-factor(as.factor(dene$sex),levels=c(1,2), labels=c(Males,Females)) sm.density.compare(dene$length, dene$sex) yet I want the sum of the areas under the two curves to be equal to 1, not the sum of the area under each curve to be equal to 1. I can plot the frequency using hist, but then I do not get the two colors indicating the difference in sex. hist(dene$length, freq=F, breaks=11) any thoughts on how to approach this would be appreciated. Thank you [[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] barplot question
On 07/20/2011 01:24 AM, Sally_roman wrote: In my first post is example data. Hi Sally, I was going to suggest: fish-read.table(fish.dat,header=TRUE) controlfish- rbind(fish$pounds[fish$net==Control fish$type == kept], fish$pounds[fish$net==Control fish$type == discard]) expfish- rbind(fish$pounds[fish$net==Experimental fish$type == kept], NA,fish$pounds[fish$net==Experimental fish$type == discard]) barplot(controlfish,xlim=c(0,8),width=0.5,space=1.2,offset=rep(-0.5,7) barplot(expfish,width=0.5,space=1.2,add=TRUE) but the offset argument seems to do nothing, so this doesn't work. 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] Fwd: Help please
On 20/07/11 21:08, Simon Knapp wrote: Hi All, This is not really an R question but a statistical one. If someone could either give me the brief explanation or point me to a reference that might help, I'd appreciate it. I want to estimate the mean of a log-normal distribution, given the (log scale normal) parameters mu and sigma squared (sigma2). I understood this should simply be: exp(mu + sigma2) I think you meant exp(mu + sigma2/2); that's what you used below (and that's what the right answer is. ... but I the following code gives me something strange: R- 1000 mu- -400 sigma2- 200 tmp- rlnorm(R, mu, sqrt(sigma2)) # a sample from the desired log-normal distribution muh- mean(log(tmp)) sigma2h- var(log(tmp)) #by my understanding, all of the the following vectors should then contain very similar numbers c(mu, muh) c(sigma2, sigma2h) c(exp(mu + sigma2/2), exp(muh + sigma2h/2), mean(tmp)) I get the following (for one sample): c(mu, muh) [1] -400. -400.0231 c(sigma2, sigma2h) [1] 200. 199.5895 c(exp(mu + sigma2/2), exp(muh + sigma2h/2), mean(tmp)) [1] 5.148200e-131 4.097249e-131 5.095888e-150 so they do all contain similar numbers, with the exception of the last vector, which is out by a factor of 10^19. Is this likely to be because one needs **very** large samples to get a reasonable estimate of the mean... or am I missing something? This is in effect an FAQ. You seem to be missing an understanding of floating point arithmetic. All of the last three values that you display are ***zero*** to all practical intents and purposes. Experiment with some values where you are not dealing with exp(-300) if you want to gain some insight into the log normal distribution. cheers, Rolf Turner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] bar chart issue
On 07/20/2011 01:56 PM, Stratford, Jeffrey wrote: Hi everyone, I determined the presence of three types parasites in a passerine bird over two years. I would like to create a bar chart that shows the proportion infected on the y and year/parasite on the x such that each type of parasite is grouped together (single label) and a bar for each year . This would show if there have been changes in the prevalence of a the parasite over two years. This is the summary data: ParasiteYear Infected Leukocytozoon 2009 0.2564 Plasmodium 2009 0.3846 Hemoproteus2009 0.0769 Leukocytozoon 2010 0.0562 Plasmodium 2010 0.7079 Hemoproteus2010 0.3034 Any2009 0.5128 Any2010 0.7753 Here are rows 86 to 92. Band and site were recorded differently each year but these are not part of any calculation. Year band site Plasmodium Hemoproteus Leukocytozoon Any 86 2010 2341-06597 1041 1 1 1 1 87 2010 2341-06598 1041 0 0 0 0 88 2010 2341-06599 1042 1 1 0 1 89 2010 2341-06600 1042 0 1 0 1 90 2009 6443 SOSP0901 0 0 1 1 91 2009 6444 SOSP0902 0 1 0 1 92 2009 6445 SOSP0903 0 0 0 0 Any suggestions on how to create this plot would be greatly appreciated. Hi Jeff, I think this could be done with the barNest function, nesting the year bars within the parasite bars. If you can't figure it out, send the complete dataset and I can provide an example. 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] multiple plots in single frame: 2 upper, 1 lower
On 20/07/11 11:07, DrCJones wrote: Hi, par(mfrow = c(2,2)) will create a 2x2 window that I can use to plot 4 diferent figures in: [plot1 plot2] [plot3 plot4] But how can do 3 so that the bottom spans the width of the upper two: [plot1 plot1] [p l o t 3] Is this possible in R? In R ***anything*** is possible. :-) Your requirement is no only possible, but easy! See ?layout You may have to expend a bit of effort to understand the syntax, but that will be good for your karma. :-) It ***will*** do exactly what you want, if you ask it nicely. cheers, Rolf Turner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 convert number (matlab) to date
2011/7/19 Prof Brian Ripley rip...@stats.ox.ac.uk: but even this is dubious, since there is no year 0 AD. In Gregorian and Julian calendars, 1 BC continues directly into 1 AD. True, but these days we are ruled by ISO 8601:2004, which does define a year 0 (the year before 1CE aka 1AD). See http://en.wikipedia.org/wiki/0_(year) . It seems also to redefine the meaning of 'Gregorian calendar' calling what you are referring to the 'BC/AD calendar system'. (Those who prefer BCE/CE to BC/AD might note the usage of the latter in the definitive international standard.) The Date class has not been extended to support -00-00; rather, the origin argument of as.Date.numeric has been extended to allow -00-00. There is no real difference between something like origin = -00-00 and origin = matlab, say. -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Calculating mean from wit mice (multiple imputation)
Sarah, You can try this mean(sapply(1:n.imp, function(x) complete(imp,x)$y)) Weidong Gu On Wed, Jul 20, 2011 at 6:05 AM, Sarah s1327...@student.rug.nl wrote: Hi all, How can I calculate the mean from several imputed data sets with the package mice? I know you can estimate regression parameters with, for example, lm and subsequently pool those parameters to get a point estimate using functions included in mice. But if I want to calculate the mean value of a variable over my multiple imputed data sets with fit - with(data=imp, expr=mean(y)) and pool(fit), I get the warning: Error in pool(fit) : Object has no coef() method. Does anyone know what is happening, and is there another way of calculating means? Thanks. -- View this message in context: http://r.789695.n4.nabble.com/Calculating-mean-from-wit-mice-multiple-imputation-tp3680347p3680347.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.
Re: [R] loops and simulation
On Jul 20, 2011, at 1:34 AM, Daniel Malter wrote: snipped requests, except that you were referring to SAS and had heard that R does not like loops. (This is factually wrong. But R can be slow looping). Where did you hear this? Can you cites any references? -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] comparing SAS and R survival analysis with time-dependent covariates
Let me expand a bit on Thomas's answer. Looking more closely at your data set you have the following: death time group 0group 1 1.5 0/413/13 3 0/4 5/5 8 4/4 0 At time 1.5 group 1 had 13 deaths out of 13 at risk, group 0 had none. Time 8 doesn't have any impact on the fit, since only one group was at risk the deaths are guarranteed to come from that group. So the actual MLE for the hazard ratio is 1/0 = infinity, 100% death rate in group 1 vs. 0% in group 0, at all the time points where the two groups can be compared. Section 3.5 of Therneau and Grambsch, Extending the Cox Model, has a picture of the log-likelihood in such a case, which very quickly approaches an asymptote as beta goes to infinity. Both phreg and coxph iterate until the loglik doesn't change anymore. The printed solution depends entirely on the convergence criteria, which are slightly different in the two programs. I chose to add a warning message. Final note: I never use the discrete option, having found the Efron approximation to be sufficient in every practical situation. Partly for that reason I have not worked very hard at optimising the code for that case while SAS has. If you insist on using the exact partial likelihood then phreg will be tens to thousands of times faster: my code is O(2^d) compute time where d=the max # of tied deaths at one time and theirs is polynomial in d. I doubt that coxph ever crashes your computer, but it is easy to construct a data set whose compute time is in days or even years. Terry Therneau __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Bruno's Panel LSDVC
*Is there an implementation of this in R? Thanks. * [[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] Coercing Logical array to Numeric array
Dear all, Coercing a logical vector to a numeric one is easy. The as.numeric function is used. However what do we use when we have a matrix or an array? Sumona __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] comparing SAS and R survival analysis with time-dependent covariates
Thomas Lumley-2 wrote: [...] The warning and error messages are correct here. Look at the point estimate. It's a log hazard ratio of about 20 in one case and about -20 in the other case. The true partial maximum likelihood estimator is infinite. The estimated standard errors are meaningless, since the partial likelihood isn't close to quadratic at the maximum. [...] I see. It explains the results for these testing data sets. But, with my real data set I get these results : With SAS : estimate FERM : 1.47654 se : 0.03117 Pr Khi 2 : .0001 hazard ratio : 4.378 convergence status : Convergence criterion (GCONV=1E-8) satisfied. This time, the hazard ratio is not big. The maximum of the partial likelihood seems to be reached. The program takes about 45 seconds to finish computation. My sample contains 6588 observations with a lot of ties (discrete time values). With R : I don't get any result. The program freezes and does not respond. I waited for about 1 hour without a result. So can I conclude in this case that the problem with the coxph function is due to computation power rather than another algorithmic problem ? -- View this message in context: http://r.789695.n4.nabble.com/comparing-SAS-and-R-survival-analysis-with-time-dependent-covariates-tp874438p3680340.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] Analysis of unbalanced data in nlme or car
I am analyzing a dataset on the effects of six pesticides on population growth rate of a predatory mite. The response variable is the population growth rate of the mite expressed as ln(Nfinal/Nstarting) of the mite, where N final the population of the mite at the end of the experiment and N starting the population of the mite at the beginning of the experiment. Each of the six treatments was ran in three time blocks with 2 replicates per block. In the third block I lost 1 replicate for four of the six treatments. I am analyzing the data in the nlme package using model-lme(growth.rate~treatment,random=~1|block). When I ran intervals(model), the confidence intervals of the variance of the random factor range from 0 to inf. Any comments as to why I get unrealistic confidence intervals for the random factor? In another study, I am investigating the interactions between pesticides in a two-way design: (pesticideA x no pesticide A) crossed with (pesticideB x no pesticide B). The blocks and number of replicates is as above, and the data are unbalanced again. The model is defined as model-lme(growth.rate~pestA*pestB,random=~1|block). When I run intervals (model), I usually get the following error message: Error in intervals.lme(model) : Cannot get confidence intervals on var-cov components: Non-positive definite approximate variance-covariance. I have read on the mailing list that the error message appears when the model is not well-specified, but I do not see an alternative way of specifying the model. Any ideas as to why I get wide confidence intervals or the error message? Any recommendations on other possibilities for analyzing the data are greatly appreciated. I cannot use aov because of the unbalanced data. I have tried to use Type III sums of squares in the car package [model-aov(growth.rate~pestA*pestB+Error(block))], but when I run Anova(model,type=c(3)) I get the following error message: Error in as.data.frame.default(data, optional = TRUE) : cannot coerce class 'function' into a data.frame Thank you very much, Menelaos Stavrinides Lecturer, Dept. of Agricultural Sciences Cyprus University of Technology P.O. Box 50329, 3603 Limassol, Cyprus Tel.: + 357 25002186 Fax: + 357 25002767 Email: m.stavrini...@cut.ac.cy [[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] np package, KleinSpady estimator, error when I estimate the bootstrapped standard errors
Dear all, I am using np package in order to estimate a model with Klein and Spady estimator. To estimate the model I use KS - npindexbw (xdat=X, ydat=Y, bandwidth.compute=TRUE, method=kleinspady, optim.maxit=10^3, ckertype=epanechnikov, ckerorder=2) and to estimate beta hats standard errors I use KSi - npindex(KS, gradients=T, boot.num=300) vcov(KSi) This is fine so far, but if I want to estimate the bootstrapped standard errors on estimates by se(KSi) then the result is NA and if I include the argument errors=TRUE instead of the default errors=FALSE as I think I should, I get the error: Error in npreg(regtype = lc, gradients = TRUE, txdat = rindex, tydat = tydat[indices], : argument is missing, with no default I couldn't find though any argument without a default. So, how can I get the bootstrapped errors? Thank you Dimitris -- View this message in context: http://r.789695.n4.nabble.com/np-package-KleinSpady-estimator-error-when-I-estimate-the-bootstrapped-standard-errors-tp3680709p3680709.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] Different result of multiple regression in R and SPSS
On Tue, Jul 19, 2011 at 4:19 PM, J. seoulseoulse...@gmail.com wrote: @Dimitri: I tried to enter it as numeric and still got the same outcome. I still wonder if there is any way to get the same result from both programs. There is. ?C ?contrasts But of course you must do your homework to understand how to use these. (See the quote in my signature). -- Bert @David, Bert: Yes, I found that the gender coefficient is R is exactly twice that of the one from SPSS. Need to study on parametrization. Thanks, Jay PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Men by nature long to get on to the ultimate truths, and will often be impatient with elementary studies or fight shy of them. If it were possible to reach the ultimate truths without the elementary studies usually prefixed to them, these would not be preparatory studies but superfluous diversions. -- Maimonides (1135-1204) Bert Gunter Genentech Nonclinical Biostatistics 467-7374 http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Coercing Logical array to Numeric array
On 20/07/2011 7:14 AM, Mitra, Sumona wrote: Dear all, Coercing a logical vector to a numeric one is easy. The as.numeric function is used. However what do we use when we have a matrix or an array? Usually you don't need to do anything: if a local is used in arithmetic, the values are automatically coerced. But if you really need the conversion, this should work: newArray - as.numeric(oldArray) dim(newArray) - dim(oldArray) 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] Coercing Logical array to Numeric array
On Jul 20, 2011, at 7:14 AM, Mitra, Sumona wrote: Dear all, Coercing a logical vector to a numeric one is easy. The as.numeric function is used. However what do we use when we have a matrix or an array? Here's one way: m -matrix(c(1, 2, 3, 4),2) m [,1] [,2] [1,] 1 3 [2,] 2 4 mode(m) - numeric m [,1] [,2] [1,]13 [2,]24 Sumona __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] transforming a matrix of logical to 0 and 1 while keeping the dim of matrix
Hi all, Suppose I have a matrix of logical value: x-matrix(c(TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE),nrow=3) I would like to change the value of FALSE to 0 and TRUE to 1. An obvious way to do it is : y-as.numeric(x) However this method doesn't keep the dim of x. I also need to copy the dim information to y too. attributes(y)-attributes(x) Is this a correct way to do it in R? Is there any single step function which can do the something? Thanks Regards, TszKin Julian __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Writing the output of a regression object to a file
Thanks for the reply. write.table(esvr.pred) worked - I got data out that's been scaled back to its original range of values. 2011/7/19, Bert Gunter gunter.ber...@gene.com: If I understand you correctly, I would like to export the esvr.pred object to a file so that I can draw a graph of it against my original data in other software that I'm using. you cannot do this. You can export **data**, but of course any R object is either a binary or text (via dput) representation of an R structure, which can only be understood by R, not another software system. See ?write, ?write.table, or the R import/export manual for how to export data (as text) to be imported by other software. Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Grouping columns
untested because I don't have access to your data, but this should work. b13.NEW - b13[, c(Gesamt, Wasser, Boden, Luft, Abwasser, Gefährliche Abfälle, nicht gefährliche Abfälle)] Geophagus wrote: *Hi @ all, I have a question concerning the possibilty of grouping the columns of a matrix. R groups the columns alphabetically. What can I do to group the columns in my specifications? The script is the following:* #R-Skript: Anzahl xyz #Quelldatei einlesen b-read.csv2(Z:/int/xyz.csv, header=TRUE) #Teilmengen für die Einzeljahre generieren b1-subset(b,jahr==2007) b2-subset(b,jahr==2008) b3-subset(b,jahr==2009) #tapply für die Einzeljahre auf die jeweilige BranchenID b1_1-tapply(b1$betriebs_id,b1$umweltkompartiment,length) b1_2-tapply(b2$betriebs_id,b2$umweltkompartiment,length) b1_3-tapply(b3$betriebs_id,b3$umweltkompartiment,length) #Verbinden der Ergebnisse b11-rbind(b1_1,b1_2,b1_3) Gesamt-apply(X=b11,MARGIN=1, sum) b13-cbind(Gesamt,b11) b13 Gesamt Abwasser Boden Gefährliche Abfälle Luft nicht gefährliche Abfälle Wasser b1_1 9832 432183147 2839 1592 1804 b1_2 10271 413283360 2920 1715 1835 b1_3 9983 404213405 2741 1691 1721 *Now I want to have the following order of the columns: Gesamt, Wasser, Boden, Luft, Abwasser, Gefährliche Abfälle, nicht gefährliche Abfälle Thanks a lot for your answers! Fak* -- View this message in context: http://r.789695.n4.nabble.com/Grouping-columns-tp3681018p3681121.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] Grouping columns
*Hi @ all, I have a question concerning the possibilty of grouping the columns of a matrix. R groups the columns alphabetically. What can I do to group the columns in my specifications? The script is the following:* #R-Skript: Anzahl xyz #Quelldatei einlesen b-read.csv2(Z:/int/xyz.csv, header=TRUE) #Teilmengen für die Einzeljahre generieren b1-subset(b,jahr==2007) b2-subset(b,jahr==2008) b3-subset(b,jahr==2009) #tapply für die Einzeljahre auf die jeweilige BranchenID b1_1-tapply(b1$betriebs_id,b1$umweltkompartiment,length) b1_2-tapply(b2$betriebs_id,b2$umweltkompartiment,length) b1_3-tapply(b3$betriebs_id,b3$umweltkompartiment,length) #Verbinden der Ergebnisse b11-rbind(b1_1,b1_2,b1_3) Gesamt-apply(X=b11,MARGIN=1, sum) b13-cbind(Gesamt,b11) b13 Gesamt Abwasser Boden Gefährliche Abfälle Luft nicht gefährliche Abfälle Wasser b1_1 9832 432183147 2839 1592 1804 b1_2 10271 413283360 2920 1715 1835 b1_3 9983 404213405 2741 1691 1721 *Now I want to have the following order of the columns: Gesamt, Wasser, Boden, Luft, Abwasser, Gefährliche Abfälle, nicht gefährliche Abfälle Thanks a lot for your answers! Fak* -- View this message in context: http://r.789695.n4.nabble.com/Grouping-columns-tp3681018p3681018.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] transforming a matrix of logical to 0 and 1 while keeping the dim of matrix
How about this: x-matrix(c(TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE),nrow=3) x [,1] [,2] [,3] [1,] TRUE FALSE TRUE [2,] FALSE TRUE FALSE [3,] TRUE FALSE TRUE ifelse(x, 1, 0) [,1] [,2] [,3] [1,]101 [2,]010 [3,]101 Sarah On Wed, Jul 20, 2011 at 11:16 AM, Julian TszKin Chan cjul...@bu.edu wrote: Hi all, Suppose I have a matrix of logical value: x-matrix(c(TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE),nrow=3) I would like to change the value of FALSE to 0 and TRUE to 1. An obvious way to do it is : y-as.numeric(x) However this method doesn't keep the dim of x. I also need to copy the dim information to y too. attributes(y)-attributes(x) Is this a correct way to do it in R? Is there any single step function which can do the something? Thanks Regards, TszKin Julian -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Grouping columns
On Jul 20, 2011, at 10:42 AM, Geophagus wrote: *Hi @ all, I have a question concerning the possibilty of grouping the columns of a matrix. R groups the columns alphabetically. What can I do to group the columns in my specifications? Dear Earth Eater; You can create a factor whose levels are ordered to your specification. Your columns: umweltkompartiment obviously has those levels. This might also offer advantages in situations where there was not complete representation of all levels in all the files So your tapply() calls could have been of this form: b1_1-tapply(b1$betriebs_id, factor( b1$umweltkompartiment, levels= c(Gesamt, Wasser, Boden, Luft, Abwasser, Gefährliche Abfälle, nicht gefährliche Abfälle) ) ,length) # code would e more compact if you created a facvtor vector and use it as an argument to factor: faclevs - c(Gesamt, Wasser, Boden, Luft, Abwasser, Gefährliche Abfälle, nicht gefährliche Abfälle) b1_1-tapply(b1$betriebs_id, factor( b1$umweltkompartiment, levels= faclev ) ,length) lather, rinse, repeat x 3 -- David. The script is the following:* #R-Skript: Anzahl xyz #Quelldatei einlesen b-read.csv2(Z:/int/xyz.csv, header=TRUE) #Teilmengen für die Einzeljahre generieren b1-subset(b,jahr==2007) b2-subset(b,jahr==2008) b3-subset(b,jahr==2009) #tapply für die Einzeljahre auf die jeweilige BranchenID b1_1-tapply(b1$betriebs_id,b1$umweltkompartiment,length) b1_2-tapply(b2$betriebs_id,b2$umweltkompartiment,length) b1_3-tapply(b3$betriebs_id,b3$umweltkompartiment,length) #Verbinden der Ergebnisse b11-rbind(b1_1,b1_2,b1_3) Gesamt-apply(X=b11,MARGIN=1, sum) b13-cbind(Gesamt,b11) b13 Gesamt Abwasser Boden Gefährliche Abfälle Luft nicht gefährliche Abfälle Wasser b1_1 9832 432183147 2839 1592 1804 b1_2 10271 413283360 2920 1715 1835 b1_3 9983 404213405 2741 1691 1721 *Now I want to have the following order of the columns: Gesamt, Wasser, Boden, Luft, Abwasser, Gefährliche Abfälle, nicht gefährliche Abfälle Thanks a lot for your answers! Fak* -- View this message in context: http://r.789695.n4.nabble.com/Grouping-columns-tp3681018p3681018.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 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] transforming a matrix of logical to 0 and 1 while keeping the dim of matrix
Two further methods: x+0 [,1] [,2] [,3] [1,]101 [2,]010 [3,]101 mode(x)- numeric; x [,1] [,2] [,3] [1,]101 [2,]010 [3,]101 On Jul 20, 2011, at 11:27 AM, Sarah Goslee wrote: How about this: x-matrix(c(TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE),nrow=3) x [,1] [,2] [,3] [1,] TRUE FALSE TRUE [2,] FALSE TRUE FALSE [3,] TRUE FALSE TRUE ifelse(x, 1, 0) [,1] [,2] [,3] [1,]101 [2,]010 [3,]101 Sarah On Wed, Jul 20, 2011 at 11:16 AM, Julian TszKin Chan cjul...@bu.edu wrote: Hi all, Suppose I have a matrix of logical value: x-matrix(c(TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE),nrow=3) I would like to change the value of FALSE to 0 and TRUE to 1. An obvious way to do it is : y-as.numeric(x) However this method doesn't keep the dim of x. I also need to copy the dim information to y too. attributes(y)-attributes(x) Is this a correct way to do it in R? Is there any single step function which can do the something? Thanks Regards, TszKin Julian -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using Mplus via R
Yes. If you want a program that does some of what Mplus does, use the lavaan package or the sem package. Dimitri Liakhovitski dimitri.liakhovit...@gmail.com Sent by: r-help-boun...@r-project.org 07/18/2011 05:36 PM To r-help r-help@r-project.org cc Subject [R] Using Mplus via R Clarification question: does one need Mplus installed in order to use Mplus Automation package? -- Dimitri Liakhovitski www.ninah.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] transforming a matrix of logical to 0 and 1 while keeping the dim of matrix
Hi, I am not sure about correct, but R stores logical values TRUE/FALSE as 1/0 already so simply changing the mode would suffice: mode(x) - numeric alternately x + 0 HTH, Josh On Wed, Jul 20, 2011 at 8:16 AM, Julian TszKin Chan cjul...@bu.edu wrote: Hi all, Suppose I have a matrix of logical value: x-matrix(c(TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE),nrow=3) I would like to change the value of FALSE to 0 and TRUE to 1. An obvious way to do it is : y-as.numeric(x) However this method doesn't keep the dim of x. I also need to copy the dim information to y too. attributes(y)-attributes(x) Is this a correct way to do it in R? Is there any single step function which can do the something? Thanks Regards, TszKin Julian __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles https://joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] (no subject)
what is exactly difference between gee, geese, and ordgee [[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] [R-pkgs] new versions of packages RWinEdt, signal, tuneR
A series of package updates is on CRAN (or in the process to get there). Already available from CRAN are: - signal: Since I took over maintainership years ago, I have not invested the required amount of time into this package - until this spring and now the package got a NAMESPACE and dozens of bugfixes, documentation improvements and hundreds of test cases - many thanks to Sarah Schnackenberg for most of the work! - tuneR: After tuneR got mp3 read support last year, we managed to include support for mel/bark/hertz scales and conversion, powerspectra, as well as full support of LPC and MFCC coefficients (and some other stuff). Note that the former code that was documented as experimental for MFCC calculations has been replaced and the API changed. Many thanks to Sebastian Krey for the contributions! On its way to CRAN is: - RWinEdt: RWinEdt 1.8-3 is a minor change that fixes minor issues when working under Windows 7. This version is compatible with WinEdt versions 5.2-5.5 but it is still not compatible with WinEdt 6! Important to remember is: + Please run it with R = 2.13.0 patched (!) under Windows 7 (there is a small bug in R = 2.13.0 causing RWinEdt to be unable to start WinEdt from R) + After installation of RWinEdt run R once with admin privileges (by right click) and say library(RWinEdt). After that, you can start R with regular permissions. We are working on a version for WinEdt 6 now. For users who cannot wait to use WinEdt 6 with R: There is a R-Sweave mode available from http://www.winedt.org/ (untested so far). Best, Uwe Ligges ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] transforming a matrix of logical to 0 and 1 while keepin
It is easier and more straightforward than any of the suggestions so far. Simply multiply the matrix by 1, or add 0 to it: x-matrix(c(TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE),nrow=3) 1*x # [,1] [,2] [,3] # [1,]101 # [2,]010 # [3,]101 0+x # [,1] [,2] [,3] # [1,]101 # [2,]010 # [3,]101 Reason: When a logical value takes part in a numeric expression, it is automatically coerced to numeric (0 or 1). As the night-club bouncer said to the un-dressed clubber: We're not letting you in just wearing Naked Truth. You've got to put on a proper black suit or white suit. Ted. On 20-Jul-11 15:40:49, Joshua Wiley wrote: Hi, I am not sure about correct, but R stores logical values TRUE/FALSE as 1/0 already so simply changing the mode would suffice: mode(x) - numeric alternately x + 0 HTH, Josh On Wed, Jul 20, 2011 at 8:16 AM, Julian TszKin Chan cjul...@bu.edu wrote: Hi all, Suppose I have a matrix of logical value: x-matrix(c(TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE,FALSE,TRUE),nrow=3) I would like to change the value of FALSE to 0 and TRUE to 1. An obvious way to do it is : y-as.numeric(x) However this method doesn't keep the dim of x. I also need to copy the dim information to y too. attributes(y)-attributes(x) Is this a correct way to do it in R? Is there any single step function which can do the something? Thanks Regards, TszKin Julian __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles https://joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 20-Jul-11 Time: 17:17:56 -- 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] Taking all complete diagonals of a matrix
-Original Message- From: Peter Lomas [mailto:peter.lo...@ucalgary.ca] Sent: Tuesday, July 19, 2011 6:42 PM To: Nordlund, Dan (DSHS/RDA) Cc: r-help@r-project.org Subject: Re: [R] Taking all complete diagonals of a matrix Thanks very much to everyone who replied. Peter got me on my way with the use diag() hint, and I came with a less pretty version of Dan's first option almost at the same time as I got that email. Seems I can't avoid one for loop, but one is better than two. Just as a note, with this code you have to make sure that you are in fact giving it a matrix, or diag() will error. I fed it a data frame unaware, but using as.matrix() works just fine. diagonals - function(mat){ R - dim(mat)[1] C - dim(mat)[2] output - matrix(NA,(R-C+1),C) for(i in 1:(R-C+1)) output[i,] - diag(mat[i:(i+C-1),]) return(output) } example - rbind(rep(1,3),rep(2,3),rep(3,3),rep(4,3),rep(5,3)) diagonals(as.data.frame(example)) Error in output[i, ] - diag(mat[i:(i + C - 1), ]) : number of items to replace is not a multiple of replacement length Thanks again, Peter On Tue, Jul 19, 2011 at 17:34, Nordlund, Dan (DSHS/RDA) nord...@dshs.wa.gov wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Peter Lomas Sent: Tuesday, July 19, 2011 2:16 PM To: r-help@r-project.org Subject: [R] Taking all complete diagonals of a matrix snip Peter, Here are two possibilities. I leave it up to you to determine whether they are cleaner or faster. diagonals1 - function(mat){ #setup R - dim(mat)[1] C - dim(mat)[2] output - matrix(0,(R-C+1),C) #get diagonals for(i in 1:(R-C+1)) output[i,] - diag(mat[i:(i+C-1),]) return(output) } diagonals2 - function(mat){ #setup R - dim(mat)[1] C - dim(mat)[2] output - matrix(0,(R-C+1),C) #get diagonals for(i in 1:(R-C+1)) output[,i] - mat[i:(i+C-1),i] return(output) } Hope this is helpful, Peter, I am not sure what happened with the diagonals2 function that I posted yesterday (which I thought I had tested and it worked) because it clearly doesn't work. Here is a revised version that does work and is faster than using the diag() function. It will also work fine with a data frame as input. diagonals2 - function(mat){ #setup R - dim(mat)[1] C - dim(mat)[2] output - matrix(0,(R-C+1),C) #get diagonals for(i in 1:C) output[,i] - mat[i:(i+R-C),i] return(output) } Hope this is more helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] [R-pkgs] ANNOUNCE -- Rjms package, message publishing using rJava and ActiveMQ
EIP(Enterprise Integration Patterns), ESB( Enterprise service bus) are commonly used terms utilized with Message oriented middleware. Apache ActiveMQ implements message queues and message topics. The Rjms package brings the capabilities of messaging to R. The description states: This package uses rJava to publish messages to an ActiveMQ queue or topic, implementing Enterprise Integration Patterns. This is the first version of the project. The usage is pretty simple: you create a logger, send messages to a queue/topic using the logger and destroy the logger. One interesting use case is in monitoring various iteration results while the code executes.Using Rjms and ActiveMQ, a user can log various values and update a chart or a table on a realtime basis. In case your iterations are heading in the wrong direction, you can interrupt the code execution. It feels good to bring the two open source projects together. [[alternative HTML version deleted]] ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] [R-pkgs] irtoys 0.1.4
A new version of irtoys is / will be available on CRAN. Two minor bugs have been fixed. One of these is more interesting: the previous code did not anticipate negative estimates for discriminations. What I did not know is that, unlike ICL or Bilog, ltm does not constrain discriminations to be positive. This means that it can be used to analyze bipolar data (think political sciences). There are also two new features: (i) Tamaki Hattori has kindly provided me with the original 1980 article of Haebara, and he has written code for the symmetrical versions of the Haebara and Stocking-Lord scaling methods, now available as an option; (ii) I have finally added a wle function for the bias-corrected estimates of ability aka Warm's estimates Kind regards Ivailo Partchev ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Taking all complete diagonals of a matrix
On Jul 20, 2011, at 03:42 , Peter Lomas wrote: Thanks very much to everyone who replied. Peter got me on my way with the use diag() hint, and I came with a less pretty version of Dan's first option almost at the same time as I got that email. Seems I can't avoid one for loop, but one is better than two. What Peter? I see Dan and Dennis in the thread Anyway, last time the subject of diagonals came up, someone pointed out that recasting a matrix into a matrix with R+1 rows causes the 2nd column to move up on row, the 3rd column two rows, etc. So m -matrix(1:5,5,3) m [,1] [,2] [,3] [1,]111 [2,]222 [3,]333 [4,]444 [5,]555 m2 - matrix(,6,3) suppressWarnings(m2[]-m) # or: m2[seq_along(m)]-m m2[1:3,] [,1] [,2] [,3] [1,]123 [2,]234 [3,]345 -Peter Just as a note, with this code you have to make sure that you are in fact giving it a matrix, or diag() will error. I fed it a data frame unaware, but using as.matrix() works just fine. diagonals - function(mat){ R - dim(mat)[1] C - dim(mat)[2] output - matrix(NA,(R-C+1),C) for(i in 1:(R-C+1)) output[i,] - diag(mat[i:(i+C-1),]) return(output) } example - rbind(rep(1,3),rep(2,3),rep(3,3),rep(4,3),rep(5,3)) diagonals(as.data.frame(example)) Error in output[i, ] - diag(mat[i:(i + C - 1), ]) : number of items to replace is not a multiple of replacement length Thanks again, Peter On Tue, Jul 19, 2011 at 17:34, Nordlund, Dan (DSHS/RDA) nord...@dshs.wa.gov wrote: -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Peter Lomas Sent: Tuesday, July 19, 2011 2:16 PM To: r-help@r-project.org Subject: [R] Taking all complete diagonals of a matrix Hi R-Help! I am trying to find a nicer way of extracting all the complete diagonals of a matrix. I am working with very large matrices that have many more rows than columns. I want to be able to extract each of the diagonals that are as long as the number of columns in the matrix. I have written a rather ugly function that presently does the job. It illustrates what I am trying to do, but I feel like there must be a cleaner (and faster) way. Does anybody have any ideas? Here is what I've done so far: diagonals - function(mat){ output - matrix(0,(dim(mat)[1]-dim(mat)[2]+1),NCOL(mat)) for(i in 1:NROW(output)){ G - c() for(j in 1:NCOL(mat)){ G - c(G,mat[(i+j-1),j]) } output[i,] - G } return(output) } example - rbind(rep(1,3),rep(2,3),rep(3,3),rep(4,3),rep(5,3)) example [,1] [,2] [,3] [1,]111 [2,]222 [3,]333 [4,]444 [5,]555 diagonals(example) [,1] [,2] [,3] [1,]123 [2,]234 [3,]345 Many thanks, Peter Peter, Here are two possibilities. I leave it up to you to determine whether they are cleaner or faster. diagonals1 - function(mat){ #setup R - dim(mat)[1] C - dim(mat)[2] output - matrix(0,(R-C+1),C) #get diagonals for(i in 1:(R-C+1)) output[i,] - diag(mat[i:(i+C-1),]) return(output) } diagonals2 - function(mat){ #setup R - dim(mat)[1] C - dim(mat)[2] output - matrix(0,(R-C+1),C) #get diagonals for(i in 1:(R-C+1)) output[,i] - mat[i:(i+C-1),i] return(output) } Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- Peter Dalgaard Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Changing a matrix based on eigen value
Dear all, my question is not directly related to R, however I believe that experts here would not mind anything to have a look on my problem. Please consider a symmetric matrix and it's eigen values: set.seed(1) mat - matrix(rnorm(36), 6) mat - mat %*% t(mat) # symmetric matrix mat [,1] [,2][,3] [,4] [,5][,6] [1,] 3.920570 1.9339770 1.29012167 -1.4627174 -1.5655953 -1.82083435 [2,] 1.933977 5.8501784 -1.70504980 0.7195951 1.4252209 -3.11543738 [3,] 1.290122 -1.7050498 3.31434984 -0.6324029 0.1860666 -0.08234236 [4,] -1.462717 0.7195951 -0.63240294 5.4179467 0.9003576 -3.61864495 [5,] -1.565595 1.4252209 0.18606662 0.9003576 4.5248002 0.52702347 [6,] -1.820834 -3.1154374 -0.08234236 -3.6186449 0.5270235 6.02038872 eigen(mat)$values [1] 11.4213448 7.3302845 5.7033748 3.9863332 0.4827576 0.1241385 Here my goal is to find the nearest matrix of mat for which the minimum eigen value is 0.20 (I would rather want to fix some arbitrary value). While finding that nearest matrix, I would like to keep all other properties (whatever are those) of my original matrix mat as unaltered as possible. Is there any algorithm to achieve that? Thanks for your 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.
[R] Grofit
Hi Is it possible to use grofit to get the AIC of several (e.g. two) growth models and compare both these and model parameters? All I can get it to do so far is return parameters for a single model. Cheers Roland [[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] timeDate with month designated by three letters.
Thanks for the assistance How does strptime(04-MAY-11 1428,format=%d-%b-%y %H%M) differ from timeDate(04-MAY-11 1428,format=%d-%b-%y %H%M) ? -Original Message- strptime(04-MAY-11 1428,format=%d-%b-%y %H%M) [1] 2011-05-04 14:28:00 -- Clint BowmanINTERNET: cl...@ecy.wa.gov Air Quality Modeler INTERNET: cl...@math.utah.edu Department of Ecology VOICE: (360) 407-6815 PO Box 47600FAX:(360) 407-7534 Olympia, WA 98504-7600 USPS: PO Box 47600, Olympia, WA 98504-7600 Parcels:300 Desmond Drive, Lacey, WA 98503-1274 -Original Message- Tena koe Michael The help file for strptime suggests you should be using %b (three letter month) rather than %m (decimal number month). HTH Peter Alspach -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of mdkz...@aol.com Sent: Wednesday, 20 July 2011 8:39 a.m. To: R-help@r-project.org Subject: [R] timeDate with month designated by three letters. Dear R Experts: I am trying to convert a date and time character field to timeDate where the month is presented as three letters, such as JUN for June, etc. This is an example of the full character field: 04-MAY-11 1428 What is the proper format syntax? I've tried timeDate(04-MAY-11 1428,format=%d-%m-%y %H%M) but only get GMT [1] [NA] If I change the month to a number as below, then it works, but that would require recoding of the data field. timeDate(04-05-11 1428,format=%d-%m-%y %H%M) gives GMT [1] [2011-05-04 14:28:00] which is correct. How do I get R to recognize the month as a 3 letter designator. Any recommendations you can provide would be greatly appreciated. Michael [[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. The contents of this e-mail are confidential and may be ...{{dropped:22}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] timeDate with month designated by three letters.
On Jul 20, 2011, at 3:38 PM, mdkz...@aol.com wrote: Thanks for the assistance How does strptime(04-MAY-11 1428,format=%d-%b-%y %H%M) differ from timeDate(04-MAY-11 1428,format=%d-%b-%y %H%M) ? Wouldn't one need to know where you got this non-base function? -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Competing risk regression with CRR slow on large datasets?
Hi, I posted this question on stats.stackexchange.com 3 days ago but the answer didn't really address my question concerning the speed in competing risk regression. I hope you don't mind me asking it in this forum: I’m doing a registry based study with almost 200 000 observations and I want to perform a competing risk analysis. My problem is that the crr() in the cmprsk package is exponentially increasing with increasing number of observations. I therefore wrote a simulation for trying different approaches; check how factors, data frames and matrixes affect the performance so that I could choose the most efficient combination. I have a 1 year old computer with 8 Gb of RAM and still it didn’t finish 70 000 observations when I left the computer overnight. My main questions: - Is there a faster way of performing competing risk analysis? - Why does Win7 4 times perform better? Is it the 64-bit version that improves the performance? - Can I do something to speed things up? - Is the simulation similarly slow on your computer? (see simulation code at the end) Thanks Max To see the output and the simulation code see the original question at http://stats.stackexchange.com/questions/13151/competing-risk-regression-with-crr-slow-on-large-datasets __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] select element from each row of the matrix
I have a 5 column matrix like 12 10 8 6 3 10 9 8 7 5 14 NA 4 NA NA NA 15 NA 10 NA 5 ... I want to select the position of the first entry for each row =5 for example, for the first row, I want to select the last element and return its position as 5; for th e third row, I want to select the third element and return its position as 3; similarly for the 4th row, I want to select the fifth element and return its position 5. I am wondering how to do this fast? Thanks a lot! [[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] select element from each row of the matrix
On Jul 20, 2011, at 4:23 PM, gallon li wrote: I have a 5 column matrix like 12 10 8 6 3 10 9 8 7 5 14 NA 4 NA NA NA 15 NA 10 NA 5 ... Probably something along the lines of aapply(mtx, 1, function(x) { c( x[ which(x = 5)[1] ], # first row are the values which(x = 5)[1]) } ) # second row the positions -- David. I want to select the position of the first entry for each row =5 for example, for the first row, I want to select the last element and return its position as 5; for th e third row, I want to select the third element and return its position as 3; similarly for the 4th row, I want to select the fifth element and return its position 5. I am wondering how to do this fast? Thanks a lot! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] select element from each row of the matrix
Tena koe Assuming your matrix is called yourMatrix, then try apply(yourMatrix, 1, function(x) which(x=5)) HTH ... Peter Alspach -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of gallon li Sent: Thursday, 21 July 2011 8:23 a.m. To: R-help@r-project.org Subject: [R] select element from each row of the matrix I have a 5 column matrix like 12 10 8 6 3 10 9 8 7 5 14 NA 4 NA NA NA 15 NA 10 NA 5 ... I want to select the position of the first entry for each row =5 for example, for the first row, I want to select the last element and return its position as 5; for th e third row, I want to select the third element and return its position as 3; similarly for the 4th row, I want to select the fifth element and return its position 5. I am wondering how to do this fast? Thanks a lot! [[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. The contents of this e-mail are confidential and may be subject to legal privilege. If you are not the intended recipient you must not use, disseminate, distribute or reproduce all or any part of this e-mail or attachments. If you have received this e-mail in error, please notify the sender and delete all material pertaining to this e-mail. Any opinion or views expressed in this e-mail are those of the individual sender and may not represent those of The New Zealand Institute for Plant and Food Research Limited. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Question about converting list items in matrix
Hi friends, I have got a list where each element might have variable number of members. $`4213` [1] 214077_x_at $`164832` [1] 225996_at 235977_at $`339010` [1] NA $`23410` [1] 221562_s_at 221913_at 49327_at $`285386` [1] 229764_at $`2099` [1] 205225_at 211233_x_at 211234_x_at 211235_s_at [5] 211627_x_at 215551_at 215552_s_at 217163_at [9] 217190_x_at I want to integrate this list in a matrix format like this : 4213 214077_x_at 164832 225996_at 164832 235977_at 339010 NA 23410 221562_s_at 23410 221913_at 23410 49327_at Any idea how can I make such type of matrix ? Thanks, Vickie [[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] Latex Table for means and standard deviations in brackets
Hi Jim, Perhaps somebody else knows a smoother way, but in the past I have just built my table in R as a matrix then used xtable. Here's what I would do with your example: library(xtable) dataset1 = matrix( c(1,2,3,4, 5, 6 ), 2 , 3) dataset2 = matrix( c(4,3,5,10, 1, 0), 2, 3) dataset - rbind(dataset1,dataset2) #combine dataset means - apply(dataset,1,mean) #calculate row means sds - apply(dataset,1,sd) #calculate row standard deviation msd - paste(round(means,2), (,round(sds,2),),sep=) #mean and standard deviation rn - c(Var1,Var2) #rownames cn - c(Dataset1,Dataset2) #column names tab - matrix(msd,2,2,dimnames=list(rn,cn)) tab Dataset1 Dataset2 Var1 3 (2) 3.33 (2.08) Var2 4 (2) 4.33 (5.13) xtable(tab) If there is a better way, I'd love to know it myself. Peter On Wed, Jul 20, 2011 at 04:05, Jim Silverton jim.silver...@gmail.com wrote: Hello all, I am new to xtable. I have several datasets in the form of matrices. Consider the following two simple datasets which are 2 x 3 matrices. The rows in both matrices have the same meaning. For example the first row of both matrices are variable 1 and the second row of both matrices are variable 2. dataset1 = matrix( c(1,2,3,4, 5, 6 ), 2 , 3) dataset2 = matrix( c(4,3,5,10, 1, 0), 2, 3) I would like to find the means and standard deviations in brackets for each data set in the form of a table that looks like: dataset1 dataset2 var1 2 3 (1.3) (2.5) var2 4 10 (2.3) (1.2) ( I used the wrong numbers). But does anyone has any idea how Xtable or some other R package can automatically create the latex table? -- Thanks, Jim. [[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] select element from each row of the matrix
Looping over the rows, as David did below, is one way. You can also loop over the columns. This can be faster when nrow(matrix)ncol(matrix). E.g., with the following 2 functions f0 - function (x) { apply(x, 1, function(aRow) which(aRow = 5)[1]) } f1 - function (x) { isGood - !is.na(x) x = 5 retval - rep(NA, nrow(x)) for (col in rev(seq_len(ncol(x { retval[isGood[, col]] - col } retval } and a 1 million row (by 5 column) matrix set.seed(1) mBig - matrix(sample(10,size=5*10^6,replace=TRUE), ncol=5, nrow=10^6) mBig[sample(length(mBig), size=length(mBig)/10)] - NA I get system.time(z0 - f0(mBig)) user system elapsed 17.840.02 17.36 system.time(z1 - f1(mBig)) user system elapsed 0.560.010.56 identical(z0,z1) [1] TRUE In either case it can save time (and sometimes use extra memory) to compute things outside of the loop. f1 already does that but f0 would be a bit quicker if you moved some repeated calculations out of the loop: f0a - function (x) { s - seq_len(ncol(x)) apply(!is.na(x) x = 5, 1, function(aRow) s[aRow][1]) } Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of David Winsemius Sent: Wednesday, July 20, 2011 1:35 PM To: gallon li Cc: R-help@r-project.org Subject: Re: [R] select element from each row of the matrix On Jul 20, 2011, at 4:23 PM, gallon li wrote: I have a 5 column matrix like 12 10 8 6 3 10 9 8 7 5 14 NA 4 NA NA NA 15 NA 10 NA 5 ... Probably something along the lines of aapply(mtx, 1, function(x) { c( x[ which(x = 5)[1] ], # first row are the values which(x = 5)[1]) } ) # second row the positions -- David. I want to select the position of the first entry for each row =5 for example, for the first row, I want to select the last element and return its position as 5; for th e third row, I want to select the third element and return its position as 3; similarly for the 4th row, I want to select the fifth element and return its position 5. I am wondering how to do this fast? Thanks a lot! [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Question about converting list items in matrix
On Jul 20, 2011, at 5:04 PM, Vickie S wrote: Hi friends, I have got a list where each element might have variable number of members. $`4213` [1] 214077_x_at $`164832` [1] 225996_at 235977_at $`339010` [1] NA $`23410` [1] 221562_s_at 221913_at 49327_at $`285386` [1] 229764_at $`2099` [1] 205225_at 211233_x_at 211234_x_at 211235_s_at [5] 211627_x_at 215551_at 215552_s_at 217163_at [9] 217190_x_at If you had posted the output from dput(head(this_list)) it would have made testing easier. Observe: dput(this_list) structure(list(`4213` = 214077_x_at, `164832` = c(225996_at, 235977_at), `339010` = NA, `23410` = c(221562_s_at, 221913_at, 49327_at), `285386` = 229764_at), .Names = c(4213, 164832, 339010, 23410, 285386)) So now all one need to do is stick a - in between the name and the structure expression and one has a reproducible example. (testing on these first four entries) matrix( c( rep(names(this_list), sapply(this_list, length)) , + unlist(this_list) +) , ncol=2) [,1] [,2] [1,] 4213 214077_x_at [2,] 164832 225996_at [3,] 164832 235977_at [4,] 339010 NA [5,] 23410 221562_s_at [6,] 23410 221913_at [7,] 23410 49327_at [8,] 285386 229764_at I want to integrate this list in a matrix format like this : 4213 214077_x_at 164832 225996_at 164832 235977_at 339010 NA 23410 221562_s_at 23410 221913_at 23410 49327_at You cannot mix modes in matrices. They all need to be character. Any idea how can I make such type of matrix ? Thanks, Vickie [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] RES: Question about converting list items in matrix
---BeginMessage--- Vickie, try something like this # Dummy data lst - list(This,c(should, work, just),fine,I,guess...,c(NA,NA)) names(lst) - letters[seq(1,length(lst))] lst # Arranging for (i in 1:length(lst)) { lst[[i]] - as.matrix(lst[[i]]) rownames(lst[[i]]) - rep(names(lst)[i], nrow(lst[[i]])) } dta - c() for (i in 1:length(lst)) dta - rbind(dta, as.matrix(lst[[i]])) dta Hope it helps. Cheers, Filipe -Mensagem original- De: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Em nome de Vickie S Enviada em: quarta-feira, 20 de julho de 2011 18:04 Para: r-help@r-project.org Assunto: [R] Question about converting list items in matrix Hi friends, I have got a list where each element might have variable number of members. $`4213` [1] 214077_x_at $`164832` [1] 225996_at 235977_at $`339010` [1] NA $`23410` [1] 221562_s_at 221913_at 49327_at $`285386` [1] 229764_at $`2099` [1] 205225_at 211233_x_at 211234_x_at 211235_s_at [5] 211627_x_at 215551_at 215552_s_at 217163_at [9] 217190_x_at I want to integrate this list in a matrix format like this : 4213 214077_x_at 164832 225996_at 164832 235977_at 339010 NA 23410 221562_s_at 23410 221913_at 23410 49327_at Any idea how can I make such type of matrix ? Thanks, Vickie [[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. ---End Message--- This message and its attachments may contain confidential and/or privileged information. If you are not the addressee, please, advise the sender immediately by replying to the e-mail and delete this message. Este mensaje y sus anexos pueden contener información confidencial o privilegiada. Si ha recibido este e-mail por error por favor bórrelo y envíe un mensaje al remitente. Esta mensagem e seus anexos podem conter informação confidencial ou privilegiada. Caso não seja o destinatário, solicitamos a imediata notificação ao remetente e exclusão da mensagem.__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] comparing SAS and R survival analysis with time-dependent covariates
On Wed, Jul 20, 2011 at 12:02 PM, AO_Statistics abouesl...@gmail.com wrote: Thomas Lumley-2 wrote: [...] The warning and error messages are correct here. Look at the point estimate. It's a log hazard ratio of about 20 in one case and about -20 in the other case. The true partial maximum likelihood estimator is infinite. The estimated standard errors are meaningless, since the partial likelihood isn't close to quadratic at the maximum. [...] I see. It explains the results for these testing data sets. But, with my real data set I get these results : With SAS : estimate FERM : 1.47654 se : 0.03117 Pr Khi 2 : .0001 hazard ratio : 4.378 convergence status : Convergence criterion (GCONV=1E-8) satisfied. This time, the hazard ratio is not big. The maximum of the partial likelihood seems to be reached. The program takes about 45 seconds to finish computation. My sample contains 6588 observations with a lot of ties (discrete time values). With R : I don't get any result. The program freezes and does not respond. I waited for about 1 hour without a result. So can I conclude in this case that the problem with the coxph function is due to computation power rather than another algorithmic problem ? I do not understand why you expect to get comparable results with SAS discrete and coxph exact. They are two different approaches to handling ties (as Terry explained; of course, some comparability should be expected in normal cases). If I understand the description of SAS discrete correctly, it is nothing else than logistic regression with the logit link, i.e., a proportional odds model. Have you tried the 'coxreg' function in 'eha' with the option method = 'ml'? It performs logistic regression with the cloglog link, i.e., a discrete analogue to the continuous time proportional hazards model. If you want to mimic exactly what SAS (discrete) does in R, try 'toBinary' in eha, and run an ordinary logistic regression on the result. Should be close to what SAS gives you. One caveat; the result of 'toBinary' may be a too huge data frame for the memory configuration of your computer. -- View this message in context: http://r.789695.n4.nabble.com/comparing-SAS-and-R-survival-analysis-with-time-dependent-covariates-tp874438p3680340.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. -- Göran Broström __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Bootstrap
Hi all, I am facing difficulty on how to use bootstrap sampling and below is my example of function. Read a data , use some functions and use iteration to find the solution( ie, convergence is reached). I want to use bootstrap approach to do it several times (200 or 300 times) this whole process and see the distribution of parameter of interest. Below is a small example that resembles my problem. However, I found out all samples are the same. So I would appreciate your help on this case. #** rm(list=ls()) xx - read.table(textConnection( y x 11 5.16 11 4.04 14 3.85 19 5.68 4 1.26 23 7.89 15 4.25 17 3.94 7 2.35 17 4.74 14 5.49 11 4.12 17 5.92), header=TRUE) data - as.matrix(xx) closeAllconnections() Nt - NULL for (Ncount in 1:100) { y - data[,1] x - data[,2] n - length(x) X - cbind(rep(1,n),x) #covariate/design matrix obeta- c(1,1) #previous/starting values of beta nbeta - c(0,0)#new beta iter=0 while(crossprod(obeta-nbeta)10^(-12)) { nbeta - obeta eta - X%*%nbeta mu- eta mu1 - 1/eta W - diag(as.vector(mu1)) Z - X%*%nbeta+(y-mu) XWX - t(X)%*%W%*%X XWZ - t(X)%*%W%*%Z Cov - solve(XWX) obeta - Cov%*%XWZ iter - iter+1 cat(Iteration # and beta1= ,iter, nbeta, \n) } Nt[Ncount] - nbeta[1,1] } Nt summary(Nt) #**e* [[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] repeat a sequence - but not for a full number of times
Apologies, for a very simple question. I forgot how to do it - although I remember reading about getting a warning in such a situation. I have a data frame. It happens to be 10 rows but it could be 11 or 3 or 13... x-data.frame(a=1:10) I need to add variable b that is a sequence of 1:3 - repeated again and again so that the result is: x a b 1 1 2 2 3 3 4 1 5 2 6 3 7 1 8 2 9 3 10 1 Thanks a lot! -- Dimitri Liakhovitski marketfusionanalytics.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] repeat a sequence - but not for a full number of times
Never mind - found it: x-data.frame(a=1:10) x$b-rep(1:3,nrow(x)%/%3,len=nrow(x)) Dimitri On Wed, Jul 20, 2011 at 6:15 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Apologies, for a very simple question. I forgot how to do it - although I remember reading about getting a warning in such a situation. I have a data frame. It happens to be 10 rows but it could be 11 or 3 or 13... x-data.frame(a=1:10) I need to add variable b that is a sequence of 1:3 - repeated again and again so that the result is: x a b 1 1 2 2 3 3 4 1 5 2 6 3 7 1 8 2 9 3 10 1 Thanks a lot! -- Dimitri Liakhovitski marketfusionanalytics.com -- Dimitri Liakhovitski marketfusionanalytics.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] repeat a sequence - but not for a full number of times
Or you could take advantage of R's automatic recycling: x$b - rep(1:3, length=nrow(x)) x a b 1 1 1 2 2 2 3 3 3 4 4 1 5 5 2 6 6 3 7 7 1 8 8 2 9 9 3 10 10 1 Thanks for providing a simple reproducible example. Sarah On Wed, Jul 20, 2011 at 6:20 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Never mind - found it: x-data.frame(a=1:10) x$b-rep(1:3,nrow(x)%/%3,len=nrow(x)) Dimitri On Wed, Jul 20, 2011 at 6:15 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Apologies, for a very simple question. I forgot how to do it - although I remember reading about getting a warning in such a situation. I have a data frame. It happens to be 10 rows but it could be 11 or 3 or 13... x-data.frame(a=1:10) I need to add variable b that is a sequence of 1:3 - repeated again and again so that the result is: x a b 1 1 2 2 3 3 4 1 5 2 6 3 7 1 8 2 9 3 10 1 -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Bootstrap
I didn't see bootstrap steps in your code. One way to modify your codes for (Ncount in 1:100) { b.data-data[sample(1:nrow(data),replace=T),] y -b.data[,1] x -b.data[,2] n - length(x) ... ### make appropriate changes if needed } Weidong Gu On Wed, Jul 20, 2011 at 6:09 PM, Val valkr...@gmail.com wrote: Hi all, I am facing difficulty on how to use bootstrap sampling and below is my example of function. Read a data , use some functions and use iteration to find the solution( ie, convergence is reached). I want to use bootstrap approach to do it several times (200 or 300 times) this whole process and see the distribution of parameter of interest. Below is a small example that resembles my problem. However, I found out all samples are the same. So I would appreciate your help on this case. #** rm(list=ls()) xx - read.table(textConnection( y x 11 5.16 11 4.04 14 3.85 19 5.68 4 1.26 23 7.89 15 4.25 17 3.94 7 2.35 17 4.74 14 5.49 11 4.12 17 5.92), header=TRUE) data - as.matrix(xx) closeAllconnections() Nt - NULL for (Ncount in 1:100) { y - data[,1] x - data[,2] n - length(x) X - cbind(rep(1,n),x) #covariate/design matrix obeta- c(1,1) #previous/starting values of beta nbeta - c(0,0) #new beta iter=0 while(crossprod(obeta-nbeta)10^(-12)) { nbeta - obeta eta - X%*%nbeta mu - eta mu1 - 1/eta W - diag(as.vector(mu1)) Z - X%*%nbeta+(y-mu) XWX - t(X)%*%W%*%X XWZ - t(X)%*%W%*%Z Cov - solve(XWX) obeta - Cov%*%XWZ iter - iter+1 cat(Iteration # and beta1= ,iter, nbeta, \n) } Nt[Ncount] - nbeta[1,1] } Nt summary(Nt) #**e* [[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] Changing a matrix based on eigen value
A homework problem? -- Bert On Wed, Jul 20, 2011 at 10:06 AM, B. Jonathan B. Jonathan bkheijonat...@gmail.com wrote: Dear all, my question is not directly related to R, however I believe that experts here would not mind anything to have a look on my problem. Please consider a symmetric matrix and it's eigen values: set.seed(1) mat - matrix(rnorm(36), 6) mat - mat %*% t(mat) # symmetric matrix mat [,1] [,2] [,3] [,4] [,5] [,6] [1,] 3.920570 1.9339770 1.29012167 -1.4627174 -1.5655953 -1.82083435 [2,] 1.933977 5.8501784 -1.70504980 0.7195951 1.4252209 -3.11543738 [3,] 1.290122 -1.7050498 3.31434984 -0.6324029 0.1860666 -0.08234236 [4,] -1.462717 0.7195951 -0.63240294 5.4179467 0.9003576 -3.61864495 [5,] -1.565595 1.4252209 0.18606662 0.9003576 4.5248002 0.52702347 [6,] -1.820834 -3.1154374 -0.08234236 -3.6186449 0.5270235 6.02038872 eigen(mat)$values [1] 11.4213448 7.3302845 5.7033748 3.9863332 0.4827576 0.1241385 Here my goal is to find the nearest matrix of mat for which the minimum eigen value is 0.20 (I would rather want to fix some arbitrary value). While finding that nearest matrix, I would like to keep all other properties (whatever are those) of my original matrix mat as unaltered as possible. Is there any algorithm to achieve that? Thanks for your 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. -- Men by nature long to get on to the ultimate truths, and will often be impatient with elementary studies or fight shy of them. If it were possible to reach the ultimate truths without the elementary studies usually prefixed to them, these would not be preparatory studies but superfluous diversions. -- Maimonides (1135-1204) Bert Gunter Genentech Nonclinical Biostatistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] PCA - princomp can only be used with more units than variables
Hi Armin, Please copy the list on your emails. Providing your matrix A (or some other reproducible example) would be useful to anyone who wanted to help you. It is easy to do by copying the output from your console from running: dput(A) This would at least let us try out your code on your data. On Wed, Jul 20, 2011 at 3:28 AM, a.me...@yahoo.co.uk a.me...@yahoo.co.uk wrote: Thanks for your continued support Joshua! I first have run prcomp() and now use principal() to reduce the principal components with varimax. Here is the code so far. print(START.) print(reading in Matrix A) A=read.delim('C:/Work/Docs/Merlyn Stuff/Leachate/A.txt') print(printing the initial Matrix A) A print(scaling determinands in Matrix A to maximum) ncols=ncol(A) c=1 while (c = ncols) { V=A[,c] max=max(V) V=V/max A[,c]=V c=c+1 } print(printing Matrix A with scaled determinands) A print(performing PCA of Matrix A to Matrix Apc) Apc = prcomp(A) print(calculating scores of Apc as Matrix Apcs) Apcs = as.matrix(A) %*% as.matrix(Apc$rotation) print(printing scores from the PCA (Matrix Apcs)) Apcs print(performing Varimax rotation of Matrix Apcs to Matrix Apcsv) library(psych) Apcsv-principal(Apcs,nfactors = 3,rotate = varimax) print(scaling Matrix Apcsv to range (0,1)) Apcsv=Apcsv-min(Apcsv) Apcsv=Apcsv*(1/max(Apcsv)) print(printing Matrix Apcsv scaled to range (0,1)) Apcsv But there is an error on this part. Apcsv-principal(Apcs,nfactors = 3,rotate = varimax) Error in eigen(r) : infinite or missing values in 'x' In addition: Warning message: In sqrt(diag(r)) : NaNs produced Have you got any ideas? I have already tried to tell you that what you are doing does not make sense to me. The only other advice I can offer is to seek the advice or help of a local statistician. Regards, Armin I have got so far as to use the principal function On 20/07/2011 03:56, Joshua Wiley wrote: On Mon, Jul 18, 2011 at 10:48 AM, a.me...@yahoo.co.uk a.me...@yahoo.co.uk wrote: Ok thank you Josh. Basically I have a matrix A with 7 rows and 18 columns. If i j (where i is the number of rows in your matrix and j is the number of columns), then the determinant of the covariance (or correlation) matrix |Sigma_A| will be 0 (or very near zero, you can easily convince yourself of this by running det(cov(matrix(rnorm(90), 9))) as many times as you need). From Cramer's Rule, if the determinant of the matrix is 0, there is not a unique solution (clarifications/corrections are welcome if any of this is wrong). What I am told is I need the 'varimax rotated scores from the PCA analysis of matrix A' Who told you that? Is this homework? You could look at the ?principal function in package psych. That said, if this is homework I would talk with your instructor more, and if this is anything beyond an exercise (i.e., has real world implications), I would seek the advice/help of a local statistician. I can choose from 3 up to 7 components. My problem is how to carry out the above. Have you any ideas? Would appreciate your help! Armin On 18/07/2011 18:07, Joshua Wiley wrote: Hi, You need to explain what you want to do. This is not a software issue, you simply cannot create more uncorrelated variables than you have observations. Josh On Mon, Jul 18, 2011 at 8:53 AM, a.me...@yahoo.co.uk a.me...@yahoo.co.uk wrote: Hi, May I ask a question about a thread https://stat.ethz.ch/pipermail/r-help/2005-March/068365.html? I understand I need to use prcomp instead of princomp when i have less units than variables. However, when I use prcomp the scores is NULL. How can I overcome this? Regards, Armin -- Kind Regards, Armin Mewes Groundesign 10 Jerusalem street Belfast BT7 1QN Tel. (0044)(0)2890280887 Email. enquir...@groundesign.net www. www.groundesign.net [[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. -- Kind Regards, Armin Mewes Groundesign 10 Jerusalem street Belfast BT7 1QN Tel. (0044)(0)2890280887 Email. enquir...@groundesign.net www. www.groundesign.net -- Kind Regards, Armin Mewes Groundesign 10 Jerusalem street Belfast BT7 1QN Tel. (0044)(0)2890280887 Email.enquir...@groundesign.net www. www.groundesign.net -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles https://joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible
[R] Cleveland Dot plots: tick labels and error bars
Dear list, I've been learning how to make a 2x2 paneled dotplot in lattice without any previous experience using lattice. my code thusfar is: nut-read.table(/Users/colinwahl/Desktop/nutsimp_noerror.csv, T, sep= ,) attach(nut) nut1-data.frame(Nitrate, Total_Nitrogen, Phosphate, Total_Phosphorus) nut1-as.matrix(nut1) rownames(nut1)-group ylimlist=list(c(0,10), c(0,10), c(0,0.25), c(0,0.25)) dotplot(nut1, groups=FALSE, horizontal=FALSE, scales = list(relation='free' ), ylim=ylimlist, ylab=Nutrient Concentration (mg/L)) I have two issues currently: eliminating y and x tick labels between panels, and creating error bars. 1st issue: Figure 4.1 in Deepayan Sarkar's book creates a simple 2x2 dotplot that only has x and y axis tick labels on the bottom and left margins of the whole figure: dotplot(VADeaths, groups = FALSE) When I add scales = list(relation='free') to customize y ranges with ylim=ylimlist, each panel has its own y and x axis tick labels. I would like the figure panels to fit to gether like this simple figure. 2nd issue: I'd like to create standard error bars for each point. The most direct option I've observed is from: http://www.unc.edu/courses/2010fall/ecol/563/001/docs/solutions/assign2.htm It seems to use the following panel function to create 95% conf. intervals: panel=function(x,y) { panel.grid(v=0, h=-6, lty=3) panel.segments(new.data$lower95, as.numeric(y), new.data$upper95, as.numeric(y), lty=1, col=1) panel.segments(new.data$lower50, as.numeric(y), new.data$upper50, as.numeric(y), lty=1, lwd=4, col='grey60') panel.xyplot(x, y, pch=16, cex=1.2, col='white') panel.xyplot(x, y, pch=1, cex=1.1, col='black') panel.abline(v=0, col=2, lty=2) } I tried to adapt this to my data resulting in the following code: dotplot(nut1, groups=FALSE, horizontal=FALSE, scales = list(relation='free' ), ylim=ylimlist, ylab=Nutrient Concentration (mg/L), panel=function(x,y) { panel.segments(nut$N.upper, as.numeric(y), nut$N.lower, as.numeric(y), lty=1 , col=1) }) I have no experience with panel functions and would very much appreciate advice. Thank you, Colin Wahl Graduate Student Dept. of Biology Western Washington University [[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] R on Multicore for Linux
Hi all, I have R installed on a box, which is running on a machine with 16 core and Redhat - Linux. I am handling huge (size of dataset will be 5 GB) dataset. Lets assume that my data is in the form of structured (multiple) logs. I access the data by using all.files(). Since by default basic version of R utilizes single core, the processing of my analysis code is taking too much time. I got to know that mclapply() can be used to use all cores (processors) to make R much faster when we have multicores. Can anyone help me in understanding how to use mclapply() function in the above situation. Thanks in advance Regards, Madana -- View this message in context: http://r.789695.n4.nabble.com/R-on-Multicore-for-Linux-tp3682318p3682318.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] Problem with RODBC
On 20/07/11 18:56, Dieter Menne wrote: David Scott-6 wrote: I have been trying to read some data from an Excel workbook without success. ... faults- sqlFetch(channel, sqtable = 'Data', +colnames = FALSE, as.is = TRUE) faults [1] HY001 -1040 [Microsoft][ODBC Excel Driver] Too many fields defined. [2] [RODBC] ERROR: Could not SQLExecDirect 'SELECT * FROM [Data$]' I have given up using odbc/Excel without named ranges, but I know it works sometimes. xlsReadWrite works well for whole sheets, while the gdata/Perl solutions can be terribly slow (minutes instead of seconds) with large files. I had seen the message above before, and it had to do with some invisible characters in the fields. I managed to get it to work by exporting value of the sheet, which seems to do a cleanup. Alternatively, a Copy/PasteValue. After that, my curiosity was satisfied, and I returned to named ranges or xlsReadWrite. Dieter Thanks Dieter. Your reply prompted me to carry out some experimentation which confirmed to me the validity of your conclusions. I was unable to read the data satisfactorily using RODBC without creating a named range. Once I created a named range all was fine. I did some searching for unusual characters in the data set, but couldn't find anything untoward. I tried removing the 1st row which had drop down lists but to no avail. Another approach which worked was to copy the data from the existing sheet to a new sheet, retaining values and number formats. Finally, I decided to save the workbook in .xlsx format, and use odbcConnectExcel2007. I was then able to read the data successfully, with one problem being that 255 columns were read, when only 20 actually contained data. The read also seemed a bit slow. So, a few workarounds for anyone facing this problem in the future: named range; copy the data values to a new sheet; or use .xlsx format. David Scott -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R on Multicore for Linux
Make this reproducible. On Wed, Jul 20, 2011 at 6:44 PM, Madana_Babu madana_b...@infosys.com wrote: Hi all, I have R installed on a box, which is running on a machine with 16 core and Redhat - Linux. I am handling huge (size of dataset will be 5 GB) dataset. Lets assume that my data is in the form of structured (multiple) logs. I access the data by using all.files(). Since by default basic version of R utilizes single core, the processing of my analysis code is taking too much time. I got to know that mclapply() can be used to use all cores (processors) to make R much faster when we have multicores. Can anyone help me in understanding how to use mclapply() function in the above situation. Thanks in advance Regards, Madana -- View this message in context: http://r.789695.n4.nabble.com/R-on-Multicore-for-Linux-tp3682318p3682318.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. -- Stephen Sefick | Auburn University | | Biological Sciences | | 331 Funchess Hall | | Auburn, Alabama | | 36849 | |___| | sas0...@auburn.edu | | http://www.auburn.edu/~sas0025 | |___| Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis A big computer, a complex algorithm and a long time does not equal science. -Robert Gentleman __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Changing a matrix based on eigen value
It is not any homework problem. I just need some pointer. Given that I think I would be able to carry forward. Thanks, On Thu, Jul 21, 2011 at 4:52 AM, Bert Gunter gunter.ber...@gene.com wrote: A homework problem? -- Bert On Wed, Jul 20, 2011 at 10:06 AM, B. Jonathan B. Jonathan bkheijonat...@gmail.com wrote: Dear all, my question is not directly related to R, however I believe that experts here would not mind anything to have a look on my problem. Please consider a symmetric matrix and it's eigen values: set.seed(1) mat - matrix(rnorm(36), 6) mat - mat %*% t(mat) # symmetric matrix mat [,1] [,2][,3] [,4] [,5][,6] [1,] 3.920570 1.9339770 1.29012167 -1.4627174 -1.5655953 -1.82083435 [2,] 1.933977 5.8501784 -1.70504980 0.7195951 1.4252209 -3.11543738 [3,] 1.290122 -1.7050498 3.31434984 -0.6324029 0.1860666 -0.08234236 [4,] -1.462717 0.7195951 -0.63240294 5.4179467 0.9003576 -3.61864495 [5,] -1.565595 1.4252209 0.18606662 0.9003576 4.5248002 0.52702347 [6,] -1.820834 -3.1154374 -0.08234236 -3.6186449 0.5270235 6.02038872 eigen(mat)$values [1] 11.4213448 7.3302845 5.7033748 3.9863332 0.4827576 0.1241385 Here my goal is to find the nearest matrix of mat for which the minimum eigen value is 0.20 (I would rather want to fix some arbitrary value). While finding that nearest matrix, I would like to keep all other properties (whatever are those) of my original matrix mat as unaltered as possible. Is there any algorithm to achieve that? Thanks for your 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. -- Men by nature long to get on to the ultimate truths, and will often be impatient with elementary studies or fight shy of them. If it were possible to reach the ultimate truths without the elementary studies usually prefixed to them, these would not be preparatory studies but superfluous diversions. -- Maimonides (1135-1204) Bert Gunter Genentech Nonclinical Biostatistics [[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] gls yields much smaller std. errors with different base for contrasts
Dear List, After running a compound symmetric model using gls, I realized that the default contrasts were not the ones that made the most sense given the biological relationships among the factor levels. When I either changed the factor levels to re-arrange the order they occur in the gls model (not shown below) OR specifically change the contrasts I get the exact same estimates for the intercepts but now with TINY standard errors for these estimates. Below is some example code and output for what I am attempting. 1 rep-as.factor(c(1,1,1,1,1,1,2,2,2,2,2,2,1,1,1,1,1,1,2,2,2,2,2,2,1,1,1,1,1,1,2,2,2,2,2,2)) 1 tank-as.factor(c(2,2,2,2,2,2,7,7,7,7,7,7,1,1,1,3,3,3,6,6,6,8,8,8,4,4,4,4,4,4,5,5,5,5,5,5)) 1 sex_ratio-as.factor(c(6m:6f,6m:6f,6m:6f,6m:6f,6m:6f,6m:6f,6m:6f,6m:6f,6m:6f, 1+ 6m:6f,6m:6f,6m:6f,3m:9f,3m:9f,3m:9f,3m:9f,3m:9f,3m:9f,3m:9f,3m:9f, 1+ 3m:9f,3m:9f,3m:9f,3m:9f,6m:0f,6m:0f,6m:0f,6m:0f,6m:0f,6m:0f,6m:0f, 1+ 6m:0f,6m:0f,6m:0f,6m:0f,6m:0f)) 1 response-c(62.62,72.25,68.88,81.31,54.82,81.60,100.54,66.17,120.74,109.64,79.23,65.84, 1+ 81.49,99.81,93.39,85.42,157.41,32.92,97.8,49.17,53.42,76.30,74.72,24.84,131.83,113.64, 1+ 103,152.05,118.94,65.71,133.98,106.40, 108.57,156.37,110.66,126.76) 1 tmp.data-data.frame(rep, tank, sex_ratio, response) 1 str(tmp.data) 'data.frame': 36 obs. of 4 variables: $ rep : Factor w/ 2 levels 1,2: 1 1 1 1 1 1 2 2 2 2 ... $ tank : Factor w/ 8 levels 1,2,3,4,..: 2 2 2 2 2 2 7 7 7 7 ... $ sex_ratio: Factor w/ 3 levels 3m:9f,6m:0f,..: 3 3 3 3 3 3 3 3 3 3 ... $ response : num 62.6 72.2 68.9 81.3 54.8 ... 1 ###Now the first model 1 library(nlme) 1 cs1-gls(response~rep * sex_ratio, data=tmp.data, 1+ corr=corCompSymm(, form=~ 1 | tank), method=ML) 1 summary(cs1) Generalized least squares fit by maximum likelihood Model: response ~ rep * sex_ratio Data: tmp.data AIC BIClogLik 223.8389 236.5071 -103.9195 Correlation Structure: Compound symmetry Formula: ~1 | tank Parameter estimate(s): Rho -0.2 Coefficients: Value Std.Error t-value p-value (Intercept) 91.74000 7.589296 12.088077 0. rep2-29.03167 10.732886 -2.704926 0.0112 sex_ratio6m:0f 22.45500 7.589296 2.958772 0.0060 sex_ratio6m:6f -21.49333 7.589296 -2.832059 0.0082 rep2:sex_ratio6m:0f 38.62667 10.732886 3.598908 0.0011 rep2:sex_ratio6m:6f 49.14500 10.732886 4.578918 0.0001 Correlation: (Intr) rep2 sx_6:0 sx_6:6 r2:_6:0 rep2-0.707 sex_ratio6m:0f -1.000 0.707 sex_ratio6m:6f -1.000 0.707 1.000 rep2:sex_ratio6m:0f 0.707 -1.000 -0.707 -0.707 rep2:sex_ratio6m:6f 0.707 -1.000 -0.707 -0.707 1.000 Standardized residuals: Min Q1Med Q3Max -2.6848135 -0.6039727 0.0249904 0.5257303 2.9974788 Residual standard error: 21.90841 Degrees of freedom: 36 total; 30 residual 1 levels(tmp.data$sex_ratio) [1] 3m:9f 6m:0f 6m:6f 1 #Now change the contrasts so the base level is the all male sex ratio (i.e., 6m:0f) 1 tmp.data$sex_ratiob-tmp.data$sex_ratio 1 contrasts(tmp.data$sex_ratio) #original contrasts 6m:0f 6m:6f 3m:9f 0 0 6m:0f 1 0 6m:6f 0 1 1 #Set new contrasts for the copied sex_ratio column (i.e., sex_ratiob) 1 contrasts(tmp.data$sex_ratiob)-contr.treatment(n=levels(tmp.data$sex_ratio), base=2, contrasts=TRUE) 1 contrasts(tmp.data$sex_ratiob) #new contrasts 3m:9f 6m:6f 3m:9f 1 0 6m:0f 0 0 6m:6f 0 1 1 ##Now try the model again 1 cs2-gls(response~rep * sex_ratiob, data=tmp.data, 1+ corr=corCompSymm(, form=~ 1 | tank), method=ML) 1 summary(cs2) Generalized least squares fit by maximum likelihood Model: response ~ rep * sex_ratiob Data: tmp.data AIC BIClogLik 223.8389 236.5071 -103.9195 Correlation Structure: Compound symmetry Formula: ~1 | tank Parameter estimate(s): Rho -0.2 Coefficients: Value Std.Error t-value p-value (Intercept) 114.19500 0.03 36429283 0. rep2 9.59500 0.04 2164380 0. sex_ratiob3m:9f -22.45500 7.589296 -3 0.0060 sex_ratiob6m:6f -43.94833 0.04 -9913590 0. rep2:sex_ratiob3m:9f -38.62667 10.732886 -4 0.0011 rep2:sex_ratiob6m:6f 10.51833 0.06 1677724 0. Correlation: (Intr) rep2 sx_3:9 sx_6:6 r2:_3: rep2 -0.707 sex_ratiob3m:9f 0.000 0.000 sex_ratiob6m:6f -0.707 0.500 0.000 rep2:sex_ratiob3m:9f 0.000 0.000 -0.707 0.000 rep2:sex_ratiob6m:6f 0.500 -0.707 0.000 -0.707 0.000 Standardized residuals: Min Q1Med Q3Max -2.6848135 -0.6039727 0.0249904 0.5257303 2.9974788 Residual standard error: 21.90841 Degrees of freedom: 36 total; 30 residual 1 #The intercepts of the sex_ratios are the same 1 coefficients(summary(cs1))[1] #3m:9f intercept in cs1 (Intercept) 91.74 1
[R] installing Rgraphviz
Hi, I attempted to install Rgraphviz but ran into a problem. It requires graphviz 2.20.3. I have this and installed it but the Windows 7 system path variable has to be modified to include the path to the graphviz bin file. How do I do this on Windows 7? It's been a long time since I had to change the path variable. Thanks, Walt Walter R. Paczkowski, Ph.D. Data Analytics Corp. 44 Hamilton Lane Plainsboro, NJ 08536 (V) 609-936-8999 (F) 609-936-3733 w...@dataanalyticscorp.com www.dataanalyticscorp.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] installing Rgraphviz
This is off-topic, and extremely easy to find an answer to using Google. --- Jeff Newmiller The . . Go Live... DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Data Analytics Corp. w...@dataanalyticscorp.com wrote: Hi, I attempted to install Rgraphviz but ran into a problem. It requires graphviz 2.20.3. I have this and installed it but the Windows 7 system path variable has to be modified to include the path to the graphviz bin file. How do I do this on Windows 7? It's been a long time since I had to change the path variable. Thanks, Walt Walter R. Paczkowski, Ph.D. Data Analytics Corp. 44 Hamilton Lane Plainsboro, NJ 08536 (V) 609-936-8999 (F) 609-936-3733 w...@dataanalyticscorp.com www.dataanalyticscorp.com _ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Changing a matrix based on eigen value
On Jul 20, 2011, at 11:17 PM, B. Jonathan B. Jonathan wrote: It is not any homework problem. I just need some pointer. Given that I think I would be able to carry forward. Then what kind of problem _is_ it? You say: nearest matrix ... using what measure for distance or similarity? ... keep all other properties (whatever are those) of my original matrix mat as unaltered as possible. ... this really does leave your question looking ... what would be kind? ... perhaps the word nebulous would be apt? How are we supposed to make choices for you in the absence of any goals? -- David Thanks, On Thu, Jul 21, 2011 at 4:52 AM, Bert Gunter gunter.ber...@gene.com wrote: A homework problem? -- Bert On Wed, Jul 20, 2011 at 10:06 AM, B. Jonathan B. Jonathan bkheijonat...@gmail.com wrote: Dear all, my question is not directly related to R, however I believe that experts here would not mind anything to have a look on my problem. Please consider a symmetric matrix and it's eigen values: set.seed(1) mat - matrix(rnorm(36), 6) mat - mat %*% t(mat) # symmetric matrix mat [,1] [,2][,3] [,4] [,5][, 6] [1,] 3.920570 1.9339770 1.29012167 -1.4627174 -1.5655953 -1.82083435 [2,] 1.933977 5.8501784 -1.70504980 0.7195951 1.4252209 -3.11543738 [3,] 1.290122 -1.7050498 3.31434984 -0.6324029 0.1860666 -0.08234236 [4,] -1.462717 0.7195951 -0.63240294 5.4179467 0.9003576 -3.61864495 [5,] -1.565595 1.4252209 0.18606662 0.9003576 4.5248002 0.52702347 [6,] -1.820834 -3.1154374 -0.08234236 -3.6186449 0.5270235 6.02038872 eigen(mat)$values [1] 11.4213448 7.3302845 5.7033748 3.9863332 0.4827576 0.1241385 Here my goal is to find the nearest matrix of mat for which the minimum eigen value is 0.20 (I would rather want to fix some arbitrary value). While finding that nearest matrix, I would like to keep all other properties (whatever are those) of my original matrix mat as unaltered as possible. Is there any algorithm to achieve that? Thanks for your help. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Changing a matrix based on eigen value
Thanks David for your pointer. Here my original matrix is VCV matrix which is the utmost important matrix in finance. However in reality what happens is that due to incomplete data. lot of missing values (or some other problems) that matrix may be unstable like min eigen value is negative or very close to zero etc. My goal is to make that unstable matrix stable for further calculation. Here I want to make the min eigen quite far from zero in positive quadrant, however still do not want to loose much information that is hidden in my original matrix (what I call it Real information). I want to have a control on: How far min eigen value I want from zero. Please let me should I need to give more information. Thanks, On Thu, Jul 21, 2011 at 9:27 AM, David Winsemius dwinsem...@comcast.netwrote: On Jul 20, 2011, at 11:17 PM, B. Jonathan B. Jonathan wrote: It is not any homework problem. I just need some pointer. Given that I think I would be able to carry forward. Then what kind of problem _is_ it? You say: nearest matrix ... using what measure for distance or similarity? ... keep all other properties (whatever are those) of my original matrix mat as unaltered as possible. ... this really does leave your question looking ... what would be kind? ... perhaps the word nebulous would be apt? How are we supposed to make choices for you in the absence of any goals? -- David Thanks, On Thu, Jul 21, 2011 at 4:52 AM, Bert Gunter gunter.ber...@gene.com wrote: A homework problem? -- Bert On Wed, Jul 20, 2011 at 10:06 AM, B. Jonathan B. Jonathan bkheijonat...@gmail.com wrote: Dear all, my question is not directly related to R, however I believe that experts here would not mind anything to have a look on my problem. Please consider a symmetric matrix and it's eigen values: set.seed(1) mat - matrix(rnorm(36), 6) mat - mat %*% t(mat) # symmetric matrix mat [,1] [,2][,3] [,4] [,5][,6] [1,] 3.920570 1.9339770 1.29012167 -1.4627174 -1.5655953 -1.82083435 [2,] 1.933977 5.8501784 -1.70504980 0.7195951 1.4252209 -3.11543738 [3,] 1.290122 -1.7050498 3.31434984 -0.6324029 0.1860666 -0.08234236 [4,] -1.462717 0.7195951 -0.63240294 5.4179467 0.9003576 -3.61864495 [5,] -1.565595 1.4252209 0.18606662 0.9003576 4.5248002 0.52702347 [6,] -1.820834 -3.1154374 -0.08234236 -3.6186449 0.5270235 6.02038872 eigen(mat)$values [1] 11.4213448 7.3302845 5.7033748 3.9863332 0.4827576 0.1241385 Here my goal is to find the nearest matrix of mat for which the minimum eigen value is 0.20 (I would rather want to fix some arbitrary value). While finding that nearest matrix, I would like to keep all other properties (whatever are those) of my original matrix mat as unaltered as possible. Is there any algorithm to achieve that? Thanks for your help. David Winsemius, MD West Hartford, CT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] loops and simulation
http://mlg.eng.cam.ac.uk/dave/rmbenchmark.php I haven't ever tried it myself, but online sources suggest that Matlab possibly gains speed by internally avoiding loops rather than looping faster. What would stand at the end if this were true, however, is improved end user speed. Daniel From: David Winsemius [dwinsem...@comcast.net] Sent: Wednesday, July 20, 2011 9:01 AM To: Daniel Malter Cc: r-help@r-project.org Subject: Re: [R] loops and simulation On Jul 20, 2011, at 1:34 AM, Daniel Malter wrote: snipped requests, except that you were referring to SAS and had heard that R does not like loops. (This is factually wrong. But R can be slow looping). Where did you hear this? Can you cites any references? -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] loops and simulation
On Jul 21, 2011, at 1:04 AM, Daniel Malter wrote: http://mlg.eng.cam.ac.uk/dave/rmbenchmark.php I haven't ever tried it myself, but online sources suggest that Matlab possibly gains speed by internally avoiding loops rather than looping faster. What would stand at the end if this were true, however, is improved end user speed. When I ran the Toeplitz matrix creation test on a 3 year-old Mac, not the fastest available at the time, inside their 20 run test with the outer() function I get: - b - outer(j, k, function(j,k) abs(j - k) + 1) Creation of a 220x220 Toeplitz matrix (loops)___ (sec): 0.0034 - When I run their code I get a number very similar to theirs: --- for (j in 1:220) { for (k in 1:220) { b[k,j] - abs(j - k) + 1 } } Creation of a 220x220 Toeplitz matrix (loops)___ (sec): 0.2338 --- So I guess that suggests that either the loop construct or the 220 x 220 assignments are the holdup since the calculation and single assignment don't take much time. I was thinking you were comparing loops to *apply strategies, but I guess your comparison was different. -- David. Daniel From: David Winsemius [dwinsem...@comcast.net] Sent: Wednesday, July 20, 2011 9:01 AM To: Daniel Malter Cc: r-help@r-project.org Subject: Re: [R] loops and simulation On Jul 20, 2011, at 1:34 AM, Daniel Malter wrote: snipped requests, except that you were referring to SAS and had heard that R does not like loops. (This is factually wrong. But R can be slow looping). Where did you hear this? Can you cites any references? -- David Winsemius, MD West Hartford, CT David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.