Re: [R] Vectorize rearrangement within each column
As with most things like this, you can trade memory for speed. Here is an obfuscated solution that appears to eschew loops entirely. ma - matrix(10:15, nr = 3) idx - matrix(c(1,3,2, 2,3,1), nr = 3) mb - ma mb[] - as.vector(ma)[as.vector(idx + outer(rep(nrow(ma), nrow(ma)), 1:ncol(ma)-1, '*'))] mb [,1] [,2] [1,] 10 14 [2,] 12 15 [3,] 11 13 Ordinarily, though, my preferred solution would be the for() loop. Bill Venables CMIS, CSIRO Laboratories, PO Box 120, Cleveland, Qld. 4163 AUSTRALIA Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely necessary):+61 7 3826 7304 Mobile (rarely used):+61 4 1963 4642 Home Phone: +61 7 3286 7700 mailto:[EMAIL PROTECTED] http://www.cmis.csiro.au/bill.venables/ -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Osorio Roberto Sent: Friday, 19 January 2007 4:15 PM To: r-help@stat.math.ethz.ch Subject: [R] Vectorize rearrangement within each column Consider a matrix like ma = matrix(10:15, nr = 3) ma [,1] [,2] [1,] 10 13 [2,] 11 14 [3,] 12 15 I want to rearrange each column according to row indexes (1 to 3) given in another matrix, as in idx = matrix(c(1,3,2, 2,3,1), nr = 3) idx [,1] [,2] [1,]12 [2,]33 [3,]21 The new matrix mb will have for each column the corresponding column of ma indexed by the corresponding column of idx, as in mb = ma for (j in 1:2) mb[,j] = ma[idx[,j], j] mb [,1] [,2] [1,] 10 14 [2,] 12 15 [3,] 11 13 Can I avoid the for() loop? I'm specially interested to find out if a fast implementation using lapply() would be feasible for large input matrices (analogues of ma and idx) transformed into data frames. Roberto Osorio __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] ability estimate with GRM of IRT
you need to use the 'resp.patterns' argument of factor.scores(); look at ?factor.scores for more info, e.g., library(ltm) fit - grm(Environment) factor.scores(fit) factor.scores(fit, resp.patterns = Environment) I hope it helps. Best, Dimitris ps, it'd be better not to call your fitted GRM model 'grm'; check library(fortunes) fortune(dog) Dimitris Rizopoulos Ph.D. Student Biostatistical Centre School of Public Health Catholic University of Leuven Address: Kapucijnenvoer 35, Leuven, Belgium Tel: +32/(0)16/336899 Fax: +32/(0)16/337015 Web: http://med.kuleuven.be/biostat/ http://www.student.kuleuven.be/~m0390867/dimitris.htm - Original Message - From: SHEN,FENG [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Sent: Friday, January 19, 2007 5:30 AM Subject: [R] ability estimate with GRM of IRT Hi my friends, I have an issue with ability estimates when running GRM of IRT. I have responses from 242 subjects but got 183 ability estimates. Below is what I did to get the estimates. 1) I have a csv file P1.csv and I imported it into R and loaded the ltm package by doing: p1-read.table(P1.csv,header=TRUE,sep=,) library(ltm) 2) I created a subset that included columns 2 to 9 for the analysis by doing: s1-p1[,2:9] 3) I converted the subset into data.frame format by doing: s1df=data.frame(s1) 4) I checked the descriptive stats for the s1df by doing: ds1df=descript(s1df) ds1df And it was confirmed that 242 subjects' responses were imported. 5)I ran GRM on the s1df dataset by doing: grm-grm(s1df, Hessian=T) grm 6)Finally, I ran the ability estimated by doing: aes1=factor.scores(grm) aes1 And I got 183 factor-scores for observed response patterns. Besides, the 183 estimates are not for the first 183 subjects of the 242 because the response patterns of No 1 on the factor-scores list do not match those of No 1 in the s1 dataset and the same thing holds true for the rest of the response patterns. Could you help me find out what the problem is? Many thanks in advance! Feng __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 in adf command
that is, equation with constant and trend is used.if i did not include constant or trend in the equation and run the command then how i can run this command in tseries. Dear Zahid, you can employ ur.df() in package 'urca' or the wrapped functions from 'urca' contained in package 'fSeries', see ?ur.df and ?UnitrootTests for more information, respectively. Best, Bernhard * Confidentiality Note: The information contained in this mess...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] kate editor for R
On Friday 19 January 2007 03:30, Frank E Harrell Jr wrote: Like kile for LaTeX, Linux/KDE's kate editor is an excellent editor for R, with easy code submission to a running R process. Syntax highlighting is good. I have not been able to figure out two things: - how to automatically reformat a line or region of text using good indentation rules (Emacs/ESS make this so easy by just hitting Tab while the cursor is in a line, or highlighting a region and hitting Esq q) - how to cause auto-indenting as you type braces. For me, kate puts a { in column one Thanks for any pointers. Dear Frank, May I ask why you are moving to Kate from Emacs? I tried Kate with R (and Python and LaTeX) and I really liked the folding (which seems a lot better than all the not-really-functional hacks for getting folding with R and Python code) and some of the function/class browsers. However, I specially missed: a) the possibility of opening as many R processes as I want, and placing that buffer in wherever place and with whichever size I want. b) most of the rest of emacs, actually (hey, where did my shells go? and my org-mode buffer? and my ...; not to talk about the keybindings). If you feel like it, I'd like to hear about your impressions. R. Frank -- Ramón Díaz-Uriarte Centro Nacional de Investigaciones Oncológicas (CNIO) (Spanish National Cancer Center) Melchor Fernández Almagro, 3 28029 Madrid (Spain) Fax: +-34-91-224-6972 Phone: +-34-91-224-6900 http://ligarto.org/rdiaz PGP KeyID: 0xE89B3462 (http://ligarto.org/rdiaz/0xE89B3462.asc) **NOTA DE CONFIDENCIALIDAD** Este correo electrónico, y en s...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] naive bayes help
Hello I have a rather simple code and for some reason it produces an error message. If someone can tell me why and how to fix it, I would be very greatful. Thank you in advance. # create data set.seed(10) n - 200 # number of training points n.test - 200 # number of test points p-2# dimension of input space z - matrix(rnorm((n+n.test)*p),ncol=p) x - matrix(0,nrow=n+n.test,ncol=p) for (i in 1:p) x[,i] - z%*%rnorm(p) truecoef - c(1,2) prob1 - exp(x%*%truecoef)/(1+exp(x%*%truecoef)) # prob is the true probability of class 1 y - rbinom(n+n.test,1,prob1) # separate the data into train and test sets mydata - data.frame(y=y[1:n],x=x[1:n,]) mydata.test - data.frame(y=y[n+(1:n.test)],x=x[n+(1: n.test),]) ## library(e1071) mydt.nb-naiveBayes(y~ ., data=mydata) m.pr-predict(mydt.nb, mydata[,-1], type=class) regards, Leah [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] RMySQL connection
Dear All, What's wrong? library(DBI); library(RMySQL); mgr-dbDriver(MySQL); con-dbConnect(mgr,dbname=test); Error in mysqlNewConnection(drv, ...) : RS-DBI driver: (could not connect (null)@(null) on dbname test) I also tried another example library(RMySQL); mycon-dbConnect(MySQL (),user='cws',dbname=cws,host=pi,password='delores'); Error in mysqlNewConnection(drv, ...) : RS-DBI driver: (could not connect [EMAIL PROTECTED] on dbname cws) I am runningR 2.1.1 DBI 0.1-9 RMySQL 0.5-6 Windows XP Thank you much for your help. Qing Jing PhD MD __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Vectorize rearrangement within each column
Matrix subscripting can be used for this: mb - ma[cbind(as.vector(idx), as.vector(col(idx)))] dim(mb) - dim(ma) mb [,1] [,2] [1,] 10 14 [2,] 12 15 [3,] 11 13 Patrick Burns [EMAIL PROTECTED] +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and A Guide for the Unwilling S User) Osorio Roberto wrote: Consider a matrix like ma = matrix(10:15, nr = 3) ma [,1] [,2] [1,] 10 13 [2,] 11 14 [3,] 12 15 I want to rearrange each column according to row indexes (1 to 3) given in another matrix, as in idx = matrix(c(1,3,2, 2,3,1), nr = 3) idx [,1] [,2] [1,]12 [2,]33 [3,]21 The new matrix mb will have for each column the corresponding column of ma indexed by the corresponding column of idx, as in mb = ma for (j in 1:2) mb[,j] = ma[idx[,j], j] mb [,1] [,2] [1,] 10 14 [2,] 12 15 [3,] 11 13 Can I avoid the for() loop? I'm specially interested to find out if a fast implementation using lapply() would be feasible for large input matrices (analogues of ma and idx) transformed into data frames. Roberto Osorio __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Robust PCA?
BertG == Bert Gunter [EMAIL PROTECTED] on Thu, 18 Jan 2007 15:28:47 -0800 writes: BertG You seem not to have received a reply. You can use BertG cov.rob in MASS or cov.Mcd in robustbase or BertG undoubtedly others to obtain a robust covariance BertG matrix and then use that for PCA. BertG Bert Gunter Nonclinical Statistics Indeed. Thank you Bert. BTW, (for the archives) do note that their is a R special interest group (=: R-SIG) on robust statistics, and mailing list R-SIG-robust (- https://stat.ethz.ch/mailman/listinfo/r-sig-robust, also for archives) with precisely the goal to foster coordinated programming and porting of robust statistics functionality in R. Expect to see more on this topic there, within the next few days. Martin Maechler, ETH Zurich -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Talbot Katz Sent: Thursday, January 18, 2007 11:44 AM To: r-help@stat.math.ethz.ch Subject: [R] Robust PCA? Hi. I'm checking into robust methods for principal components analysis. There seem to be several floating around. I'm currently focusing my attention on a method of Hubert, Rousseeuw, and Vanden Branden (http://wis.kuleuven.be/stat/Papers/robpca.pdf) mainly because I'm familiar with other work by Rousseeuw and Hubert in robust methodologies. Of course, I'd like to obtain code for this method, or another good robust PCA method, if there's one out there. I haven't noticed the existence on CRAN of a package for robust PCA (the authors of the ROBPCA method do provide MATLAB code). -- TMK -- 212-460-5430 home 917-656-5351 cell __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Vectorize rearrangement within each column
Turn each matrix into a data.frame and then use mapply with the [ function, converting back to matrix when done: as.matrix(mapply([, as.data.frame(ma), as.data.frame(idx))) V1 V2 [1,] 10 14 [2,] 12 15 [3,] 11 13 On 1/19/07, Osorio Roberto [EMAIL PROTECTED] wrote: Consider a matrix like ma = matrix(10:15, nr = 3) ma [,1] [,2] [1,] 10 13 [2,] 11 14 [3,] 12 15 I want to rearrange each column according to row indexes (1 to 3) given in another matrix, as in idx = matrix(c(1,3,2, 2,3,1), nr = 3) idx [,1] [,2] [1,]12 [2,]33 [3,]21 The new matrix mb will have for each column the corresponding column of ma indexed by the corresponding column of idx, as in mb = ma for (j in 1:2) mb[,j] = ma[idx[,j], j] mb [,1] [,2] [1,] 10 14 [2,] 12 15 [3,] 11 13 Can I avoid the for() loop? I'm specially interested to find out if a fast implementation using lapply() would be feasible for large input matrices (analogues of ma and idx) transformed into data frames. Roberto Osorio __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] RMySQL connection
On Fri, 2007-01-19 at 09:02 +, qing Jing wrote: snip / Dear All, What's wrong? snip / I am runningR 2.1.1 DBI 0.1-9 RMySQL 0.5-6 Windows XP I'd start with updating your R installation to something less archaic - yours is at least 18 months out of date. Latest version is R 2.4.1. Thank you much for your help. Qing Jing PhD MD If you still have problems, first read the posting guide and then email the list, following the instructions in the guide. HTH G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] if else statement
?switch H. Paul Benton [EMAIL PROTECTED] writes: I'm doing some scripting and I've noticed that R doesn't seem to have an if (cond){ do }ifelse (cond) { do } else { do } type block. Is this correct or am I missing something. -- Jeff __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] kate editor for R
Ramon Diaz-Uriarte wrote: On Friday 19 January 2007 03:30, Frank E Harrell Jr wrote: Like kile for LaTeX, Linux/KDE's kate editor is an excellent editor for R, with easy code submission to a running R process. Syntax highlighting is good. I have not been able to figure out two things: - how to automatically reformat a line or region of text using good indentation rules (Emacs/ESS make this so easy by just hitting Tab while the cursor is in a line, or highlighting a region and hitting Esq q) - how to cause auto-indenting as you type braces. For me, kate puts a { in column one Thanks for any pointers. Dear Frank, May I ask why you are moving to Kate from Emacs? I tried Kate with R (and Python and LaTeX) and I really liked the folding (which seems a lot better than all the not-really-functional hacks for getting folding with R and Python code) and some of the function/class browsers. However, I specially missed: a) the possibility of opening as many R processes as I want, and placing that buffer in wherever place and with whichever size I want. b) most of the rest of emacs, actually (hey, where did my shells go? and my org-mode buffer? and my ...; not to talk about the keybindings). If you feel like it, I'd like to hear about your impressions. R. Good question Ramon. We have dozens of R users in our department and many of them were not brought up on Emacs and find it hard to learn. We are looking for an alternative to recommend for them. I love Emacs myself and find that it is the fastest editor by a significant margin, and I am used to its keybindings. But I prefer kate for printing and for managing multiple files in a project. kate has a nice sidebar for navigating the files, and indicates which files have been changed since they were saved. kate also schematically depicts nested code with side symbols connected by vertical lines for {}. Scrolling of the R output window is a little more logical in kate than in ESS. I find myself having to type Esc-shift- often in ESS/Emacs to get to the bottom of the R output but kate puts the cursor at the bottom. Also I get a little frustrated with package management in Xemacs (I know however that it's nice to be able to load thousands of packages) related to file permissions, ftp commands, anonymous logins, etc. And from a purely looks standpoint kate is superior. I tried jedit for a bit. jedit has a lot of nice features but also has problems with indenting in R. Frank Frank -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Error in basehaz function ?
Hello R-users. I believe that the way basehaz (in the survival package) compute the baseline hazard function is false. I come to question this function when it gives me hazard probabilities greater than 1. Looking at the code I think I've localised the error : hazard probability is computed as : H - -log(surv) but it seems to me that hazard probabilities is rather an instantaneous survival rate that could be computed this way : H[i] - 1 - surv[i] / surv[i-1] Using this rule I achieve satisfiable results with the two following functions : surv2haz - function(surv) { haz - surv haz[1] - 1 - surv[1] for(i in c(2:length(surv))) { haz[i] - 1 - surv[i] / surv[i - 1] } return(haz) } haz2surv - function(haz) { surv - haz surv[1] - 1 - haz[1] for(i in c(2:length(haz))) { surv[i] - (1 - haz[i]) * surv[i-1] } return(surv) } If I'm right, wouldn't it be a good idea to change the basehaz function, to avoid misleading the overconfident user (as I happen to be) ? I hope this will help contributing to a wonderful tool that speed up my understanding of statistical analysis and my research. David -- David Mas ERMES-FRE 2887-CNRS Université Pantheon-Assas Paris II 12, place du Pantheon F-75230 Paris Cedex 05 Tel: +33 (0)1 44 41 89 91 Mob: +33 (0)6 84 15 77 67 Fax: +33 (0)1 40 51 81 30 http://www.u-paris2.fr/ermes/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] kate editor for R
On Friday 19 January 2007 14:12, Frank E Harrell Jr wrote: Ramon Diaz-Uriarte wrote: On Friday 19 January 2007 03:30, Frank E Harrell Jr wrote: Like kile for LaTeX, Linux/KDE's kate editor is an excellent editor for R, with easy code submission to a running R process. Syntax highlighting is good. I have not been able to figure out two things: - how to automatically reformat a line or region of text using good indentation rules (Emacs/ESS make this so easy by just hitting Tab while the cursor is in a line, or highlighting a region and hitting Esq q) - how to cause auto-indenting as you type braces. For me, kate puts a { in column one Thanks for any pointers. Dear Frank, May I ask why you are moving to Kate from Emacs? I tried Kate with R (and Python and LaTeX) and I really liked the folding (which seems a lot better than all the not-really-functional hacks for getting folding with R and Python code) and some of the function/class browsers. However, I specially missed: a) the possibility of opening as many R processes as I want, and placing that buffer in wherever place and with whichever size I want. b) most of the rest of emacs, actually (hey, where did my shells go? and my org-mode buffer? and my ...; not to talk about the keybindings). If you feel like it, I'd like to hear about your impressions. R. Thanks for your reply, Frank. Good question Ramon. We have dozens of R users in our department and many of them were not brought up on Emacs and find it hard to learn. We are looking for an alternative to recommend for them. I love Emacs myself and find that it is the fastest editor by a significant margin, and I am used to its keybindings. But I prefer kate for printing and for managing multiple files in a project. kate has a nice sidebar for navigating the files, and indicates which files have been changed since they were saved. Ouch, I had missed that. kate also schematically depicts nested code with side symbols connected by vertical lines for {}. Yes, this feature I _really_ like. Nothing like it that I know of for emacs (I use fold-dwim, but I find it clunky). Scrolling of the R output window is a little more logical in kate than in ESS. I find myself having to type Esc-shift- often in ESS/Emacs to get to the bottom of the R output but kate puts the cursor at the bottom. Also I get a little frustrated with package management in Xemacs (I know however that it's nice to be able to load thousands of packages) related to file permissions, ftp commands, anonymous logins, etc. And from a purely looks standpoint kate is superior. I tried jedit for a bit. jedit has a lot of nice features but also has problems with indenting in R. Thanks for your feedback. I think I'll play again with kate this weekend. Best, R. Frank Frank -- Ramón Díaz-Uriarte Centro Nacional de Investigaciones Oncológicas (CNIO) (Spanish National Cancer Center) Melchor Fernández Almagro, 3 28029 Madrid (Spain) Fax: +-34-91-224-6972 Phone: +-34-91-224-6900 http://ligarto.org/rdiaz PGP KeyID: 0xE89B3462 (http://ligarto.org/rdiaz/0xE89B3462.asc) **NOTA DE CONFIDENCIALIDAD** Este correo electrónico, y en s...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] kate editor for R
On Fri, 2007-01-19 at 07:12 -0600, Frank E Harrell Jr wrote: snip Scrolling of the R output window is a little more logical in kate than in ESS. I find myself having to type Esc-shift- often in ESS/Emacs to get to the bottom of the R output but kate puts the cursor at the bottom. snip Frank, On the last point about getting the R output to scroll to the bottom, put the following in your ~/.emacs file in the custom-set-variables section: ... '(comint-move-point-for-output (quote others)) ... That will cause the R buffer to scroll to the bottom of the output, while leaving other buffers unaltered. HTH, Marc __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Problem with C extension
Hello, I try to write an extension in C, to get a faster functions. Therefore I have to add an element (vector) to a vector. The command in R is very simple: x = c(x,a) But in C I have the problem to reallocate my vector for getting more space. Everything I tried, I get a Segmentation fault. So, how can I combine two vectors in C and give the result back to R (return(x))? Thanks Markus Schmidberger -- Dipl.-Tech. Math. Markus Schmidberger Ludwig-Maximilians-Universität München IBE - Institut für medizinische Informationsverarbeitung, Biometrie und Epidemiologie Marchioninistr. 15, D-81377 Muenchen URL: http://ibe.web.med.uni-muenchen.de Mail: Markus.Schmidberger [at] ibe.med.uni-muenchen.de Tel: +49 (089) 7095 - 4599 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] if else statement
Hi also note the difference between if and ifelse. The former is similar to other languages if (true or false codition) {do this} else {do that} but ifelse(logical vector, vector for true elements, vector for false elements) see corespondent help pages. HTH Petr On 18 Jan 2007 at 19:02, H. Paul Benton wrote: Date sent: Thu, 18 Jan 2007 19:02:49 -0800 From: H. Paul Benton [EMAIL PROTECTED] To: r-help@stat.math.ethz.ch Subject:[R] if else statement Hello, I'm doing some scripting and I've noticed that R doesn't seem to have an if (cond){ do }ifelse (cond) { do } else { do } type block. Is this correct or am I missing something. THX Paul -- Research Technician Mass Spectrometry o The / o Scripps \ o Research / o Institute __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Petr Pikal [EMAIL PROTECTED] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] kate editor for R
Ramon, Frank, Great discussion. Nothing like an editor feud over morning coffee. Just kidding. On 19 January 2007 at 11:18, Ramon Diaz-Uriarte wrote: | However, I specially missed: | | a) the possibility of opening as many R processes as I want, and placing that | buffer in wherever place and with whichever size I want. | | b) most of the rest of emacs, actually (hey, where did my shells go? and my | org-mode buffer? and my ...; not to talk about the keybindings). [ Thanks for the org-mode suggestion. That looks very useful. How do I get it to sync to my Palm, though? ;-) ] On 19 January 2007 at 07:12, Frank E Harrell Jr wrote: [...] | and I am used to its keybindings. But I prefer kate for printing and | for managing multiple files in a project. kate has a nice sidebar for | navigating the files, and indicates which files have been changed since As I am doing more C++ work, I glanced at oo-browser, sidebar, ecb (all in Debian/Ubuntu). Would a real Emacs hacker be able to these to R code too? | they were saved. kate also schematically depicts nested code with side | symbols connected by vertical lines for {}. Scrolling of the R output | window is a little more logical in kate than in ESS. I find myself | having to type Esc-shift- often in ESS/Emacs to get to the bottom of | the R output but kate puts the cursor at the bottom. Also I get a | little frustrated with package management in Xemacs (I know however that | it's nice to be able to load thousands of packages) related to file | permissions, ftp commands, anonymous logins, etc. And from a purely | looks standpoint kate is superior. I switched back to GNU Emacs, using the emacs-snapshot-gtk package in Debian and Ubuntu. Prettier, and still emacs :) I get by without locally install elisp code in /usr/local -- everything I needed was apt-get'able. Dirk -- Hell, there are no rules here - we're trying to accomplish something. -- Thomas A. Edison __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] naive bayes help
change the last line m.pr-predict(mydt.nb, mydata[,-1], type=class) into m.pr-predict(mydt.nb, mydata[,-1], type=raw) see ?naiveBayes and ?predict.naiveBayes Your y is a continous dependent variable. HTH, weiwei On 1/19/07, leah martell [EMAIL PROTECTED] wrote: Hello I have a rather simple code and for some reason it produces an error message. If someone can tell me why and how to fix it, I would be very greatful. Thank you in advance. # create data set.seed(10) n - 200 # number of training points n.test - 200 # number of test points p-2# dimension of input space z - matrix(rnorm((n+n.test)*p),ncol=p) x - matrix(0,nrow=n+n.test,ncol=p) for (i in 1:p) x[,i] - z%*%rnorm(p) truecoef - c(1,2) prob1 - exp(x%*%truecoef)/(1+exp(x%*%truecoef)) # prob is the true probability of class 1 y - rbinom(n+n.test,1,prob1) # separate the data into train and test sets mydata - data.frame(y=y[1:n],x=x[1:n,]) mydata.test - data.frame(y=y[n+(1:n.test)],x=x[n+(1: n.test),]) ## library(e1071) mydt.nb-naiveBayes(y~ ., data=mydata) m.pr-predict(mydt.nb, mydata[,-1], type=class) regards, Leah [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Weiwei Shi, Ph.D Research Scientist GeneGO, Inc. Did you always know? No, I did not. But I believed... ---Matrix III __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] kate editor for R
Hi Dirk, On Friday 19 January 2007 15:39, Dirk Eddelbuettel wrote: Ramon, Frank, Great discussion. Nothing like an editor feud over morning coffee. Just kidding. Not at the editor flame war stage yet (nobody mentioned vim :-). On 19 January 2007 at 11:18, Ramon Diaz-Uriarte wrote: | However, I specially missed: | | a) the possibility of opening as many R processes as I want, and placing | that buffer in wherever place and with whichever size I want. | | b) most of the rest of emacs, actually (hey, where did my shells go? and | my org-mode buffer? and my ...; not to talk about the keybindings). [ Thanks for the org-mode suggestion. That looks very useful. How do I get it to sync to my Palm, though? ;-) ] I asked the same at the org-mode list some time back and there was a short thread (http://lists.gnu.org/archive/html/emacs-orgmode/2006-11/msg3.html). The bottom line is this: a) for the general org files, you send them to the palm as text, and you edit them there with a suitable editor (e.g., PalmED). If org-mode files are kept under version control, life becomes easier. b) dealing with calendar is a more serious problem. c) there seems to be some (not a lot of) interest in these issues, but things are not smooth yet. (I am using my Palm a lot less now, so I am no longer even doing a) regularly). On 19 January 2007 at 07:12, Frank E Harrell Jr wrote: [...] | and I am used to its keybindings. But I prefer kate for printing and | for managing multiple files in a project. kate has a nice sidebar for | navigating the files, and indicates which files have been changed since As I am doing more C++ work, I glanced at oo-browser, sidebar, ecb (all in Debian/Ubuntu). Would a real Emacs hacker be able to these to R code too? I use ecb with R directly out of the ecb box. No problem. | they were saved. kate also schematically depicts nested code with side | symbols connected by vertical lines for {}. Scrolling of the R output | window is a little more logical in kate than in ESS. I find myself | having to type Esc-shift- often in ESS/Emacs to get to the bottom of | the R output but kate puts the cursor at the bottom. Also I get a | little frustrated with package management in Xemacs (I know however that | it's nice to be able to load thousands of packages) related to file | permissions, ftp commands, anonymous logins, etc. And from a purely | looks standpoint kate is superior. I switched back to GNU Emacs, using the emacs-snapshot-gtk package in Debian and Ubuntu. Prettier, and still emacs :) I get by without locally install elisp code in /usr/local -- everything I needed was apt-get'able. I had problems with one of the packages ecb depends upon (semantic ?), and emacs-snapshot. IIRC it was a documented problem related to a bug in semantic (?); maybe it's been fixed now. But what does emacs-snapshot-gtk provide you now (besides the pretinness) that you'd miss with 21-4? R. Dirk -- Ramón Díaz-Uriarte Centro Nacional de Investigaciones Oncológicas (CNIO) (Spanish National Cancer Center) Melchor Fernández Almagro, 3 28029 Madrid (Spain) Fax: +-34-91-224-6972 Phone: +-34-91-224-6900 http://ligarto.org/rdiaz PGP KeyID: 0xE89B3462 (http://ligarto.org/rdiaz/0xE89B3462.asc) **NOTA DE CONFIDENCIALIDAD** Este correo electrónico, y en s...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Error in basehaz function ?
Hi, David Mas wrote: I believe that the way basehaz (in the survival package) compute the baseline hazard function is false. I come to question this function when it gives me hazard probabilities greater than 1. Looking at the code I think I've localised the error : hazard probability is computed as : H - -log(surv) Maybe the documentation is not clear enough about that, but what you obtain in the previous code line is not the hazard probability but the Cumulative Hazard Rate. The hazard rate is typically defined h(t)=f(t)/S(t) where f(t) is the density at time t and S(t) is the value of the survival function at time t. And please note that this is not a probability. The hazard can take on values larger than 1. Besides the literature given in ?basehaz, I can recommend Klein, JP Moeschberger, ML. Survival Analysis: Techniques for Censored and Truncated Data. Springer 2003 Starting at page 27, the hazard function and the cumulative hazard are introduced. Hope this helps, Roland [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Reading contingency tables
Thank you, Prof Ripley. However, there is still something unclear to me about read.ftable. I noticed the following behavior, which I found strange. I expected read.ftable to be an inverse of write.ftable, so to speak. Is there something I am missing, or is this a problem in read.ftable? Thanks, Giovanni file - tempfile() cat( Intercourse\n, + Race Gender Yes No\n, + White Male43 134\n, + Female 26 149\n, + Black Male29 23\n, + Female 22 36\n, + file = file) file.show(file) Intercourse Race Gender Yes No White Male43 134 Female 26 149 Black Male29 23 Female 22 36 ft - read.ftable(file) ft ## OK so far Intercourse Yes No Race Gender White Male43 134 Female 26 149 Black Male29 23 Female 22 36 x - as.table(ft) write.ftable(ftable(x, col.vars=2:3), file) file.show(file) Gender Male Female Intercourse Yes NoYes No Race White 43 134 26 149 Black 29 23 22 36 ft2 - read.ftable(file) ft2 Gender Male Female Intercourse Yes No Yes NoYes No Yes No Race White 43 134 26 149 29 23 22 36 Black 43 134 26 149 29 23 22 36 version _ platform sparc-sun-solaris2.8 arch sparc os solaris2.8 system sparc, solaris2.8 status major 2 minor 4.1 year 2006 month 12 day18 svn rev40228 language R version.string R version 2.4.1 (2006-12-18) -- Giovanni Petris [EMAIL PROTECTED] Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] x-axis in filled.contour
The filled.contour function gives me some strange output. What did I do wrong? x=seq(0,1,length=10) y=seq(0,1,length=10) z=array(rnorm(100),dim=c(10,10)) filled.contour(x,y,z) lines(0.4,0.8,type=p) abline(v=0.4,lty=dashed) the x-cooridnate of the line and the point is 0.4, but it's slightly above. This problem just appears with filled.contour, so I guess there is a problem with the key on the right. I use 2.4.0 under unbuntu Thomas __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Reading contingency tables
You are writing out x rather than ft. If you do: write.ftable(ft, file = stdout()) it looks the same as the input. On 1/19/07, Giovanni Petris [EMAIL PROTECTED] wrote: Thank you, Prof Ripley. However, there is still something unclear to me about read.ftable. I noticed the following behavior, which I found strange. I expected read.ftable to be an inverse of write.ftable, so to speak. Is there something I am missing, or is this a problem in read.ftable? Thanks, Giovanni file - tempfile() cat( Intercourse\n, + Race Gender Yes No\n, + White Male43 134\n, + Female 26 149\n, + Black Male29 23\n, + Female 22 36\n, + file = file) file.show(file) Intercourse Race Gender Yes No White Male43 134 Female 26 149 Black Male29 23 Female 22 36 ft - read.ftable(file) ft ## OK so far Intercourse Yes No Race Gender White Male43 134 Female 26 149 Black Male29 23 Female 22 36 x - as.table(ft) write.ftable(ftable(x, col.vars=2:3), file) file.show(file) Gender Male Female Intercourse Yes NoYes No Race White 43 134 26 149 Black 29 23 22 36 ft2 - read.ftable(file) ft2 Gender Male Female Intercourse Yes No Yes NoYes No Yes No Race White 43 134 26 149 29 23 22 36 Black 43 134 26 149 29 23 22 36 version _ platform sparc-sun-solaris2.8 arch sparc os solaris2.8 system sparc, solaris2.8 status major 2 minor 4.1 year 2006 month 12 day18 svn rev40228 language R version.string R version 2.4.1 (2006-12-18) -- Giovanni Petris [EMAIL PROTECTED] Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 in adf command
ur.df(y, type = c(none, drift, trend), lags = 1) in urca. this gives me all out put .but i need only p.value fromm the output. when i run the following command ur.df(y, type = c(none, drift, trend), lags = 1)$p.value this in response null.kindly help me in this regard. thanks With Best Regards Hello Zahid, you do not need to send your message three times to the list. As the package's documentation outlines: 'urca' utilises formal classes (i.e. S4). Hence, to obtain slots, you should use '@' and not '$'. Anyway, who is telling you, that p.value is a slot of a returned ur.df object? At least not ?ur.df. Now, if you take a look at ?UnitrootTests in package 'fSeries' you will read that these test implementation do contain p.values, hence: library(urca) library(fSeries) ## to generate some data use the example example(UnitrootTests) test.adf - adfTest(y, type = 'c') slotNames(test.adf) names([EMAIL PROTECTED]) [EMAIL PROTECTED] Best, Bernhard * Confidentiality Note: The information contained in this mess...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Reading contingency tables
On 1/19/07, Giovanni Petris [EMAIL PROTECTED] wrote: Date: Fri, 19 Jan 2007 11:08:22 -0500 From: Gabor Grothendieck [EMAIL PROTECTED] Cc: [EMAIL PROTECTED], r-help@stat.math.ethz.ch DomainKey-Signature: a=rsa-sha1; c=nofws;d=gmail.com; s=beta; You are writing out x rather than ft. If you do: write.ftable(ft, file = stdout()) it looks the same as the input. You are wright. The point I was trying to make is that read.ftable does not work as (I) expected for an ftable with two column variables. x is not of class ftable. It is of class table. It may print with two column variables but it does not intrinsically have two column variables. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Where can I get the latex format manual?
In www.r-project.org I can find html and pdf format, and the R-x.x-x/doc/manual has texinfo format only. I can not find latex format manual. Am I miss something? Thanks for your hints. -- Ronggui Huang Department of Sociology Fudan University, Shanghai, China 黄荣贵 复旦大学社会学系 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Reading contingency tables
Date: Fri, 19 Jan 2007 11:08:22 -0500 From: Gabor Grothendieck [EMAIL PROTECTED] Cc: [EMAIL PROTECTED], r-help@stat.math.ethz.ch DomainKey-Signature: a=rsa-sha1; c=nofws;d=gmail.com; s=beta; You are writing out x rather than ft. If you do: write.ftable(ft, file = stdout()) it looks the same as the input. You are wright. The point I was trying to make is that read.ftable does not work as (I) expected for an ftable with two column variables. Giovanni On 1/19/07, Giovanni Petris [EMAIL PROTECTED] wrote: Thank you, Prof Ripley. However, there is still something unclear to me about read.ftable. I noticed the following behavior, which I found strange. I expected read.ftable to be an inverse of write.ftable, so to speak. Is there something I am missing, or is this a problem in read.ftable? Thanks, Giovanni file - tempfile() cat( Intercourse\n, + Race Gender Yes No\n, + White Male43 134\n, + Female 26 149\n, + Black Male29 23\n, + Female 22 36\n, + file = file) file.show(file) Intercourse Race Gender Yes No White Male43 134 Female 26 149 Black Male29 23 Female 22 36 ft - read.ftable(file) ft ## OK so far Intercourse Yes No Race Gender White Male43 134 Female 26 149 Black Male29 23 Female 22 36 x - as.table(ft) write.ftable(ftable(x, col.vars=2:3), file) file.show(file) Gender Male Female Intercourse Yes NoYes No Race White 43 134 26 149 Black 29 23 22 36 ft2 - read.ftable(file) ft2 Gender Male Female Intercourse Yes No Yes NoYes No Yes No Race White 43 134 26 149 29 23 22 36 Black 43 134 26 149 29 23 22 36 version _ platform sparc-sun-solaris2.8 arch sparc os solaris2.8 system sparc, solaris2.8 status major 2 minor 4.1 year 2006 month 12 day18 svn rev40228 language R version.string R version 2.4.1 (2006-12-18) -- Giovanni Petris [EMAIL PROTECTED] Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/ __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 loading tkrplot
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Prof Brian Ripley Sent: Thursday, January 18, 2007 11:05 PM To: jim holtman Cc: R-help@stat.math.ethz.ch Subject: Re: [R] Problem with loading tkrplot As it happens I used TeachingDemos/tkrplot on Windows (R 2.4.1) with a class example yesterday. Wow, first I make it into the fortunes package. Now I find out that Prof. Ripley is using my package in the classroom. I am starting to feel like a contributing member of society. As a side note, I just realized that this spring marks 20 years since I first used a port of the S language, I'm starting to feel old. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] integrate and quadratic forms
Thanks Jim. But a narrower problem still remains. Please, look at this new code: lambda=c(.6,.3) integral = function(u) { theta = (atan(.6*u) + atan(.3*u))/2 - .1*u/2 rho = (1+.6^2*u^2)^(1/4) * (1+.3^2*u^2)^(1/4) integrand = sin(theta)/(u*rho) } integrate(integral,0,Inf)$value [1] 1.222688 If I replace theta = sum(atan(lambda*u))/2 - .1*u/2 I get integrate(integral,0,Inf)$value [1] 1.517134 It seems there is a problem between the sum() and integrate() functions. Is there a way to solve this problem? Thanks in advance. Rogerio. -- Part of the Original Message --- They do give the same answer, unfortunately the examples you sent were not the same. Integral2 was missing a 'sin'. So I would assume there might be something else wrong with your functions. You might want to try breaking it down into smaller steps so you can see what you are doing. It definitely is hard to read in both cases. Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] hiccup in apply?
Hello, I don't understand the behavior of apply() on the data frame below. test - structure(list(Date = structure(c(13361, 13361, 13361, 13361, 13361, 13361, 13361, 13361, 13362, 13362, 13362, 13362, 13362, 13362, 13362, 13362, 13363, 13363, 13363, 13363, 13363, 13363, 13363, 13363, 13364, 13364, 13364, 13364, 13364, 13364, 13364, 13364, 13365, 13365, 13365, 13365, 13365, 13365, 13365, 13365, 13366, 13366, 13366, 13366, 13366, 13366, 13366, 13366, 13367, 13367), class = Date), RANK = as.integer(c(19, 7, 5, 4, 6, 3, 3, 4, 18, 7, 6, 4, 6, 3, 3, 4, 19, 7, 6, 4, 6, 3, 3, 4, 18, 6, 7, 4, 6, 3, 3, 4, 18, 6, 7, 4, 6, 3, 3, 4, 18, 6, 7, 4, 6, 3, 3, 4, 18, 6))), .Names = c(Date, RANK), row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50), class = data.frame) #---fine summary(test) Date RANK Min. :2006-08-01 Min. : 3.00 1st Qu.:2006-08-02 1st Qu.: 4.00 Median :2006-08-04 Median : 5.50 Mean :2006-08-03 Mean : 6.62 3rd Qu.:2006-08-05 3rd Qu.: 6.75 Max. :2006-08-07 Max. :19.00 #---isn't this supposed to work? apply(test,2,mean) Date RANK NA NA Warning messages: 1: argument is not numeric or logical: returning NA in: mean.default(newX[, i], ...) 2: argument is not numeric or logical: returning NA in: mean.default(newX[, i], ...) Thank you, b. platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 4.0 year 2006 month 10 day03 svn rev39566 language R version.string R version 2.4.0 (2006-10-03) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] x-axis in filled.contour
The filled.contour function first plots the contour plot, then the legend to the side. The plotting parameters that are in effect after the call are based on the legend, not the original plot, so the coordinate system apears to be messed up. One way around this is to use the plot.axis argument to do your annotation, look at the example in ?filled.contour that is labelled # Annotating a filled contour plot Hope this helps, -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare [EMAIL PROTECTED] (801) 408-8111 -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Thomas Steiner Sent: Friday, January 19, 2007 8:56 AM To: r-help@stat.math.ethz.ch Subject: [R] x-axis in filled.contour The filled.contour function gives me some strange output. What did I do wrong? x=seq(0,1,length=10) y=seq(0,1,length=10) z=array(rnorm(100),dim=c(10,10)) filled.contour(x,y,z) lines(0.4,0.8,type=p) abline(v=0.4,lty=dashed) the x-cooridnate of the line and the point is 0.4, but it's slightly above. This problem just appears with filled.contour, so I guess there is a problem with the key on the right. I use 2.4.0 under unbuntu Thomas __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Where can I get the latex format manual?
ronggui == ronggui [EMAIL PROTECTED] on Sat, 20 Jan 2007 00:26:23 +0800 writes: ronggui In www.r-project.org I can find html and pdf format, and the ronggui R-x.x-x/doc/manual has texinfo format only. ronggui I can not find latex format manual. Am I miss something? Thanks for your hints. Hint: Apart from the Reference (all the help pages), there is none, so it's understandable you can't find it.. Texinfo is a (very simple) dialect of TeX, LaTeX is a different (much more sophisticated) dialect. BTW, I still read (and search!) these manuals in the *info* format via Emacs [C-h i ..] which (for me) is faster than anything else.. Martin Maechler, ETH Zurich __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 C extension
Markus == Markus Schmidberger [EMAIL PROTECTED] on Fri, 19 Jan 2007 15:02:31 +0100 writes: Markus Hello, Markus I try to write an extension in C, to get a faster functions. Markus Therefore I have to add an element (vector) to a vector. The command in Markus R is very simple: x = c(x,a) aka x - c(x,a) see that's why you'd probably rather stick with R a bit longer, and profile [- help(Rprof)] your code and try to speedup quite a bit before thinking about using C ... Markus But in C I have the problem to reallocate my vector for getting more Markus space. Everything I tried, I get a Segmentation fault. Markus So, how can I combine two vectors in C and give the result back to R Markus (return(x))? and you have a copy of Writing R Extensions right in front of you, electronically at least, I mean? To return the new vector via C's return() you'd definitely need to work with .Call() {which is a good thing but really not for C-beginners}, and that needs a bit time of reading the above manual from cover to cover. Note that you probably should start with (5.8) on .Call. I'm also tending to recommend even starting to peek into R's own C source, notably the header files (src/include/...), and maybe src/main/* in order to see how R objects (SEXPs) are handled, how you add names(), dimnames() etc internally.. Hoping that helps, Martin Maechler, ETH Zurich Markus Thanks Markus Markus Schmidberger Markus -- Markus Dipl.-Tech. Math. Markus Schmidberger __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] hiccup in apply?
On Fri, 2007-01-19 at 11:36 -0500, bogdan romocea wrote: Hello, I don't understand the behavior of apply() on the data frame below. test - structure(list(Date = structure(c(13361, 13361, 13361, 13361, 13361, 13361, 13361, 13361, 13362, 13362, 13362, 13362, 13362, 13362, 13362, 13362, 13363, 13363, 13363, 13363, 13363, 13363, 13363, 13363, 13364, 13364, 13364, 13364, 13364, 13364, 13364, 13364, 13365, 13365, 13365, 13365, 13365, 13365, 13365, 13365, 13366, 13366, 13366, 13366, 13366, 13366, 13366, 13366, 13367, 13367), class = Date), RANK = as.integer(c(19, 7, 5, 4, 6, 3, 3, 4, 18, 7, 6, 4, 6, 3, 3, 4, 19, 7, 6, 4, 6, 3, 3, 4, 18, 6, 7, 4, 6, 3, 3, 4, 18, 6, 7, 4, 6, 3, 3, 4, 18, 6, 7, 4, 6, 3, 3, 4, 18, 6))), .Names = c(Date, RANK), row.names = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50), class = data.frame) #---fine summary(test) Date RANK Min. :2006-08-01 Min. : 3.00 1st Qu.:2006-08-02 1st Qu.: 4.00 Median :2006-08-04 Median : 5.50 Mean :2006-08-03 Mean : 6.62 3rd Qu.:2006-08-05 3rd Qu.: 6.75 Max. :2006-08-07 Max. :19.00 #---isn't this supposed to work? apply(test,2,mean) Date RANK NA NA Warning messages: 1: argument is not numeric or logical: returning NA in: mean.default(newX[, i], ...) 2: argument is not numeric or logical: returning NA in: mean.default(newX[, i], ...) Look at ?apply and details. Argument X of apply is supposed to be an array. Details says: If 'X' is not an array but has a dimension attribute, 'apply' attempts to coerce it to an array via 'as.matrix' if it is two-dimensional (e.g., data frames) or via 'as.array'. So you should look at what is happening with as.matrix(): str(as.matrix(test)) chr [1:50, 1:2] 2006-08-01 2006-08-01 2006-08-01 ... - attr(*, dimnames)=List of 2 ..$ : chr [1:50] 1 2 3 4 ... ..$ : chr [1:2] Date RANK Notice this is now a character matrix and not what you thought it was. So look at ?as.matrix and we see: 'as.matrix' is a generic function. The method for data frames will convert any non-numeric/complex column into a character vector using 'format' and so return a character matrix, except that all-logical data frames will be coerced to a logical matrix. When coercing a vector, it produces a one-column matrix, and promotes the names (if any) of the vector to the rownames of the matrix. Which explains what is happening. Workaround: lapply(test, mean) sapply(test, mean) Both work HTH, G Thank you, b. platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 4.0 year 2006 month 10 day03 svn rev39566 language R version.string R version 2.4.0 (2006-10-03) __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] integrate and quadratic forms
As the documentation for integrate() says, the function must be vectorized f: an R function taking a numeric first argument and returning a numeric vector of the same length. so you can't use sum(). You need matrix operations or an explicit loop to add up the terms. -thomas On Thu, 18 Jan 2007, rdporto1 wrote: Hi all. I'm trying to numerically invert the characteristic function of a quadratic form following Imhof's (1961, Biometrika 48) procedure. The parameters are: lambda=c(.6,.3,.1) h=c(2,2,2) sigma=c(0,0,0) q=3 I've implemented Imhof's procedure two ways that, for me, should give the same answer: #more legible integral1 = function(u) { o=(1/2)*sum(h*atan(lambda*u)+sigma^2*lambda*u/(1+lambda^2*u^2)) - q*u/2 rho=prod((1+lambda^2*u^2)^(h/4))*exp( (1/2)*sum((sigma*lambda*u)^2/(1+lambda^2*u^2)) ) integrand = sin(o)/(u*rho) } #same as above integral2= function(u) { ((1/2)*sum(h*atan(lambda*u)+sigma^2*lambda*u/(1+lambda^2*u^2)) - q*u/2)/ (u*(prod((1+lambda^2*u^2)^(h/4))* exp( (1/2)*sum((sigma*lambda*u)^2/(1+lambda^2*u^2)) ))) } The following should be near 0.18. However, nor the answers are near this value neither they agree each other! 1/2+(1/pi)*integrate(integral1,0,Inf)$value [1] 1.022537 1/2+(1/pi)*integrate(integral2,0,Inf)$value [1] 1.442720 What's happening? Is this a bug or OS specific? Shouldn't they give the same answer? Why do I get results so different from 0.18? In time: the procedure works fine for q=.2. I'm running R 2.4.1 in a PC with Windows XP 32bits. Other ways (in R) to find the distribution of general quadratic forms are welcome. Thanks in advance. Rogerio. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Thomas Lumley Assoc. Professor, Biostatistics [EMAIL PROTECTED] University of Washington, Seattle __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 with ets function in forecast package
I have been trying to use the ets function in the forecast package on a daily time series (ts2 is a ts object with frequency =7). However when I run the following code I get an error related to etsmodel. I have looked at ets and I can see that there is a call to the function etsmodel, but I cant seem to find info on the ets function anywhere. Does anyone know anything about the etsmodel function? this is a sample data set with sample code library(forecast) ts2 - ts(c(67,55,55,59,65,74,80,56,40,59,54,96,67,66,80,58,61,53, 76,74,67,47,63,57,54,67,85,81,70,68,53,60,72,70,60,66, 73,65,67,81,94,59,71,67,76,61,79,78,82,85,60,69,51,68, 88,70,70,53,63,70,77,79,63,74,72,85,69,85,79,75,71,61, 68,68,80,72,70,82,80,53,71,88,76,71,57,65,68,67,73,95, 94,68,64,67,65,85,92,73,67,57,58,69,82,82,76,67,77,74),frequency=7) ets(ts2) I get the following error: [1] Model: ETS(A,N,A) Error in etsmodel(y, errortype[i], trendtype[j], seasontype[k], damped[l], : Parameters out of range Any help would be appreciated. thanks, Spencer [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 C extension
This is a programming question, and I am sending a solution to R-devel (please see the posting guide). On Fri, 19 Jan 2007, Markus Schmidberger wrote: Hello, I try to write an extension in C, to get a faster functions. Therefore I have to add an element (vector) to a vector. The command in R is very simple: x = c(x,a) But in C I have the problem to reallocate my vector for getting more space. Everything I tried, I get a Segmentation fault. So, how can I combine two vectors in C and give the result back to R (return(x))? Thanks Markus Schmidberger -- Brian D. Ripley, [EMAIL PROTECTED] 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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Newbie question: Statistical functions (e.g., mean, sd) in a transform statement?
Greetings listeRs - Given a data frame such as times time1time2 time3time4 1 70.408543 48.92378 7.399605 95.93050 2 17.231940 27.48530 82.962916 10.20619 3 20.279220 10.33575 66.209290 30.71846 4 NA 53.31993 12.398237 35.65782 5 9.295965 NA 48.929201 NA 6 63.966518 42.16304 1.777342 NA one can use transform to total all or some columns, thus, times2 - transform(times,totaltime=time1+time2+time3+time4) times2 time1time2 time3time4 totaltime 1 70.408543 48.92378 7.399605 95.93050 222.6624 2 17.231940 27.48530 82.962916 10.20619 137.8863 3 20.279220 10.33575 66.209290 30.71846 127.5427 4 NA 53.31993 12.398237 35.65782NA 5 9.295965 NA 48.929201 NANA 6 63.966518 42.16304 1.777342 NANA I cannot, however, find a way, other than for looping, to use statistical functions, such as mean or sd, to compute the new column. For example, times2-transform(times,meantime=(mean(c(time1,time2,time3,time4),na.rm= TRUE))) times2 time1time2 time3time4 meantime 1 70.408543 48.92378 7.399605 95.93050 45.54178 2 17.231940 27.48530 82.962916 10.20619 45.54178 3 20.279220 10.33575 66.209290 30.71846 45.54178 4 NA 53.31993 12.398237 35.65782 45.54178 5 9.295965 NA 48.929201 NA 45.54178 6 63.966518 42.16304 1.777342 NA 45.54178 How can this be done? And, generally, what is the recommended method for creating computed new columns in data frames when for loops take too long? With thanks for any suggestions, Ben Fairbank Using version 2.4.1 on a Windows XP professional operating system. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] kate editor for R
Dirk Eddelbuettel wrote: Ramon, Frank, Great discussion. Nothing like an editor feud over morning coffee. Just kidding. On 19 January 2007 at 11:18, Ramon Diaz-Uriarte wrote: | However, I specially missed: | | a) the possibility of opening as many R processes as I want, and placing that | buffer in wherever place and with whichever size I want. | | b) most of the rest of emacs, actually (hey, where did my shells go? and my | org-mode buffer? and my ...; not to talk about the keybindings). [ Thanks for the org-mode suggestion. That looks very useful. How do I get it to sync to my Palm, though? ;-) ] On 19 January 2007 at 07:12, Frank E Harrell Jr wrote: [...] | and I am used to its keybindings. But I prefer kate for printing and | for managing multiple files in a project. kate has a nice sidebar for | navigating the files, and indicates which files have been changed since As I am doing more C++ work, I glanced at oo-browser, sidebar, ecb (all in Debian/Ubuntu). Would a real Emacs hacker be able to these to R code too? | they were saved. kate also schematically depicts nested code with side | symbols connected by vertical lines for {}. Scrolling of the R output | window is a little more logical in kate than in ESS. I find myself | having to type Esc-shift- often in ESS/Emacs to get to the bottom of | the R output but kate puts the cursor at the bottom. Also I get a | little frustrated with package management in Xemacs (I know however that | it's nice to be able to load thousands of packages) related to file | permissions, ftp commands, anonymous logins, etc. And from a purely | looks standpoint kate is superior. I switched back to GNU Emacs, using the emacs-snapshot-gtk package in Debian and Ubuntu. Prettier, and still emacs :) I get by without locally install elisp code in /usr/local -- everything I needed was apt-get'able. Dirk Thanks for the pointer to emacs-snapshot-gtk Dirk. I installed it in debian but it looked virtually identical to the emacs21 I've been using. Frank __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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 C extension
[A programming question moved from R-help] On Fri, 19 Jan 2007, Markus Schmidberger wrote: Hello, I try to write an extension in C, to get a faster functions. Therefore I have to add an element (vector) to a vector. The command in R is very simple: x = c(x,a) I don't see how you are going to code this in C appreciably faster than the R developers already have. But in C I have the problem to reallocate my vector for getting more space. Everything I tried, I get a Segmentation fault. We have no idea how you are trying to do this, or even which interface (.C, .Call, .External) you are trying to use. So, how can I combine two vectors in C and give the result back to R (return(x))? The code below is just a beginning (it does no coercion, there are missing cases and it can be improved by caching e.g. REAL(a)), but can be used by dyn.load(my_c.so) my_c - function(a, b) .Call(my_c, a, b) % cat my_c.c #include R.h #include Rinternals.h SEXP my_c(SEXP a, SEXP b) { SEXP ans; int i, na, nb; if(TYPEOF(a) != TYPEOF(b)) error(type mismatch); switch(TYPEOF(a)) { case LGLSXP: case INTSXP: case REALSXP: case STRSXP: break; default: error(unimplemented type); } na = LENGTH(a); nb = LENGTH(b); PROTECT(ans = allocVector(TYPEOF(a), na+nb)); switch(TYPEOF(a)) { case LGLSXP: case INTSXP: for(i = 0; i na; i++) INTEGER(ans)[i] = INTEGER(a)[i]; for(i = 0; i nb; i++) INTEGER(ans)[na+i] = INTEGER(a)[i]; break; case REALSXP: for(i = 0; i na; i++) REAL(ans)[i] = REAL(a)[i]; for(i = 0; i nb; i++) REAL(ans)[na+i] = REAL(a)[i]; break; case STRSXP: for(i = 0; i na; i++) SET_STRING_ELT(ans, i, STRING_ELT(a, i)); for(i = 0; i nb; i++) SET_STRING_ELT(ans, na+i, STRING_ELT(a, i)); break; } UNPROTECT(1); return ans; } -- Brian D. Ripley, [EMAIL PROTECTED] 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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Error in heatmap()
Hi, I run into following error when using heatmap() for data matrix xx. Any help is appreciated? xx contains many NAs. hv - heatmap(data.matrix(xx)) Error in hclustfun(distfun(if (symm) x else t(x))) : NA/NaN/Inf in foreign function call (arg 11) Thanks a lot. Yuhong * THIS ELECTRONIC MAIL MESSAGE AND ANY ATTACHMENT IS CONFIDENTIAL AND MAY CONTAIN LEGALLY PRIVILEGED INFORMATION INTENDED ONLY FOR THE USE OF THE INDIVIDUAL OR INDIVIDUALS NAMED ABOVE. If the reader is not the intended recipient, or the employee or agent responsible to deliver it to the intended recipient, you are hereby notified that any dissemination, distribution or copying of this communication is strictly prohibited. If you have received this communication in error, please reply to the sender to notify us of the error and delete the original message. Thank You. * [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help with ets function in forecast package
Maybe you are using an old version? This is what I get: packageDescription(forecast)$Version [1] 1.03 R.version.string # XP [1] R version 2.4.1 Patched (2006-12-30 r40331) ts2 - ts(c(67,55,55,59,65,74,80,56,40,59,54,96,67,66,80,58,61,53, + 76,74,67,47,63,57,54,67,85,81,70,68,53,60,72,70,60,66, + 73,65,67,81,94,59,71,67,76,61,79,78,82,85,60,69,51,68, + 88,70,70,53,63,70,77,79,63,74,72,85,69,85,79,75,71,61, + 68,68,80,72,70,82,80,53,71,88,76,71,57,65,68,67,73,95, + 94,68,64,67,65,85,92,73,67,57,58,69,82,82,76,67,77,74),frequency=7) ets(ts2) ETS(A,N,A) Call: ets(y = ts2) Smoothing parameters: alpha = 0.0646 gamma = 0.01 Initial states: l = 64.1174 s = 2.0613 10.2135 8.756 -7.7316 -5.1641 -6.6847 -1.4503 On 1/19/07, sj [EMAIL PROTECTED] wrote: I have been trying to use the ets function in the forecast package on a daily time series (ts2 is a ts object with frequency =7). However when I run the following code I get an error related to etsmodel. I have looked at ets and I can see that there is a call to the function etsmodel, but I cant seem to find info on the ets function anywhere. Does anyone know anything about the etsmodel function? this is a sample data set with sample code library(forecast) ts2 - ts(c(67,55,55,59,65,74,80,56,40,59,54,96,67,66,80,58,61,53, 76,74,67,47,63,57,54,67,85,81,70,68,53,60,72,70,60,66, 73,65,67,81,94,59,71,67,76,61,79,78,82,85,60,69,51,68, 88,70,70,53,63,70,77,79,63,74,72,85,69,85,79,75,71,61, 68,68,80,72,70,82,80,53,71,88,76,71,57,65,68,67,73,95, 94,68,64,67,65,85,92,73,67,57,58,69,82,82,76,67,77,74),frequency=7) ets(ts2) I get the following error: [1] Model: ETS(A,N,A) Error in etsmodel(y, errortype[i], trendtype[j], seasontype[k], damped[l], : Parameters out of range Any help would be appreciated. thanks, Spencer [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Newbie question: Statistical functions (e.g., mean, sd) in a transform statement?
On Jan 19, 2007, at 12:54 PM, Ben Fairbank wrote: Given a data frame such as times time1time2 time3time4 1 70.408543 48.92378 7.399605 95.93050 2 17.231940 27.48530 82.962916 10.20619 3 20.279220 10.33575 66.209290 30.71846 4 NA 53.31993 12.398237 35.65782 5 9.295965 NA 48.929201 NA 6 63.966518 42.16304 1.777342 NA I cannot, however, find a way, other than for looping, to use statistical functions, such as mean or sd, to compute the new column. times - data.frame(time1 = rnorm(6, 50, 20), time2 = rnorm(6, 40, 15), time3 = rnorm(6, 60, 25), time4 = rnorm(6, 55, 23)) times[4,1] - NA times[5, c(2, 4)] - NA times[6, 4] - NA times$totaltime - apply(times, 1, sum, na.rm = T) times$meantime - apply(times, 1, mean, na.rm = T) times$sdtime - apply(times, 1, sd, na.rm = T) time1time2time3time4 totaltime meantime sdtime 1 28.84859 29.94037 92.11518 71.80472 222.70886 89.08354 71.11911 2 50.72260 39.02439 61.18364 31.63962 182.57024 73.02810 55.68944 3 11.75829 28.61262 72.37066 79.23817 191.97974 76.79189 62.99902 4 NA 27.23659 75.69952 38.19262 141.12872 70.56436 44.52787 5 31.05109 NA 52.41755 NA 83.46864 55.64576 21.52078 6 54.01291 52.48922 53.97689 NA 160.47902 80.23951 46.33038 _ Professor Michael Kubovy University of Virginia Department of Psychology USPS: P.O.Box 400400Charlottesville, VA 22904-4400 Parcels:Room 102Gilmer Hall McCormick RoadCharlottesville, VA 22903 Office:B011+1-434-982-4729 Lab:B019+1-434-982-4751 Fax:+1-434-982-4766 WWW:http://www.people.virginia.edu/~mk9y/ [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] kate editor for R
On Fri, Jan 19, 2007 at 12:06:59PM -0600, Frank E Harrell Jr wrote: Thanks for the pointer to emacs-snapshot-gtk Dirk. I installed it in debian but it looked virtually identical to the emacs21 I've been using. Note that it does not replace the emacs21 binary, so you need to start it as 'emacs-snapshot-gtk'. Likeweise you need to tell R/ESS to use emacslient.emacs-snapshot instead of emacsclient as the value of optios(editor) Below is what one of Edge machines as work has: ~: ls -l /usr/bin/emacs* lrwxrwxrwx 1 root root 23 2006-04-05 12:26 /usr/bin/emacs - /etc/alternatives/emacs lrwxrwxrwx 1 root root 9 2006-12-05 11:27 /usr/bin/emacs21 - emacs21-x -rwxr-xr-x 1 root root 4412588 2006-09-15 12:35 /usr/bin/emacs21-x lrwxrwxrwx 1 root root 29 2006-04-05 12:26 /usr/bin/emacsclient - /etc/alternatives/emacsclient -rwxr-xr-x 1 root root7080 2006-09-15 12:35 /usr/bin/emacsclient.emacs21 -rwxr-xr-x 1 root root9248 2006-09-19 16:28 /usr/bin/emacsclient.emacs-snapshot lrwxrwxrwx 1 root root 32 2006-10-19 18:55 /usr/bin/emacs-snapshot - /etc/alternatives/emacs-snapshot -rwxr-xr-x 1 root root 5674120 2006-09-19 16:28 /usr/bin/emacs-snapshot-gtk Hth, Dirk -- Hell, there are no rules here - we're trying to accomplish something. -- Thomas A. Edison __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Newbie question: Statistical functions (e.g., mean, sd) in a transform statement?
Try this using the builtin data set anscombe: transform(anscombe, rowMeans = rowMeans(anscombe)) On 1/19/07, Ben Fairbank [EMAIL PROTECTED] wrote: Greetings listeRs - Given a data frame such as times time1time2 time3time4 1 70.408543 48.92378 7.399605 95.93050 2 17.231940 27.48530 82.962916 10.20619 3 20.279220 10.33575 66.209290 30.71846 4 NA 53.31993 12.398237 35.65782 5 9.295965 NA 48.929201 NA 6 63.966518 42.16304 1.777342 NA one can use transform to total all or some columns, thus, times2 - transform(times,totaltime=time1+time2+time3+time4) times2 time1time2 time3time4 totaltime 1 70.408543 48.92378 7.399605 95.93050 222.6624 2 17.231940 27.48530 82.962916 10.20619 137.8863 3 20.279220 10.33575 66.209290 30.71846 127.5427 4 NA 53.31993 12.398237 35.65782NA 5 9.295965 NA 48.929201 NANA 6 63.966518 42.16304 1.777342 NANA I cannot, however, find a way, other than for looping, to use statistical functions, such as mean or sd, to compute the new column. For example, times2-transform(times,meantime=(mean(c(time1,time2,time3,time4),na.rm= TRUE))) times2 time1time2 time3time4 meantime 1 70.408543 48.92378 7.399605 95.93050 45.54178 2 17.231940 27.48530 82.962916 10.20619 45.54178 3 20.279220 10.33575 66.209290 30.71846 45.54178 4 NA 53.31993 12.398237 35.65782 45.54178 5 9.295965 NA 48.929201 NA 45.54178 6 63.966518 42.16304 1.777342 NA 45.54178 How can this be done? And, generally, what is the recommended method for creating computed new columns in data frames when for loops take too long? With thanks for any suggestions, Ben Fairbank Using version 2.4.1 on a Windows XP professional operating system. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Newbie question: Statistical functions (e.g., mean, sd) in a transform statement?
Ben, transform() is probably the wrong tool if what you want is to 'apply a function' to the corresponding elements of time1, time2, ... , and return a vector of results. If this is what you are after, the 'apply' family of functions is what you want. See ?apply and ?mapply and the 'See Also's on each page. Chuck Berry On Fri, 19 Jan 2007, Ben Fairbank wrote: Greetings listeRs - Given a data frame such as times time1time2 time3time4 1 70.408543 48.92378 7.399605 95.93050 2 17.231940 27.48530 82.962916 10.20619 3 20.279220 10.33575 66.209290 30.71846 4 NA 53.31993 12.398237 35.65782 5 9.295965 NA 48.929201 NA 6 63.966518 42.16304 1.777342 NA one can use transform to total all or some columns, thus, times2 - transform(times,totaltime=time1+time2+time3+time4) times2 time1time2 time3time4 totaltime 1 70.408543 48.92378 7.399605 95.93050 222.6624 2 17.231940 27.48530 82.962916 10.20619 137.8863 3 20.279220 10.33575 66.209290 30.71846 127.5427 4 NA 53.31993 12.398237 35.65782NA 5 9.295965 NA 48.929201 NANA 6 63.966518 42.16304 1.777342 NANA I cannot, however, find a way, other than for looping, to use statistical functions, such as mean or sd, to compute the new column. For example, times2-transform(times,meantime=(mean(c(time1,time2,time3,time4),na.rm= TRUE))) times2 time1time2 time3time4 meantime 1 70.408543 48.92378 7.399605 95.93050 45.54178 2 17.231940 27.48530 82.962916 10.20619 45.54178 3 20.279220 10.33575 66.209290 30.71846 45.54178 4 NA 53.31993 12.398237 35.65782 45.54178 5 9.295965 NA 48.929201 NA 45.54178 6 63.966518 42.16304 1.777342 NA 45.54178 How can this be done? And, generally, what is the recommended method for creating computed new columns in data frames when for loops take too long? With thanks for any suggestions, Ben Fairbank Using version 2.4.1 on a Windows XP professional operating system. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:[EMAIL PROTECTED] UC San Diego http://biostat.ucsd.edu/~cberry/ La Jolla, San Diego 92093-0901 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Newbie question: Statistical functions (e.g., mean, sd) in a transform statement?
On Fri, 2007-01-19 at 11:54 -0600, Ben Fairbank wrote: Greetings listeRs - Here are two solutions, depending on whether you wanted the NA's or not, and I assume you wanted the row means: times3 - transform(times, meantime = rowMeans(times)) times3 time1time2 time3time4 meantime 1 70.408543 48.92378 7.399605 95.93050 55.66561 2 17.231940 27.48530 82.962916 10.20619 34.47159 3 20.279220 10.33575 66.209290 30.71846 31.88568 4NA 53.31993 12.398237 35.65782 NA 5 9.295965 NA 48.929201 NA NA 6 63.966518 42.16304 1.777342 NA NA times4 - transform(times, meantime = rowMeans(times, na.rm = TRUE)) times4 time1time2 time3time4 meantime 1 70.408543 48.92378 7.399605 95.93050 55.66561 2 17.231940 27.48530 82.962916 10.20619 34.47159 3 20.279220 10.33575 66.209290 30.71846 31.88568 4NA 53.31993 12.398237 35.65782 33.79200 5 9.295965 NA 48.929201 NA 29.11258 6 63.966518 42.16304 1.777342 NA 35.96897 HTH G Given a data frame such as times time1time2 time3time4 1 70.408543 48.92378 7.399605 95.93050 2 17.231940 27.48530 82.962916 10.20619 3 20.279220 10.33575 66.209290 30.71846 4 NA 53.31993 12.398237 35.65782 5 9.295965 NA 48.929201 NA 6 63.966518 42.16304 1.777342 NA one can use transform to total all or some columns, thus, times2 - transform(times,totaltime=time1+time2+time3+time4) times2 time1time2 time3time4 totaltime 1 70.408543 48.92378 7.399605 95.93050 222.6624 2 17.231940 27.48530 82.962916 10.20619 137.8863 3 20.279220 10.33575 66.209290 30.71846 127.5427 4 NA 53.31993 12.398237 35.65782NA 5 9.295965 NA 48.929201 NANA 6 63.966518 42.16304 1.777342 NANA I cannot, however, find a way, other than for looping, to use statistical functions, such as mean or sd, to compute the new column. For example, times2-transform(times,meantime=(mean(c(time1,time2,time3,time4),na.rm= TRUE))) times2 time1time2 time3time4 meantime 1 70.408543 48.92378 7.399605 95.93050 45.54178 2 17.231940 27.48530 82.962916 10.20619 45.54178 3 20.279220 10.33575 66.209290 30.71846 45.54178 4 NA 53.31993 12.398237 35.65782 45.54178 5 9.295965 NA 48.929201 NA 45.54178 6 63.966518 42.16304 1.777342 NA 45.54178 How can this be done? And, generally, what is the recommended method for creating computed new columns in data frames when for loops take too long? With thanks for any suggestions, Ben Fairbank Using version 2.4.1 on a Windows XP professional operating system. [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] split data set
I have a data(ABC) like this: x y A 3 4 A 1 3 B 2 6 B 4 8 C 5 4 C 6 7 I want to split this data into A: x y A 3 4 A 1 3 B B 2 6 B 4 8 C C 5 4 C 6 7 anyone knows how to do that? thanks, Aimin Yan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Vectorize rearrangement within each column
Thanks for the solutions. Here are some time tests for ma and idx being 100 X 100,000. The machine is a 2.16 GHz Intel MacBook Pro with 2 GB memory. ma - matrix(rnorm(1e7), nr = 100) # 100 X 100,000 idx - matrix(round( runif(1e7, 1, 100) ), nr = 100) # Original: system.time( { mb - ma; for (j in 1:1e5) mb[,j] - ma[idx[j],j] } ) [1] 1.354 0.087 1.435 0.000 0.000 # Prof. Venables' version: system.time( mb[] - as.vector(ma)[as.vector(idx + outer(rep(nrow(ma), nrow(ma)), 1:ncol(ma)-1, '*'))] ) [1] 0.885 0.857 2.262 0.000 0.000 # Patrick Burns' version: system.time( { mb - ma[cbind(as.vector(idx), as.vector(col(idx)))]; dim(mb) - dim(ma) } ) [1] 1.672 0.615 2.277 0.000 0.000 # Gabor Grothendieck's version led to some memory handling issue. I stepped one order of magnitude down in the number of columns but it's still very slow. ma - matrix(rnorm(1e6), nr = 100) # 100 X 10,000 idx = matrix(round( runif(1e6, 1, 100) ), nr = 100) system.time( as.matrix(mapply([, as.data.frame(ma), as.data.frame(idx))) ) [1] 2.060 0.133 2.768 0.000 0.000 So, Prof. Venables' solution is the fastest. In view of only moderate time savings, I will take his advice and keep the original loop for code clarity. Roberto Osorio -- __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] split data set
Aimin Yan wrote: I have a data(ABC) like this: x y A 3 4 A 1 3 B 2 6 B 4 8 C 5 4 C 6 7 I want to split this data into A: x y A 3 4 A 1 3 B B 2 6 B 4 8 C C 5 4 C 6 7 anyone knows how to do that? ?split df - data.frame(L = rep(c(A,B,C), each =2), x = runif(6), y=runif(6)) df L x y 1 A 0.57411628 0.01975706 2 A 0.21079282 0.62153084 3 B 0.46798592 0.97374423 4 B 0.08731642 0.33845989 5 C 0.08801709 0.93843814 6 C 0.54576658 0.26798882 split(df, df$L) $A L x y 1 A 0.5741163 0.01975706 2 A 0.2107928 0.62153084 $B L x y 3 B 0.46798592 0.9737442 4 B 0.08731642 0.3384599 $C L x y 5 C 0.08801709 0.9384381 6 C 0.54576658 0.2679888 thanks, Aimin Yan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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)
Dear R user, I am trying to reproduce the results in Montgomery D.C (2001, chap 13, example 13-1). Briefly, there are three suppliers, four batches nested within suppliers and three determinations of purity (response variable) on each batch. It is a two stage nested design, where suppliers are fixed and batches are random. y_ijk=mu+tau_i+beta_j(nested in tau_i)+epsilon_ijk Here are the data, purity-c(1,-2,-2,1, -1,-3, 0,4, 0,-4, 1, 0, 1,0,-1,0, -2,4,0,3, -3,2,-2,2, 2,-2,1,3, 4,0,-1,2, 0,2,2,1) suppli-factor(c(rep(1,12),rep(2,12),rep(3,12))) batch-factor(rep(c(1,2,3,4),9)) material-data.frame(purity,suppli,batch) If I use the function aov, I get material.aov-aov(purity~suppli+suppli:batch,data=material) summary(material.aov) Df Sum Sq Mean Sq F value Pr(F) suppli2 15.056 7.528 2.8526 0.07736 . suppli:batch 9 69.917 7.769 2.9439 0.01667 * Residuals24 63.333 2.639 --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 and I can estimate the variance component for the batches as (7.769- 2.639)/3=1.71 which is the way it is done in Montgomery, D. I want to use the function lme because I would like to make a diagnosis of the model, and I think it is more appropriate. Looking at Pinheiro and Bates, I have tried the following, library(nlme) material.lme-lme(purity~suppli,random=~1|suppli/batch,data=material) VarCorr(material.lme) Variance StdDev suppli =pdLogChol(1) (Intercept) 1.563785 1.250514 batch = pdLogChol(1) (Intercept) 1.709877 1.307622 Residual2.638889 1.624466 material.lme Linear mixed-effects model fit by REML Data: material Log-restricted-likelihood: -71.42198 Fixed: purity ~ suppli (Intercept) suppli2 suppli3 -0.417 0.750 1.583 Random effects: Formula: ~1 | suppli (Intercept) StdDev:1.250514 Formula: ~1 | batch %in% suppli (Intercept) Residual StdDev:1.307622 1.624466 Number of Observations: 36 Number of Groups: suppli batch %in% suppli 312 From VarCorr I obtain the variance component 1.71, but I am not sure if this is the way to fit the model for the nested design. Here, I also have a variance component for suppli and this is a fixed factor. Can anyone give me a clue? [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] kate editor for R
On Fri, 2007-01-19 at 16:09 +0100, Ramon Diaz-Uriarte wrote: snip I had problems with one of the packages ecb depends upon (semantic ?), and emacs-snapshot. IIRC it was a documented problem related to a bug in semantic (?); maybe it's been fixed now. But what does emacs-snapshot-gtk provide you now (besides the pretinness) that you'd miss with 21-4? snip Ramon, Just a quick heads up on the ECB issue. I am using Emacs 23 from CVS and had to update ECB and the associated packages to use this version of Emacs. I have emacs 23 installed and run from a separate download folder, so that I do not overwrite the installed stable version. I use the CEDET cedet-1.0pre3.tar.gz aggregate package from http://cedet.sourceforge.net/ as well as the ECB cvs snap shot package ecb.tar.gz from http://ecb.sourceforge.net/downloads.html. The CEDET package includes cogre, ede, eieio, semantic and speedbar. Extract these two files and then modify ~/.emacs with the following: ;; Load ECB (setq semantic-load-turn-everything-on t) (load-file /PATH/TO/CEDET/cedet-1.0pre3/common/cedet.el) (add-to-list 'load-path /PATH/TO/ECB/ecb-snap) (require 'ecb) And all seems well. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] GOF for continuous data
Is there a handy R-function for computing the chi-square goodness of fit for a regression result with a continuous variable? Rick [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Bartlett test
Bonjour, Je voudrais tester l'homoscédasdicité entre des groupes. J'aurais alors aimé savoir quelle était l'hypothèse nulle du test de bartlett. Merci pour votre aide. Matthieu. This e-mail has been scanned for all viruses by Star. The\ s...{{dropped}} __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Suggestion on how to improve efficiency when using MASS:::hubers on high-dimensional arrays
Hi Everyone, Given the scenario I have, I was wondering if anyone would be able to give me a hind on how to get the results from hubers() in a more efficient way. I have an outcome on an array [N x S x D]. I also have a factor (levels 1,2,3) stored on a matrix N x S. My objective is to get mu and sigma for each of the N rows (outcome) stratified by the factor (levels 1, 2 and 3) for each of the D levels, but using MASS:hubers(). Ideally the final result would be an array [N x D x 3 x 2]. The following toy example demonstrates what I want to do, and I'd like to improve the performance when working on my case, where S=400 and N 20 Thank you very much for any suggestion. benilton ## begin toy example set.seed(1) N - 100 S - 5 D - 2 outcome - array(rnorm(N*S*D), dim=c(N, S, D)) classes - matrix(sample(c(1:3, NA), N*S, rep=T), ncol=S) results - array(NA, dim=c(N, D, 3, 2)) library(MASS) myHubers - function(x) if (length(x)1) as.numeric(hubers(x)) else c(NA, NA) for (n in 1:N) for (d in 1:D){ tmp - outcome[n,,d] grp - classes[n,] results[n, d,,] - t(sapply(split(tmp, factor(grp, levels=1:3)), myHubers)) } ## end -- Benilton Carvalho PhD Candidate Department of Biostatistics Johns Hopkins University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Bartlett test
The null hypothesis is that the variances do not differ across groups. The Bartlett test is sensitive to non-normality and that might lead you to consider something more robust (eg, Levene's test). b On Jan 19, 2007, at 9:04 AM, Matthieu Mourroux wrote: Bonjour, Je voudrais tester l'homoscédasdicité entre des groupes. J'aurais alors aimé savoir quelle était l'hypothèse nulle du test de bartlett. Merci pour votre aide. Matthieu. __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] split data set
abc id x y 1 A 3 4 2 A 1 3 3 B 2 6 4 B 4 8 5 C 5 4 6 C 6 7 split(abc, abc$id) $A id x y 1 A 3 4 2 A 1 3 $B id x y 3 B 2 6 4 B 4 8 $C id x y 5 C 5 4 6 C 6 7 On 1/19/07, Aimin Yan [EMAIL PROTECTED] wrote: I have a data(ABC) like this: x y A 3 4 A 1 3 B 2 6 B 4 8 C 5 4 C 6 7 I want to split this data into A: x y A 3 4 A 1 3 B B 2 6 B 4 8 C C 5 4 C 6 7 anyone knows how to do that? thanks, Aimin Yan __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? [[alternative HTML version deleted]] __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] kate editor for R
Hi Marc, Thanks a lot for the detailed explanation! I'll give it a try. (But still, why emacs23? what is missing in v. 21 that you get in 23?). Best, R. On 1/19/07, Marc Schwartz [EMAIL PROTECTED] wrote: On Fri, 2007-01-19 at 16:09 +0100, Ramon Diaz-Uriarte wrote: snip I had problems with one of the packages ecb depends upon (semantic ?), and emacs-snapshot. IIRC it was a documented problem related to a bug in semantic (?); maybe it's been fixed now. But what does emacs-snapshot-gtk provide you now (besides the pretinness) that you'd miss with 21-4? snip Ramon, Just a quick heads up on the ECB issue. I am using Emacs 23 from CVS and had to update ECB and the associated packages to use this version of Emacs. I have emacs 23 installed and run from a separate download folder, so that I do not overwrite the installed stable version. I use the CEDET cedet-1.0pre3.tar.gz aggregate package from http://cedet.sourceforge.net/ as well as the ECB cvs snap shot package ecb.tar.gz from http://ecb.sourceforge.net/downloads.html. The CEDET package includes cogre, ede, eieio, semantic and speedbar. Extract these two files and then modify ~/.emacs with the following: ;; Load ECB (setq semantic-load-turn-everything-on t) (load-file /PATH/TO/CEDET/cedet-1.0pre3/common/cedet.el) (add-to-list 'load-path /PATH/TO/ECB/ecb-snap) (require 'ecb) And all seems well. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ramon Diaz-Uriarte Statistical Computing Team Structural Biology and Biocomputing Programme Spanish National Cancer Centre (CNIO) http://ligarto.org/rdiaz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] kate editor for R
xft anti-aliasing is incorporated into the version 23 unicode trunk. So it looks great on a hi-res LCD panel. Without xft, even using Bitstream fonts, it was still pretty rough on the eyes. It also fully supports GTK widgets, which is great if you are using GNOME, which I do. xft was added as a patch to version 22, but it was not very stable. Note that version 23 is in alpha status, so use at your own risk if you decide to pursue this. 21 is still the current stable release version, but 23 has been rock solid for me. I can provide you with a shell script to build it. Let me know. Best regards, Marc On Sat, 2007-01-20 at 03:59 +0100, Ramon Diaz-Uriarte wrote: Hi Marc, Thanks a lot for the detailed explanation! I'll give it a try. (But still, why emacs23? what is missing in v. 21 that you get in 23?). Best, R. On 1/19/07, Marc Schwartz [EMAIL PROTECTED] wrote: On Fri, 2007-01-19 at 16:09 +0100, Ramon Diaz-Uriarte wrote: snip I had problems with one of the packages ecb depends upon (semantic ?), and emacs-snapshot. IIRC it was a documented problem related to a bug in semantic (?); maybe it's been fixed now. But what does emacs-snapshot-gtk provide you now (besides the pretinness) that you'd miss with 21-4? snip Ramon, Just a quick heads up on the ECB issue. I am using Emacs 23 from CVS and had to update ECB and the associated packages to use this version of Emacs. I have emacs 23 installed and run from a separate download folder, so that I do not overwrite the installed stable version. I use the CEDET cedet-1.0pre3.tar.gz aggregate package from http://cedet.sourceforge.net/ as well as the ECB cvs snap shot package ecb.tar.gz from http://ecb.sourceforge.net/downloads.html. The CEDET package includes cogre, ede, eieio, semantic and speedbar. Extract these two files and then modify ~/.emacs with the following: ;; Load ECB (setq semantic-load-turn-everything-on t) (load-file /PATH/TO/CEDET/cedet-1.0pre3/common/cedet.el) (add-to-list 'load-path /PATH/TO/ECB/ecb-snap) (require 'ecb) And all seems well. HTH, Marc Schwartz __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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] Suggestion on how to improve efficiency when using MASS:::hubers on high-dimensional arrays
The usual advice would seem to apply here: - profile (the real application, not a toy example) to see where the bottlenecks are. - rewrite those in C. It is quite possible that hubers would benefit in your problem by being rewritten in C. However, there is a reason why it was not. It is a univariate location estimator, and using multiple univariate location estimators is not a robust multivariate location estimator. So in so far as I understand your problem sketch, you would be better off with a multivariate estimator for your N outcomes. There may be problems which need the application of very large numbers of univariate robust estimators, but they are not commonplace. On Fri, 19 Jan 2007, Benilton Carvalho wrote: Hi Everyone, Given the scenario I have, I was wondering if anyone would be able to give me a hind on how to get the results from hubers() in a more efficient way. I have an outcome on an array [N x S x D]. I also have a factor (levels 1,2,3) stored on a matrix N x S. My objective is to get mu and sigma for each of the N rows (outcome) stratified by the factor (levels 1, 2 and 3) for each of the D levels, but using MASS:hubers(). Ideally the final result would be an array [N x D x 3 x 2]. The following toy example demonstrates what I want to do, and I'd like to improve the performance when working on my case, where S=400 and N 20 Thank you very much for any suggestion. benilton ## begin toy example set.seed(1) N - 100 S - 5 D - 2 outcome - array(rnorm(N*S*D), dim=c(N, S, D)) classes - matrix(sample(c(1:3, NA), N*S, rep=T), ncol=S) results - array(NA, dim=c(N, D, 3, 2)) library(MASS) myHubers - function(x) if (length(x)1) as.numeric(hubers(x)) else c(NA, NA) for (n in 1:N) for (d in 1:D){ tmp - outcome[n,,d] grp - classes[n,] results[n, d,,] - t(sapply(split(tmp, factor(grp, levels=1:3)), myHubers)) } ## end -- Benilton Carvalho PhD Candidate Department of Biostatistics Johns Hopkins University __ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/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, [EMAIL PROTECTED] 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@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.