Re: [R] how does one print code
I downloaded the code, as Duncan Murdoch suggested. I also used sink() as suggested by others and found that the two methods gave identical results. I then fixed the bug in a private file and tried it out on a number of examples. It now seems to work fine, as far as I can tell. From CRAN, I found a publication date in 2005, and the author's email address. Should I do anything else, in addition to writing to the author, which I have already done? Thanks David -- View this message in context: http://n4.nabble.com/how-does-one-print-code-tp1788686p1810973.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] SSH Through R Script
Hi, I am trying to SSH to a remote server through R script. In other words, I would like to know how I can get a SSH connection to the remote server and then execute commands on that server with the R script. So in bash, I would normally type ssh -lusername remoteserver.com; press enter and then wait for the password prompt to key in my password. I have tried system(ssh remoteserver.com) but that doesn't work because, from what I know, SSH requires user interactivity - I am required to key in my password. I tried looking up about putting password as a command line parameter, but SSH doesn't allow that, my only option then is to set up a private/public key pair. But the admin of the remoteserver doesn't allow me to do that. Is there a way in which I can SSH in? Or is there a command in R that allows me to interact with the command prompts interactively? thanks, afoo -- View this message in context: http://n4.nabble.com/SSH-Through-R-Script-tp1809635p1809635.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] general linear hypothesis testing for manova model
John Fox wrote: Dear Philippe, The linear.hypothesis() function in the car package should do what you want. I hope this helps, John Also, at least in many cases, anova.mlm in the base package. The catch is that the L of the LBM==0 has to correspond to a linear model reduction. The M is the transpose of the transformation matrix (which anova.mlm calls T). -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to get the penalty matrix for natural cubic spline?
Hi, all I am trying to get the basis matrix and penalty matrix for natural cubic splines. In the splines package of R,ns can generate the B-spline basis matrix for a natural cubic spline. How can I get the basis matrix and penalty matrix for natural cubic spline. Thanks a lot! Lee [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to use tapply for quantile
Hi James, I don't know how to solve it with tapply (something with split I think..), but you could use plyr (from Hadley Wickham). library(plyr) # Generate some data set.seed(321) myD - data.frame( Place = sample(c(AWQ,DFR, WEQ), 10, replace=T), Light = sample(LETTERS[1:2], 15, replace=T), value=rnorm(30) ) myD[c(3,12,29), value] - NA # data.frame to data.frame ddply(myD, .(Place, Light), summarise, quan_value = quantile(value, na.rm=TRUE)) # data.frame to list quant - function(df) quantile(df$value, na.rm=TRUE) dlply(myD, .(Place, Light), quant) Cheers Patrick Am 09.04.2010 03:24, schrieb James Rome: I am trying to calculate quantiles of a data frame column split up by two factors: # Calculate the quantiles quarts = tapply(gdf$tt, list(gdf$Runway, gdf$OnHour), FUN=quantile, na.rm = TRUE) This does not work: quarts 04L 04R 15R 22L 22R 2732 33L 33R 0 NULL Numeric,5 NULL Numeric,5 NULL Numeric,5 NULL Numeric,5 NULL 1 NULL Numeric,5 NULL Numeric,5 NULL NULL NULL Numeric,5 NULL 2 NULL NULL NULL Numeric,5 NULL NULL NULL NULL NULL 3 NULL NULL NULL NULL NULL NULL NULL Numeric,5 NULL 4 NULL NULL NULL NULL NULL NULL NULL NULL NULL 5 NULL NULL NULL NULL NULL NULL NULL NULL NULL 6 NULL NULL NULL NULL NULL NULL NULL NULL NULL 7 NULL Numeric,5 NULL NULL NULL Numeric,5 NULL Numeric,5 NULL 8 NULL Numeric,5 NULL Numeric,5 NULL Numeric,5 NULL Numeric,5 NULL . . . But if I leave out either of the two factors, it does work quarts = tapply(gdf$tt, list(gdf$Runway), FUN=quantile, na.rm = TRUE) quarts $`04L` 0% 25% 50% 75% 100% 489 10 20 $`04R` 0% 25% 50% 75% 100% 09 10 11 28 . . . . How can I get this to work? Thanks, Jim Rome __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] xts off by one confusion or error
I find the following even more confusing as I thought that xts was a subclass of zoo and I'd expected that the conversion would have been more transparent aggregate (vv, as.yearmon(index(vv)), mean) Feb 2010 6.08 xts (aggregate (vv, as.yearmon(index(vv)), mean)) x Jan 2010 6.08 zoo (aggregate (vv, as.yearmon(index(vv)), mean)) x Feb 2010 6.08 On 8 Apr 2010, at 15:53, Tim Coote wrote: On 8 Apr 2010, at 15:53, Tim Coote wrote: Hullo I may have missed something blindingly obvious here. I'm using xts to handle some timeseries data. I've got daily measurements for 100 years. If I try to reduce the error rate by taking means of each month, I'm getting what at first sight appears to be conflicting information. Here's a small subset to show the problem: A small set of data: vv x 2010-02-01 6.1 2010-02-02 6.1 2010-02-03 6.0 2010-02-04 6.0 2010-02-05 6.0 2010-02-06 6.1 2010-02-07 6.1 2010-02-08 6.1 2010-02-09 6.1 2010-02-10 6.2 Aggregate: aggregate (vv, as.yearmon (index (vv)), mean) Feb 2010 6.08 That's fine. But if I explicitly convert to xts (which the answer ought to be, so this should be a noop), the values shift back by one month: xts (aggregate (vv, as.yearmon (index (vv)), mean)) x Jan 2010 6.08 Just to confirm the classes: class (aggregate (vv, as.yearmon (index (vv)), mean)) [1] zoo class (vv) [1] xts zoo And to confirm that as.yearmon is returning the right month: as.yearmon (index (vv)) [1] Feb 2010 Feb 2010 Feb 2010 Feb 2010 Feb 2010 Feb 2010 [7] Feb 2010 Feb 2010 Feb 2010 Feb 2010 This run was on a stock Fedora 10 build: version _ platform i386-redhat-linux-gnu arch i386 os linux-gnu system i386, linux-gnu status major 2 minor 10.0 year 2009 month 10 day26 svn rev50208 language R version.string R version 2.10.0 (2009-10-26) And from installed.packages (): xtsNA NA GPL-32.10.0 zooNA NA GPL-22.10.0 Any help gratefully received. Tim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Tim Coote t...@coote.org vincit veritas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Biplot for PCA using labdsv package
Dilys Vela dilysvd at gmail.com writes: Hi everyone, I am doing PCA with labdsv package. I was trying to create a biplot graphs in order to observe arrows related to my variables. However when I run the script for this graph, the console just keep saying: *Error in nrow(y) : element 1 is empty; the part of the args list of 'dim' being evaluated was: (x)* could please someone tell me what this means? what i am doing wrong? I will really appreciate any suggestions and help. Dilys, This seems to work: m - pca(bryceveg) stats:::biplot.princomp(m) or, alternatively, class(m) - c(class(m), princomp) biplot(m) Explanation: the pca() function in labdsv returns an object that resembles a lot the princomp() result (although Dave uses prcomp for actual calculation), and you can use methods of princomp objects to display the results. However, the output does not show this inheritance in its class(), and therefore you can either explicitly use princomp methods or set the class to inherit from princomp. Since biplot.princomp is not exported, you must use stats:::biplot.princomp notation to access the biplot() function if you do not set the class. Cheers, Jari Oksanen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] a small question about R with Winbugs
On 8 April 2010 22:58, dcflyer dcfl...@gmail.com wrote: I try to do a test for dirichlet process for Multivariate normal, but Winbugs always says expected multivariate node, does that mean I miss something at initialization? I will really appreciate the help to solve this problem Here is the R code, and Winbugs code. This is a BUGS error, not an R error. The problem is that logical nodes can only be expressed as scalars, so this doesn't work: mu[i,1:2] - mu.star[S[i],] you have to specify these nodes in a loop: for(d in 1:2) {mu[i,d] - mu.star[S[i],d]] There might be other errors too: I always develop my BUGS code in BUGS, and go to R afterwards. Bob -- Bob O'Hara Biodiversity and Climate Research Centre Senckenberganlage 25 D-60325 Frankfurt am Main, Germany Tel: +49 69 798 40216 Mobile: +49 1515 888 5440 WWW: http://www.bik-f.de/root/index.php?page_id=219 Blog: http://blogs.nature.com/boboh Google Wave: rni@googlewave.com Journal of Negative Results - EEB: www.jnr-eeb.org [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Installation of R on a MIPS netbook
Hi everybody, I received a question from a collegue (see below) and I searched on the site for information to answer him Writing in Search mips installation I found the page R installation and administration, and specifically the section 2 on Unix-alikes systems. I send him too the section 2.2 of the R Faq written by K. Hornik. But I'm not a specialist of Unix and I'm not sure of the efficiency of my help. Could someone help him ? Thanks in advance, Frédéric Chiroleu -- Dr. Frédéric Chiroleu CIRAD UMR 53 PVBMT (Peuplements Végétaux et Bio-agresseurs en Milieu Tropical) Pôle de Protection des Plantes (3P) 7, chemin de l'IRAT - Ligne Paradis 97410 Saint-Pierre Île de la Réunion - France Tél. : +262 (0)262 499 230 Fax : +262 (0)262 499 293 Message original Sujet : Submission to Liste-R Date : Thu, 8 Apr 2010 11:01:54 +0200 De :a.g.par...@iaea.org Pour : frederic.chiro...@cirad.fr Dear Fred, Could you please circulate this to Liste R? Thanks. Is there a MIPS binary of R? I am starting to learn R and would like to run it on my MIPS netbook with the 3MX Ultra OS whilst learning, but there is no compiler in this version of the OS. If no binary is available I will load 3MX v4.0 which has gcc and try to compile it. Has anyone tried this? Any advice? Regards, Andrew Parker Insect Pest Control Laboratory Joint FAO/IAEA Programme of Nuclear Techniques in Food and Agriculture International Atomic Energy Agency Agency's Laboratories A-2444 Seibersdorf Austria Tel: +43 1 2600 28408 Fax: +43 1 26007 28408 http://www-naweb.iaea.org/nafa/ipc/index.html [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Accessing elements of plm outputs
Dear all, just to confirm that as far as I know (Yves please correct me if I'm wrong) Achim's fix is currently the way to go. The sum-of-squares statistics part of 'plm' outputs is currently quite minimal and due for some extension. Cases like Eduardo's give us a sample of what the useRs may need, so thanks for the feedback. And of course thanks to Achim for the prompt help. Cheers Giovanni -Original Message- From: Achim Zeileis [mailto:achim.zeil...@uibk.ac.at] Sent: Thu 08/04/2010 21.21 To: ECAMF Cc: r-help@r-project.org; yves.croiss...@univ-reunion.fr; Millo Giovanni Subject: Re: [R] Accessing elements of plm outputs On Thu, 8 Apr 2010, ECAMF wrote: Dear all, I've just migrated from STATA to R for runing panel regressions and I was very happy to discover the plm package. However, I have a problem when trying to access the Total Sum of Squares and Residual Sum of Squares on this output: summary(output) Oneway (individual) effect Within Model Call: plm(formula = Y ~ X1 + X2, data = db, model = within) Unbalanced Panel: n=10, T=9-11, N=108 Residuals : Min. 1st Qu. Median 3rd Qu.Max. -6.500 -2.200 -0.374 1.550 8.730 Coefficients : Estimate Std. Error t-value Pr(|t|) X1 113.302650 8.517736 13.302 2e-16 *** X2 -0.084414 0.109625 -0.770 0.4432 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 Total Sum of Squares:3208.3 Residual Sum of Squares: 1059.6 F-statistic: 97.3365 on 2 and 96 DF, p-value: 2.22e-16 I would like to do so because I'm running some hundreds times a similar regression and I want to store those results in a vector and then plot them. I've tried to do so with summary(output)[] but neither the Total Sum of Squares or the Residual Sum of Squares are on the list. The residual sum of squares can be computed via sum(residuals(output)^2) The total sum of squares is more difficult, I think. plm contains a tss() generic with suitable methods - but this is only used internally but not exported in the user interface. Thus, you currently have to do plm:::tss.plm(output) This is really dirty as it accesses a specific method (rather than the generic) in the namespace (rather than the exported user interface). But I don't think there's currently a better way. The package authors (both Cc) might be able to give more guidance though. hth, Z I would be glad if somebody can help me. Thank you very much! Eduardo Marinho. -- View this message in context: http://n4.nabble.com/Accessing-elements-of-plm-outputs-tp1774143p1774143.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Ai sensi del D.Lgs. 196/2003 si precisa che le informazi...{{dropped:15}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] fill in values between rollapply
Hi, Sorry ahead of time for not including data with this question. Using rollapply to calculate mean values for 5 day blocks, I'd use this: Roll5mean - rollapply(data, 5, mean, by=5, align = c(left)) My question is, can someone tell me how to fill in the days between each of these means with the previously calculated mean? If this doesn't make sense, I will clarify and provide data for an example. Thanks. Brad -- View this message in context: http://n4.nabble.com/fill-in-values-between-rollapply-tp1816885p1816885.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to replace all non-maximum values in a row with 0
Hi, I would like to replace all the max values per row with 1 and all other values with 0. If there are two max values, then 0 for both. Example: from: 2 3 0 0 200 30 0 0 2 50 0 0 3 0 0 0 0 8 8 0 to: 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 Thanks! -- View this message in context: http://n4.nabble.com/How-to-replace-all-non-maximum-values-in-a-row-with-0-tp1819018p1819018.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to replace all non-maximum values in a row with 0
Am 09.04.2010 10:04, schrieb burgundy: Hi, I would like to replace all the max values per row with 1 and all other values with 0. If there are two max values, then 0 for both. Example: from: 2 3 0 0 200 30 0 0 2 50 0 0 3 0 0 0 0 8 8 0 to: 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 Thanks! Nice little homework to get the day started. :-) This worked for me, but is probably not the shortest possible answer A - matrix (c(2, 3, 0, 0, 200, 30, 0, 0, 2, 50, 0, 0, 3, 0, 0, 0, 0, 8, 8, 0), nrow = 4, byrow=T) nr - nrow(A) nc - ncol(A) B - matrix(0,nrow=nr, ncol=nc) for(i in 1:nr){ x - which(A[i,]==max(A[i,])) B[i,x] - 1 if(sum(B[i,])1) B[i,] - as.vector(rep(0,nc)) } -- Owe Jessen Nettelbeckstr. 5 24105 Kiel p...@owejessen.de http://privat.owejessen.de __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] fill in values between rollapply
Brad Patrick Schneid wrote: If this doesn't make sense, I will clarify and provide data for an example. Which is always a good idea. Dieter -- View this message in context: http://n4.nabble.com/fill-in-values-between-rollapply-tp1816885p1819092.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] NAs are not allowed in subscripted assignments
I'm trying to assign NAs to values that satisfy certain conditions (more complex than shown below) and it gives the right result, but breaks the loop having done the first one viz: new-c(rep(5,4),6) for (i in 1:6) {new[new[i]5.5][i]-NA} gives the correct result, though an error message appears which causes a break if it's in a loop. If I can get rid of the error message and get the loop to continue, this should work fine. I'm sure I'm missing a simple solution, but can't seem to see it, Any help, as always, greatly appreciated, Paul -- View this message in context: http://n4.nabble.com/NAs-are-not-allowed-in-subscripted-assignments-tp1819094p1819094.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] terminating function
Hi everyone, I 'm building a function, in the middle it controls the sign of a variable x. If x 0 the function write a warning (Error: negative value!). At this point I want the function stops without execute the remaining code. How can I do to terminate the function before your ending? Thanks in advance. Paolo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to replace all non-maximum values in a row with 0
It can be done faster and more elegant with apply and rowSums rows - 10 A - matrix(rpois(n = rows * 20, lambda = 100), nrow = rows) A[4, c(1,3)] - 1000 system.time({ y - t(apply(A, 1, function(z){ 1 * (z == max(z)) })) y[rowSums(y) 1, ] - 0 }) system.time({ nr - nrow(A) nc - ncol(A) B - matrix(0,nrow=nr, ncol=nc) for(i in 1:nr){ x - which(A[i,]==max(A[i,])) B[i,x] - 1 if(sum(B[i,])1) B[i,] - as.vector(rep(0,nc)) } }) all.equal(y, B) HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie Kwaliteitszorg Gaverstraat 4 9500 Geraardsbergen Belgium Research Institute for Nature and Forest team Biometrics Quality Assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Owe Jessen Verzonden: vrijdag 9 april 2010 11:08 Aan: r-help@r-project.org Onderwerp: Re: [R] How to replace all non-maximum values in a row with 0 Am 09.04.2010 10:04, schrieb burgundy: Hi, I would like to replace all the max values per row with 1 and all other values with 0. If there are two max values, then 0 for both. Example: from: 2 3 0 0 200 30 0 0 2 50 0 0 3 0 0 0 0 8 8 0 to: 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 Thanks! Nice little homework to get the day started. :-) This worked for me, but is probably not the shortest possible answer A - matrix (c(2, 3, 0, 0, 200, 30, 0, 0, 2, 50, 0, 0, 3, 0, 0, 0, 0, 8, 8, 0), nrow = 4, byrow=T) nr - nrow(A) nc - ncol(A) B - matrix(0,nrow=nr, ncol=nc) for(i in 1:nr){ x - which(A[i,]==max(A[i,])) B[i,x] - 1 if(sum(B[i,])1) B[i,] - as.vector(rep(0,nc)) } -- Owe Jessen Nettelbeckstr. 5 24105 Kiel p...@owejessen.de http://privat.owejessen.de __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Druk dit bericht a.u.b. niet onnodig af. Please do not print this message unnecessarily. Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] NAs are not allowed in subscripted assignments
Maybe you can withdraw the [i] in your code... for (i in 1:6) + {new[new[i]5.5]-NA} new [1] 5 5 5 5 NA Alain On 09-Apr-10 11:23, Paul Chatfield wrote: I'm trying to assign NAs to values that satisfy certain conditions (more complex than shown below) and it gives the right result, but breaks the loop having done the first one viz: new-c(rep(5,4),6) for (i in 1:6) {new[new[i]5.5][i]-NA} gives the correct result, though an error message appears which causes a break if it's in a loop. If I can get rid of the error message and get the loop to continue, this should work fine. I'm sure I'm missing a simple solution, but can't seem to see it, Any help, as always, greatly appreciated, Paul -- Alain Guillet Statistician and Computer Scientist SMCS - IMMAQ - Université catholique de Louvain Bureau c.316 Voie du Roman Pays, 20 B-1348 Louvain-la-Neuve Belgium tel: +32 10 47 30 50 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] terminating function
Hi, Look at the function stop which does what you want. ?stop Alain On 09-Apr-10 11:27, Covelli Paolo wrote: Hi everyone, I 'm building a function, in the middle it controls the sign of a variable x. If x 0 the function write a warning (Error: negative value!). At this point I want the function stops without execute the remaining code. How can I do to terminate the function before your ending? Thanks in advance. Paolo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Alain Guillet Statistician and Computer Scientist SMCS - IMMAQ - Université catholique de Louvain Bureau c.316 Voie du Roman Pays, 20 B-1348 Louvain-la-Neuve Belgium tel: +32 10 47 30 50 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] NAs are not allowed in subscripted assignments
Sorry I forgot to add that you don't need the for loop: new[new5.5] - NA new [1] 5 5 5 5 NA Alain On 09-Apr-10 11:23, Paul Chatfield wrote: new-c(rep(5,4),6) for (i in 1:6) {new[new[i]5.5][i]-NA} -- Alain Guillet Statistician and Computer Scientist SMCS - IMMAQ - Université catholique de Louvain Bureau c.316 Voie du Roman Pays, 20 B-1348 Louvain-la-Neuve Belgium tel: +32 10 47 30 50 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] NAs are not allowed in subscripted assignments
Hi Paul, what's wrong with new[new5.5]-NA ? Btw. your variable new has a length of 5 not 6. hth. Am 09.04.2010 11:23, schrieb Paul Chatfield: I'm trying to assign NAs to values that satisfy certain conditions (more complex than shown below) and it gives the right result, but breaks the loop having done the first one viz: new-c(rep(5,4),6) for (i in 1:6) {new[new[i]5.5][i]-NA} gives the correct result, though an error message appears which causes a break if it's in a loop. If I can get rid of the error message and get the loop to continue, this should work fine. I'm sure I'm missing a simple solution, but can't seem to see it, Any help, as always, greatly appreciated, Paul -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Accessing elements of plm outputs
Thank you Achim! It worked perfectly! And to be honest with you, I'm not really concerned by the fact it looks dirty. So, many thanks!! Giovanni and Yves, it would be great if one could also have on the output the R-squared decomposition (within, between and overall) that is provided by STATA. Anyway, I'm already very happy to be able to run a panel regression in a open-source software, so I have to thank you guys also! Cheers, Eduardo. On Fri, Apr 9, 2010 at 10:08, Millo Giovanni giovanni_mi...@generali.comwrote: Dear all, just to confirm that as far as I know (Yves please correct me if I'm wrong) Achim's fix is currently the way to go. The sum-of-squares statistics part of 'plm' outputs is currently quite minimal and due for some extension. Cases like Eduardo's give us a sample of what the useRs may need, so thanks for the feedback. And of course thanks to Achim for the prompt help. Cheers Giovanni -Original Message- From: Achim Zeileis [mailto:achim.zeil...@uibk.ac.atachim.zeil...@uibk.ac.at ] Sent: Thu 08/04/2010 21.21 To: ECAMF Cc: r-help@r-project.org; yves.croiss...@univ-reunion.fr; Millo Giovanni Subject: Re: [R] Accessing elements of plm outputs On Thu, 8 Apr 2010, ECAMF wrote: Dear all, I've just migrated from STATA to R for runing panel regressions and I was very happy to discover the plm package. However, I have a problem when trying to access the Total Sum of Squares and Residual Sum of Squares on this output: summary(output) Oneway (individual) effect Within Model Call: plm(formula = Y ~ X1 + X2, data = db, model = within) Unbalanced Panel: n=10, T=9-11, N=108 Residuals : Min. 1st Qu. Median 3rd Qu.Max. -6.500 -2.200 -0.374 1.550 8.730 Coefficients : Estimate Std. Error t-value Pr(|t|) X1 113.302650 8.517736 13.302 2e-16 *** X2 -0.084414 0.109625 -0.770 0.4432 --- Signif. codes: 0 ?***? 0.001 ?**? 0.01 ?*? 0.05 ?.? 0.1 ? ? 1 Total Sum of Squares:3208.3 Residual Sum of Squares: 1059.6 F-statistic: 97.3365 on 2 and 96 DF, p-value: 2.22e-16 I would like to do so because I'm running some hundreds times a similar regression and I want to store those results in a vector and then plot them. I've tried to do so with summary(output)[] but neither the Total Sum of Squares or the Residual Sum of Squares are on the list. The residual sum of squares can be computed via sum(residuals(output)^2) The total sum of squares is more difficult, I think. plm contains a tss() generic with suitable methods - but this is only used internally but not exported in the user interface. Thus, you currently have to do plm:::tss.plm(output) This is really dirty as it accesses a specific method (rather than the generic) in the namespace (rather than the exported user interface). But I don't think there's currently a better way. The package authors (both Cc) might be able to give more guidance though. hth, Z I would be glad if somebody can help me. Thank you very much! Eduardo Marinho. -- View this message in context: http://n4.nabble.com/Accessing-elements-of-plm-outputs-tp1774143p1774143.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Ai sensi del D.Lgs. 196/2003 si precisa che le informazioni contenute in questo messaggio sono riservate ed a uso esclusivo del destinatario. Qualora il messaggio in parola Le fosse pervenuto per errore, La invitiamo ad eliminarlo senza copiarlo e a non inoltrarlo a terzi, dandocene gentilmente comunicazione. Grazie. Pursuant to Legislative Decree No. 196/2003, you are hereby informed that this message contains confidential information intended only for the use of the addressee. If you are not the addressee, and have received this message by mistake, please delete it and immediately notify us. You may not copy or disseminate this message to anyone. Thank you. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] error bars on barplot
Hi I was hoping someone might be able to help me I have this data: birdid timetaken numvisits ptachchoice time bold 1087 810 1 AM0 108728 6 1 PM0 108713 3 2 AM0 1087 121 0 2 PM0 1046 121 0 1 AM1 1046 121 0 1 PM1 i've plotted the means like this: by(numvisits,patchchoice,summary) numvisits.means- by(numvisits,list(time=time,patchchoice=patchchoice),mean) numvisits.means barplot(numvisits.means,xlab=Patch Choice,ylab=Number of Visits,col=c(red,darkblue),beside=T,ylim=c(0,4)) labs-c(AM,PM) legend(1.09,3.98,labs,fill=cols) and need to add error bars, but i'm unsure as to how to do this. Thanks Sam [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] plm package twoways effect problem
well thanks anyway even just for replying, i understand the lack of information causes no response... but if no one tells me that they need more information how could i send. anyway here more information about the procedure that i am applying to define the model after reading and attaching my data; eco1=(wwater0) eco2=(wgas0) eco3=(wgarbage0) eco4=(noise0) eco=(eco10|eco20|eco30|eco40) inno=(researchtot0|purtot0) RD=(researchtot0) all of the above are my dummies as you can understand lnLP=lnQ-lnL # then i define my dependent variable then, newdata = plm.data(ds,index=c(stno,year)) # individual and time indexes after that i define the followings; dsnri3LP=plm(lnLP~lnC+lnL+lnM+lnE+eco+eco*lnE+eco*lnM+inno+inno*eco, data=newdata,model=random) dsnfi3LP=plm(lnLP~lnC+lnL+lnM+lnE+eco+eco*lnE+eco*lnM+inno+inno*eco, data=newdata,model=within) which are working quite well and when i define the effect= twoways, model=within dsnfi3LP=plm(lnLP~lnC+lnL+lnM+lnE+eco+eco*lnE+eco*lnM+inno+inno*eco, data=newdata,effect=twoways,model=within) i get the following error Error in rep.int(c(1, numeric(n)), n - 1L) : negative length vectors are not allowed so i hope this time i could send sufficient information about the process and the error, sorry that i cant send my data since it is more than 60MB. Thanks for everyone again for the possible help -- View this message in context: http://n4.nabble.com/plm-package-twoways-effect-problem-tp1774246p1819172.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] bootstrap confidence intervals, non iid
hi glen, i need conf.intervals for blocked data, as described in the first place. i've learned in the meantime, that the boot() function can handle this. i had to formulate the function for the boot command, put sites to the strata argument and resample from each subsetted level of the factor stage. with boot.ci() i then yielded the boot ci's for each stage. hi glen, i need conf.intervals for blocked data, as described in the first place. i've learned in the meantime, that the boot() function can handle this. i needed to formulate the function for the boot command, put sites to the strata argument and to resample from each subsetted level of the factor stage. with boot.ci() i then yielded the boot ci's for each stage. here's the worked example, for anyone who is interested: ### #my data: ### sim-data.frame(list(structure(list(stage = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c(A, B, C, D), class = factor), site = structure(c(1L, 1L, 1L, 1L, 2L, 2L, 2L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 8L, 8L, 8L, 8L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 11L, 11L, 12L, 12L, 12L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 16L, 16L, 16L, 17L, 17L, 17L, 17L, 18L, 18L, 19L, 19L, 19L, 19L, 20L, 20L, 20L, 20L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 22L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 25L, 25L, 25L, 25L, 26L, 26L, 26L, 26L, 27L, 27L, 27L, 27L, 28L, 28L, 28L, 28L, 29L, 29L, 29L, 30L, 30L, 30L, 30L, 31L, 31L, 32L, 32L, 32L, 32L, 33L, 33L, 33L, 33L, 34L, 34L, 34L, 34L, 35L, 35L, 35L, 35L, 36L, 36L, 36L, 36L, 37L, 37L, 38L, 38L, 38L, 38L, 39L, 39L, 39L ), .Label = c(A11, A12, A14, A15, A16, A17, A18, A19, A20, A5, A7, A8, B1, B12, B13, B14, B15, B17, B18, B2, B4, B7, B8, B9, C1, C10, C11, C15, C17, C18, C19, C2, C20, C3, C4, C6, D1, D4, D7), class = factor), MH.Index = c(0.392156863, 0.602434077, 0.576923077, 0.647482014, 0.989010989, 0.857142857, 1, 1, 1, 0, 1, 0.378378378, 0.839087948, 0.252915554, 1, 0.22556391, 0.510366826, 0.476190476, 0.555819477, 0.961538462, 0.7, 0.089285714, 0.923076923, 0.571428571, 0, 0.923076923, 0.617647059, 0.599423631, 0, 0.727272727, 0.998112812, 0, 0, 0, 1, 0.565656566, 0.75, 0.923076923, 0.654545455, 0.14084507, 0.617647059, 0.315789474, 0.179347826, 0.583468021, 0.165525114, 0.817438692, 0.41457, 0.49548886, 0.556127703, 0.707431246, 0.506757551, 0.689655172, 0.241433511, 0.379232506, 0.241935484, 0, 0.30848329, 0.530973451, 0.148148148, 0, 0.976744186, 0.550218341, 0.542168675, 0.769230769, 0.153310105, 0, 0, 0.380569406, 0.742174733, 0.2, 0.046925432, 0, 0.068076328, 0.772727273, 0.830039526, 0.503458415, 0.863910822, 0.39401263, 0.081818182, 0.368421053, 0.088607595, 0, 0.575499851, 0.605657238, 0.714854232, 0.855881172, 0.815689401, 0.552207228, 0.81708081, 0.583228133, 0.334466349, 0.259477365, 0.194711538, 0.278916707, 0.636304805, 0.593715432, 0.661016949, 0.626865672, 0.420219245, 0.453535143, 0.471243706, 0.462427746, 0.56980057, 0.453821155, 0.052828527, 0.926829268, 0.51988266, 0.472200264, 0.351219512, 0.290030211, 0.765258974, 0.564894108, 0.789699571, 0.863378215, 0.525181559, 0.803061458, 0.260164645, 0.477265792, 0.265889379, 0.317791411, 0.107623318, 0.279181709, 0.471953363, 0.463724265, 0.241966696, 0.403647213, 0.693087992, 0.494259925, 0.68904453, 0.39329147, 0.498161213, 0.376225983, 0.407001046, 0.825016633, 0.718991658, 0.662995912)), .Names = c(stage, site, MH.Index), class = data.frame, row.names = c(NA, -136L ### #my code: ### library(boot) library(Hmisc) function: mean.fun - function(x, index){mean(x[index])} X-A ###the mean: mean.fun(sim$MH.Index[sim$stage==X]) ###the boot sample and the ci's: boot-boot(sim$MH.Index[sim$stage==X], mean.fun, R=1000, strata=sim$site[sim$stage==X]) ci-boot.ci(boot,type = c(norm, basic, perc)) ###get ci's (method: normal) ci[2]-meanA data.frame(ci[4])[1,2]-lowA data.frame(ci[4])[1,3]-uppA X-B ###the mean: mean.fun(sim$MH.Index[sim$stage==X]) ###the boot sample and the ci's: boot-boot(sim$MH.Index[sim$stage==X], mean.fun, R=1000, strata=sim$site[sim$stage==X]) ci-boot.ci(boot,type = c(norm, basic, perc)) ###get ci's (method: normal) ci[2]-meanB data.frame(ci[4])[1,2]-lowB
Re: [R] SSH Through R Script
You might try setting up ssh so that you do not need a password. See man ssh-keygen In essence, you make a key for the machine you are on with (for example): ssh -t dsa which produces a public and a private key. You upload the public key to remoteserver.com, and put it in your .ssh directory by adding it to (or creating) a file called authorized_keys, e.g. cat id_dsa.pub .ssh/authorized_keys When you are asked for a passphrase, leave it blank. Then you don't need to enter your username or password in order to connect. This assumes that remoteserver.com runes linux or unix. If not, I have no idea what to do. My impression is that this method is no less secure on the whole than using passwords. (I do it with the full knowledge of our security-obsessed computing staff.) Jon On 04/08/10 22:01, afoo wrote: Hi, I am trying to SSH to a remote server through R script. In other words, I would like to know how I can get a SSH connection to the remote server and then execute commands on that server with the R script. So in bash, I would normally type ssh -lusername remoteserver.com; press enter and then wait for the password prompt to key in my password. I have tried system(ssh remoteserver.com) but that doesn't work because, from what I know, SSH requires user interactivity - I am required to key in my password. I tried looking up about putting password as a command line parameter, but SSH doesn't allow that, my only option then is to set up a private/public key pair. But the admin of the remoteserver doesn't allow me to do that. Is there a way in which I can SSH in? Or is there a command in R that allows me to interact with the command prompts interactively? thanks, afoo -- View this message in context: http://n4.nabble.com/SSH-Through-R-Script-tp1809635p1809635.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jonathan Baron, Professor of Psychology, University of Pennsylvania Home page: http://www.sas.upenn.edu/~baron Editor: Judgment and Decision Making (http://journal.sjdm.org) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] erasing an area of a graph
On 04/09/2010 04:51 AM, Terry Therneau wrote: I have a case where the easiest way to draw a particular symbol would be to draw something a little bigger, and then use polygon(... , col=0) to erase the extra stuff. Just how to do this best when par('bg') = 'transparent' is, however, eluding me. I've looked through the archives and the book R Graphics without quite seeing the light. Help or pointers to help would be welcome. Terry T Details (for the inquiring mind). In drawing a pedigree subjects are depicted as cirle, square, diamond, or triangle (for gender= male, female, unknown, terminated). This can be subdivided into shaded regions to show the value of various ancillary variables. One ancillary is easy - just fill with a color. For two you fill the left and right half separately, etc. Two, three, four, ... variables become special cases for each symbol. An easy solution is to draw a larger circle with the requisite number of shaded slices, then erase away what we don't want. Hi Terry, The kludge that is used in axis.break and similar functions is to set the polygon fill color to white if par(bg) is transparent. This works okay for most displays, and for hard copy. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] computation of dispersion parameter in quasi-poisson glm
Hi list, can anybody point me to the trick how glm is computing the dispersion parameter in quasi-poisson regression, eg. glm(...,family=quasipoisson)? Thanks regards, Sven __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to run Shapiro-Wilk test for each grouped variable?
I want to run Shapiro-Wilk test for each variable in my dataset, each grouped by variable groupFactor. I have these working commands: data.n-names(data) # put names into a vector called data.n by(eval(parse(text=(paste(data,data.n[3],sep=$, data$factor, shapiro.test) #run shapiro.test but I must to change the variable number manualy. How to automate this? I tried this: for (r in 3:18) { by(eval(parse(text=(paste(data,data.n[3],sep=$, data$groupFactor, shapiro.test) } but not working and no errors. Why? Please help. -- Regards, Iurie Malai, Senior Lecturer Department of Psychology Faculty of Psychology and Special Education Ion Creanga Moldova Pedagogical State University - www.upsm.md http://en.wikipedia.org/wiki/Ion_Creang%C4%83_Pedagogical_State_University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] computation of dispersion parameter in quasi-poisson glm
On Fri, 9 Apr 2010, Sven Garbade wrote: Hi list, can anybody point me to the trick how glm is computing the dispersion parameter in quasi-poisson regression, eg. glm(...,family=quasipoisson)? It's the sum of squared Pearson residuals divided by the residual degrees of freedom. For example: example(glm) fm - glm(counts ~ outcome + treatment, family = quasipoisson) summary(fm) sum(residuals(fm, type = pearson)^2)/df.residual(fm) hth, Z Thanks regards, Sven __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error bars on barplot
On 04/09/2010 08:55 PM, Samantha Reynolds wrote: Hi I was hoping someone might be able to help me I have this data: birdid timetaken numvisits ptachchoice time bold 1087 810 1 AM0 108728 6 1 PM0 108713 3 2 AM0 1087 121 0 2 PM0 1046 121 0 1 AM1 1046 121 0 1 PM1 i've plotted the means like this: by(numvisits,patchchoice,summary) numvisits.means- by(numvisits,list(time=time,patchchoice=patchchoice),mean) numvisits.means barplot(numvisits.means,xlab=Patch Choice,ylab=Number of Visits,col=c(red,darkblue),beside=T,ylim=c(0,4)) labs-c(AM,PM) legend(1.09,3.98,labs,fill=cols) and need to add error bars, but i'm unsure as to how to do this. Hi Sam, Perhaps I should submit a FAQ on this one. Try: bar.err (agricolae) plotCI (gplots) xYplot (Hmisc) error.bars (psych) dispersion (plotrix) plotCI (plotrix) and there are probably others. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Combining ggplot2 objects and/or extracting layers
Hi, Other then rebuilding the plots, is there any way either (1) to combine existing ggplot2 plots or (2) to extract a layer from an existing plot so that it can be added to another? Thanks. -- Dr. Marshall Feldman, PhD Director of Research and Academic Affairs Center for Urban Studies and Research The University of Rhode Island email: marsh @ uri .edu (remove spaces) Contact Information: Kingston: 202 Hart House Charles T. Schmidt Labor Research Center The University of Rhode Island 36 Upper College Road Kingston, RI 02881-0815 tel. (401) 874-5953: fax: (401) 874-5511 Providence: 206E Shepard Building URI Feinstein Providence Campus 80 Washington Street Providence, RI 02903-1819 tel. (401) 277-5218 fax: (401) 277-5464 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error bars on barplot
Jim Lemon wrote: On 04/09/2010 08:55 PM, Samantha Reynolds wrote: Hi I was hoping someone might be able to help me I have this data: birdid timetaken numvisits ptachchoice time bold 1087 810 1 AM0 108728 6 1 PM0 108713 3 2 AM0 1087 121 0 2 PM0 1046 121 0 1 AM1 1046 121 0 1 PM1 i've plotted the means like this: by(numvisits,patchchoice,summary) numvisits.means- by(numvisits,list(time=time,patchchoice=patchchoice),mean) numvisits.means barplot(numvisits.means,xlab=Patch Choice,ylab=Number of Visits,col=c(red,darkblue),beside=T,ylim=c(0,4)) labs-c(AM,PM) legend(1.09,3.98,labs,fill=cols) and need to add error bars, but i'm unsure as to how to do this. Hi Sam, Perhaps I should submit a FAQ on this one. Try: bar.err (agricolae) plotCI (gplots) xYplot (Hmisc) error.bars (psych) dispersion (plotrix) plotCI (plotrix) and there are probably others. Jim geom_errorbar (ggplot2) Joh __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] computation of dispersion parameter in quasi-poisson glm
On Fri, 9 Apr 2010, Sven Garbade wrote: Hi list, can anybody point me to the trick how glm is computing the dispersion parameter in quasi-poisson regression, eg. glm(...,family=quasipoisson)? It isn't. glm() does not need (and does not compute) the dispersion parameter. summary.glm will ... list it and the code is in the top few lines. There is no 'trick': this is as described in MASS pp 186, 208 (which also explains some of the pitfalls). Thanks regards, Sven -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Combining ggplot2 objects and/or extracting layers
Other then rebuilding the plots, is there any way either (1) to combine existing ggplot2 plots or (2) to extract a layer from an existing plot so that it can be added to another? Not really, although you can always pull apart the plot components. Can you give an example of what you are trying to achieve? Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] NAs are not allowed in subscripted assignments
Thank you â thatâs sorted it. Trying to make things too complicated! J From: Alain Guillet-2 [via R] [mailto:ml-node+1819104-1154170184-120...@n4.nabble.com] Sent: 09 April 2010 10:34 To: Paul Chatfield Subject: Re: NAs are not allowed in subscripted assignments Maybe you can withdraw the [i] in your code... for (i in 1:6) + {new[new[i]5.5]-NA} new [1] 5 5 5 5 NA Alain On 09-Apr-10 11:23, Paul Chatfield wrote: I'm trying to assign NAs to values that satisfy certain conditions (more complex than shown below) and it gives the right result, but breaks the loop having done the first one viz: new-c(rep(5,4),6) for (i in 1:6) {new[new[i]5.5][i]-NA} gives the correct result, though an error message appears which causes a break if it's in a loop. If I can get rid of the error message and get the loop to continue, this should work fine. I'm sure I'm missing a simple solution, but can't seem to see it, Any help, as always, greatly appreciated, Paul -- Alain Guillet Statistician and Computer Scientist SMCS - IMMAQ - Université catholique de Louvain Bureau c.316 Voie du Roman Pays, 20 B-1348 Louvain-la-Neuve Belgium tel: +32 10 47 30 50 __ [hidden email] http://n4.nabble.com/user/SendEmail.jtp?type=nodenode=1819104i=0 mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. View message @ http://n4.nabble.com/NAs-are-not-allowed-in-subscripted-assignments-tp1819094p1819104.html To unsubscribe from NAs are not allowed in subscripted assignments, click here (link removed) = . -- View this message in context: http://n4.nabble.com/NAs-are-not-allowed-in-subscripted-assignments-tp1819094p1819280.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Beyond reshape: automatically streamlining data
Hello, I've been very impressed by the reshape package and how easy it makes reorganizing statistical data structures. This makes me wonder if there's another package out there that addresses another set of tasks that one often does when preparing data for analysis. For any particular set of analyses, one typically recodes variables and deletes cases and variables. It would be really nice to have a package that, for example, if one selected cases from a larger data set based on the values of certain variables would inspect the resulting data and drop any variables that have the same value for all cases. Similarly, if any cases are entirely zero or NA, the package could (under user control) drop these cases. Finally, it could take a set of data transformations and keep them as an object, so that the same selection/reshape/streamlining can easily be applied to similar data sets. My motivation for this came from working with employment data this morning. I started out with 11 variables and 35569 cases for Rhode Island, a few selections later I had only 420 cases and 3 variables. It struck me that the process I went through, which included not only making selections but also inspecting the results and deleting unnecessary cases/variables, could be automated at least to eliminate the inspection step. Also, since I want to do the same thing with data for other states, automation would be very nice indeed. I realize that programming this kind of stuff in R is relatively easy, but the reshape package makes me wonder if someone has already done it. Thanks Marsh Feldman __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Okay, here is what I am doing
Dear Romain, I am working with a PC with Windows-XP I do have Rtools installed and running the code you propose, this is what I get as a result: code - '#include Rdefines.h\nSEXP f(){\n return R_NilValue ; }' writeLines( code, test.c ) dyn.load( test.so ) Error in inDL(x, as.logical(local), as.logical(now), ...) : unable to load shared library 'C:/Documents and Settings/L01359.BCRA/Mis documentos/R/test.so': LoadLibrary failure: No se puede encontrar el módulo especificado. .Call( f ) Error in .Call(f) : C symbol name f not in load table Sergio -- View this message in context: http://n4.nabble.com/I-can-t-run-the-example-shown-in-the-inline-package-tp1774328p1819298.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] C-index and Cox model
Bessy wrote: Dear all R users, I am building a Cox PH model on a small dataset. I am wondering how to measure the predictive power of my cox model? Normally the ROC curve or Gini value are used in logistic regression model. Is there any similar measurement suitable for Cox model? Also if I use C-index statistic to measure the predictive power, is it a time-dependent value (i.e. do I need to calculate it for each time period?) or we can calculate it as a single value for the whole model ignoring the time? Thank you so much. Bessy Frank H added: install.packages('Hmisc') ?rcorr.cens You can also use the survConcordance function, which is part of the survival package. (Why two functions? I wrote this one before I was aware of Frank's.) Terry T __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to run Shapiro-Wilk test for each grouped variable?
On Apr 9, 2010, at 8:16 AM, Iurie Malai wrote: I want to run Shapiro-Wilk test for each variable in my dataset, each grouped by variable groupFactor. I have these working commands: data.n-names(data) # put names into a vector called data.n by(eval(parse(text=(paste(data,data.n[3],sep=$, data $factor, shapiro.test) #run shapiro.test but I must to change the variable number manualy. How to automate this? I tried this: for (r in 3:18) { by(eval(parse(text=(paste(data,data.n[3],sep=$, data $groupFactor, shapiro.test) } Not able to test since you have provided code that works with data that is not available. Inside for loops one needs either to make an assignment or print the results. Had the data been available I would have wrapped print() around the full by expression to see if my hypothesis could be tested. -- David. but not working and no errors. Why? Please help. -- Regards, Iurie Malai, Senior Lecturer Department of Psychology Faculty of Psychology and Special Education Ion Creanga Moldova Pedagogical State University - www.upsm.md http://en.wikipedia.org/wiki/Ion_Creang%C4%83_Pedagogical_State_University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error bars on barplot
bar.err (agricolae) plotCI (gplots) xYplot (Hmisc) error.bars (psych) dispersion (plotrix) plotCI (plotrix) Not to mention: http://biostat.mc.vanderbilt.edu/wiki/Main/DynamitePlots Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] I can´t run the example shown in the inline pa ckage
What happened to the line that contained R CMD SHLIB ? This is the bit that compiles the code. On windows (you were asked to tell us that you are running windows, both through the posting guide and from my previous email) you need to install the same tools that one needs for building a package. See http://cran.r-project.org/doc/manuals/R-admin.html#The-Windows-toolset Romain Le 09/04/10 15:11, satu a écrit : Dear Romain, I am working with a PC with Windows-XP I do have Rtools installed and running the code you propose, this is what I get as a result: code- '#includeRdefines.h\nSEXP f(){\n return R_NilValue ; }' writeLines( code, test.c ) dyn.load( test.so ) Error in inDL(x, as.logical(local), as.logical(now), ...) : unable to load shared library 'C:/Documents and Settings/L01359.BCRA/Mis documentos/R/test.so': LoadLibrary failure: No se puede encontrar el módulo especificado. .Call( f ) Error in .Call(f) : C symbol name f not in load table Sergio -- Romain Francois Professional R Enthusiast +33(0) 6 28 91 30 30 http://romainfrancois.blog.free.fr |- http://bit.ly/9aKDM9 : embed images in Rd documents |- http://tr.im/OIXN : raster images and RImageJ |- http://tr.im/OcQe : Rcpp 0.7.7 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to run Shapiro-Wilk test for each grouped variable?
Hi, Maybe you should change the 3 in the loop with r like: for (r in 3:18) { by(eval(parse(text=(paste(data,data.n[r],sep=$, data$groupFactor, shapiro.test) } I think it should work, if not, I have already a similar script for that. HTH, Ivan Le 4/9/2010 15:17, David Winsemius a écrit : On Apr 9, 2010, at 8:16 AM, Iurie Malai wrote: I want to run Shapiro-Wilk test for each variable in my dataset, each grouped by variable groupFactor. I have these working commands: data.n-names(data) # put names into a vector called data.n by(eval(parse(text=(paste(data,data.n[3],sep=$, data$factor, shapiro.test) #run shapiro.test but I must to change the variable number manualy. How to automate this? I tried this: for (r in 3:18) { by(eval(parse(text=(paste(data,data.n[3],sep=$, data$groupFactor, shapiro.test) } Not able to test since you have provided code that works with data that is not available. Inside for loops one needs either to make an assignment or print the results. Had the data been available I would have wrapped print() around the full by expression to see if my hypothesis could be tested. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to run Shapiro-Wilk test for each grouped variable?
On Apr 9, 2010, at 9:39 AM, Ivan Calandra wrote: Hi, Maybe you should change the 3 in the loop with r like: for (r in 3:18) { by(eval(parse(text=(paste(data,data.n[r],sep=$, data $groupFactor, shapiro.test) } I think it should work, if not, I have already a similar script for that. HTH, Ivan Good catch, Ivan. There's a phrase ... if it's not one thing, it's another, and it applies here although it needs to be modified to ... if it's not one thing, it's two things. If one uses the example in the by help page with the warpbreaks data: attach(warpbreaks) for (i in 1:2) { by(warpbreaks[, 1], list(wool = wool, tension = tension), summary) } for (i in 1:2) { print(by(warpbreaks[, 1], list(wool = wool, tension = tension), summary)) } The first for-loop produces no output, the second one fills the screen. -- David. Le 4/9/2010 15:17, David Winsemius a écrit : On Apr 9, 2010, at 8:16 AM, Iurie Malai wrote: I want to run Shapiro-Wilk test for each variable in my dataset, each grouped by variable groupFactor. I have these working commands: data.n-names(data) # put names into a vector called data.n by(eval(parse(text=(paste(data,data.n[3],sep=$, data $factor, shapiro.test) #run shapiro.test but I must to change the variable number manualy. How to automate this? I tried this: for (r in 3:18) { by(eval(parse(text=(paste(data,data.n[3],sep=$, data $groupFactor, shapiro.test) } Not able to test since you have provided code that works with data that is not available. Inside for loops one needs either to make an assignment or print the results. Had the data been available I would have wrapped print() around the full by expression to see if my hypothesis could be tested. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/mitarbeiter.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Combining ggplot2 objects and/or extracting layers
Hi Hadley, Thanks for the terrific package! If you'd like I could give you my code, but conceptually what I'm trying to do is pretty simple. The chart on this page http://www.businessinsider.com/20-reasons-why-the-us-economy-is-dying-and-is-simply-not-going-to-recover-2010-2#hard-to-find-jobs-3 (http://www.businessinsider.com/20-reasons-why-the-us-economy-is-dying-and-is-simply-not-going-to-recover-2010-2#hard-to-find-jobs-3) is pretty typical. It shows a line chart of time series data against a backdrop of shaded bars that indicate periods of recession. This is what I'm doing. The tis package can do this and has a function that works with ggplot2. However, I see three problems with the approach in tis. (1) It only adds the bars to an existing plot being displayed. I would like to have it as a separate object that can be constructed once and added to any number of plots whether they are displayed or not. (2) I'd like to see the bars by themselves on a plot. For consistency's sake, once I do this and am satisfied with the display, I don't want to have to and do a separate reconstruction. Instead, I want to take the bars from the satisfactory display. This way there's less room for accidentally breaking the consistency of the plots. (3) The tis plots are fixed in their format. They span the y dimension and have widths equal to the durations of the recessions. There are instances when one might like something different, such as stacked bars or multiple bars of varying heights (patterns, etc.) side-by-side that together have a width equal to the recession's duration. Obviously what I'm trying to do can be done with more work, but I'm trying to minimize unnecessary repetitions. I already coded a function that draws not only the recession bars but also that can draw bars whose height represents the value of some variable but with widths equal to the durations of the recessions. Once I create a free-standing plot, I'd like to be able to use it in various other contexts, including adding it to other existing plots. The alternative is to reconstruct the plot as a layer and add it to the other plots, but this is time-consuming and introduces more room for programming error. Thanks for your help. Marsh On 4/9/2010 8:48 AM, hadley wickham wrote: Other then rebuilding the plots, is there any way either (1) to combine existing ggplot2 plots or (2) to extract a layer from an existing plot so that it can be added to another? Not really, although you can always pull apart the plot components. Can you give an example of what you are trying to achieve? Hadley [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to run Shapiro-Wilk test for each grouped variable?
Thank you, David! Here is the code to read my file: data - read.table(data.txt, header=TRUE, sep=;, na.strings=NA, dec=., strip.white=TRUE) Jorge Ivan Velez gave me a working solution, but I am ready to learn yours to. Iurie 2010/4/9 David Winsemius dwinsem...@comcast.net: OK, we have the data, now ... where is the code that you used to read that data? It is labeled as a csv file but does not have commas as separators. Post any follow-ups to the r-help list. I do not offered offlist consulting. When you post data to the list it needs to have a file extension of .txt -- David On Apr 9, 2010, at 10:08 AM, Iurie Malai wrote: I attached a file with data and corrected in the working commands grouping factor name: data.n-names(data) # put names into a vector called data.n by(eval(parse(text=(paste(data,data.n[3],sep=$, data$groupFactor, shapiro.test) # run shapiro.test and not working: for (r in 3:18) { by(eval(parse(text=(paste(data,data.n[3],sep=$, data$groupFactor, shapiro.test) } 2010/4/9 David Winsemius dwinsem...@comcast.net: On Apr 9, 2010, at 8:16 AM, Iurie Malai wrote: I want to run Shapiro-Wilk test for each variable in my dataset, each grouped by variable groupFactor. I have these working commands: data.n-names(data) # put names into a vector called data.n by(eval(parse(text=(paste(data,data.n[3],sep=$, data$factor, shapiro.test) #run shapiro.test but I must to change the variable number manualy. How to automate this? I tried this: for (r in 3:18) { by(eval(parse(text=(paste(data,data.n[3],sep=$, data$groupFactor, shapiro.test) } Not able to test since you have provided code that works with data that is not available. Inside for loops one needs either to make an assignment or print the results. Had the data been available I would have wrapped print() around the full by expression to see if my hypothesis could be tested. -- David. but not working and no errors. Why? Please help. -- Regards, Iurie Malai, Senior Lecturer Department of Psychology Faculty of Psychology and Special Education Ion Creanga Moldova Pedagogical State University - www.upsm.md http://en.wikipedia.org/wiki/Ion_Creang%C4%83_Pedagogical_State_University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT data.csv David Winsemius, MD West Hartford, CT -- Regards, Iurie Malai, Senior Lecturer Department of Psychology Faculty of Psychology and Special Education Ion Creanga Moldova Pedagogical State University - www.upsm.md http://en.wikipedia.org/wiki/Ion_Creang%C4%83_Pedagogical_State_University groupFactor;x1;x2;x3;x4;x5;x6;x7;x8;x9;x10;x11;x12;x13;x14;x15;x16 int;9;2;2;2;6;14;9;3;2;3;2;5;3;6;22;97 int;8;4;3;4;6;11;4;4;4;4;5;9;6;6;17;89 int;10;0;0;1;0;20;17;5;4;7;8;8;7;10;24;85 int;9;0;2;4;2;18;16;4;8;8;10;10;10;10;29;107 int;10;4;0;6;2;9;12;5;6;9;9;9;7;10;12;73 int;8;5;5;4;6;20;12;2;3;5;5;5;4;10;28;113 int;8;0;0;1;1;11;3;3;5;5;5;5;3;2;18;91 int;8;0;0;1;1;13;13;5;6;7;8;9;8;10;24;100 int;9;0;0;1;0;11;9;2;4;6;6;8;5;6;14;73 int;8;1;0;1;1;14;12;5;6;5;5;6;4;10;18;91 int;9;4;1;2;3;16;15;5;7;6;8;7;5;10;15;86 int;9;4;1;1;5;17;18;3;3;5;6;6;6;10;26;103 int;8;0;0;0;1;16;8;4;5;5;8;7;4;10;5;79 int;10;0;0;0;1;15;14;3;4;1;6;5;4;2;41;108 int;9;3;3;1;1;14;11;2;6;2;2;4;3;10;28;106 int;9;3;2;3;2;17;17;1;3;6;9;8;6;10;29;99 int;9;0;0;1;0;18;14;4;6;5;8;7;8;10;11;88 int;10;0;0;1;0;17;10;4;4;4;7;7;6;6;12;73 int;10;1;1;1;1;14;14;3;4;4;5;6;4;10;22;82 int;9;0;1;2;2;16;17;6;4;5;9;8;8;10;10;79 int;11;3;4;3;4;11;15;6;3;8;7;9;9;2;16;73 int;9;4;0;3;0;22;12;4;4;6;5;6;3;10;31;102 int;10;0;0;1;1;17;18;2;6;8;8;7;6;6;37;110 int;9;1;1;3;4;11;12;3;4;4;5;3;6;10;20;94 int;9;3;2;4;2;17;15;2;4;5;6;8;6;6;42;127 int;9;0;1;1;1;14;15;4;8;9;8;9;10;10;20;94 int;10;3;2;3;3;11;3;0;3;4;4;6;5;6;18;82 int;11;6;2;2;4;15;9;5;6;7;8;8;7;6;15;67 int;10;2;1;1;2;13;18;5;4;6;6;7;4;10;16;73 int;8;0;0;0;0;7;15;1;2;2;7;7;4;6;21;104 int;8;5;4;4;6;16;17;3;4;5;6;7;7;6;16;97 int;8;6;3;3;4;9;13;3;4;4;3;4;3;10;8;84 int;11;4;5;2;3;14;6;5;5;7;8;6;7;10;34;87 int;10;4;4;1;5;20;15;5;7;8;9;9;7;10;33;104 int;9;6;3;3;6;19;10;3;4;7;6;6;6;10;36;113 int;9;6;2;1;3;19;18;3;5;7;7;9;5;10;36;113 int;10;2;2;5;4;14;4;3;7;8;8;9;8;10;21;80 int;11;3;2;1;6;18;16;4;5;5;6;7;5;10;22;82 int;8;0;1;1;0;10;6;2;6;6;5;5;3;2;4;77 int;11;5;3;4;6;18;5;1;5;6;7;8;5;10;26;87 int;8;3;5;2;4;17;10;4;4;6;6;7;5;6;53;143 int;13;5;2;4;5;19;14;3;6;7;9;7;6;10;34;87 int;10;5;2;3;2;7;1;4;1;1;5;6;3;2;12;73 int;8;4;0;0;3;17;6;3;3;4;5;6;4;6;21;104 int;9;0;1;1;1;19;11;5;5;8;9;10;9;6;22;97 int;8;5;4;3;6;17;1;2;3;4;2;5;7;2;11;89 int;9;1;2;3;3;16;14;5;7;5;9;7;8;10;16;88 int;11;1;2;2;4;4;4;2;4;5;5;5;1;2;19;78 int;9;4;3;2;5;9;4;2;3;6;7;7;6;2;9;77 int;11;3;2;4;1;19;12;5;5;2;7;7;5;10;20;73
Re: [R] Data manipulation problem
In the end after going at it from scratch...This worked out allright... ##set up data age.cat-seq(0,100,10) year-(1953:(1953+55)) dat.vec-sample(1:10,(length(age.cat)*length(year))) dat.matrix-matrix(dat.vec,c(length(age.cat),length(year))) rownames(dat.matrix)-age.cat colnames(dat.matrix)-year year.int-seq(1950,2010,5) age.div-cut(year,year.int,include.lowest=T) ##summarise by another variable a-do.call(cbind,by(t(dat.matrix),age.div,function(x)colSums(x)));a //M On 6. apr. 2010, at 21.41, David Winsemius wrote: On Apr 6, 2010, at 3:30 PM, David Winsemius wrote: On Apr 6, 2010, at 9:56 AM, moleps islon wrote: OK... next question.. Which is still a data manipulation problem so I believe the heading is still OK. ##So now I read my population data from excel. No, you read it from a text file and providing the first ten lines of that text file should have been really easy. Read the Posting Guide for advice about offering datasets either as structure() objects with dput or dump or as attached files with *.txt extension (not .csv). Just change the file name with your file browser. pop-read.csv(pop.csv) typeof(pop) ## yields a list Really? I would have guessed it to yield just list. where I have age-specific population rows and a yearly column population, where the years are suffixed by X And had you used class(pop) you would have learned it was a dataframe and even more informative would have been str(pop). c-(1953:2008) No, no, no. Do not use variable names that are important function names. The R interpreter can (usually) keep things straight but it is our brains that experience problems. Other function names to avoid: data, df, cut, mean, sd, list, vector, matrix names(pop)-c c.div-cut(c,break=seq(1950,2010,by=5) (You should have gotten an error here.) After fixing the error, did you you notice that there were only 3 of the first level??? Watch out for cut(). It uses the default convention of ( , ] , i.e. open interval at right er, ^left^ which is backwards to what some (most?) of us think natural. Because of that the lowest level gets dropped unless you take special precautions. That is undoubtedly why Harrell set up his Hmisc::cut2 to have the default be [ , ) Aggregating across columns? Certainly possible, but maybe not as natural a fit to functions like split as would occur with working across rows. I suppose you could use something like this untested (because _still_ no sample dataset provided) code: apply(pop, 1,# this works a row a time function(x) tapply(x, list(c.div), sum) ) ) # or use aggregate which uses tapply I'm not sure it will work, since I don't know if the column names would get carried over into x by apply(). You might need to create a separate index that used the numeric positions of the columns rather than their names. Perhaps use c.div - seq(0,(2008-1953)) %/% 5 or some such inside tapply. Now I'd like to sum the agespecific population over the individual levels of -c.div- and generate a new table for this with agespecific rows and columns containing the 5-year bins instead of the original yearly data. Do I have to program this from scratch or is it possible to use an already existing function? I think you ought to read more introductory material (and the Posting Guide regarding how to offer example datasets). In this case there are many functions that do data aggregation and most of them should be illustrated in a good introductory text. -- David. //M qta- table(cut(age,breaks = seq(0, 100, by = 10),include.lowest = TRUE),cut(year,breaks=seq(1950,2010,by=5),include.lowest=TRUE On Mon, Apr 5, 2010 at 10:11 PM, moleps mole...@gmail.com wrote: Thx Erik, I have no idea what went wrong with the other code snippet, but this one works.. Appreciate it. qta- table(cut(age,breaks = seq(0, 100, by = 10),include.lowest = TRUE),cut(year,breaks=seq(1950,2010,by=5),include.lowest=TRUE)) M On 5. apr. 2010, at 21.45, Erik Iverson wrote: I don't know what your data are like, since you haven't given a reproducible example. I was imagining something like: ## generate fake data age - sample(20:90, 100, replace = TRUE) year - sample(1950:2000, 100, replace = TRUE) ##look at big table table(age, year) ## categorize data ## see include.lowest and right arguments to cut age.factor - cut(age, breaks = seq(20, 90, by = 10), include.lowest = TRUE) year.factor - cut(year, breaks = seq(1950, 2000, by = 10), include.lowest = TRUE) table(age.factor, year.factor) moleps wrote: I already did try the regression modeling approach. However the epidemiologists (referee) turns out to be quite fond of comparing the incidence rates to different standard populations, hence the need
Re: [R] How to run Shapiro-Wilk test for each grouped variable?
Thank you very much, Jorge! Your example worked for me. Here is the code: d - data.frame(data$groupFactor, data[2:17]) d # p-values for the shapiro test (by levels of groupFactor) with(d, aggregate(d[,-1], list(d[,1]), FUN = function(x) shapiro.test(x)$p.value)) Iurie 2010/4/9 Jorge Ivan Velez jorgeivanve...@gmail.com: Hi Iurie, Take a look at this example: # some data set.seed(123) x - matrix(rnorm(100), ncol = 10) f - sample(1:3, 100, replace = TRUE) d - data.frame(f, x) d # p-values for the shapiro test (by levels of f) with(d, aggregate(d[,-1], list(d[,1]), FUN = function(x) shapiro.test(x)$p.value)) HTH, Jorge On Fri, Apr 9, 2010 at 8:16 AM, Iurie Malai wrote: I want to run Shapiro-Wilk test for each variable in my dataset, each grouped by variable groupFactor. I have these working commands: data.n-names(data) # put names into a vector called data.n by(eval(parse(text=(paste(data,data.n[3],sep=$, data$factor, shapiro.test) #run shapiro.test but I must to change the variable number manualy. How to automate this? I tried this: for (r in 3:18) { by(eval(parse(text=(paste(data,data.n[3],sep=$, data$groupFactor, shapiro.test) } but not working and no errors. Why? Please help. -- Regards, Iurie Malai, Senior Lecturer Department of Psychology Faculty of Psychology and Special Education Ion Creanga Moldova Pedagogical State University - www.upsm.md http://en.wikipedia.org/wiki/Ion_Creang%C4%83_Pedagogical_State_University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Beyond reshape: automatically streamlining data
Hi Marshall, On Fri, Apr 9, 2010 at 8:59 AM, Marshall Feldman ma...@uri.edu wrote: ... For any particular set of analyses, one typically recodes variables and deletes cases and variables. It would be really nice to have a package that, for example, if one selected cases from a larger data set based on the values of certain variables would inspect the resulting data and drop any variables that have the same value for all cases. Similarly, if any cases are entirely zero or NA, the package could (under user control) drop these cases. Finally, it could take a set of data transformations and keep them as an object, so that the same selection/reshape/streamlining can easily be applied to similar data sets. ... Some of the utilities in the caret package might be related to the things your after: http://cran.r-project.org/package=caret There is a writeup about using caret to build predictive models in R in the Journal of Statistical Software (it's a PDF): http://www.jstatsoft.org/v28/i05/paper I'd recommend reading through that if you haven't before, since caret offers many handy wrapper/utility functions, but check out section 3: Data Preparation, in particular, where Max talks about zero-variance-predictors and the multicollinearity problem. Hope that helps. -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Ranking correlation with R
Hey Everyone, Im fresh new in R, and Im supposed to write a code to give me a correlation between two rankings. So I have two ranking lists, which contain file names, e.g.: Ranking list 1: file1.java file3.java file2.java Ranking list 2: fiile2.java file4.java file1.java I need to see how much are these two ranking lists are alike, get a correlation between them. I dont even know where to start. Can anyone bring me some light or tips? Thank you in advance. Cheers, -- David Nemer [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to replace all non-maximum values in a row with 0
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of ONKELINX, Thierry Sent: Friday, April 09, 2010 2:25 AM To: jes...@econinfo.de; r-help@r-project.org Subject: Re: [R] How to replace all non-maximum values in a row with 0 It can be done faster and more elegant with apply and rowSums rows - 10 A - matrix(rpois(n = rows * 20, lambda = 100), nrow = rows) A[4, c(1,3)] - 1000 system.time({ y - t(apply(A, 1, function(z){ 1 * (z == max(z)) })) y[rowSums(y) 1, ] - 0 }) S+ has a rowMaxs() function but base R doesn't appear to have one. When ncol(A)nrow(A) the following version of rowMaxs() runs faster than the above call to apply rowMaxs - function(x) { retval-x[,1] for(j in seq_len(ncol(x))[-1L]){ which-retvalx[,j] if(any(which)) retval[which]-x[which,j] } retval } so the following function, f, is faster: f - function(A) { retval - rowMaxs(A)==A # relies on column-major order of data in matrix retval[rowSums(retval)1,] - 0L retval } E.g., for your A I get: system.time(z-f(A)) user system elapsed 0.270.020.30 system.time({ + y - t(apply(A, 1, function(z){ + 1 * (z == max(z)) + })) + y[rowSums(y) 1, ] - 0 + }) user system elapsed 1.880.041.84 all.equal(y,z) [1] TRUE This could be sped up more, with some loss of readability, but my point is that looping over columns instead of rows can help when there are many more rows than columns. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com system.time({ nr - nrow(A) nc - ncol(A) B - matrix(0,nrow=nr, ncol=nc) for(i in 1:nr){ x - which(A[i,]==max(A[i,])) B[i,x] - 1 if(sum(B[i,])1) B[i,] - as.vector(rep(0,nc)) } }) all.equal(y, B) HTH, Thierry -- -- ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek team Biometrie Kwaliteitszorg Gaverstraat 4 9500 Geraardsbergen Belgium Research Institute for Nature and Forest team Biometrics Quality Assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Owe Jessen Verzonden: vrijdag 9 april 2010 11:08 Aan: r-help@r-project.org Onderwerp: Re: [R] How to replace all non-maximum values in a row with 0 Am 09.04.2010 10:04, schrieb burgundy: Hi, I would like to replace all the max values per row with 1 and all other values with 0. If there are two max values, then 0 for both. Example: from: 2 3 0 0 200 30 0 0 2 50 0 0 3 0 0 0 0 8 8 0 to: 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 Thanks! Nice little homework to get the day started. :-) This worked for me, but is probably not the shortest possible answer 0, 3, 0, 0, 0, 0, 8, 8, 0), nrow = 4, byrow=T) nr - nrow(A) nc - ncol(A) B - matrix(0,nrow=nr, ncol=nc) for(i in 1:nr){ x - which(A[i,]==max(A[i,])) B[i,x] - 1 if(sum(B[i,])1) B[i,] - as.vector(rep(0,nc)) } -- Owe Jessen Nettelbeckstr. 5 24105 Kiel p...@owejessen.de http://privat.owejessen.de __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Druk dit bericht a.u.b. niet onnodig af. Please do not print this message unnecessarily. Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide
[R] Dallas R Users Group has a Yahoo Group for signup now
If you are interested in joining the Dallas RUG please go to the following link to show your interest and get things started. http://tech.groups.yahoo.com/group/Dallas_RUG/ My first thought would to have some informal meet ups at some local Dallas locations to discuss overall goals, ideas, wishes of the RUG. The next step would be to nominate and elect a leadership team. Then get the ball rolling to a more formal meet up process with presentations, workshops, and tutorial sessions. Larry [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] garch estimation with exogenouse variables
Hello All, I need to estimate a GARCH model. The mean equation contains exogenous variables like Y = B * X + et. I understand the garch function in tseries package can handle univariate model, and garchFit in fGarch can handle ARMA specification. Is there any function that can handle exogenous variables? Thank you, Edwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to get the penalty matrix for natural cubic spline?
Yan Li wrote: Hi, all I am trying to get the basis matrix and penalty matrix for natural cubic splines. In the splines package of R,ns can generate the B-spline basis matrix for a natural cubic spline. How can I get the basis matrix and penalty matrix for natural cubic spline. Thanks a lot! Lee In usual practice the natural cubic spline does not use penalization. Frank -- Frank E Harrell Jr Professor and ChairmanSchool of Medicine Department of Biostatistics Vanderbilt University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] SSH Through R Script
When I do what you're describing, I get prompted for my password: system('ssh -l usernm rmthost') use...@rmthost's password: After I enter my password, nothing seems to happen. But if I hit ctrl-c then I get a command line prompt, and it turns out that it's a shell prompt on the remote host. I can issue standard unix commands, and they execute on the remote host. To get back into R on my local host I type 'exit'. Or: Here's a couple of lines from one of my scripts that might help ... cmd - 'ssh -l username remotehost /bin/lpstat -a' lprs - read.table(pipe(cmd),fill=TRUE,as.is=TRUE)[,1] I get prompted for my password when I source these lines on my local host. With the result that the lprs object has the names of printers available on the remote host. -Don At 10:01 PM -0800 4/8/10, afoo wrote: Hi, I am trying to SSH to a remote server through R script. In other words, I would like to know how I can get a SSH connection to the remote server and then execute commands on that server with the R script. So in bash, I would normally type ssh -lusername remoteserver.com; press enter and then wait for the password prompt to key in my password. I have tried system(ssh remoteserver.com) but that doesn't work because, from what I know, SSH requires user interactivity - I am required to key in my password. I tried looking up about putting password as a command line parameter, but SSH doesn't allow that, my only option then is to set up a private/public key pair. But the admin of the remoteserver doesn't allow me to do that. Is there a way in which I can SSH in? Or is there a command in R that allows me to interact with the command prompts interactively? thanks, afoo -- View this message in context: http://*n4.nabble.com/SSH-Through-R-Script-tp1809635p1809635.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://*stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://*www.*R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Ranking correlation with R
Dear David, Are the rankings the numbers? Like List 1: 1 3 2 If so you should be able to do it fairly easily with cor() If you have a lot of file names and need to extract the numbers look at ?strsplit or ?substring. This will be easier or harder depending how variable the names are. For instance with your example names x - c(file1.java,file2.java) as.numeric(substring(x,5,5)) [1] 1 2 but this assumes that there is only 1 number and that it always occurs as five characters from the left. Best regards, Joshua On Fri, Apr 9, 2010 at 8:22 AM, David Nemer davidne...@gmail.com wrote: Hey Everyone, Im fresh new in R, and Im supposed to write a code to give me a correlation between two rankings. So I have two ranking lists, which contain file names, e.g.: Ranking list 1: file1.java file3.java file2.java Ranking list 2: fiile2.java file4.java file1.java I need to see how much are these two ranking lists are alike, get a correlation between them. I dont even know where to start. Can anyone bring me some light or tips? Thank you in advance. Cheers, -- David Nemer [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Senior in Psychology University of California, Riverside http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Rsge: recursive parallelization
In principle, I'd like to be able to do something like this: sge.parLapply(seq(10), function(x) parLapply(seq(x), function(x) x^2)) In practice, however, I have to resort to acrobatics like this: sge.options(sge.remove.files=FALSE) sge.options(sge.qsub.options='-cwd -V') sge.parLapply(seq(10), function(x) { sge.options(sge.save.global=TRUE) sge.options(sge.remove.files=FALSE) sge.parLapply(seq(x), function(x) x^2, cluster=TRUE, debug=FALSE, trace=FALSE, file.prefix='Rsge_data', global.savelist=NULL, packages=NULL) }, function.savelist=c('sge.parLapply', 'sge.parParApply', 'sge.options', 'sge.taskPrep'), global.savelist=c('sge.parParApply', 'sge.globalPrep', 'global.savelist', 'sge.taskPrep', 'sge.checkNotNow', 'sge.get.jobid', 'sge.get.result', 'docall', 'enquote'), packages=NULL) and I still get bizarre behavior: half of the results will be NULL, for instance; the other half, incomplete. Would non-trivial changes to Rsge be required to make something like this possible? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Read data in sequences
RockO wrote: I tried to find a solution in the search list, but I cannot find it. I would like to read a .txt file with, let say, three variables, with two of which have repeated values in a number a columns. The variables: Treat, x1, x2. The values: A 2.5 3.4 2.7 5.6 5.7 5.4 10.1 9.4 ... B 5.3 5.4 6.5 7.5 1.3 4.5 10.5 4.1 ... ... In the first column, the letters represent the variable Treat, and the sequence of numbers on a same line represent pairs of values for x1 and x2. Looks like SAS is quite elegant here (don't kill me, I could not afford using SAS, R has save my retirement fund). I would first read it in as usual, and do the reformatting later. library(reshape) wide = read.table(wideseq.txt,sep= ) # renames columns names(wide) = c(varname,rep(c(x1,x2),ncol(wide)%/%2)) str(wide) melt(wide) Now you have the long format, which is not exactly what you want, but typically much more useful in R than the format you require. You might use one of the function in package reshape to get your format. Dieter -- View this message in context: http://n4.nabble.com/Read-data-in-sequences-tp1819487p1819559.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Data manipulation problem
Bert Gunter wrote: Yes. Don't do this. (what you probably really want to do is fit a model with age as a factor, which can be done statistically e.g. by logistic regression; or graphically using conditioning plots, e.g. via trellis graphics (the lattice package). This avoids the arbitrariness and discontinuities of binning by age range.) Moleps' reply: the reviewer wants it. Dieter: Sigh. Too often have received such a request, asking for all pairwise tests of each age groups. Applying the most generic Bonferroni correction often ends the debate quickly. Dieter -- View this message in context: http://n4.nabble.com/Data-manipulation-problem-tp1751932p1819579.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Ranking correlation with R
On Fri, Apr 9, 2010 at 8:58 AM, David Nemer davidne...@gmail.com wrote: Hello Joshua, Thanks for your help. The ranking list doesn't have numbers (it doesn't matter the name of the file), just the file name, and the ranking is assumed base on the position of the file name in the list (so the first filename to appear is ranked number 1). So I guess I would just need to add the filenames into a vector (array) for both rankings and then compare them.. is You would add both lists to vectors. it right? And to compare them I would use cor() right? cor() requires numeric data. To use it in this case, you would need to come up with rankings based on the position for each file name, and use those pairs of numbers with cor(). Cheers, -- David Nemer -- Joshua Wiley Senior in Psychology University of California, Riverside http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Bootcov for two stage bootstrap
Dear users, I'm trying to implement the nonparametric two-stage bootstrap (Davison and Hinkley 1997, pag 100-102) in R. As far as I understood, 'bootcov' is the most appropriate method to implement NONPARAMETRIC bootstrap in R when you have clustered data (?). I read the 'bootcov' manual but I still have a few questions: 1 - When the variable 'cluster' is introduced, then only clusters will be resampled (with replacement)? 2 - I can implement 'two-stage' bootstrap in STATA by running bootstrap sampling on top of the bootstrap command. Example: bootsrap cost, cluster(group): bsampling cost treat This means that in the 1st stage I resample clusters (with replacement) and then resample individuals within those clusters. I wonder whether we could do a similar procedure in R, i.e. if it is sensible to do something like: f-boot(cost~treat) mod-bootcov(f, cluster, B=1000, coef.reps=TRUE) Do you have any other ideas? Do I need to define 'fitter'? Thanks a lot, Manuel Gomes -- View this message in context: http://n4.nabble.com/Bootcov-for-two-stage-bootstrap-tp1819605p1819605.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Ranking correlation with R
On Apr 9, 2010, at 12:14 PM, Joshua Wiley wrote: On Fri, Apr 9, 2010 at 8:58 AM, David Nemer davidne...@gmail.com wrote: Hello Joshua, Thanks for your help. The ranking list doesn't have numbers (it doesn't matter the name of the file), just the file name, and the ranking is assumed base on the position of the file name in the list (so the first filename to appear is ranked number 1). So I guess I would just need to add the filenames into a vector (array) for both rankings and then compare them.. is You would add both lists to vectors. it right? And to compare them I would use cor() right? cor() requires numeric data. To use it in this case, you would need to come up with rankings based on the position for each file name, and use those pairs of numbers with cor(). One possible source for such numbers would be row.names(dfrm) since by default (assuming they are in a data.frame) row.names are an ascending series of integers, but one could also number them by appending a colrankn=1:nrow(dfrm). Cheers, -- David Nemer -- Joshua Wiley Senior in Psychology David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to replace all non-maximum values in a row with 0
Hi: This isn't much shorter than the previous solution, but here's another take, operating row-wise. A - matrix (c(2, 3, 0, 0, 200, 30, 0, 0, 2, 50, 0, 0, 3, 0, 0, 0, 0, 8, 8, 0), nrow = 4, byrow=T) # Write a vector function to apply to each row: begin by initializing a zero # vector of length = no. columns. Next, find which indices of the row vector x # match the maximum. If that number is 1, return a zero vector, else replace # the index where the maximum resides to 1. f - function(x) { o - rep(0, length(x)) w - which(x == max(x)) r - if(length(w) 1) {o} else { o[w] - 1; o} r } # Test: t(apply(A, 1, f)) [,1] [,2] [,3] [,4] [,5] [1,]00001 [2,]00001 [3,]00100 [4,]00000 HTH, Dennis On Fri, Apr 9, 2010 at 1:04 AM, burgundy saub...@yahoo.com wrote: Hi, I would like to replace all the max values per row with 1 and all other values with 0. If there are two max values, then 0 for both. Example: from: 2 3 0 0 200 30 0 0 2 50 0 0 3 0 0 0 0 8 8 0 to: 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 0 0 Thanks! -- View this message in context: http://n4.nabble.com/How-to-replace-all-non-maximum-values-in-a-row-with-0-tp1819018p1819018.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Read data in sequences
Dear R users, I tried to find a solution in the search list, but I cannot find it. I would like to read a .txt file with, let say, three variables, with two of which have repeated values in a number a columns. An example: The variables: Treat, x1, x2. The values: A 2.5 3.4 2.7 5.6 5.7 5.4 10.1 9.4 ... B 5.3 5.4 6.5 7.5 1.3 4.5 10.5 4.1 ... ... In the first column, the letters represent the variable Treat, and the sequence of numbers on a same line represent pairs of values for x1 and x2. In SAS, this type of dataset is easy to read using @@ as in: data a; input Treat @ x1 x2 @@; But I would like to know how to read it with R, to get rid of my addiction to SAS. Thank You, Rock Ouimet DRF-MRNF, Quebec -- View this message in context: http://n4.nabble.com/Read-data-in-sequences-tp1819487p1819487.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] I can´t run the example shown in the inline pa ckage
Dear Romain, you are right. Apologies, here is the complete result from your script: code - '#include Rdefines.h\nSEXP f(){\n return R_NilValue ; }' writeLines( code, test.c ) system( R CMD SHLIB test.c ) gcc -IC:/R/R-210~1.1/include-O3 -Wall -std=gnu99 -c test.c -o test.o gcc -shared -s -o test.dll tmp.def test.o -LC:/R/R-210~1.1/bin -lR dyn.load( test.so ) Error in inDL(x, as.logical(local), as.logical(now), ...) : unable to load shared library 'C:/Documents and Settings/L01359.BCRA/Mis documentos/R/test.so': LoadLibrary failure: No se puede encontrar el módulo especificado. .Call( f ) Error in .Call(f) : C symbol name f not in load table The system(,,,) bit seems to work, but then errors show up Sergio -- View this message in context: http://n4.nabble.com/I-can-t-run-the-example-shown-in-the-inline-package-tp1774328p1819514.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Trouble with mChoice() in the Hmisc package.
Hi All:-- I've started using the the Hmisc reporting facilities recently, mostly successfully. I'm having some trouble with mChoice() multiple-choice objects, though. Here's some example code and output from R-help a couple of years ago: library(Hmisc) Symptom1 - c(Headache, Headache, NA) Symptom2 - c(NA, Anxiety, NA) Symptoms - mChoice(Symptom1, Symptom2) summary(~ Symptoms, method=reverse) [Output:] Descriptive Statistics (N=3) +---+---+ | | | +---+---+ |Symptom1 : Headache|67% (2)| +---+---+ |NA |67% (2)| +---+---+ |Anxiety|33% (1)| +---+---+ However, if I try this same example using R 2.10.1 and the latest version of Hmisc, I get the following output table: +---++ | || +---++ |Symptom1 : Headache|100% (3)| +---++ |NA |100% (3)| +---++ |Anxiety|100% (3)| +---++ Further, as.double(Symptoms) incorrectly returns Headache NA Anxiety [1,]11 1 [2,]11 1 [3,]11 1 instead of Headache NA Anxiety [1,]11 0 [2,]10 1 [3,]01 0 N.B.: levels(Symptoms) [1] Headache NA Anxiety The problems with as.double.mChoice() appear related to inmChoice(), which calls match.mChoice(). The Hmisc docs say, inmChoice() creates a logical vector the same length as x whose elements are TRUE when the observation in x contains at least one of the codes or value labels in the second argument, but inmChoice() doesn't seem to be returning a vector the same length as x; it incorrectly returns, e.g., inmChoice(Symptoms, 1) # Headache [1] TRUE instead of [1] TRUE TRUE FALSE I tried rewriting inmChoice() to avoid the call to match.mChoice(), which fixed as.double.mChoice(), but that didn't change the output from summary.formula(). The R function match.mChoice() '.Call's the C function do_mchoice_match(SEXP x, SEXP table, SEXP nomatch), which may contain the source of these problems, but I haven't had the time to try and debug it yet. Until then, I thought I'd post the problem here in hope of getting the attention of someone who might recognize the problem I'm having. I get the same results on various Windows systems -- XP (x86), Vista (x64), Windows 7 (x86). Thanks to anyone who can help. I really like Hmisc reporting, so if I'm able to make the changes myself I'll update this thread. -- Jim Java R.Version() $platform [1] i386-pc-mingw32 $arch [1] i386 $os [1] mingw32 $system [1] i386, mingw32 $status [1] $major [1] 2 $minor [1] 10.1 $year [1] 2009 $month [1] 12 $day [1] 14 $`svn rev` [1] 50720 $language [1] R $version.string [1] R version 2.10.1 (2009-12-14) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Ranking correlation with R
cor() requires numeric data. To use it in this case, you would need to come up with rankings based on the position for each file name, and use those pairs of numbers with cor(). One possible source for such numbers would be row.names(dfrm) since by default (assuming they are in a data.frame) row.names are an ascending series of integers, but one could also number them by appending a colrankn=1:nrow(dfrm). What about this? x - c(A,C,B) y - c(A,B,C) ranks - match(y,x) ranks [1] 1 3 2 cor(seq_along(x), ranks) [1] 0.5 It seems like as long as both sets of filenames contain exactly the same names, that should work. David Winsemius, MD West Hartford, CT -- Joshua Wiley Senior in Psychology University of California, Riverside http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] fill in values between rollapply
Hi: Not exactly elegant, but here's one approach: library(zoo) x - zoo( rpois(100, 40) ) w - rollapply(x, 5, mean, by = 5, align = c('left')) x2 - rep(w, each = 5) Does that work? HTH, Dennis On Fri, Apr 9, 2010 at 12:32 AM, Brad Patrick Schneid bpsch...@gmail.comwrote: Hi, Sorry ahead of time for not including data with this question. Using rollapply to calculate mean values for 5 day blocks, I'd use this: Roll5mean - rollapply(data, 5, mean, by=5, align = c(left)) My question is, can someone tell me how to fill in the days between each of these means with the previously calculated mean? If this doesn't make sense, I will clarify and provide data for an example. Thanks. Brad -- View this message in context: http://n4.nabble.com/fill-in-values-between-rollapply-tp1816885p1816885.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] GARCH estimation with exogenous variables in the mean equation
Hello, I have the similar issue in estimating a GARCH model with exogenous variables in the mean equation. Currently, to my understanding, the garch function in tseries package can handle univariate model, and garchFit in fGarch can handle ARMA specification. I wonder if there is any R function that can handle exogenous variables in estimating GARCH? Thank you a lot. Edwin -- View this message in context: http://n4.nabble.com/another-GARCH-problem-tp859307p1819640.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Read data in sequences
Rock - Here's one way: x = textConnection('A 2.5 3.4 2.7 5.6 5.7 5.4 10.1 9.4 + B 5.3 5.4 6.5 7.5 1.3 4.5 10.5 4.1') dat = read.table(x) names(dat) = c('grp','x1','x2','x3','x4','x5','x6','x7','x8') reshape(dat,idvar='grp',varying=list(c('x1','x3','x5','x7'), + c('x2','x4','x6','x8')), + direction='long',timevar=NULL) grp x1 x2 A.1 A 2.5 3.4 B.1 B 5.3 5.4 A.2 A 2.7 5.6 B.2 B 6.5 7.5 A.3 A 5.7 5.4 B.3 B 1.3 4.5 A.4 A 10.1 9.4 B.4 B 10.5 4.1 You could generalize the varying argument like this: mkvarying = function(n)list(paste('x',seq(1,n,by=2),sep=''), paste('x',seq(2,n,by=2),sep='')) and use reshape(dat,idvar='grp',varying=mkvarying(8),direction='long',timevar=NULL) - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Fri, 9 Apr 2010, RockO wrote: Dear R users, I tried to find a solution in the search list, but I cannot find it. I would like to read a .txt file with, let say, three variables, with two of which have repeated values in a number a columns. An example: The variables: Treat, x1, x2. The values: A 2.5 3.4 2.7 5.6 5.7 5.4 10.1 9.4 ... B 5.3 5.4 6.5 7.5 1.3 4.5 10.5 4.1 ... ... In the first column, the letters represent the variable Treat, and the sequence of numbers on a same line represent pairs of values for x1 and x2. In SAS, this type of dataset is easy to read using @@ as in: data a; input Treat @ x1 x2 @@; But I would like to know how to read it with R, to get rid of my addiction to SAS. Thank You, Rock Ouimet DRF-MRNF, Quebec -- View this message in context: http://n4.nabble.com/Read-data-in-sequences-tp1819487p1819487.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to run Shapiro-Wilk test for each grouped variable?
On Apr 9, 2010, at 10:51 AM, Iurie Malai wrote: Thank you, David! Here is the code to read my file: data - read.table(data.txt, header=TRUE, sep=;, na.strings=NA, dec=., strip.white=TRUE) Jorge Ivan Velez gave me a working solution, but I am ready to learn yours to. I don't think I want to play anymore. Running Jorge's code seemed at first to be pretty good evidence that doing such an investigation is prone to very misleading results to which I would not want to expose the unwary. Only one of those thirty tests of normality on what appeared at first glance to be normal data actually accepted the Null Hypothesis. (That arose because he only selected 100 normal values and then replicated them across 10 and 100 rows and columns. You can prove this by table(unlist(d[,-1]) ), so I suppose the widespread rejection could be considered a proper result. Notice that d[11,2] == d[1,20] ) Automating the task of testing for normality reminds me of the methods I was forced to use in Green Belt class, although their favorite normality statistic was the Anderson-Darling test. I had by that point decided to bite my tongue because the Black Belt instructors were rather annoyed at hearing my objections and pained reactions to their version of statistics. -- David. Iurie 2010/4/9 David Winsemius dwinsem...@comcast.net: OK, we have the data, now ... where is the code that you used to read that data? It is labeled as a csv file but does not have commas as separators. Post any follow-ups to the r-help list. I do not offered offlist consulting. When you post data to the list it needs to have a file extension of .txt -- David On Apr 9, 2010, at 10:08 AM, Iurie Malai wrote: I attached a file with data and corrected in the working commands grouping factor name: data.n-names(data) # put names into a vector called data.n by(eval(parse(text=(paste(data,data.n[3],sep=$, data $groupFactor, shapiro.test) # run shapiro.test and not working: for (r in 3:18) { by(eval(parse(text=(paste(data,data.n[3],sep=$, data $groupFactor, shapiro.test) } 2010/4/9 David Winsemius dwinsem...@comcast.net: On Apr 9, 2010, at 8:16 AM, Iurie Malai wrote: I want to run Shapiro-Wilk test for each variable in my dataset, each grouped by variable groupFactor. I have these working commands: data.n-names(data) # put names into a vector called data.n by(eval(parse(text=(paste(data,data.n[3],sep=$, data $factor, shapiro.test) #run shapiro.test but I must to change the variable number manualy. How to automate this? I tried this: for (r in 3:18) { by(eval(parse(text=(paste(data,data.n[3],sep=$, data$groupFactor, shapiro.test) } Not able to test since you have provided code that works with data that is not available. Inside for loops one needs either to make an assignment or print the results. Had the data been available I would have wrapped print() around the full by expression to see if my hypothesis could be tested. -- David. but not working and no errors. Why? Please help. -- Regards, Iurie Malai, Senior Lecturer Department of Psychology Faculty of Psychology and Special Education Ion Creanga Moldova Pedagogical State University - www.upsm.md http://en.wikipedia.org/wiki/Ion_Creang%C4%83_Pedagogical_State_University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT data.csv David Winsemius, MD West Hartford, CT -- Regards, Iurie Malai, Senior Lecturer Department of Psychology Faculty of Psychology and Special Education Ion Creanga Moldova Pedagogical State University - www.upsm.md http://en.wikipedia.org/wiki/Ion_Creang%C4%83_Pedagogical_State_University data.txt__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to use tapply for quantile
On Thu, 8 Apr 2010, James Rome wrote: I am trying to calculate quantiles of a data frame column split up by two factors: # Calculate the quantiles quarts = tapply(gdf$tt, list(gdf$Runway, gdf$OnHour), FUN=quantile, na.rm = TRUE) This does not work: It seems like it did work. It returned a matrix list of the results, some of which are NULL and some of which are numeric vectors of length 5. Try str( quarts ) to get a sense of what is going on. HTH, Chuck p.s. providing commented, minimal, self-contained, reproducible code (as requested) will give you more informative answers. quarts 04L 04R 15R 22L 22R 2732 33L 33R 0 NULL Numeric,5 NULL Numeric,5 NULL Numeric,5 NULL Numeric,5 NULL 1 NULL Numeric,5 NULL Numeric,5 NULL NULL NULL Numeric,5 NULL 2 NULL NULL NULL Numeric,5 NULL NULL NULL NULL NULL 3 NULL NULL NULL NULL NULL NULL NULL Numeric,5 NULL 4 NULL NULL NULL NULL NULL NULL NULL NULL NULL 5 NULL NULL NULL NULL NULL NULL NULL NULL NULL 6 NULL NULL NULL NULL NULL NULL NULL NULL NULL 7 NULL Numeric,5 NULL NULL NULL Numeric,5 NULL Numeric,5 NULL 8 NULL Numeric,5 NULL Numeric,5 NULL Numeric,5 NULL Numeric,5 NULL . . . But if I leave out either of the two factors, it does work quarts = tapply(gdf$tt, list(gdf$Runway), FUN=quantile, na.rm = TRUE) quarts $`04L` 0% 25% 50% 75% 100% 489 10 20 $`04R` 0% 25% 50% 75% 100% 09 10 11 28 . . . . How can I get this to work? Thanks, Jim Rome __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Ranking correlation with R
On Fri, Apr 9, 2010 at 10:23 AM, David Nemer davidne...@gmail.com wrote: Would that also work if in one ranking I have a filename that it is not in the other ranking? match() will return an NA, if it cannot find a match, in which case you could use the argument: use=pairwise.complete.obs) in cor() to have it only use pairs with complete data. Eg: Ranking X: A B C Ranking Y: A D C In this example, you would get a correlation of 1, because B from x does not match anything in y, and D from y does not match x, so you're left with A and C which are in the same positions. -- David Nemer -- Joshua Wiley Senior in Psychology University of California, Riverside http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Question on implementing Random Forests scoring
So I've been working with Random Forests ( R library is randomForest) and I curious if Random Forests could be applied to classifying on a real time basis. For instance lets say I've scored fraud from a group of transactions. If I want to score any new incoming transactions for fraud could Random Forests be used in that context. Linear Regression is nice in that it is very easy to score. I suppose R could be used as a real time API to load in data, score, then output results. Is there any other way with Random Forests? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Excel R1C1 reference style in Rcom?
Hi, I have created the Boolean function below to evaluate if a given cell in an Excel file contains a formula. I have to process hundreds of excel files and I want to filter out any cells that contain formulae. Now I want to use the isXlsFormula function below when I loop through all the cells of a sheet, and all sheets of an excel file. For this, it would be very convenient if I could use the alternative R1C1 excel reference style, instead of the alphabetic style, as shown below. Is this possible? library(rcom) isXlsFormula - function(cellref=A1) { excel - comGetObject(Excel.Application) sheet - comGetProperty(excel, ActiveSheet) cell - comGetProperty(sheet, Range, cellref, cellref) isformula - comGetProperty(cell, hasFormula) return(isformula) } isXlsFormula() # returns TRUE if cell A1 (R1C1) contains a formula, FALSE otherwise. Thank you in advance. Cheers!! Albert-Jan ~~ All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a fresh water system, and public health, what have the Romans ever done for us? ~~ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Multiple comparisons for a two-factor ANCOVA
On Wed, Apr 7, 2010 at 9:25 PM, Eric Scott ersco...@illinois.edu wrote: Thank you for your reply. The WoodEnergy example helped a lot. I understand now that it is inappropriate to make all pairwise comparisons with an interaction present and better to make comparisons between levels of one factor within a constant level of the second factor. As I understand it, the solution in the WoodEnergy example is to produce separate ANOVAs for each type of wood and then perform the multiple comparisons between stove types within each wood type. This makes a lot of sense. For my data, I'm using glm.nb and if I run the model separately for each level of site, it estimates a different theta for each which I immagine is a problem. Is this ok, or do I need to find a way to use the coefficients from the full model with the interaction to compare levels of clipping within fixed levels of site? -Eric Scott The right solution is to fit one model and then work with its coefficients. For this example the R glht function did not, at the time I wrote the example, have the option of averaging over the wood types. It now has experimental options for interaction_average covariate_average These usually, but not always, do the right thing. For this example, I prefer the analysis in file HH/demo/MMC.WoodEnergy.s.R in which one aov model is calculated and the adjustments are made for the levels of Wood. That file works in S-Plus, but not in R. As I noted before, I still need to revise the WoodEnergy example to use the experimental option in glht to duplicate the results I get from S-Plus. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] rjags syntax error
Hi, I am getting the following error when I'm running jags.model() meas1 - jags.model(file=measurement.bug,data=dat.test) syntax error, unexpected '}', expecting ',' or ')' Error in jags.model(file = measurement.bug, data = dat.test) : Parse error on line 1 Below is my JAGS model. Please cc me as I'm a digest subscriber if you reply. Thanks! Chris JAGS model ... model { for(i in 1:N){ ## # measurement equation model ## for(j in 1:P){ y[i,j]~dnorm(mu[i,j],psi[j]) } ## # alp[i] corresponds to the intercepts ## mu[i,1]-xi[i,1]+alp[1] ## Ext1 mu[i,2]-lam[1]*xi[i,1]+alp[2] mu[i,3]-lam[2]*xi[i,1]+alp[3] mu[i,4]-xi[i,2]+alp[4] ## Soc1 mu[i,5]-lam[3]*xi[i,2]+alp[5] mu[i,6]-lam[4]*xi[i,2]+alp[6] mu[i,7]-xi[i,3]+alp[7] ## Aca1 mu[i,8]-lam[5]*xi[i,3]+alp[8] mu[i,9]-lam[6]*xi[i,3]+alp[9] mu[i,10]-xi[i,4]+alp[10] ## Ext2 mu[i,11]-lam[7]*xi[i,4]+alp[11] mu[i,12]-lam[8]*xi[i,4]+alp[12] mu[i,13]-xi[i,5]+alp[13] ## Soc2 mu[i,14]-lam[9]*xi[i,5]+alp[14] mu[i,15]-lam[10]*xi[i,5]+alp[15] mu[i,16]-xi[i,6]+alp[16] ## Aca2 mu[i,17]-lam[11]*xi[i,6]+alp[17] mu[i,18]-lam[12]*xi[i,6]+alp[18] mu[i,19]-xi[i,7]+alp[19] ## Work2 mu[i,20]-lam[13]*xi[i,7]+alp[20] mu[i,21]-lam[14]*xi[i,7]+alp[21] mu[i,22]-xi[i,8]+alp[22] ## Ext3 mu[i,23]-lam[15]*xi[i,8]+alp[23] mu[i,24]-lam[16]*xi[i,8]+alp[24] mu[i,25]-xi[i,9]+alp[25] ## Soc3 mu[i,26]-lam[17]*xi[i,9]+alp[26] mu[i,27]-lam[18]*xi[i,9]+alp[27] mu[i,28]-xi[i,10]+alp[28] ## Aca3 mu[i,29]-lam[19]*xi[i,10]+alp[29] mu[i,30]-lam[20]*xi[i,10]+alp[30] mu[i,31]-xi[i,11]+alp[31] ## Work3 mu[i,32]-lam[21]*xi[i,11]+alp[32] mu[i,33]-lam[22]*xi[i,11]+alp[3] mu[i,34]-xi[i,12]+alp[34] ## Ext4 mu[i,35]-lam[23]*xi[i,12]+alp[35] mu[i,36]-lam[24]*xi[i,12]+alp[36] mu[i,37]-xi[i,13]+alp[37] ## Soc4 mu[i,38]-lam[25]*xi[i,13]+alp[38] mu[i,39]-lam[26]*xi[i,13]+alp[39] mu[i,40]-xi[i,14]+alp[40] ## Aca4 mu[i,41]-lam[27]*xi[i,14]+alp[41] mu[i,42]-lam[28]*xi[i,14]+alp[42] mu[i,43]-xi[i,15]+alp[43] ## Work4 mu[i,44]-lam[29]*xi[i,15]+alp[44] mu[i,45]-lam[30]*xi[i,15]+alp[45] xi[i,1:45]~dmnorm(u[1:15],phi[1:15,1:15]) } for(j in 1:45){alp[j]~dnorm(0.0, 1.0)} for(j in 1:30){lam[j]~dnorm(0.8,psi[j]} for(j in 1:P){ psi[j]~dgamma(9.0, 4.0) sgm[j]-1/psi[j] } psd~dgamma(9.0, 4.0) sgd-1/psd phi[1:3,1:3]~dwish(R[1:3,1:3], 5) phx[1:3,1:3]-inverse(phi[1:3,1:3]) } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] maSigPro
Hello, I am using the maSigPro package to use the two.ways.stepback command, this command performs backward selection, I would like it to do it wtihout an intercept in the regression, do you know how can I do this, or how can I see the packages code or scripts in order to be able to modify it? thank you Felipe Parra [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] step function
Hello I am using the step function in order to do backward selection for a linear model of 52 variables with the following commands: object-lm(vars[,1] ~ (vars[,2:(ncol(predictors)+1)]-1)) BackS-step(object,direction=backward) but it isn't dropping any if the variables in the model, but there are lots of not significant variables as you can see here object-lm(vars[,1] ~ (vars[,2:(ncol(predictors)+1)]-1)) summary(object) Call: lm(formula = vars[, 1] ~ (vars[, 2:(ncol(predictors) + 1)] - 1)) Residuals: Min 1Q Median 3Q Max -0.56388 -0.10762 -0.01433 0.08495 0.82477 Coefficients: Estimate Std. Error t value Pr(|t|) vars[, 2:(ncol(predictors) + 1)]SS.1 0.028772 0.025458 1.130 0.260896 vars[, 2:(ncol(predictors) + 1)]Precio.Promedio.Bolsa[1] -0.308076 0.096243 -3.201 0.001795 ** vars[, 2:(ncol(predictors) + 1)]Precio.Promedio.Bolsa[2] 0.130134 0.101734 1.279 0.203559 vars[, 2:(ncol(predictors) + 1)]Precio.Promedio.Bolsa[3] 0.014345 0.106282 0.135 0.892887 vars[, 2:(ncol(predictors) + 1)]Precio.Promedio.Bolsa[4] -0.175958 0.107097 -1.643 0.103268 vars[, 2:(ncol(predictors) + 1)]Precio.Promedio.Bolsa[5] 0.016270 0.106081 0.153 0.878391 vars[, 2:(ncol(predictors) + 1)]Precio.Promedio.Bolsa[6] -0.089018 0.091132 -0.977 0.330834 vars[, 2:(ncol(predictors) + 1)]Precio.Promedio.Bolsa[7] -0.270550 0.075537 -3.582 0.000512 *** vars[, 2:(ncol(predictors) + 1)]Precio.Promedio.Bolsa[8] -0.106691 0.074448 -1.433 0.154694 vars[, 2:(ncol(predictors) + 1)]Precio.Promedio.Bolsa[9] 0.118962 0.076886 1.547 0.124699 vars[, 2:(ncol(predictors) + 1)]Precio.Promedio.Bolsa[10] -0.055112 0.076225 -0.723 0.471218 vars[, 2:(ncol(predictors) + 1)]Precio.Promedio.Bolsa[11] -0.135113 0.076307 -1.771 0.079415 . vars[, 2:(ncol(predictors) + 1)]Precio.Promedio.Bolsa[12] 0.082478 0.075130 1.098 0.274707 vars[, 2:(ncol(predictors) + 1)]Anomalia[0]0.123054 0.213980 0.575 0.566426 vars[, 2:(ncol(predictors) + 1)]Anomalia[1]0.078511 0.507544 0.155 0.877353 vars[, 2:(ncol(predictors) + 1)]Anomalia[2] -0.399726 0.581594 -0.687 0.493357 vars[, 2:(ncol(predictors) + 1)]Anomalia[3] -0.002103 0.583109 -0.004 0.997129 vars[, 2:(ncol(predictors) + 1)]Anomalia[4]0.596937 0.678115 0.880 0.380640 vars[, 2:(ncol(predictors) + 1)]Anomalia[5] -0.547555 0.710687 -0.770 0.442695 vars[, 2:(ncol(predictors) + 1)]Anomalia[6] -0.142452 0.678536 -0.210 0.834106 vars[, 2:(ncol(predictors) + 1)]Anomalia[7]0.506431 0.692960 0.731 0.466455 vars[, 2:(ncol(predictors) + 1)]Anomalia[8] -0.117177 0.662596 -0.177 0.859958 vars[, 2:(ncol(predictors) + 1)]Anomalia[9] -0.550570 0.563421 -0.977 0.330638 vars[, 2:(ncol(predictors) + 1)]Anomalia[10] 0.799499 0.555007 1.441 0.152587 vars[, 2:(ncol(predictors) + 1)]Anomalia[11] -0.577416 0.504046 -1.146 0.254485 vars[, 2:(ncol(predictors) + 1)]Anomalia[12] 0.204479 0.221030 0.925 0.356948 vars[, 2:(ncol(predictors) + 1)]demanda.nacional[0] -0.572351 1.303885 -0.439 0.661561 vars[, 2:(ncol(predictors) + 1)]demanda.nacional[1]0.270387 1.715912 0.158 0.875082 vars[, 2:(ncol(predictors) + 1)]demanda.nacional[2]1.939207 1.806931 1.073 0.285549 vars[, 2:(ncol(predictors) + 1)]demanda.nacional[3]1.501964 1.779253 0.844 0.400432 vars[, 2:(ncol(predictors) + 1)]demanda.nacional[4]1.292790 1.759802 0.735 0.464147 vars[, 2:(ncol(predictors) + 1)]demanda.nacional[5]1.197978 1.760600 0.680 0.497670 vars[, 2:(ncol(predictors) + 1)]demanda.nacional[6]0.338068 1.720709 0.196 0.844608 vars[, 2:(ncol(predictors) + 1)]demanda.nacional[7] -2.197186 1.616212 -1.359 0.176805 vars[, 2:(ncol(predictors) + 1)]demanda.nacional[8] -2.050263 1.542936 -1.329 0.186687 vars[, 2:(ncol(predictors) + 1)]demanda.nacional[9] -0.103823 1.541956 -0.067 0.946441 vars[, 2:(ncol(predictors) + 1)]demanda.nacional[10] 0.349220 1.545823 0.226 0.821693 vars[, 2:(ncol(predictors) + 1)]demanda.nacional[11] -0.654607 1.476141 -0.443 0.658313 vars[, 2:(ncol(predictors) + 1)]demanda.nacional[12] -0.254144 1.193506 -0.213 0.831772 vars[, 2:(ncol(predictors) + 1)]Nivel.Embalse[0] -1.500119 0.428395 -3.502 0.000671 *** vars[, 2:(ncol(predictors) + 1)]Nivel.Embalse[1] -1.058775 0.475011 -2.229 0.027869 * vars[, 2:(ncol(predictors) + 1)]Nivel.Embalse[2] 0.818735 0.497920 1.644 0.102994 vars[, 2:(ncol(predictors) + 1)]Nivel.Embalse[3] 0.057331 0.528216 0.109 0.913769 vars[, 2:(ncol(predictors) + 1)]Nivel.Embalse[4] -0.529271 0.519284 -1.019 0.310350 vars[, 2:(ncol(predictors) + 1)]Nivel.Embalse[5] -0.649193 0.508210 -1.277 0.204171 vars[, 2:(ncol(predictors) +
Re: [R] 3-D response surface using wireframe()
Hi David and Felix, Thank you very much for your suggestions. To be honest, this has become beyond my understanding of lattice plots now. I am relatively new to lattice plots, so have no idea how function within function works (for example, how does panel.3dpolygon() within panel.3d.wireframe() within wirefarme() works, totally have no clue. Felix, your example code of panel.3dpolygon() for volcano plot does what I want, but again, I don't know how to tweak your example to suit my case. I attached an example dataset, and an example of the plot that I wanted to make (especially those grid lines on the 3 bounding surfaces of the box, and if possible remove those front edges of the box to make it look like open). dat-read.table(dat.txt,sep='\t',header=T,row.names=1) library(lattice) wireframe(z ~ x*y, data = dat, scales = list(arrows = FALSE, cex=0.9, col=black,font=3, tick.number=6, z=list(tick.number=10, tck=0.8,distance=0.8),x=list(tck=0.8,distance=0.6),y=list(tck=0.7,distance=0.6)), zlim=seq(-14,4,by=2), zlab=list(label=Z, rot=90,cex=0.9), xlab=list(label=X, rot=15.5), ylab=list(label=Y, rot=-33), drape = T, at=seq(min(dat$z),max(dat$z),length=50), col.regions=rgb(colorRamp(c(white, red))(seq(0, 1, length = 50)), max = 255), colorkey = F, par.box=list(lwd=2), ## line width of box screen = list(z = 210, x = -75, y = 5), scpos=list(x=9,y=5,z=2) ## where axes are draw ) Thank you all very much for the help. It's fun to learn. John --- On Thu, 4/8/10, Felix Andrews fe...@nfrac.org wrote: From: Felix Andrews fe...@nfrac.org Subject: Re: [R] 3-D response surface using wireframe() To: David Winsemius dwinsem...@comcast.net Cc: array chip arrayprof...@yahoo.com, r-help@r-project.org Date: Thursday, April 8, 2010, 9:56 PM On 9 April 2010 11:18, David Winsemius dwinsem...@comcast.net wrote: On Apr 8, 2010, at 8:29 PM, array chip wrote: David, Thansk again! Sarkar's Lattice book is excellent source for lattice. Here is a link for all the figures and codes used in the book. You example is figure 13.7. http://lmdvr.r-forge.r-project.org/figures/figures.html I got the first point! For the second point below, Figure 13.7 an excellent example for projecting the 3D dataset onto the bounding surface, but it's not what I meant. I think I didn't explain what I wanted clearly. What I really wanted is a simple straight grid lines across the tick marks for 3 bounding surfaces of the box, not a projection of the 3D dataset. Hope I have explained clearly this time. You have not convinced me that I misunderstood what you wanted. I figured that you would use something other than transforming the data driven contour lines. But if you want to use a lattice function there is a panel.grid, but I still suspect it will need to be 3dto3d transformed onto one of the lim extremes. Might be a little easier to use panel.3dpolygon from latticeExtra. (or not) e.g. something like wireframe(volcano, drape = TRUE, scales = list(arrows = FALSE), panel.3d.wireframe = function(x,y,z,...) { panel.3dwire(x,y,z,...) panel.3dpolygon(x = rep(pretty(x), each = 3), y = min(y), z = c(range(z),NA), ..., border=grey, lwd=2) }) Many thanks John --- On Thu, 4/8/10, David Winsemius dwinsem...@comcast.net wrote: From: David Winsemius dwinsem...@comcast.net Subject: Re: [R] 3-D response surface using wireframe() To: array chip arrayprof...@yahoo.com Cc: r-help@r-project.org Date: Thursday, April 8, 2010, 3:46 PM On Apr 8, 2010, at 3:13 PM, array chip wrote: David, That does the job! Thanks a lot. Now I am very very close to what I want. Still have a couple of small adjustments to make. 1. I use drape=TRUE to draw grid and color on the surface, is there a parameter to adjust the density of the grid? If you mean the spacing between points, then isn't that determined by the density of the gridded data arguments before they get to the wireframe function? 2. Is there a way that I can add grid to the axis surface? I mean the sides of the box, between x y, between x z, and between y z? And I need to choose which 3 side of the box that I want to add grid? See Figure 13.7 of Sarkar's Lattice text for an example of a panel function that collapses the contourLines of the volcano dataset at the top bounding surface by using ltransform3dto3d with a z argument of zlim.scaled[2]. I would think that a grid could be 3dto3d transformed similarly. -- David. Thank you all for the help. It's fun to play with wireframe John --- On Wed, 4/7/10, David Winsemius dwinsem...@comcast.net wrote: From: David Winsemius dwinsem...@comcast.net Subject: Re: [R] 3-D response surface using wireframe() To: array chip arrayprof...@yahoo.com Cc: r-help@r-project.org Date:
[R] Brier's score for bootstrap sample (coxph)
Dear all, How can i get brier's score for the bootsrap sample for survival analysis. this are the code i am using for the validation. f1 - cph(Surv(time,dead ) ~ strata(x1)+strata(x2)+strata(x3), x=TRUE, y=TRUE, surv=TRUE, time.inc=12, data=new) validate(f1,B=200,u=12,dxy=T) Thanks Paaveen _ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Evaluate variable
Dear R-users: I would like to create a system of regression equations of length n, where the variables are drawn from a data frame. The result I would like is given by the variable named system in the code below. However, when I use a loop to create the system of equations, I cannot seem to get the expressions to evaluate immediately, and so the variable system2 does not replicate the result I would like. Is there a way to force the evaluation of the loop variable i (I have tried eval() and force() without success)? Thanks for your help, Nic Rivers Simon Fraser University dat - data.frame(lhs.1=rnorm(100,1,1),lhs.2=rnorm(100,2,1),rhs. 1=rnorm(100,3,1),rhs.2=rnorm(100,4,1)) lhs - c(lhs.1,lhs.2) rhs - c(rhs.1,rhs.2) n - 2 # number of equations r - vector(list,length=n) # create system of equations manually r[[1]] - dat[lhs[1]] ~ dat[rhs[1]] r[[2]] - dat[lhs[2]] ~ dat[rhs[2]] system - c(r[[1]],r[[2]]) # create system of equations with a loop system2 - list() for (i in 1:n) { r[[i]] - dat[lhs[i]] ~ dat[rhs[i]] system2 - append(system2,r[i]) } system system2 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Evaluate variable
You probably want to use substitute() to construct your formula and be careful of the distinction between character strings and names substitute(foo ~ bar, list(foo = as.name(y), bar = as.name(x))) y ~ x On Fri, Apr 9, 2010 at 2:06 PM, Nic Rivers njriv...@sfu.ca wrote: Dear R-users: I would like to create a system of regression equations of length n, where the variables are drawn from a data frame. The result I would like is given by the variable named system in the code below. However, when I use a loop to create the system of equations, I cannot seem to get the expressions to evaluate immediately, and so the variable system2 does not replicate the result I would like. Is there a way to force the evaluation of the loop variable i (I have tried eval() and force() without success)? Thanks for your help, Nic Rivers Simon Fraser University dat - data.frame(lhs.1=rnorm(100,1,1),lhs.2=rnorm(100,2,1),rhs.1=rnorm(100,3,1),rhs.2=rnorm(100,4,1)) lhs - c(lhs.1,lhs.2) rhs - c(rhs.1,rhs.2) n - 2 # number of equations r - vector(list,length=n) # create system of equations manually r[[1]] - dat[lhs[1]] ~ dat[rhs[1]] r[[2]] - dat[lhs[2]] ~ dat[rhs[2]] system - c(r[[1]],r[[2]]) # create system of equations with a loop system2 - list() for (i in 1:n) { r[[i]] - dat[lhs[i]] ~ dat[rhs[i]] system2 - append(system2,r[i]) } system system2 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question on implementing Random Forests scoring
From: Larry D'Agostino So I've been working with Random Forests ( R library is randomForest) and I curious if Random Forests could be applied to classifying on a real time basis. For instance lets say I've scored fraud from a group of transactions. If I want to score any new incoming transactions for fraud could Random Forests be used in that context. Linear Regression is nice in that it is very easy to score. I suppose R could be used as a real time API to load in data, score, then output results. Is there any other way with Random Forests? Yes, but not without more work. You can write the forest out to a file (with simple R code), and then write a stand-alone C code to read that model file and score the new data. The C function that scores new data from the model can be found in the source code of the package. Your C code just need to wrap around that. Andy Notice: This e-mail message, together with any attachme...{{dropped:10}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question on implementing Random Forests scoring
On Fri, Apr 9, 2010 at 2:15 PM, Liaw, Andy andy_l...@merck.com wrote: From: Larry D'Agostino So I've been working with Random Forests ( R library is randomForest) and I curious if Random Forests could be applied to classifying on a real time basis. For instance lets say I've scored fraud from a group of transactions. If I want to score any new incoming transactions for fraud could Random Forests be used in that context. Linear Regression is nice in that it is very easy to score. I suppose R could be used as a real time API to load in data, score, then output results. Is there any other way with Random Forests? Yes, but not without more work. You can write the forest out to a file (with simple R code), and then write a stand-alone C code to read that model file and score the new data. The C function that scores new data from the model can be found in the source code of the package. Your C code just need to wrap around that. Andy Notice: This e-mail message, together with any attach...{{dropped:18}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] 3-D response surface using wireframe()
Sorry the example plot didn't go through last time, here it is: Thanks John --- On Fri, 4/9/10, array chip arrayprof...@yahoo.com wrote: From: array chip arrayprof...@yahoo.com Subject: Re: [R] 3-D response surface using wireframe() To: David Winsemius dwinsem...@comcast.net, Felix Andrews fe...@nfrac.org Cc: r-help@r-project.org Date: Friday, April 9, 2010, 1:09 PM Hi David and Felix, Thank you very much for your suggestions. To be honest, this has become beyond my understanding of lattice plots now. I am relatively new to lattice plots, so have no idea how function within function works (for example, how does panel.3dpolygon() within panel.3d.wireframe() within wirefarme() works, totally have no clue. Felix, your example code of panel.3dpolygon() for volcano plot does what I want, but again, I don't know how to tweak your example to suit my case. I attached an example dataset, and an example of the plot that I wanted to make (especially those grid lines on the 3 bounding surfaces of the box, and if possible remove those front edges of the box to make it look like open). dat-read.table(dat.txt,sep='\t',header=T,row.names=1) library(lattice) wireframe(z ~ x*y, data = dat, scales = list(arrows = FALSE, cex=0.9, col=black,font=3, tick.number=6, z=list(tick.number=10, tck=0.8,distance=0.8),x=list(tck=0.8,distance=0.6),y=list(tck=0.7,distance=0.6)), zlim=seq(-14,4,by=2), zlab=list(label=Z, rot=90,cex=0.9), xlab=list(label=X, rot=15.5), ylab=list(label=Y, rot=-33), drape = T, at=seq(min(dat$z),max(dat$z),length=50), col.regions=rgb(colorRamp(c(white, red))(seq(0, 1, length = 50)), max = 255), colorkey = F, par.box=list(lwd=2), ## line width of box screen = list(z = 210, x = -75, y = 5), scpos=list(x=9,y=5,z=2) ## where axes are draw ) Thank you all very much for the help. It's fun to learn. John --- On Thu, 4/8/10, Felix Andrews fe...@nfrac.org wrote: From: Felix Andrews fe...@nfrac.org Subject: Re: [R] 3-D response surface using wireframe() To: David Winsemius dwinsem...@comcast.net Cc: array chip arrayprof...@yahoo.com, r-help@r-project.org Date: Thursday, April 8, 2010, 9:56 PM On 9 April 2010 11:18, David Winsemius dwinsem...@comcast.net wrote: On Apr 8, 2010, at 8:29 PM, array chip wrote: David, Thansk again! Sarkar's Lattice book is excellent source for lattice. Here is a link for all the figures and codes used in the book. You example is figure 13.7. http://lmdvr.r-forge.r-project.org/figures/figures.html I got the first point! For the second point below, Figure 13.7 an excellent example for projecting the 3D dataset onto the bounding surface, but it's not what I meant. I think I didn't explain what I wanted clearly. What I really wanted is a simple straight grid lines across the tick marks for 3 bounding surfaces of the box, not a projection of the 3D dataset. Hope I have explained clearly this time. You have not convinced me that I misunderstood what you wanted. I figured that you would use something other than transforming the data driven contour lines. But if you want to use a lattice function there is a panel.grid, but I still suspect it will need to be 3dto3d transformed onto one of the lim extremes. Might be a little easier to use panel.3dpolygon from latticeExtra. (or not) e.g. something like wireframe(volcano, drape = TRUE, scales = list(arrows = FALSE), panel.3d.wireframe = function(x,y,z,...) { panel.3dwire(x,y,z,...) panel.3dpolygon(x = rep(pretty(x), each = 3), y = min(y), z = c(range(z),NA), ..., border=grey, lwd=2) }) Many thanks John --- On Thu, 4/8/10, David Winsemius dwinsem...@comcast.net wrote: From: David Winsemius dwinsem...@comcast.net Subject: Re: [R] 3-D response surface using wireframe() To: array chip arrayprof...@yahoo.com Cc: r-help@r-project.org Date: Thursday, April 8, 2010, 3:46 PM On Apr 8, 2010, at 3:13 PM, array chip wrote: David, That does the job! Thanks a lot. Now I am very very close to what I want. Still have a couple of small adjustments to make. 1. I use drape=TRUE to draw grid and color on the surface, is there a parameter to adjust the density of the grid? If you mean the spacing between points, then isn't that determined by the density of the gridded data arguments before they get to the wireframe function? 2. Is there a way that I can add grid to the axis surface? I mean the sides of the box, between x y, between x z, and between y z? And I need to choose which 3 side of the box that I want to add grid? See Figure 13.7 of Sarkar's Lattice text for an example of a panel function that collapses the
Re: [R] Question on implementing Random Forests scoring
You may also wish to check out the PMML approach. Check out the PMML package. eRic - Original message - From: Liaw, Andy andy_l...@merck.com To: Larry D'Agostino ieorto...@gmail.com, r-help r-help@r-project.org Date: Fri, 9 Apr 2010 15:15:11 -0400 Subject: Re: [R] Question on implementing Random Forests scoring From: Larry D'Agostino So I've been working with Random Forests ( R library is randomForest) and I curious if Random Forests could be applied to classifying on a real time basis. For instance lets say I've scored fraud from a group of transactions. If I want to score any new incoming transactions for fraud could Random Forests be used in that context. Linear Regression is nice in that it is very easy to score. I suppose R could be used as a real time API to load in data, score, then output results. Is there any other way with Random Forests? Yes, but not without more work. You can write the forest out to a file (with simple R code), and then write a stand-alone C code to read that model file and score the new data. The C function that scores new data from the model can be found in the source code of the package. Your C code just need to wrap around that. Andy Notice: This e-mail message, together with any attachme...{{dropped:10}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 3-D response surface using wireframe()
I do not think the mail server accepts .jpg formats which was the format in which I got your attachment the first time (because of your having copied me directly.) I don't see much need to send a pdf because the code you offered does work and the data made it through (because .txt and .pdf are types that the mailserver accepts.) Back in 2007 Sarkar suggested that it would be possible to project grids on the walls of the bounding box but since the original poster did not reply, it appears Sarkar did not deliver a worked solution. http://finzi.psych.upenn.edu/R/Rhelp02/archive/95759.html And then in 2008 he referred the questioner to the section of the Lattice examples I earlier cited: http://finzi.psych.upenn.edu/Rhelp10/2008-October/176466.html -- David. On Apr 9, 2010, at 3:27 PM, array chip wrote: Sorry the example plot didn't go through last time, here it is: Thanks John --- On Fri, 4/9/10, array chip arrayprof...@yahoo.com wrote: From: array chip arrayprof...@yahoo.com Subject: Re: [R] 3-D response surface using wireframe() To: David Winsemius dwinsem...@comcast.net, Felix Andrews fe...@nfrac.org Cc: r-help@r-project.org Date: Friday, April 9, 2010, 1:09 PM Hi David and Felix, Thank you very much for your suggestions. To be honest, this has become beyond my understanding of lattice plots now. I am relatively new to lattice plots, so have no idea how function within function works (for example, how does panel.3dpolygon() within panel.3d.wireframe() within wirefarme() works, totally have no clue. Felix, your example code of panel.3dpolygon() for volcano plot does what I want, but again, I don't know how to tweak your example to suit my case. I attached an example dataset, and an example of the plot that I wanted to make (especially those grid lines on the 3 bounding surfaces of the box, and if possible remove those front edges of the box to make it look like open). dat-read.table(dat.txt,sep='\t',header=T,row.names=1) library(lattice) wireframe(z ~ x*y, data = dat, scales = list(arrows = FALSE, cex=0.9, col=black,font=3, tick.number=6, z=list(tick.number=10, tck = 0.8 ,distance =0.8),x=list(tck=0.8,distance=0.6),y=list(tck=0.7,distance=0.6)), zlim=seq(-14,4,by=2), zlab=list(label=Z, rot=90,cex=0.9), xlab=list(label=X, rot=15.5), ylab=list(label=Y, rot=-33), drape = T, at=seq(min(dat$z),max(dat$z),length=50), col.regions=rgb(colorRamp(c(white, red))(seq(0, 1, length = 50)), max = 255), colorkey = F, par.box=list(lwd=2), ## line width of box screen = list(z = 210, x = -75, y = 5), scpos=list(x=9,y=5,z=2) ## where axes are draw ) Thank you all very much for the help. It's fun to learn. John --- On Thu, 4/8/10, Felix Andrews fe...@nfrac.org wrote: From: Felix Andrews fe...@nfrac.org Subject: Re: [R] 3-D response surface using wireframe() To: David Winsemius dwinsem...@comcast.net Cc: array chip arrayprof...@yahoo.com, r-help@r-project.org Date: Thursday, April 8, 2010, 9:56 PM On 9 April 2010 11:18, David Winsemius dwinsem...@comcast.net wrote: On Apr 8, 2010, at 8:29 PM, array chip wrote: David, Thansk again! Sarkar's Lattice book is excellent source for lattice. Here is a link for all the figures and codes used in the book. You example is figure 13.7. http://lmdvr.r-forge.r-project.org/figures/figures.html I got the first point! For the second point below, Figure 13.7 an excellent example for projecting the 3D dataset onto the bounding surface, but it's not what I meant. I think I didn't explain what I wanted clearly. What I really wanted is a simple straight grid lines across the tick marks for 3 bounding surfaces of the box, not a projection of the 3D dataset. Hope I have explained clearly this time. You have not convinced me that I misunderstood what you wanted. I figured that you would use something other than transforming the data driven contour lines. But if you want to use a lattice function there is a panel.grid, but I still suspect it will need to be 3dto3d transformed onto one of the lim extremes. Might be a little easier to use panel.3dpolygon from latticeExtra. (or not) e.g. something like wireframe(volcano, drape = TRUE, scales = list(arrows = FALSE), panel.3d.wireframe = function(x,y,z,...) { panel.3dwire(x,y,z,...) panel.3dpolygon(x = rep(pretty(x), each = 3), y = min(y), z = c(range(z),NA), ..., border=grey, lwd=2) }) Many thanks John --- On Thu, 4/8/10, David Winsemius dwinsem...@comcast.net wrote: From: David Winsemius dwinsem...@comcast.net Subject: Re: [R] 3-D response surface using wireframe() To: array chip arrayprof...@yahoo.com Cc: r-help@r-project.org Date: Thursday, April 8, 2010, 3:46 PM On Apr 8, 2010, at 3:13 PM, array chip wrote: David, That does the job! Thanks a lot. Now I am very very close to what I want. Still have a couple of small adjustments to make. 1. I use drape=TRUE to draw grid and color on the surface, is there a
[R] Fox's algorithm?
I'm interested in a serial implementation of fox's algorithm for memory management reasons. Does anybody know if there is anything available in R or C libraries? [eg A %*% B is too big to allocate memory for. I really want the values written to disk, so I was thinking that it would be easiest to use something like Fox's algorithm to load submatrices/blocks of A and B iteratively, do the multiplies, write to disk, and repeat to get the rest of the submatrices of A%*%B. If A and B were sufficiently sparse, I would use spam... Best, Blair __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Bars in lattice- barcharts
Well, when the error message says argument 'lx' is missing, with no default, it really means that argument 'lx' is missing, with no default. Your panel function has an argument 'lx', which you forgot to change to 'ly' as you did with the prepanel function. Hope that helps... Thanks for the help Felix! It was a bit obvious what the problem was and I apologize for not thinking about the error message more clearly. I am going to continue this as I think that it would be helpful if there was a working example of this type of plot. Unfortunately, I do not have it yet. The modified example below produced a stacked barplot with lovely error bars. However, I can't seem to produce a plot that doesn't stack the bars. stack=FALSE doesn't seem to have any effect. Any thoughts? Thanks in advance. Sam #Generating the data library(lattice) temp - abs(rnorm(81*5)) err - as.data.frame(temp) err$section=c(down,down,down,mid,mid,mid, up,up, up) err$depth=c(Surface,D50, 2xD50) err$err.date=c(05/09/2009,12/09/2009,13/10/2009,19/10/2009,21/09/2009) err.split - with(err, split(temp, list(depth,section, err.date))) #I've tried to alter the panel function according to the thread to produce #vertical error bars in my barcharts prepanel.ci - function(x, y, ly, uy, subscripts, ...) { y - as.numeric(y) ly - as.numeric(ly[subscripts]) uy - as.numeric(uy[subscripts]) list(ylim = range(y, uy, ly, finite = TRUE)) } panel.ci - function(x, y, ly, uy, subscripts, pch = 16, ...) { x - as.numeric(x) y - as.numeric(y) ly - as.numeric(ly[subscripts]) uy - as.numeric(uy[subscripts]) panel.arrows(x, ly, x, uy, col = 'black', length = 0.25, unit = native, angle = 90, code = 3) panel.barchart(x, y, pch = pch, ...) } se -function(x) sqrt(var(x)/length(x)) err.ucl - sapply(err.split, function(x) { st - boxplot.stats(x) c(mean(x), mean(x) + se(x), mean(x) -se(x)) }) err.ucl - as.data.frame(t(err.ucl)) names(err.ucl) - c(mean, upper.se, lower.se) err.ucl$label - factor(rownames(err.ucl),levels = rownames(err.ucl)) # add factor, grouping and by variables err.ucl$section=c(down,down,down,mid,mid,mid, up,up, up) err.ucl$depth=c(Surface,D50, 2xD50) s err.ucl$err.date=c(05/09/2009,12/09/2009,13/10/2009,19/10/2009,21/09/2009) #This produces the figure I am looking for minus the error bars. with(err.ucl, barchart(mean ~ err.date | section, group=depth, layout=c(1,3), horizontal=FALSE, scales=list(x=list(rot=45)), )) #OK, now that this work and the error bars are drawn, I am curious why the stack=TRUE doesn't produce each bar beside each other. with(err.ucl, barchart(mean ~ err.date| section, group=depth, layout=c(1,3), horizontal=FALSE, stack=FALSE, scales=list(x=list(rot=45)), ly=lower.se, uy=upper.se, auto.key = list(points = FALSE, rectangles = TRUE, space= right, title = Depth, border = TRUE), #auto.key=TRUE, prepanel=prepanel.ci, panel=panel.superpose, panel.groups=panel.ci )) -- * Sam Albers Geography Program University of Northern British Columbia University Way Prince George, British Columbia Canada, V2N 4Z9 phone: 250 960-6777 * [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] perhaps regular expression bug with | sign ??
Here is my interaction with R: sub(x='|t|',pattern = '|t',replacement='zz') [1] zz|t| So I say to myself Clearly the | signs need to be escaped, so let's try this sub(x='|t|',pattern = '\|t',replacement='zz') [1] zz|t| Warning messages: 1: '\|' is an unrecognized escape in a character string 2: unrecognized escape removed from \|t How can \| be an unrecognized escape? This flatly contradicts help('regex'), or am I misunderstanding the help? The first pattern above works if one uses extended=F. What do R experts think? David -- View this message in context: http://n4.nabble.com/perhaps-regular-expression-bug-with-sign-tp1819872p1819872.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] perhaps regular expression bug with | sign ??
you need to escape it (twice): sub(x='|t|',pattern = '\\|t',replacement='zz') [1] zz| On Fri, Apr 9, 2010 at 4:35 PM, David.Epstein david.epst...@warwick.ac.ukwrote: Here is my interaction with R: sub(x='|t|',pattern = '|t',replacement='zz') [1] zz|t| So I say to myself Clearly the | signs need to be escaped, so let's try this sub(x='|t|',pattern = '\|t',replacement='zz') [1] zz|t| Warning messages: 1: '\|' is an unrecognized escape in a character string 2: unrecognized escape removed from \|t How can \| be an unrecognized escape? This flatly contradicts help('regex'), or am I misunderstanding the help? The first pattern above works if one uses extended=F. What do R experts think? David -- View this message in context: http://n4.nabble.com/perhaps-regular-expression-bug-with-sign-tp1819872p1819872.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] 3-D response surface using wireframe()
David, Thanks for the 2 previous posts from Sarkar. Actually, I am now one step closer. I am now able to remove the 3 outer lines of the bounding box using par.box argument, even Sarkar said in his 2008 post that par.box() does not control different boundaries, so maybe it was fixed. Replacing par.box=list(lwd=2) in my original code with par.box=list(lwd=2,col=c(1,1,1,NA,1,1,NA,NA,1)) will now remove the 3 outer lines of the bounding box. The only thing missing here is the 3 inner lines of the box (behind the plot) are dashed lines, not solid. And par.box argument only control those 9 visible lines of the bounding box. As for how to draw grid lines onto the 3 surfaces, I still have no clue. But as you pointed out Sarkar indicated in his 2007 post that it might be possible. Thanks John --- On Fri, 4/9/10, David Winsemius dwinsem...@comcast.net wrote: From: David Winsemius dwinsem...@comcast.net Subject: Re: [R] 3-D response surface using wireframe() To: array chip arrayprof...@yahoo.com Cc: r-help@r-project.org Date: Friday, April 9, 2010, 3:48 PM I do not think the mail server accepts .jpg formats which was the format in which I got your attachment the first time (because of your having copied me directly.) I don't see much need to send a pdf because the code you offered does work and the data made it through (because .txt and .pdf are types that the mailserver accepts.) Back in 2007 Sarkar suggested that it would be possible to project grids on the walls of the bounding box but since the original poster did not reply, it appears Sarkar did not deliver a worked solution. http://finzi.psych.upenn.edu/R/Rhelp02/archive/95759.html And then in 2008 he referred the questioner to the section of the Lattice examples I earlier cited: http://finzi.psych.upenn.edu/Rhelp10/2008-October/176466.html -- David. On Apr 9, 2010, at 3:27 PM, array chip wrote: Sorry the example plot didn't go through last time, here it is: Thanks John --- On Fri, 4/9/10, array chip arrayprof...@yahoo.com wrote: From: array chip arrayprof...@yahoo.com Subject: Re: [R] 3-D response surface using wireframe() To: David Winsemius dwinsem...@comcast.net, Felix Andrews fe...@nfrac.org Cc: r-help@r-project.org Date: Friday, April 9, 2010, 1:09 PM Hi David and Felix, Thank you very much for your suggestions. To be honest, this has become beyond my understanding of lattice plots now. I am relatively new to lattice plots, so have no idea how function within function works (for example, how does panel.3dpolygon() within panel.3d.wireframe() within wirefarme() works, totally have no clue. Felix, your example code of panel.3dpolygon() for volcano plot does what I want, but again, I don't know how to tweak your example to suit my case. I attached an example dataset, and an example of the plot that I wanted to make (especially those grid lines on the 3 bounding surfaces of the box, and if possible remove those front edges of the box to make it look like open). dat-read.table(dat.txt,sep='\t',header=T,row.names=1) library(lattice) wireframe(z ~ x*y, data = dat, scales = list(arrows = FALSE, cex=0.9, col=black,font=3, tick.number=6, z=list(tick.number=10, tck = 0.8 ,distance =0.8),x=list(tck=0.8,distance=0.6),y=list(tck=0.7,distance=0.6)), zlim=seq(-14,4,by=2), zlab=list(label=Z, rot=90,cex=0.9), xlab=list(label=X, rot=15.5), ylab=list(label=Y, rot=-33), drape = T, at=seq(min(dat$z),max(dat$z),length=50), col.regions=rgb(colorRamp(c(white, red))(seq(0, 1, length = 50)), max = 255), colorkey = F, par.box=list(lwd=2), ## line width of box screen = list(z = 210, x = -75, y = 5), scpos=list(x=9,y=5,z=2) ## where axes are draw ) Thank you all very much for the help. It's fun to learn. John --- On Thu, 4/8/10, Felix Andrews fe...@nfrac.org wrote: From: Felix Andrews fe...@nfrac.org Subject: Re: [R] 3-D response surface using wireframe() To: David Winsemius dwinsem...@comcast.net Cc: array chip arrayprof...@yahoo.com, r-help@r-project.org Date: Thursday, April 8, 2010, 9:56 PM On 9 April 2010 11:18, David Winsemius dwinsem...@comcast.net wrote: On Apr 8, 2010, at 8:29 PM, array chip wrote: David, Thansk again! Sarkar's Lattice book is excellent source for lattice. Here is a link for all the figures and codes used in the book. You example is figure 13.7. http://lmdvr.r-forge.r-project.org/figures/figures.html I got the first point! For the second point below, Figure 13.7 an excellent example for projecting the 3D dataset onto the bounding surface, but it's not what I meant. I think I didn't explain what I wanted clearly. What I really wanted is a simple straight grid lines across the tick marks for 3 bounding surfaces of the box, not a projection of the 3D
Re: [R] perhaps regular expression bug with | sign ??
Try this: sub(x='|t|',pattern = '\\|t',replacement='zz') On Fri, Apr 9, 2010 at 5:35 PM, David.Epstein david.epst...@warwick.ac.uk wrote: Here is my interaction with R: sub(x='|t|',pattern = '|t',replacement='zz') [1] zz|t| So I say to myself Clearly the | signs need to be escaped, so let's try this sub(x='|t|',pattern = '\|t',replacement='zz') [1] zz|t| Warning messages: 1: '\|' is an unrecognized escape in a character string 2: unrecognized escape removed from \|t How can \| be an unrecognized escape? This flatly contradicts help('regex'), or am I misunderstanding the help? The first pattern above works if one uses extended=F. What do R experts think? David -- View this message in context: http://n4.nabble.com/perhaps-regular-expression-bug-with-sign-tp1819872p1819872.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] perhaps regular expression bug with | sign ??
David - Here's the last paragraph of the Details section of the regex help page: Patterns are described here as they would be printed by ‘cat’: (_do remember that backslashes need to be doubled when entering R character strings_, e.g. from the keyboard). You can get around this restriction using readline: pat = readline() \t pat [1] \\t cat(pat,'\n') \t It also should be remembered that R will add an extra backslash when it prints a single backslash -- as can be seen, this is avoided when you use cat(). - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Fri, 9 Apr 2010, David.Epstein wrote: Here is my interaction with R: sub(x='|t|',pattern = '|t',replacement='zz') [1] zz|t| So I say to myself Clearly the | signs need to be escaped, so let's try this sub(x='|t|',pattern = '\|t',replacement='zz') [1] zz|t| Warning messages: 1: '\|' is an unrecognized escape in a character string 2: unrecognized escape removed from \|t How can \| be an unrecognized escape? This flatly contradicts help('regex'), or am I misunderstanding the help? The first pattern above works if one uses extended=F. What do R experts think? David -- View this message in context: http://n4.nabble.com/perhaps-regular-expression-bug-with-sign-tp1819872p1819872.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] perhaps regular expression bug with | sign ??
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of David.Epstein Sent: Friday, April 09, 2010 1:36 PM To: r-help@r-project.org Subject: [R] perhaps regular expression bug with | sign ?? Here is my interaction with R: sub(x='|t|',pattern = '|t',replacement='zz') [1] zz|t| So I say to myself Clearly the | signs need to be escaped, so let's try this sub(x='|t|',pattern = '\|t',replacement='zz') [1] zz|t| Warning messages: 1: '\|' is an unrecognized escape in a character string 2: unrecognized escape removed from \|t How can \| be an unrecognized escape? This flatly contradicts help('regex'), It would be a bit clearer if the warnings indicated that they were from the R parser (the function that converts your text input to R expressions which are later evaluated). The parser is trying to say that it is treating \| as |. The backlash has special meaning in things like \n (newline), \t (tab), and \123 (character number in octal), but not before a vertical bar. Because the parser removed the backslash sub() never saw it. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com or am I misunderstanding the help? The first pattern above works if one uses extended=F. What do R experts think? David -- View this message in context: http://n4.nabble.com/perhaps-regular-expression-bug-with-sign- tp1819872p1819872.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] function rep
Hi, I've got the following code: p - 0.34 pb - p*100 pr - (1-p)*100 A - rep(0,pb) # a vector with 34 zeros B - rep(1,pr) # a vector with 66 ones Now if I type length(A), R answer correctly 34 but if I type length(B), R answer 65 instead of 66. I don't understand why it happens. Can anyone help me? Thanks in advance. Paolo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] function rep
Hello, Covelli Paolo wrote: Hi, I've got the following code: p - 0.34 pb - p*100 pr - (1-p)*100 A - rep(0,pb) # a vector with 34 zeros B - rep(1,pr) # a vector with 66 ones Not true. I counted them myself. There are only 65. I see pr == 66 [1] FALSE pr 66 [1] TRUE So pr must not be what you think it is. For the reason why, see FAQ 7.31. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] function rep
pr is a numeric number indeed slightly less than 66, hence, the vector generated by rep(1,pr) is of length 65 rather than 66... On Fri, Apr 9, 2010 at 1:58 PM, Covelli Paolo pcove...@tele2.it wrote: Hi, I've got the following code: p - 0.34 pb - p*100 pr - (1-p)*100 A - rep(0,pb) # a vector with 34 zeros B - rep(1,pr) # a vector with 66 ones Now if I type length(A), R answer correctly 34 but if I type length(B), R answer 65 instead of 66. I don't understand why it happens. Can anyone help me? Thanks in advance. Paolo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] function rep
See FAQ 7.31 Why doesn't R think these numbers are equal? and try this: rep(1, ceiling(pr)) On Fri, Apr 9, 2010 at 5:58 PM, Covelli Paolo pcove...@tele2.it wrote: Hi, I've got the following code: p - 0.34 pb - p*100 pr - (1-p)*100 A - rep(0,pb) # a vector with 34 zeros B - rep(1,pr) # a vector with 66 ones Now if I type length(A), R answer correctly 34 but if I type length(B), R answer 65 instead of 66. I don't understand why it happens. Can anyone help me? Thanks in advance. Paolo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.