Re: [R] R Square Help (this debate again, i know!)
surreyj wrote: Now all the other demand literature reports the %/proportion of variance accounted for (or R squared) as well as the parameter values and standard error. ... I had a chat to a supervisor and he suggested I post to here and see if someone can give me a reference/references backing up why I shouldn't use r-squared. .. For references to the printed literature , see http://markmail.org/message/qoup5oerbxchejmy I sympathize with the point you mention in a more general context. There many against-all-reviewers wisdoms in this community -- F-test in ANOVA (early years) -- Exegesis/Venables -- Nesting (most helpful sentence by D Bates: I never understood this) -- p-values (most lately brought up by lmer's refusal to produce these) -- r-squared for nonlinear that will prevail in the long run, but we (oldies) make students or colleagues in applied fields suffer by not producing these. It is easy for FoxBatsRipley to tell statistical reviewers that they are wrong, but what about surreyi's master thesis against the sheer mass of papers with nonlinear R^2 and more-p-better-paper reviewers? Or Frank Harrell against a Mayo Clinics Medical professor? (Sorry, Frank, I made up the example) Surprisingly, it's mostly the not-so-top papers that cause problems here. When Lancet, New English or BMJ reject some statistical argument, they have good reasons. Dieter -- View this message in context: http://r.789695.n4.nabble.com/R-Square-Help-this-debate-again-i-know-tp3316844p3316931.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] NPMC - replacement has 0 rows (multiple comparisons)
Hi folks, sorry if this has been answered before, I searched long and hard before deciding to make a thread. I'm trying to include multiple variables in a non-parametric analysis (hah!). So far what I've managed to figure out is that the NPMC package from CRAN MIGHT be able to do what I need, but I can't get it to. First I created a dataset as NPMC calls for. Ind=Individual| - predictor D=Day | - predictor S=Sex | - predictor hand = handlingtotal | - response occy.df-data.frame(hand,Ind,D,S) Then I checked the classes of each variable (factor, integer, factor, numeric from top to bottom). Ok, go! npmc(occy.ds) But alas, I get this error: Error in `$-.data.frame`(`*tmp*`, class, value = integer(0)) : replacement has 0 rows, data has 48 I thought maybe this was a problem to do with Day being an integer (seeing as it mentions integer in the error message), but no dice. Can any R-guru's out there please share their wisdom and apply some magic to solving this problem? The world of non-parametric analysis is somewhere I didn't willingly blunder into, but now that I'm here I'm in over my head, and any help you can throw my way would be super super appreciated. Kind regards, Dean. -- View this message in context: http://r.789695.n4.nabble.com/NPMC-replacement-has-0-rows-multiple-comparisons-tp3316788p3316788.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] Interpreting the example given by Prof Frank Harrell in {Design} validate.cph
Dear R-help, I am having a problem with the interpretation of result from validate.cph in the Design package. My purpose is to fit a cox model and validate the Somer's Dxy. I used the hypothetical data given in the help manual with modification to the cox model fit. My research problem is very similar to this example. This is the model without stratification: library(Design) f1 - cph(S ~ age, x=TRUE, y=TRUE) coef(f) age 0.0440095 set.seed(1) validate(f1, B=10, dxy=T) index.orig training test optimism index.corrected n Dxy -0.3376784858 -0.3287537760 -0.3376784858 0.0089247099 -0.34660320 10 R2 0.0627722521 0.0636136044 0.0627722521 0.0008413523 0.06193090 10 Slope 1.00 1.00 0.9896987441 0.0103012559 0.98969874 10 D 0.0237993965 0.0239476118 0.0237993965 0.0001482153 0.02365118 10 U -0.0008208378 -0.0008141441 0.0007104737 -0.0015246178 0.00070378 10 Q 0.0246202342 0.0247617559 0.0230889228 0.0016728331 0.02294740 10 But if I fit a stratified cox model to the same data, the result becomes: f2- cph(S ~ age + strat(sex), x=TRUE, y=TRUE, surv=TRUE, time.inc=2) coef(f) age 0.04271953 set.seed(1) validate(f2, dxy=TRUE, u=2, B=10) index.orig training test optimism index.corrected n Dxy0.3514778665 0.3259011492 0.3044982080 0.02140294120.3300749254 10 R2 0.0622369082 0.0651967502 0.0622369082 0.00295984190.0592770663 10 Slope 1.00 1.00 0.9621830568 0.03781694320.9621830568 10 D 0.0257519780 0.0267239073 0.0257519780 0.00097192930.0247800486 10 U -0.0009257142 -0.0009125388 0.0009102968 -0.00182283560.0008971213 10 Q 0.0266776922 0.0276364461 0.0248416812 0.00279476490.0238829273 10 The coefficients are similar between the models, so I expect the results would be somewhat similar, yet the two models give totally contrasting Dxy. I reckon a negative Dxy value is normal in the sense that the survival time and the prediction are concordant, but why does the result become discordant when stratification is used? Is there something wrong or is there a sensible interpretation for this? This problem is very critical to me because the Design package is the only one I can use for my purpose. Any advice is greatly appreciated. Best regards, Vikki -- View this message in context: http://r.789695.n4.nabble.com/Interpreting-the-example-given-by-Prof-Frank-Harrell-in-Design-validate-cph-tp3316820p3316820.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] Bootstraps standard error
Thanks for the answer. The R code is here: library(bivpois) data(ex3.health) # Bivariate Poisson models ex3.model.a - lm.bp(doctorco~sex+age+income, prescrib~sex+age+income, data=ex3.health) Bootstrap standard errors can be obtained easily using the following script for model (a): n - length(ex3.health$doctorco) bootdata-ex3.health bootrep - 200 results - matrix(NA,bootrep,10) for (i in 1:bootrep) { bootx1 - rpois(n,ex3.model.a$lambda1) bootx2 - rpois(n,ex3.model.a$lambda2) bootx3 - rpois(n,ex3.model.a$lambda3) bootdata$doctorco - bootx1+bootx3 bootdata$prescrib - bootx2+bootx3 # Model (a) testtemp - lm.bp(doctorco~sex+age+income, prescrib~sex+age+income, data=bootdata) betafound - c(testtemp$beta,testtemp$beta3) results[i,] - betafound } This is for my thesis. I'm trying to find the standard errors with the bootstrap method but I've never done in my life and so I've asked in this forum. If you install the package bivpois that is in the archive of CRAN-R and if you try this code, the result matrix is like that I had posted above. And I don't understand the phrase: At the end matrix results contains the bootstrap values of the parameters and thus bootstrap standard errors can be obtained merely by calculating the standard errors of the columns. that is in pdf file because the columns of that end matrix results contains every equal columns. I hope you can help me... Thanks a lot -- View this message in context: http://r.789695.n4.nabble.com/Bootstraps-standard-error-tp3313322p3316849.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] Regarding Soft Independent Modeling Computational Analysis
Hi I'm a B.E student pursuing my Project in the CEERI unit of the Council of Scientific and Industrial Research, Chennai, TN, India. I'm working on R -Language for my project. I'm in need of the functionality of SIMCA for the project. Is there any in-built function for SIMCA in R? Or are there people working on it? It would be a great help if you let us know as soon as possible. Regards Reynolds __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] multiple plots using a loop
Dear R users, I am trying to write myself a loop in order to produce a set of 20 length frequency plots each pertaining to a factor level. I would like each of these plots to be available on the same figure, so I have used par(mfrow = c(4, 5)). However, when I run my loop below, it produces 20 plots for each factor level and only displays the last factor levels LF plots. I'm fairly new to loops in R, so any help would be greatly appreciated. I have provided an example data set below if required with just 4 factors and adjusted par settings accordingly. Factor - rep(factor(letters[1:4]), each = 10) Size - runif(40) * 100 par(mfrow = c(2, 2)) for (i in Factor) { LFchart - hist(Size[Factor == i], main = i, xlab = c(n =,length(Size[Factor == i])), ylab = ) } P.S. Also just a quick annoying question. My xlab displays: n = 120 I would like it to display: n = 120 but just cant get it to work. Any thoughts. Regar __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R Square Help (this debate again, i know!)
Hello everyone, I have been using R to do some behavioural economic analysis for my masters thesis, specifically fitting demand curves using nls. E.g. Formula: y ~ c + b * x - a * exp(x) Parameters: Estimate Std. Error t value Pr(|t|) c -0.445097 0.080823 -5.507 0.005304 ** b -0.777105 0.059528 -13.054 0.000199 *** a 0.011908 0.003886 3.064 0.037495 * --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Residual standard error: 0.1046 on 4 degrees of freedom Number of iterations to convergence: 1 Achieved convergence tolerance: 1.119e-06 (1 observation deleted due to missingness) Now all the other demand literature reports the %/proportion of variance accounted for (or R squared) as well as the parameter values and standard error. From reading these forums I can see that R squared isn't a feature in NLS with reasoning backing this up. I had a chat to a supervisor and he suggested I post to here and see if someone can give me a reference/references backing up why I shouldn't use r-squared. However he also said that it is used throughout all of the other demand literature and it would appear odd to not have it in my thesis. My second supervisor agrees it needs to be included in the analysis. Can someone please advise me how to do this in R? I suppose I could always use excel or something but I would rather make use of the code I already have and get it looping through quickly. (The R-squared is the last thing that is holding me up for finishing my results section). Any advice would be greatly appreciated. Regards Surrey :) -- View this message in context: http://r.789695.n4.nabble.com/R-Square-Help-this-debate-again-i-know-tp3316844p3316844.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] (no subject)
What is plot.new? How can I fix this data or add plot.new so it works? library(maps) library(splancs) area = 6*4 lambda = 1.5 N = rpois(1,lambda*area) u = runif(N,-2,4) v = runif(N,0,4) plot(u,v,asp=1) h = chull(u,v) h = c(h,h[1]) plot(u[h],v[h],1,asp=1) Error in plot.xy(xy, type, ...) : invalid plot type '1' plot(u[h],v[h],l,asp=1) points(u,v) Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet pts=as.points(u,v) pointmap(pts) hullpoly=as.points(u[h],v[h]) polymap(hullpolly,add=TRUE) Error in xy.coords(x, y) : object 'hullpolly' not found help(polymap) help(plot.net) No documentation for 'plot.net' in specified packages and libraries: you could try '??plot.net' help(plot.new) plot(u[h],v[h],l,asp=1) plot.new(u,v) Error in plot.new(u, v) : unused argument(s) (u, v) plot.new() points(u,v) Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet plot.new(u,v) Error in plot.new(u, v) : unused argument(s) (u, v) plot.new(xy.coords(x,y)) Error in plot.new(xy.coords(x, y)) : unused argument(s) (xy.coords(x, y)) plot.new(uv.coords(u,v)) Error in plot.new(uv.coords(u, v)) : unused argument(s) (uv.coords(u, v)) plot.new - function() + {} { } NULL plot.new - function() + { } { } NULL { for } Error: unexpected '}' in { for } area = 60*20 lambda = 2 N = rpois(1,lambda*area) u = runif(N,20,40) v = runif(N,-10,10) plot(u,v,asp=1) plot(u,v,asp=1) u = runif(N,20,40) v = runif(N,-10,10) plot(u,v,asp=1) plot(u,v,asp=1) u = runif(N,20,40) v = runif(N,-10,10) plot(u,v,asp=1) u = runif(N,20,40) v = runif(N,-10,10) plot(u,v,asp=1) h = chull(u,v) h = c(h,h[1]) plot(u[h],v[h],l,asp=1) points(u,v) Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet pts=as.points(u,v) pointmap(pts) hullpoly=as.points(u[h],v[h]) polymap(hullpolly,add=TRUE) Error in xy.coords(x, y) : object 'hullpolly' not found No help files found matching hullpoly using fuzzy matching pointmap(as.points(hullpoly), add=TRUE) Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet hullpoly=as.points(u[h],v[h]) polymap(hullpoly$poly, add=TRUE) Error in hullpoly$poly : $ operator is invalid for atomic vectors polymap(hullpoly,add=TRUE) Error in polygon(poly, ...) : plot.new has not been called yet plot.new() NULL par(new=TRUE) Warning message: In par(new = TRUE) : calling par(new=TRUE) with no plot plot.new() NULL par(new=TRUE) Warning message: In par(new = TRUE) : calling par(new=TRUE) with no plot new.u=runif(50,20,40) new.v=ruinf(50,-10,10) Error: could not find function ruinf new.v=runif(50,-10,10) pts.in=pip(as.points(new.u,new.v),hullpoly,out=FALSE) pointmap(pts.in,col=red,add=TRUE) Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet [[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 calculate standard error for the predicted value from geeglm?
Dear Sue, I am also having problems with this. As far as I can gather the predict function will work with geeglm to give you predicted values from the model but it does not produce the standard errors automatically. I have posted a similar question and have had no answers. However, I know that there must be a way to do this?! Did you manage to find the answer? Or can anybody else help? Thanks Anna -- View this message in context: http://r.789695.n4.nabble.com/how-to-calculate-standard-error-for-the-predicted-value-from-geeglm-tp3064560p3317037.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] (no subject)
Hi! 21.02.2011 08:50, Schmidt, Lindsey C (MU-Student) wrote: What is plot.new? How can I fix this data or add plot.new so it works? ?plot.new ?plot plot(u[h],v[h],type=l,asp=1) seems to work for me... HTH, Kimmo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Segfaults of eigen
Hi, with small matrices eigen works as expected: eigen(cbind(c(1,4),c(4,7)), only.values = TRUE) $values [1] 9 -1 $vectors NULL eigen(cbind(c(1,4),c(4,7))) $values [1] 9 -1 $vectors [,1] [,2] [1,] 0.4472136 -0.8944272 [2,] 0.8944272 0.4472136 eigen(cbind(c(1,-1),c(1,-1))) $values [1] -3.25177e-17+1.570092e-16i -3.25177e-17-1.570092e-16i $vectors [,1] [,2] [1,] 0.7071068+0i 0.7071068+0i [2,] -0.7071068+0i -0.7071068-0i With large(?) matrices eigen produces on several of my systems segfaults: data(iris) D - dist(iris[,-5]) str(D) Class 'dist' atomic [1:11175] 0.539 0.51 0.648 0.141 0.616 ... ..- attr(*, Size)= int 150 ..- attr(*, Diag)= logi FALSE ..- attr(*, Upper)= logi FALSE ..- attr(*, method)= chr euclidean ..- attr(*, call)= language dist(x = iris[, -5]) eigen(D) *** caught segfault *** address (nil), cause 'unknown' Traceback: 1: .Call(La_rs, x, only.values, PACKAGE = base) 2: eigen(D) All systems are Gentoo systems, i.e. R-2.12.1 and blas-atlas-3.9.23-r4 is installed by compiling the sources. Recompiling R and blas-atlas did not solve the issue. This issue seems the reason that example(svm) creates segfaults, too. Any hint is appreciated. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Console output
Hi there, I though there has been a possibility to force the output on the console with one element per line. Instead of this: 1:10 [1] 1 2 3 4 5 6 7 8 9 10 something like this 1:10 [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 [6] 6 [7] 7 [8] 8 [9] 9 [10] 10 Can anybody help? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Segfaults of eigen
Am Montag, den 21.02.2011, 11:11 +0100 schrieb Juergen Rose: Hi, with small matrices eigen works as expected: eigen(cbind(c(1,4),c(4,7)), only.values = TRUE) $values [1] 9 -1 $vectors NULL eigen(cbind(c(1,4),c(4,7))) $values [1] 9 -1 $vectors [,1] [,2] [1,] 0.4472136 -0.8944272 [2,] 0.8944272 0.4472136 eigen(cbind(c(1,-1),c(1,-1))) $values [1] -3.25177e-17+1.570092e-16i -3.25177e-17-1.570092e-16i $vectors [,1] [,2] [1,] 0.7071068+0i 0.7071068+0i [2,] -0.7071068+0i -0.7071068-0i With large(?) matrices eigen produces on several of my systems segfaults: data(iris) D - dist(iris[,-5]) str(D) Class 'dist' atomic [1:11175] 0.539 0.51 0.648 0.141 0.616 ... ..- attr(*, Size)= int 150 ..- attr(*, Diag)= logi FALSE ..- attr(*, Upper)= logi FALSE ..- attr(*, method)= chr euclidean ..- attr(*, call)= language dist(x = iris[, -5]) eigen(D) *** caught segfault *** address (nil), cause 'unknown' Traceback: 1: .Call(La_rs, x, only.values, PACKAGE = base) 2: eigen(D) All systems are Gentoo systems, i.e. R-2.12.1 and blas-atlas-3.9.23-r4 is installed by compiling the sources. Recompiling R and blas-atlas did not solve the issue. This issue seems the reason that example(svm) creates segfaults, too. Any hint is appreciated. Still some additional information: root@moose:/root(5)# R R version 2.12.1 (2010-12-16) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. sessionInfo() R version 2.12.1 (2010-12-16) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] C attached base packages: [1] stats graphics grDevices utils datasets methods base __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Regarding Soft Independent Modeling Computational Analysis
Hi: If by SIMCA you mean 'Soft Independent Modeling of Class Analogy', a search with package sos indicated that a few functions in the plsRglm package have some support for it. HTH, Dennis On Sun, Feb 20, 2011 at 9:15 PM, reynolds pravindev reynoldspravin...@gmail.com wrote: Hi I'm a B.E student pursuing my Project in the CEERI unit of the Council of Scientific and Industrial Research, Chennai, TN, India. I'm working on R -Language for my project. I'm in need of the functionality of SIMCA for the project. Is there any in-built function for SIMCA in R? Or are there people working on it? It would be a great help if you let us know as soon as possible. Regards Reynolds __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Segfaults of eigen
Juergen Rose wrote: eigen(D) *** caught segfault *** address (nil), cause 'unknown' Traceback: 1: .Call(La_rs, x, only.values, PACKAGE = base) 2: eigen(D) All systems are Gentoo systems, i.e. R-2.12.1 and blas-atlas-3.9.23-r4 is installed by compiling the sources. Recompiling R and blas-atlas did not solve the issue. This issue seems the reason that example(svm) creates segfaults, too. FWIW, this does *not* crash R on my system, running 2.12.2 RC with GotoBLAS2. -- Karl Ove Hufthammer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Console output
I am not aware of one, bu I don`t know that much. You an change the vector to a data.frame but it could introduce complications.:) Example: === vec - 1:10 df1 - data.frame(vec) df1 === --- On Mon, 2/21/11, Antje Niederlein niederlein-rs...@yahoo.de wrote: From: Antje Niederlein niederlein-rs...@yahoo.de Subject: [R] Console output To: r-help@r-project.org Received: Monday, February 21, 2011, 5:21 AM Hi there, I though there has been a possibility to force the output on the console with one element per line. Instead of this: 1:10 [1] 1 2 3 4 5 6 7 8 9 10 something like this 1:10 [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 [6] 6 [7] 7 [8] 8 [9] 9 [10] 10 Can anybody help? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Console output
Hi, You may try invisible(sapply(1:10, print)) Yves Le 21/02/2011 11:21, Antje Niederlein a écrit : Hi there, I though there has been a possibility to force the output on the console with one element per line. Instead of this: 1:10 [1] 1 2 3 4 5 6 7 8 9 10 something like this 1:10 [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 [6] 6 [7] 7 [8] 8 [9] 9 [10] 10 Can anybody help? Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Console output
That doesn't produce quite what Antje asked for (since each line gets number [1]). The following does work: print(cbind(NULL,(1:10))) [,1] [1,]1 [2,]2 [3,]3 [4,]4 [5,]5 [6,]6 [7,]7 [8,]8 [9,]9 [10,] 10 (apart from the unwanted column-name [,1], and the , in rows). Ted. On 21-Feb-11 10:30:37, Yves REECHT wrote: Hi, You may try invisible(sapply(1:10, print)) Yves Le 21/02/2011 11:21, Antje Niederlein a écrit : Hi there, I though there has been a possibility to force the output on the console with one element per line. Instead of this: 1:10 [1] 1 2 3 4 5 6 7 8 9 10 something like this 1:10 [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 [6] 6 [7] 7 [8] 8 [9] 9 [10] 10 Can anybody help? Antje E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 21-Feb-11 Time: 11:08:17 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Subset according to groups NA proportion within specific variables
Dear R-List, I have a dataframe with one grouping variable (x) and three response variables (y,z,w). df-data.frame(x=c(rep(1,3),rep(2,4),rep(3,5)),y=rnorm(12),z=c(3,4,5,NA,NA,NA,NA,1,2,1,2,1),w=c(1,2,3,3,4,3,5,NA,5,NA,7,8)) df x y z w 1 0.29306106 3 1 1 0.54797780 4 2 1 -1.38365548 5 3 2 -0.20407986 NA 3 2 -0.87322574 NA 4 2 -1.23356250 NA 3 2 0.43929374 NA 5 3 1.16405483 1 NA 3 1.07083464 2 5 3 -0.67463191 1 NA 3 -0.66410552 2 7 3 -0.02543358 1 8 Now I want to make a new dataframe df.sub comprising only cases pertaining to groups, where the overall proportion of NAs in either of the response variables y,z,w does not exceed 50%. In the above example, e.g., this would be a dataframe with all cases of the groups 1 and 3 (since there are 100% NAs in z for group 2) df.sub x y z w 1 0.29306106 3 1 1 0.54797780 4 2 1 -1.38365548 5 3 3 1.16405483 1 NA 3 1.07083464 2 5 3 -0.67463191 1 NA 3 -0.66410552 2 7 3 -0.02543358 1 8 Please excuse me if the problem has already been treated somewhere, but so far I was not able to find the right threat for my question in RSeek. Can anyone help? Thanks in advance! D. Alain [[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] Segfaults of eigen
So there is very likely a bug in your system software or compiler. There is no such problem on other x86_64 systems (including Fedora 14 and 12, FreeBSD, Solaris and Windows). You can debug segfaults for yourself (see 'Writing R Extensions') or ask your vendor for support. On Mon, 21 Feb 2011, Juergen Rose wrote: Am Montag, den 21.02.2011, 11:11 +0100 schrieb Juergen Rose: Hi, with small matrices eigen works as expected: eigen(cbind(c(1,4),c(4,7)), only.values = TRUE) $values [1] 9 -1 $vectors NULL eigen(cbind(c(1,4),c(4,7))) $values [1] 9 -1 $vectors [,1] [,2] [1,] 0.4472136 -0.8944272 [2,] 0.8944272 0.4472136 eigen(cbind(c(1,-1),c(1,-1))) $values [1] -3.25177e-17+1.570092e-16i -3.25177e-17-1.570092e-16i $vectors [,1] [,2] [1,] 0.7071068+0i 0.7071068+0i [2,] -0.7071068+0i -0.7071068-0i With large(?) matrices eigen produces on several of my systems segfaults: data(iris) D - dist(iris[,-5]) str(D) Class 'dist' atomic [1:11175] 0.539 0.51 0.648 0.141 0.616 ... ..- attr(*, Size)= int 150 ..- attr(*, Diag)= logi FALSE ..- attr(*, Upper)= logi FALSE ..- attr(*, method)= chr euclidean ..- attr(*, call)= language dist(x = iris[, -5]) eigen(D) *** caught segfault *** address (nil), cause 'unknown' Traceback: 1: .Call(La_rs, x, only.values, PACKAGE = base) 2: eigen(D) All systems are Gentoo systems, i.e. R-2.12.1 and blas-atlas-3.9.23-r4 is installed by compiling the sources. Recompiling R and blas-atlas did not solve the issue. This issue seems the reason that example(svm) creates segfaults, too. Any hint is appreciated. Still some additional information: root@moose:/root(5)# R R version 2.12.1 (2010-12-16) Copyright (C) 2010 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: x86_64-pc-linux-gnu (64-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. sessionInfo() R version 2.12.1 (2010-12-16) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] C attached base packages: [1] stats graphics grDevices utils datasets methods base __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] multiple plots using a loop
Hi: Here's one way with the plyr package and function d_ply(); the hist() function itself is not very elegant, but it 'works' for this example. Factor - rep(factor(letters[1:4]), each = 10) Size - runif(40) * 100 library(plyr) par(mfrow = c(2, 2)) d - data.frame(Factor, Size) # Function to produce a histogram for a generic (subset of a) data frame f - function(df) { hist(df$Size, main = df$Factor[1], xlab = paste('n =', nrow(df)), ylab = '') } d_ply(d, 'Factor', f) d2 - data.frame(Factor = rep(LETTERS[1:4], c(10, 20, 30, 40)), Size = runif(100, 0, 100)) d_ply(d2, 'Factor', f) # Another way, using a loop with data frame d2 above: par(mfrow = c(2, 2)) for(i in seq_along(levels(d2$Factor))) { val - levels(d2$Factor)[i] df - subset(d2, Factor == val) hist(unlist(df['Size']), main = val, xlab = paste('n =', nrow(df)), ylab = '') } par(mfrow = c(1, 1)) The advantage of the plyr method is that you can change the data frame, and as long as it has the same variable names with the same classes, it should work. Except for the sample sizes as x-axis labels, this could be easily done in lattice in one line: library(lattice) histogram(~ Size | Factor)# if using the original vectors histogram(~ Size | Factor, data = d2) # if using a data frame instead # change the panel ordering and use counts instead of percents histogram(~ Size | Factor, data = d2, as.table = TRUE, type = 'count') I'll give someone else the opportunity to show how to get the sample sizes as x-labels in each panel; I'm not that good at writing panel functions in lattice. HTH, Dennis On Mon, Feb 21, 2011 at 1:25 AM, Darcy Webber darcy.web...@gmail.comwrote: Dear R users, I am trying to write myself a loop in order to produce a set of 20 length frequency plots each pertaining to a factor level. I would like each of these plots to be available on the same figure, so I have used par(mfrow = c(4, 5)). However, when I run my loop below, it produces 20 plots for each factor level and only displays the last factor levels LF plots. I'm fairly new to loops in R, so any help would be greatly appreciated. I have provided an example data set below if required with just 4 factors and adjusted par settings accordingly. Factor - rep(factor(letters[1:4]), each = 10) Size - runif(40) * 100 par(mfrow = c(2, 2)) for (i in Factor) { LFchart - hist(Size[Factor == i], main = i, xlab = c(n =,length(Size[Factor == i])), ylab = ) } P.S. Also just a quick annoying question. My xlab displays: n = 120 I would like it to display: n = 120 but just cant get it to work. Any thoughts. Regar __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] how to calculate standard error for the predicted value from geeglm?
On 21.02.2011 10:23, AB29 wrote: Dear Sue, I am also having problems with this. As far as I can gather the predict function will work with geeglm to give you predicted values from the model but it does not produce the standard errors automatically. I have posted a similar question and have had no answers. However, I know that there must be a way to do this?! Did you manage to find the answer? Or can anybody else help? Thanks Anna Please note this is a mailing list in the first place and readers of the list really do not know what you are referring to. If you want to contact Sue, please do so and don't write to the lsut. Thanks, Uwe Ligges __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Generating uniformly distributed correlated data.
hw-function(r){ (3-sqrt(1+8*r))/4 } x-runif(1000) y-(x+runif(1000,-hw(0.5),hw(0.5))) %% 1 x and y will have correlation 0.5 and will be uniformly distributed on the unit interval. Replacing 0.5 by any nonnegative number r between 0 and 1 will create correlated uniformly distributed random numbers with correlation r. plot(x,y) will show the construction of the joint distribution of these random numbers. The rest is simple algebra. On 2/20/2011 3:17 AM, Søren Faurby wrote: I wish to generate a vector of uniformly distributed data with a defined correlation to another vector The only function I have been able to find doing something similar is corgen from the library ecodist. The following code generates data with the desired correlation to the vector x but the resulting vector y is normal and not uniform distributed library(ecodist) x - runif(10^5) y - corgen(x=x, r=.5)$y Do anyone know a similar function generating uniform distributed data or a way of transforming y to the desired distribution while keeping the correlation between x and y Kind regards, Soren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Help Metafor
Dear Mario, If you could tell me how to define and interpret I^2 and H^2 for models with moderators, I may consider implementing these measures for such models. However, I am not aware of any work that has extended these measures to meta-regression models. Best, -- Wolfgang Viechtbauer Department of Psychiatry and Neuropsychology School for Mental Health and Neuroscience Maastricht University, P.O. Box 616 6200 MD Maastricht, The Netherlands Tel: +31 (43) 368-5248 Fax: +31 (43) 368-8689 Web: http://www.wvbauer.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of petre...@unina.it Sent: Sunday, February 20, 2011 13:59 To: r-help@r-project.org Subject: [R] Help Metafor Dear Sir, I'm using the Metafor package; however, introducing moderators, I'm unable to obtain both I^2 (% of total variability due to heterogeneity) and H^2 (total variability / within-study variance). It is possible to obtain I^2 and H^2 also with moderators? As example _Dataset - sqlQuery(channel = 1, select * from [Foglio1$]) names(Dataset) - make.names(names(Dataset)) alloc.a - ifelse(dat$alloc == a, 1, 0) alloc.b - ifelse(dat$alloc == b, 1, 0) alloc.c - ifelse(dat$alloc == c, 1, 0) res-rma.uni(yi, vi, mods=cbind(alloc.a, alloc.b, Year), measure=GEN, intercept=TRUE, data=dat, slab=Author, subset, add=1/2, to=only0, vtype=LS, method=REML, weighted=TRUE, knha=FALSE, btt=c(2,3)) print (res) Mixed-Effects Model (k = 22; tau^2 estimator: REML) tau^2 (estimate of residual amount of heterogeneity): 0.7810 (SE = 0.2924) tau (sqrt of the estimate of residual heterogeneity): 0.8838 Test for Residual Heterogeneity: QE(df = 18) = 223.3159, p-val .0001 Test of Moderators (coefficient(s) 2,3): QM(df = 2) = 0.8251, p-val = 0.6620 Model Results: estimate se zval pval ci.lb ci.ub intrcpt -135.3524 54.4487 -2.4859 0.0129 -242.0700 -28.6349 * alloc.a -0.3836 0.4529 -0.8469 0.3971 -1.2713 0.5042 alloc.b -0.3656 0.5529 -0.6613 0.5084 -1.4493 0.7180 Year 0.0673 0.0273 2.4677 0.0136 0.0139 0.1208 * Many thanks _ Mario Petretta Dipartimento di Medicina Clinica Scienze Cardiovascolari e Immunologiche Facoltà di Medicina e Chirurgia Università di Napoli Federico II 081 - 7462233 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Subset according to groups NA proportion within specific variables
D. Alain wrote: Now I want to make a new dataframe df.sub comprising only cases pertaining to groups, where the overall proportion of NAs in either of the response variables y,z,w does not exceed 50%. One simple example: library(plyr) na.prop = function(x) data.frame(x, missing=nrow(na.omit(x))/nrow(x) ) newdf = ddply(df, .(x), na.prop) Now you can use ‘subset’ on ‘newdf’ to obtain the required rows. (For very large data sets it may be better to not create an entire data frame in ‘na.prop’, duplicating the data in ’df’, but instead just return the proportion.) -- Karl Ove Hufthammer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Console output
Ted Harding ted.hard...@wlandres.net on Mon, 21 Feb 2011 11:08:19 - (GMT) writes: That doesn't produce quite what Antje asked for (since each line gets number [1]). The following does work: print(cbind(NULL,(1:10))) [,1] [1,]1 [2,]2 [3,]3 [4,]4 [5,]5 [6,]6 [7,]7 [8,]8 [9,]9 [10,] 10 (apart from the unwanted column-name [,1], and the , in rows). In principle, there would be a true solution, but as you see, it's not quite possibly (by that means): op - options(width=7) Error in options(width = 7) : invalid 'width' parameter, allowed 10...1 op - options(width=10) 1:10 [1] 1 2 [3] 3 4 [5] 5 6 [7] 7 8 [9] 9 10 1000+ 0:9 ## works for these [1] 1000 [2] 1001 [3] 1002 [4] 1003 [5] 1004 [6] 1005 [7] 1006 [8] 1007 [9] 1008 [10] 1009 --- In principle, the lower bound (10) for the width option could be lowered a bit more, as I think 10 had been a somewhat arbitrary choice protecting useRs from hanging themselves.. Martin Ted. On 21-Feb-11 10:30:37, Yves REECHT wrote: Hi, You may try invisible(sapply(1:10, print)) Yves Le 21/02/2011 11:21, Antje Niederlein a écrit : Hi there, I though there has been a possibility to force the output on the console with one element per line. Instead of this: 1:10 [1] 1 2 3 4 5 6 7 8 9 10 something like this 1:10 [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 [6] 6 [7] 7 [8] 8 [9] 9 [10] 10 Can anybody help? Antje E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 21-Feb-11 Time: 11:08:17 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Subset according to groups NA proportion within specific variables
Hi: Here's one way with package plyr: df-data.frame(x=c(rep(1,3),rep(2,4),rep(3,5)), y=rnorm(12), z=c(3,4,5,NA,NA,NA,NA,1,2,1,2,1), w=c(1,2,3,3,4,3,5,NA,5,NA,7,8)) library(plyr) fun - function(d) { u - apply(d[, -1], 2, function(y) sum(is.na(y)))/nrow(d) if(all(u = 0.5)) return(d) } ddply(df, 'x', fun) ddply(df, 'x', fun) x y z w 1 1 -1.22768415 3 1 2 1 0.03108696 4 2 3 1 0.90246871 5 3 4 3 -0.47387908 1 NA 5 3 1.59577665 2 5 6 3 -0.80792438 1 NA 7 3 0.20927614 2 7 8 3 -0.46172477 1 8 On Mon, Feb 21, 2011 at 3:20 AM, D. Alain dialva...@yahoo.de wrote: Dear R-List, I have a dataframe with one grouping variable (x) and three response variables (y,z,w). df-data.frame(x=c(rep(1,3),rep(2,4),rep(3,5)),y=rnorm(12),z=c(3,4,5,NA,NA,NA,NA,1,2,1,2,1),w=c(1,2,3,3,4,3,5,NA,5,NA,7,8)) df xyz w 1 0.29306106 3 1 1 0.54797780 4 2 1 -1.38365548 5 3 2 -0.20407986 NA3 2 -0.87322574 NA4 2 -1.23356250 NA3 2 0.43929374 NA5 3 1.16405483 1NA 3 1.07083464 2 5 3 -0.67463191 1NA 3 -0.66410552 2 7 3 -0.02543358 1 8 Now I want to make a new dataframe df.sub comprising only cases pertaining to groups, where the overall proportion of NAs in either of the response variables y,z,w does not exceed 50%. In the above example, e.g., this would be a dataframe with all cases of the groups 1 and 3 (since there are 100% NAs in z for group 2) df.sub xyz w 1 0.29306106 3 1 1 0.54797780 4 2 1 -1.38365548 5 3 3 1.16405483 1NA 3 1.07083464 2 5 3 -0.67463191 1NA 3 -0.66410552 2 7 3 -0.02543358 1 8 Please excuse me if the problem has already been treated somewhere, but so far I was not able to find the right threat for my question in RSeek. Can anyone help? Thanks in advance! D. Alain [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] multiple plots using a loop
It is also a one-liner with ggplot2 dataset - data.frame(Factor = rep(factor(letters[1:4]), each = 10), Size = runif(40) * 100) library(ggplot2) ggplot(dataset, aes(x = Size)) + geom_histogram() + facet_wrap(~Factor) 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 Dennis Murphy Verzonden: maandag 21 februari 2011 12:45 Aan: Darcy Webber CC: r-help@r-project.org Onderwerp: Re: [R] multiple plots using a loop Hi: Here's one way with the plyr package and function d_ply(); the hist() function itself is not very elegant, but it 'works' for this example. Factor - rep(factor(letters[1:4]), each = 10) Size - runif(40) * 100 library(plyr) par(mfrow = c(2, 2)) d - data.frame(Factor, Size) # Function to produce a histogram for a generic (subset of a) data frame f - function(df) { hist(df$Size, main = df$Factor[1], xlab = paste('n =', nrow(df)), ylab = '') } d_ply(d, 'Factor', f) d2 - data.frame(Factor = rep(LETTERS[1:4], c(10, 20, 30, 40)), Size = runif(100, 0, 100)) d_ply(d2, 'Factor', f) # Another way, using a loop with data frame d2 above: par(mfrow = c(2, 2)) for(i in seq_along(levels(d2$Factor))) { val - levels(d2$Factor)[i] df - subset(d2, Factor == val) hist(unlist(df['Size']), main = val, xlab = paste('n =', nrow(df)), ylab = '') } par(mfrow = c(1, 1)) The advantage of the plyr method is that you can change the data frame, and as long as it has the same variable names with the same classes, it should work. Except for the sample sizes as x-axis labels, this could be easily done in lattice in one line: library(lattice) histogram(~ Size | Factor)# if using the original vectors histogram(~ Size | Factor, data = d2) # if using a data frame instead # change the panel ordering and use counts instead of percents histogram(~ Size | Factor, data = d2, as.table = TRUE, type = 'count') I'll give someone else the opportunity to show how to get the sample sizes as x-labels in each panel; I'm not that good at writing panel functions in lattice. HTH, Dennis On Mon, Feb 21, 2011 at 1:25 AM, Darcy Webber darcy.web...@gmail.comwrote: Dear R users, I am trying to write myself a loop in order to produce a set of 20 length frequency plots each pertaining to a factor level. I would like each of these plots to be available on the same figure, so I have used par(mfrow = c(4, 5)). However, when I run my loop below, it produces 20 plots for each factor level and only displays the last factor levels LF plots. I'm fairly new to loops in R, so any help would be greatly appreciated. I have provided an example data set below if required with just 4 factors and adjusted par settings accordingly. Factor - rep(factor(letters[1:4]), each = 10) Size - runif(40) * 100 par(mfrow = c(2, 2)) for (i in Factor) { LFchart - hist(Size[Factor == i], main = i, xlab = c(n =,length(Size[Factor == i])), ylab = ) } P.S. Also just a quick annoying question. My xlab displays: n = 120 I would like it to display: n = 120 but just cant get it to work. Any thoughts. Regar __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Console output
Thanks for every helpful answer :-) ! I thought it was something easier but as long as there is a solution it's fine for me. Ciao, Antje On 21 February 2011 13:12, Martin Maechler maech...@stat.math.ethz.ch wrote: Ted Harding ted.hard...@wlandres.net on Mon, 21 Feb 2011 11:08:19 - (GMT) writes: That doesn't produce quite what Antje asked for (since each line gets number [1]). The following does work: print(cbind(NULL,(1:10))) [,1] [1,] 1 [2,] 2 [3,] 3 [4,] 4 [5,] 5 [6,] 6 [7,] 7 [8,] 8 [9,] 9 [10,] 10 (apart from the unwanted column-name [,1], and the , in rows). In principle, there would be a true solution, but as you see, it's not quite possibly (by that means): op - options(width=7) Error in options(width = 7) : invalid 'width' parameter, allowed 10...1 op - options(width=10) 1:10 [1] 1 2 [3] 3 4 [5] 5 6 [7] 7 8 [9] 9 10 1000+ 0:9 ## works for these [1] 1000 [2] 1001 [3] 1002 [4] 1003 [5] 1004 [6] 1005 [7] 1006 [8] 1007 [9] 1008 [10] 1009 --- In principle, the lower bound (10) for the width option could be lowered a bit more, as I think 10 had been a somewhat arbitrary choice protecting useRs from hanging themselves.. Martin Ted. On 21-Feb-11 10:30:37, Yves REECHT wrote: Hi, You may try invisible(sapply(1:10, print)) Yves Le 21/02/2011 11:21, Antje Niederlein a écrit : Hi there, I though there has been a possibility to force the output on the console with one element per line. Instead of this: 1:10 [1] 1 2 3 4 5 6 7 8 9 10 something like this 1:10 [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 [6] 6 [7] 7 [8] 8 [9] 9 [10] 10 Can anybody help? Antje E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 21-Feb-11 Time: 11:08:17 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Subset according to groups NA proportion within specific variables
one way is the following: DF - data.frame(x = c(rep(1,3),rep(2,4),rep(3,5)), y = rnorm(12), z = c(3,4,5,NA,NA,NA,NA,1,2,1,2,1), w = c(1,2,3,3,4,3,5,NA,5,NA,7,8) ) na.ind - sapply(DF[-1], is.na) na.ind - ave(na.ind, rep(DF$x, 3), col(na.ind)) 0.5 DF[apply(na.ind, 1, all), ] I hope it helps. Best, Dimitris On 2/21/2011 12:20 PM, D. Alain wrote: Dear R-List, I have a dataframe with one grouping variable (x) and three response variables (y,z,w). df-data.frame(x=c(rep(1,3),rep(2,4),rep(3,5)),y=rnorm(12),z=c(3,4,5,NA,NA,NA,NA,1,2,1,2,1),w=c(1,2,3,3,4,3,5,NA,5,NA,7,8)) df xyz w 1 0.29306106 3 1 1 0.54797780 4 2 1 -1.38365548 5 3 2 -0.20407986 NA3 2 -0.87322574 NA4 2 -1.23356250 NA3 2 0.43929374 NA5 3 1.16405483 1NA 3 1.07083464 2 5 3 -0.67463191 1NA 3 -0.66410552 2 7 3 -0.02543358 1 8 Now I want to make a new dataframe df.sub comprising only cases pertaining to groups, where the overall proportion of NAs in either of the response variables y,z,w does not exceed 50%. In the above example, e.g., this would be a dataframe with all cases of the groups 1 and 3 (since there are 100% NAs in z for group 2) df.sub xyz w 1 0.29306106 3 1 1 0.54797780 4 2 1 -1.38365548 5 3 3 1.16405483 1NA 3 1.07083464 2 5 3 -0.67463191 1NA 3 -0.66410552 2 7 3 -0.02543358 1 8 Please excuse me if the problem has already been treated somewhere, but so far I was not able to find the right threat for my question in RSeek. Can anyone help? Thanks in advance! D. Alain [[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. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] multiple plots using a loop
On Mon, Feb 21, 2011 at 4:25 AM, Darcy Webber darcy.web...@gmail.com wrote: Dear R users, I am trying to write myself a loop in order to produce a set of 20 length frequency plots each pertaining to a factor level. I would like each of these plots to be available on the same figure, so I have used par(mfrow = c(4, 5)). However, when I run my loop below, it produces 20 plots for each factor level and only displays the last factor levels LF plots. I'm fairly new to loops in R, so any help would be greatly appreciated. I have provided an example data set below if required with just 4 factors and adjusted par settings accordingly. Factor - rep(factor(letters[1:4]), each = 10) Size - runif(40) * 100 par(mfrow = c(2, 2)) for (i in Factor) { LFchart - hist(Size[Factor == i], main = i, xlab = c(n =,length(Size[Factor == i])), ylab = ) } P.S. Also just a quick annoying question. My xlab displays: n = 120 I would like it to display: n = 120 but just cant get it to work. Any thoughts. In the above example Factor has length 40 so the for loop produces 40 plots and you see the last 4. You really want to loop over the levels of Factor, not Factor itself: for(i in levels(Factor)) { ... } -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Interpreting the example given by Prof Frank Harrell in {Design} validate.cph
Vikky, You'll notice that the model containing sex in addition to age has a higher apparent Dxy as you would expect [R^2 is not higher because it captures only the age effect]. The validated Dxy's may be as they are because of the very low number of bootstrap resamples (10) that you used. Please following the posting guide, i.e., include a simple self-reproducing script that I can run - one that simulates its own dataset. Please switch to the rms package is this is the one that is being fully supported. See http://biostat.mc.vanderbilt.edu/Rrms. Frank - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/Interpreting-the-example-given-by-Prof-Frank-Harrell-in-Design-validate-cph-tp3316820p3317265.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] multiple plots using a loop
Hi Darcy This works for me: Factor - rep(factor(letters[1:4]), each = 10) Size - runif(40) * 100 par(mfrow = c(2, 2)) for (i in unique(Factor)) { hist(Size[Factor == i], main = i, xlab = paste(n =,length(Size[Factor == i])), ylab = ) } I think that using for (i in Factor) cycles through every occurrence of a level and so you only get four plots of the last level rather than a plot for every level. cheers iain --- On Mon, 21/2/11, Darcy Webber darcy.web...@gmail.com wrote: From: Darcy Webber darcy.web...@gmail.com Subject: [R] multiple plots using a loop To: r-help@r-project.org Date: Monday, 21 February, 2011, 9:25 Dear R users, I am trying to write myself a loop in order to produce a set of 20 length frequency plots each pertaining to a factor level. I would like each of these plots to be available on the same figure, so I have used par(mfrow = c(4, 5)). However, when I run my loop below, it produces 20 plots for each factor level and only displays the last factor levels LF plots. I'm fairly new to loops in R, so any help would be greatly appreciated. I have provided an example data set below if required with just 4 factors and adjusted par settings accordingly. Factor - rep(factor(letters[1:4]), each = 10) Size - runif(40) * 100 par(mfrow = c(2, 2)) for (i in Factor) { LFchart - hist(Size[Factor == i], main = i, xlab = c(n =,length(Size[Factor == i])), ylab = ) } P.S. Also just a quick annoying question. My xlab displays: n = 120 I would like it to display: n = 120 but just cant get it to work. Any thoughts. Regar __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Query: matrix definition
Dear list users, if within a function I first define a matrix mymat - matrix(NA, nrow=m, ncol=n) and somewhere afterwards by mistake mymat - c(1,2,3) this second command deletes the first one. How can I make sure that within the function mymat will always remain the matrix defined at the beginning, without possibility of changing it throughout the code? Secondly, is it possible to define mymat as a matrix of integers, with no possibility of loading real numbers? Thank you for your help Stefano Sofia AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario. IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Generating uniformly distributed correlated data.
Date: Mon, 21 Feb 2011 13:03:53 +0100 From: erich.neuwi...@univie.ac.at To: soren.fau...@biology.au.dk; r-help@r-project.org Subject: Re: [R] Generating uniformly distributed correlated data. hw-function(r){ (3-sqrt(1+8*r))/4 } x-runif(1000) y-(x+runif(1000,-hw(0.5),hw(0.5))) %% 1 x and y will have correlation 0.5 and will be uniformly distributed on the unit interval. Replacing 0.5 by any nonnegative number r between 0 and 1 will create correlated uniformly distributed random numbers with correlation r. plot(x,y) will show the construction of the joint distribution of these random numbers. The rest is simple algebra. Let me see if I can explain this since I puzzled over it for a whlie. To decorrelate x and y, the general strategy is to add noise. This of course makes the resulting distribtuion the convolution of the two source distro's, may not be simple algrebra to some :) To get back the uniform, you could consider things like warping the output values. This is rather clever, at least I hadn't seen it, as you are convolving a large rectangle with a smaller one. This is uniform already in most places except the ends where you can translate the out of range part back into place, exactly adding back the the uniform distribution. I guess it it still isn't obvious to me what the mod does to cor. Do you have an exact relation between your innovation amplitude and the resulting cor? I'd try it myself but can see i need more coffee first. It is probably easy to show by suitable calculation of E(x) and E(x^2) ? for ( a in (1:10)/10 ) { + yaa-(xaa+runif(10,-hw(a),hw(a))) %% 1 + print(a); print (cor(xaa,yaa)); + } [1] 0.1 [1] 0.09678492 [1] 0.2 [1] 0.201 [1] 0.3 [1] 0.3017615 [1] 0.4 [1] 0.3948470 [1] 0.5 [1] 0.4995593 [1] 0.6 [1] 0.6023712 [1] 0.7 [1] 0.7005193 [1] 0.8 [1] 0.8010425 [1] 0.9 [1] 0.8992287 [1] 1 [1] 1 On 2/20/2011 3:17 AM, Søren Faurby wrote: I wish to generate a vector of uniformly distributed data with a defined correlation to another vector The only function I have been able to find doing something similar is corgen from the library ecodist. The following code generates data with the desired correlation to the vector x but the resulting vector y is normal and not uniform distributed library(ecodist) x - runif(10^5) y - corgen(x=x, r=.5)$y Do anyone know a similar function generating uniform distributed data or a way of transforming y to the desired distribution while keeping the correlation between x and y Kind regards, Soren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Query: matrix definition
By careful programming practices you should be able to avoid the problem. There is no way to prevent it since the program is only doing what you ask it to do and if you make a mistake and ask it do to something, it is not the program's fault. One of the nice things ( bad things) about R is that you can redefine what the object is on the fly. On Mon, Feb 21, 2011 at 7:50 AM, Stefano Sofia stefano.so...@regione.marche.it wrote: Dear list users, if within a function I first define a matrix mymat - matrix(NA, nrow=m, ncol=n) and somewhere afterwards by mistake mymat - c(1,2,3) this second command deletes the first one. How can I make sure that within the function mymat will always remain the matrix defined at the beginning, without possibility of changing it throughout the code? Secondly, is it possible to define mymat as a matrix of integers, with no possibility of loading real numbers? Thank you for your help Stefano Sofia AVVISO IMPORTANTE: Questo messaggio di posta elettronica può contenere informazioni confidenziali, pertanto è destinato solo a persone autorizzate alla ricezione. I messaggi di posta elettronica per i client di Regione Marche possono contenere informazioni confidenziali e con privilegi legali. Se non si è il destinatario specificato, non leggere, copiare, inoltrare o archiviare questo messaggio. Se si è ricevuto questo messaggio per errore, inoltrarlo al mittente ed eliminarlo completamente dal sistema del proprio computer. Ai sensi dell’art. 6 della DGR n. 1394/2008 si segnala che, in caso di necessità ed urgenza, la risposta al presente messaggio di posta elettronica può essere visionata da persone estranee al destinatario. IMPORTANT NOTICE: This e-mail message is intended to be received only by persons entitled to receive the confidential information it may contain. E-mail messages to clients of Regione Marche may contain information that is confidential and legally privileged. Please do not read, copy, forward, or store this message unless you are an intended recipient of it. If you have received this message in error, please forward it to the sender and delete it completely from your computer system. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Segfaults of eigen with blas-atlas at x86_64-pc-linux-gnu systems
Am Montag, den 21.02.2011, 11:25 +0100 schrieb Karl Ove Hufthammer: Juergen Rose wrote: eigen(D) *** caught segfault *** address (nil), cause 'unknown' Traceback: 1: .Call(La_rs, x, only.values, PACKAGE = base) 2: eigen(D) All systems are Gentoo systems, i.e. R-2.12.1 and blas-atlas-3.9.23-r4 is installed by compiling the sources. Recompiling R and blas-atlas did not solve the issue. This issue seems the reason that example(svm) creates segfaults, too. FWIW, this does *not* crash R on my system, running 2.12.2 RC with GotoBLAS2. Thanks Karl and Brian, under gentoo I have the possibility to switch (by eselect) between some different blas versions, if there are installed. Usually I have blas-atlas and blas-reference installed. For blas-atlas it is still possible to switch between pure blas-atlas and blas-atlas-threads. I tried at some systems, which are now available for me, to reproduce these segfaults with eigen in R. I got the following. blas versioneigen(dist(iris[,-5])) inspiron (32-bit) blas-reference OK i686-pc-linux-gnu cheetah (32-bit)blas-atlas OK i686-pc-linux-gnu tiger (32-bit) blas-atlas OK i686-pc-linux-gnu moose (64-bit) blas-atlas-threads Segfault x86_64-pc-linux-gnu blas-atlas Segfault blas-reference OK orca (64-bit) blas-atlas-threads Segfault x86_64-pc-linux-gnu blas-atlas Segfault blas-reference OK R was everytime recompiled after switching to an other blas version. R is on every computer R-2.12.1, blas-atlas is blas-atlas-3.9.23-r4, blas-reference is blas-reference-20070226-r2. It would be rather interesting for me, if anybody with similar blas-atlas version is able to run eigen(dist(iris[,-5])) without segfaults under R. What are the differences between blas-reference, blas-atlas and blas-goto. And what will happen with the other blas depended packages as apbs, gromacs, grass, arpack, ccp4-libs and umfpack, if I switch to blas-goto? Do you have some insight? Regards __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Plot
Hi! 21.02.2011 08:50, Schmidt, Lindsey C (MU-Student) wrote: What is plot.new? How can I fix this data or add plot.new so it works? ?plot.new ?plot plot(u[h],v[h],type=l,asp=1) seems to work for me... HTH, Kimmo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] NPMC - replacement has 0 rows (multiple comparisons)
On 2011-02-20 20:02, Karmatose wrote: Hi folks, sorry if this has been answered before, I searched long and hard before deciding to make a thread. I'm trying to include multiple variables in a non-parametric analysis (hah!). So far what I've managed to figure out is that the NPMC package from CRAN MIGHT be able to do what I need, but I can't get it to. First I created a dataset as NPMC calls for. Ind=Individual|- predictor D=Day |- predictor S=Sex |- predictor hand = handlingtotal |- response occy.df-data.frame(hand,Ind,D,S) Then I checked the classes of each variable (factor, integer, factor, numeric from top to bottom). Ok, go! npmc(occy.ds) But alas, I get this error: Error in `$-.data.frame`(`*tmp*`, class, value = integer(0)) : replacement has 0 rows, data has 48 How is npmc() to know what is your response and what is your classification variable? The help page indicates that you must use the name 'var' for the response and 'class' for the predictor and, yes, only one predictor seems to be handled. You might be able to combine your predictors meaningfully into a single classification variable. While the help page cites a reference article, they unhelpfully neglect to provide journal information. Googling suggests that it is Biometrical Journal 43:553-569 (2001). Peter Ehlers I thought maybe this was a problem to do with Day being an integer (seeing as it mentions integer in the error message), but no dice. Can any R-guru's out there please share their wisdom and apply some magic to solving this problem? The world of non-parametric analysis is somewhere I didn't willingly blunder into, but now that I'm here I'm in over my head, and any help you can throw my way would be super super appreciated. Kind regards, Dean. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Console output
On 2011-02-21 04:21, Antje Niederlein wrote: Thanks for every helpful answer :-) ! I thought it was something easier but as long as there is a solution it's fine for me. Ciao, Antje Here's one more that I use: cat( 1:10, sep=\n ) But this won't give you the row numbers. [I keep a function around: cat1 - function(x) cat(x, sep=\n) ] I often use Ted's suggestion but you don't need the NULL: cbind(1:10) will do. I wasn't aware of Martin's clever idea. Peter Ehlers On 21 February 2011 13:12, Martin Maechlermaech...@stat.math.ethz.ch wrote: Ted Hardingted.hard...@wlandres.net on Mon, 21 Feb 2011 11:08:19 - (GMT) writes: That doesn't produce quite what Antje asked for (since each line gets number [1]). The following does work: print(cbind(NULL,(1:10))) [,1] [1,]1 [2,]2 [3,]3 [4,]4 [5,]5 [6,]6 [7,]7 [8,]8 [9,]9 [10,] 10 (apart from the unwanted column-name [,1], and the , in rows). In principle, there would be a true solution, but as you see, it's not quite possibly (by that means): op- options(width=7) Error in options(width = 7) : invalid 'width' parameter, allowed 10...1 op- options(width=10) 1:10 [1] 1 2 [3] 3 4 [5] 5 6 [7] 7 8 [9] 9 10 1000+ 0:9 ## works for these [1] 1000 [2] 1001 [3] 1002 [4] 1003 [5] 1004 [6] 1005 [7] 1006 [8] 1007 [9] 1008 [10] 1009 --- In principle, the lower bound (10) for the width option could be lowered a bit more, as I think 10 had been a somewhat arbitrary choice protecting useRs from hanging themselves.. Martin Ted. On 21-Feb-11 10:30:37, Yves REECHT wrote: Hi, You may try invisible(sapply(1:10, print)) Yves Le 21/02/2011 11:21, Antje Niederlein a écrit : Hi there, I though there has been a possibility to force the output on the console with one element per line. Instead of this: 1:10 [1] 1 2 3 4 5 6 7 8 9 10 something like this 1:10 [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 [6] 6 [7] 7 [8] 8 [9] 9 [10] 10 Can anybody help? Antje E-Mail: (Ted Harding)ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 21-Feb-11 Time: 11:08:17 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Segfaults of eigen with blas-atlas at x86_64-pc-linux-gnu systems
Juergen Rose wrote: What are the differences between blas-reference, blas-atlas and blas-goto. They are different. The reference BLAS is (relatively) slow; the other ones are fast. If you’re happy with the performance of the reference BLAS, or don’t use much matrix algebra-dependent code, there is no reason to switch, though. And what will happen with the other blas depended packages as apbs, gromacs, grass, arpack, ccp4-libs and umfpack, if I switch to blas-goto? Do you have some insight? See the R Installation and Administration manual http://cran.r-project.org/doc/manuals/R-admin.html#BLAS and especially http://cran.r-project.org/doc/manuals/R-admin.html#Shared-BLAS -- Karl Ove Hufthammer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Console output
On 21-Feb-11 13:55:24, Peter Ehlers wrote: On 2011-02-21 04:21, Antje Niederlein wrote: Thanks for every helpful answer :-) ! I thought it was something easier but as long as there is a solution it's fine for me. Ciao, Antje Here's one more that I use: cat( 1:10, sep=\n ) But this won't give you the row numbers. [I keep a function around: cat1 - function(x) cat(x, sep=\n) ] I often use Ted's suggestion but you don't need the NULL: cbind(1:10) will do. I wasn't aware of Martin's clever idea. Peter Ehlers And I wasn;t aware that you don't need the NULL! While I am at it, I've just thought of a way to get rid of the unwanted column-name [,1]: cbind( =1:10) [1,] 1 [2,] 2 [3,] 3 [4,] 4 [5,] 5 [6,] 6 [7,] 7 [8,] 8 [9,] 9 [10,] 10 (Well, it's there; but you can't see it). Ted. On 21 February 2011 13:12, Martin Maechlermaech...@stat.math.ethz.ch wrote: Ted Hardingted.hard...@wlandres.net on Mon, 21 Feb 2011 11:08:19 - (GMT) writes: That doesn't produce quite what Antje asked for (since each line gets number [1]). The following does work: print(cbind(NULL,(1:10))) [,1] [1,]1 [2,]2 [3,]3 [4,]4 [5,]5 [6,]6 [7,]7 [8,]8 [9,]9 [10,] 10 (apart from the unwanted column-name [,1], and the , in rows). In principle, there would be a true solution, but as you see, it's not quite possibly (by that means): op- options(width=7) Error in options(width = 7) : invalid 'width' parameter, allowed 10...1 op- options(width=10) 1:10 [1] 1 2 [3] 3 4 [5] 5 6 [7] 7 8 [9] 9 10 1000+ 0:9 ## works for these [1] 1000 [2] 1001 [3] 1002 [4] 1003 [5] 1004 [6] 1005 [7] 1006 [8] 1007 [9] 1008 [10] 1009 --- In principle, the lower bound (10) for the width option could be lowered a bit more, as I think 10 had been a somewhat arbitrary choice protecting useRs from hanging themselves.. Martin Ted. On 21-Feb-11 10:30:37, Yves REECHT wrote: Hi, You may try invisible(sapply(1:10, print)) Yves Le 21/02/2011 11:21, Antje Niederlein a écrit : Hi there, I though there has been a possibility to force the output on the console with one element per line. Instead of this: 1:10 [1] 1 2 3 4 5 6 7 8 9 10 something like this 1:10 [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 [6] 6 [7] 7 [8] 8 [9] 9 [10] 10 Can anybody help? Antje --- - E-Mail: (Ted Harding)ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 21-Feb-11 Time: 11:08:17 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 21-Feb-11 Time: 14:09:18 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to calculate standard error for the predicted value from geeglm?
Dear Sue, I am also having problems with this. As far as I can gather the predict function will work with geeglm to give you predicted values from the model but it does not produce the standard errors automatically. I have posted a similar question and have had no answers. However, I know that there must be a way to do this?! Did you manage to find the answer? Or can anybody else help? Thanks Anna Li, Sue wrote: Hello R-helpers, I would like to calculate the standard error for the predicted value from geeglm. As an example, I would like to calculate the GEE mean of treatments and their standard error. I first specified the model as mod - geeglm(resp ~ trt, data=dat,id=id,family=Gaussian,corstr=ar1,weights=weight) Then I predicted the GEE mean and se using the following code pred.mean - predict(mod,data.frame(trt=factor(unique(dat$trt),levels=levels(dat$trt) )),se=T) I got the error message Error in XRinv^2 %*% rep(res.var, p) : non-conformable arguments. Thanks for your help, Sue [[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. -- View this message in context: http://r.789695.n4.nabble.com/how-to-calculate-standard-error-for-the-predicted-value-from-geeglm-tp3064560p3317287.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] Function within functions and MLE
Hi, I am trying to determine the MLE of the following function: http://r.789695.n4.nabble.com/file/n3317341/untitled.bmp I have defined both parts of the equation as separate functions and looped over the t and G values to get summations of each part. The lamda function has 3 unknowns which I am trying to determine using MLE bub tin order to try and get the overall function working these have been assigned values at the moment. So what I am trying to do is write a function l(t|0) that is the sum of two functions X and Y which are represented by the summations in the above equation. My R code is as follows te - c(11,161,337,684,1075,1639,2021,2325,2715,3052,3711,3928,4417,4808,5527,6489,6832,7641,8074) G - c(106,164,314,350,523,317,281,378,327,578,201,427,338,682,952,337,803,424,0) Poisson.lik - function(theta0, theta1, theta2, w, t1, t2) { X - array(0, dim=c(1,19)) for (i in 1:19) { X[i] - function(theta0, theta1, theta2, w, t1, t2) (((theta0*w*t2)-(theta1*cos(w*t2))+(theta2*sin(w*t2)))/w) - (((theta0*w*t1)-(theta1*cos(w*t1))+(theta2*sin(w*t1)))/w) } XX - -sum(X) Y - array(0, dim=c(1,19)) for (i in 1:19) { Y[i] - function(theta0, theta1, theta2, w, t2) theta0 + theta1*sin(w*t2) + theta2*cos(w*t2) } YY - sum(log(Y)) LL - XX+YY return (-LL) } optim(c(0,100), Poisson.lik, w=6.28, t1=te[i], t2=te[i]+G[i]) The code isn't working but I am also not sure if this is the best way to go about it as I am not sure about how to define functions within functions. What I want out is the MLE for theta, theta1 and theta1. Can anyone help? Apologies if the code is confusing! Thanks, Doug -- View this message in context: http://r.789695.n4.nabble.com/Function-within-functions-and-MLE-tp3317341p3317341.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] fitting logit to data
Hello, I'd like to fit a logit function to my data. The data is distributed like a logit (like in this plot on wikipedia http://en.wikipedia.org/wiki/File:Logit.png) but the values on the x-axis are not between 0 and 1. I don't think using a glm is the solution because I simply want to infer the parameters of the logit function (offset, compression, slope...), so I can apply it to all my values on x and get my value y. It works in gnuplot with this command: fit f(x) 'myData' using x:y via a,b,c,d and after some iterations gnuplot will return the values a,b,c,d Is there something like this in R? Thanks for the help! Sylvia [[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] linear regression and t-distribution
Hello I have a data set with outlier and it is not normally distributed. I would instead like to use a more robust distribution like t-distribution. My question is if the coefficients of the regression are different from zero, but assuming a t-distribution. Could someone hint me what package to use or Thanks in advance Rosario __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Regarding Soft Independent Modeling Computational Analysis
Date: Mon, 21 Feb 2011 10:45:17 +0530 From: reynoldspravin...@gmail.com To: r-help@r-project.org Subject: [R] Regarding Soft Independent Modeling Computational Analysis Hi I'm a B.E student pursuing my Project in the CEERI unit of the Council of Scientific and Industrial Research, Chennai, TN, India. I'm working on R -Language for my project. I'm in need of the functionality of SIMCA for the project. Is there any in-built function for SIMCA in R? Or are there people working on it? It would be a great help if you let us know as soon as possible. Sometimes you can find unpublished lurkers with similar interests but if you want people who have already published in the area often google scholar or citeseer can help give you names with email for direct contact. For example, http://www.google.com/#hl=enq=R+SIMCA+computational++citeseer Regards Reynolds __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 source() a .R file which was saved using UTF-8 encoding on Windows?
Dear all, [Note: This was originally posted over at Stack Overflow, but it was suggested that the problem may be an error in R on Windows, so I have cross posted over here too. ref: http://goo.gl/pd54D) The following, when copied and pasted directly into R works fine: character_test - function() print(R同时也被称为GNU S是一个强烈的功能性语言和环境,探索统计数据集,使许多从自定义数据图形显示...) character_test() [1] R同时也被称为GNU S是一个强烈的功能性语言和环境,探索统计数据集,使许多从自定义数据图形显示... However, if I make a file called character_test.R containing the EXACT SAME code, save it in UTF-8 encoding (so as to retain the special Chinese characters), then when I source() it in R, I get the following error: source(file=C:\\Users\\Tony\\Desktop\\character_test.R, encoding = UTF-8) Error in source(file = C:\\Users\\Tony\\Desktop\\character_test.R, encoding = utf-8) : C:\Users\Tony\Desktop\character_test.R:3:0: unexpected end of input 1: character.test - function() print(R 2: ^ In addition: Warning message: In source(file = C:\\Users\\Tony\\Desktop\\character_test.R, encoding = UTF-8) : invalid input found on input connection 'C:\Users\Tony\Desktop \character_test.R' Any help you can offer in solving and helping me to understand what is going on here would be much appreciated. Best, Tony Breyal ### Session information ### sessionInfo() # Windows 7 Pro x64 R version 2.12.1 (2010-12-16) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United Kingdom.1252 [2] LC_CTYPE=English_United Kingdom.1252 [3] LC_MONETARY=English_United Kingdom.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices utils datasets methods [7] base loaded via a namespace (and not attached): [1] tools_2.12.1 and l10n_info() $MBCS [1] FALSE $`UTF-8` [1] FALSE $`Latin-1` [1] TRUE $codepage [1] 1252 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plotting individual trajectories from individual growth model
Hi Dennis, That's very helpful. The plot appears appears to be of the data and not the fitted linear trajectories, however, as the lines are not linear. Is it possible to plot the fitted linear trajectories (according to the fixed/random intercepts and slopes of the lme model)? Thanks again! -- View this message in context: http://r.789695.n4.nabble.com/Plotting-individual-trajectories-from-individual-growth-model-tp3315494p3317362.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] Fiting a beta distribution in R
Is there any R package that can fit a beta distribution in R? -- Thanks, Jim. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Equivalent of log file in R?
Hi everyone, Is there a way to make R save the workspace output (just the results, not the objects themselves) as you go? I'm running analysis that takes a long time to run and I want to be able to interrupt it without losing all the output to date. Is there an alternative to putting save.image() commands after every couple lines of code? Best, Tatyana __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] naming vectors
Hello R users I was trying to find a less annoying way of naming vectors than: x-1:10 names(x)[1:length(x)]-A So I tried: x-1:10 names(x)-A #but this gave only the first element named (as described in the help files) and x-1:10 names(x)[]-A #but this gave all elements named NA The curious thing with this last option is that if the same line is ran a second time, now the vector gets the name A for all elements, which is what is desired names(x)[]-A I'm guessing the first time the names attribute is created and the second time values are given to this attribute. But shouldn't we expect the elements to be all named on the first try with the given value? Cheers Francois [[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] Console output
It's nice to see all those solutions, but I'm wondering how it would be helpful to have the display like this. I'm a bit curious because for me the R output formatting is not very important. Ivan Le 2/21/2011 15:09, (Ted Harding) a écrit : On 21-Feb-11 13:55:24, Peter Ehlers wrote: On 2011-02-21 04:21, Antje Niederlein wrote: Thanks for every helpful answer :-) ! I thought it was something easier but as long as there is a solution it's fine for me. Ciao, Antje Here's one more that I use: cat( 1:10, sep=\n ) But this won't give you the row numbers. [I keep a function around: cat1- function(x) cat(x, sep=\n) ] I often use Ted's suggestion but you don't need the NULL: cbind(1:10) will do. I wasn't aware of Martin's clever idea. Peter Ehlers And I wasn;t aware that you don't need the NULL! While I am at it, I've just thought of a way to get rid of the unwanted column-name [,1]: cbind( =1:10) [1,] 1 [2,] 2 [3,] 3 [4,] 4 [5,] 5 [6,] 6 [7,] 7 [8,] 8 [9,] 9 [10,] 10 (Well, it's there; but you can't see it). Ted. On 21 February 2011 13:12, Martin Maechlermaech...@stat.math.ethz.ch wrote: Ted Hardingted.hard...@wlandres.net on Mon, 21 Feb 2011 11:08:19 - (GMT) writes: That doesn't produce quite what Antje asked for (since each line gets number [1]). The following does work: print(cbind(NULL,(1:10))) [,1] [1,]1 [2,]2 [3,]3 [4,]4 [5,]5 [6,]6 [7,]7 [8,]8 [9,]9 [10,] 10 (apart from the unwanted column-name [,1], and the , in rows). In principle, there would be a true solution, but as you see, it's not quite possibly (by that means): op- options(width=7) Error in options(width = 7) : invalid 'width' parameter, allowed 10...1 op- options(width=10) 1:10 [1] 1 2 [3] 3 4 [5] 5 6 [7] 7 8 [9] 9 10 1000+ 0:9 ## works for these [1] 1000 [2] 1001 [3] 1002 [4] 1003 [5] 1004 [6] 1005 [7] 1006 [8] 1007 [9] 1008 [10] 1009 --- In principle, the lower bound (10) for the width option could be lowered a bit more, as I think 10 had been a somewhat arbitrary choice protecting useRs from hanging themselves.. Martin Ted. On 21-Feb-11 10:30:37, Yves REECHT wrote: Hi, You may try invisible(sapply(1:10, print)) Yves Le 21/02/2011 11:21, Antje Niederlein a écrit : Hi there, I though there has been a possibility to force the output on the console with one element per line. Instead of this: 1:10 [1] 1 2 3 4 5 6 7 8 9 10 something like this 1:10 [1] 1 [2] 2 [3] 3 [4] 4 [5] 5 [6] 6 [7] 7 [8] 8 [9] 9 [10] 10 Can anybody help? Antje --- - E-Mail: (Ted Harding)ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 21-Feb-11 Time: 11:08:17 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. E-Mail: (Ted Harding)ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 21-Feb-11 Time: 14:09:18 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal,
Re: [R] naming vectors
Try this: names(x) - rep(A, length(x)) On Mon, Feb 21, 2011 at 11:44 AM, Francois Rousseu francoisrous...@hotmail.com wrote: Hello R users I was trying to find a less annoying way of naming vectors than: x-1:10 names(x)[1:length(x)]-A So I tried: x-1:10 names(x)-A #but this gave only the first element named (as described in the help files) and x-1:10 names(x)[]-A #but this gave all elements named NA The curious thing with this last option is that if the same line is ran a second time, now the vector gets the name A for all elements, which is what is desired names(x)[]-A I'm guessing the first time the names attribute is created and the second time values are given to this attribute. But shouldn't we expect the elements to be all named on the first try with the given value? Cheers Francois [[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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[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] Generating uniformly distributed correlated data.
We want to generate a distribution on the unit square with the following properties * It is concentrated on a reasonable subset of the square, and the restricted distribution is uniform on this subset. * Both marginal distributions are uniform on the unit interval. * All horizontal and all vertical cross sections are sets of lines segments with the same total length If we find a geometric figure with these properties, we have solved the problem. So we define the distribution to be uniform on the following area: (it is distorted but should give the idea) x***/-/***x |**/-/| |*/-/*| |/-/**| |-/**/| |/**/-| |---/**/--| |--/**/---| |-/**/| |/**/-| |---/**/--| |--/**/---| |-/**/| |/**/-| |---/**/--| |--/**/---| |-/**/| |/**/-| |---/**/--| |--/**/---| |-/**/| |/**/-| |**/-/| |*/-/*| |/-/**| x***/-/***x There is the same number of stars in each horizontal row and each vertical column. So we define g(x1,x2)= 1 abs(x1-x2) = a or abs(x1-x2+1) = a or abs(x1-x2-1) = a 0 elsewhere The total area of the shape is 2*a. The admissible range for a is 0,1/2 therefore f(x1,x2)=g(x1,x2)/(2*a) is a density functions. This is where simple algebra comes in. This distribution has expected value 1/2 and variance 1/12 for both margins (uniform distribution), and it has covariance = (1-3*a+2*a2)/12 and correlation = 1 - 3*a + 2*a2 The inverse function of 1 - 3*2 + 2*a2 is (3-sqrt(1+8*r))/4 Therefore we can compute that our distribution with a=(3-sqrt(1+8*r))/4 will produce a given r. Ho do we create random numbers from this distribution? By using conditional densities. x1 is sampled from the uniform distribution, and for a give x1 we produce x2 by a uniform distribution on the along the vertical cross cut of the geometrical shape (which is either 1 or 2 intervals). And which is most easily implemented by using the modulo operator %%. This mechanism is NOT a convolution. Applying module after the addition makes it a nonconvolution. Adding independent random variables without doing anything further is a convolution, by applying a trimming operation, the convolution property gets lost. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Building an array from matrix blocks
Well, you can lose B by just adding to X in the first for-loop, can't you? For (...) X - X + A[...] But if you want elegance, you could try: X = Reduce(+,lapply(1:(p+1), function(i) A[i:(n-p-1+i),i:(n-p-1+i)])) I imagine someone can be even more eleganter than this. rad -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Eduardo de Oliveira Horta Sent: Saturday, February 19, 2011 9:49 AM To: r-help Subject: [R] Building an array from matrix blocks Hello, I've googled for a while and couldn't find anything on this topic: say I have a matrix A and want to build matrices B1, B2,... using blocks from A (or equivalently an array B with B[,,i] being a block from A), and that I must sum the B[,,i]'s. I've come up with this rather non-elegant code: n = 6 p = 3 A - matrix(1:(n^2), n, n, byrow=TRUE) B - array(0, c(n-p, n-p, p+1)) for (i in 1:(p+1)) B[,,i] - A[i:(n-p-1+i), i:(n-p-1+i)] X - matrix(0, n-p, n-p) for (i in 1:(p+1)) X - X + B[,,i] A [,1] [,2] [,3] [,4] [,5] [,6] [1,]123456 [2,]789 10 11 12 [3,] 13 14 15 16 17 18 [4,] 19 20 21 22 23 24 [5,] 25 26 27 28 29 30 [6,] 31 32 33 34 35 36 B , , 1 [,1] [,2] [,3] [1,]123 [2,]789 [3,] 13 14 15 , , 2 [,1] [,2] [,3] [1,]89 10 [2,] 14 15 16 [3,] 20 21 22 , , 3 [,1] [,2] [,3] [1,] 15 16 17 [2,] 21 22 23 [3,] 27 28 29 , , 4 [,1] [,2] [,3] [1,] 22 23 24 [2,] 28 29 30 [3,] 34 35 36 X [,1] [,2] [,3] [1,] 46 50 54 [2,] 70 74 78 [3,] 94 98 102 Note that the blocks B[,,i] are obtained by sweeping the diagonal of A. I wonder if there is a better and faster way to achieve this using block matrix operations for instance. Actually what matters most for me is getting to the matrix X, so if it is possible to do this without having to construct the array B it would be ok as well... Interesting observation: system.time(for (j in 1:1) {X - matrix(0, n-p, n-p); for (i in 1:(p+1)) X - X + B[,,i]}) user system elapsed 0.270.000.26 system.time(for (j in 1:1) {X - apply(B,c(1,2),sum)}) user system elapsed 1.820.021.86 Thanks in advance, and best regards, Eduardo Horta sessionInfo() R version 2.11.1 (2010-05-31) x86_64-pc-mingw32 locale: [1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252 [3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C [5] LC_TIME=Portuguese_Brazil.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] Revobase_4.2.0 RevoScaleR_1.1-1 lattice_0.19-13 loaded via a namespace (and not attached): [1] grid_2.11.1 pkgXMLBuilder_1.0 revoIpe_1.0 tools_2.11.1 [5] XML_3.1-0 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. message may contain confidential information. If you are not the designated recipient, please notify the sender immediately, and delete the original and any copies. Any use of the message by you is prohibited. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] naming vectors
It is indeed an interesting behavior and I have no idea what you could do except what you did, though I would use: names(x) - rep(A, length(x)) But I don't really understand why you want to give the same name to all elements? There might be another way around depending on your goal Ivan Le 2/21/2011 15:44, Francois Rousseu a écrit : Hello R users I was trying to find a less annoying way of naming vectors than: x-1:10 names(x)[1:length(x)]-A So I tried: x-1:10 names(x)-A #but this gave only the first element named (as described in the help files) and x-1:10 names(x)[]-A #but this gave all elements named NA The curious thing with this last option is that if the same line is ran a second time, now the vector gets the name A for all elements, which is what is desired names(x)[]-A I'm guessing the first time the names attribute is created and the second time values are given to this attribute. But shouldn't we expect the elements to be all named on the first try with the given value? Cheers Francois [[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. -- 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/1525_8_1.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] Fiting a beta distribution in R
Hi, Sure. Check fitdistr from MASS or fitdist from fitdistrplus package. Best, Gergely On Mon, Feb 21, 2011 at 3:29 PM, Jim Silverton jim.silver...@gmail.comwrote: Is there any R package that can fit a beta distribution in R? -- Thanks, Jim. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] Generating uniformly distributed correlated data.
Date: Mon, 21 Feb 2011 15:53:26 +0100 From: erich.neuwi...@univie.ac.at To: marchy...@hotmail.com CC: soren.fau...@biology.au.dk; r-help@r-project.org Subject: Re: [R] Generating uniformly distributed correlated data. We want to generate a distribution on the unit square with the following properties * It is concentrated on a reasonable subset of the square, and the restricted distribution is uniform on this subset. * Both marginal distributions are uniform on the unit interval. * All horizontal and all vertical cross sections are sets of lines segments with the same total length If we find a geometric figure with these properties, we have solved the problem. So we define the distribution to be uniform on the following area: (it is distorted but should give the idea) x***/-/***x |**/-/| |*/-/*| |/-/**| |-/**/| |/**/-| |---/**/--| |--/**/---| |-/**/| |/**/-| |---/**/--| |--/**/---| |-/**/| |/**/-| |---/**/--| |--/**/---| |-/**/| |/**/-| |---/**/--| |--/**/---| |-/**/| |/**/-| |**/-/| |*/-/*| |/-/**| x***/-/***x There is the same number of stars in each horizontal row and each vertical column. So we define g(x1,x2)= 1 abs(x1-x2) = a or abs(x1-x2+1) = a or abs(x1-x2-1) = a 0 elsewhere The total area of the shape is 2*a. The admissible range for a is 0,1/2 therefore f(x1,x2)=g(x1,x2)/(2*a) is a density functions. This is where simple algebra comes in. This distribution has expected value 1/2 and variance 1/12 for both margins (uniform distribution), and it has covariance = (1-3*a+2*a2)/12 and correlation = 1 - 3*a + 2*a2 The inverse function of 1 - 3*2 + 2*a2 is (3-sqrt(1+8*r))/4 Therefore we can compute that our distribution with a=(3-sqrt(1+8*r))/4 will produce a given r. Ho do we create random numbers from this distribution? By using conditional densities. x1 is sampled from the uniform distribution, and for a give x1 we produce x2 by a uniform distribution on the along the vertical cross cut of the geometrical shape (which is either 1 or 2 intervals). And which is most easily implemented by using the modulo operator %%. This mechanism is NOT a convolution. Applying module after the addition makes it a nonconvolution. Adding independent random variables without doing anything further is a convolution, by applying a trimming operation, the convolution property gets lost. The thing inside the mod allows convolution, as I mentioned the effect of the mod is to move back the pieces that fall outside the desired range and they happen to restore the uniform distribution. I thought my explanation was simple and easy after the fact but not sure it would have motivated the original design too well. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] naming vectors
I guess I will just get over my laziness and use the rep function instead! But my goal was more to point out the weird names attribution behaviour. I'm using named vectors of dates that can be associated to 2 stages (incubation and rearing in nesting birds) to overlay a vector of observed data and a vector of theoritical data to see if the stages match on same dates. A data frame could also be used for this task, but I thought that vectors are a bit simpler and faster to create. Francois Rousseu Date: Mon, 21 Feb 2011 15:58:36 +0100 From: ivan.calan...@uni-hamburg.de To: r-help@r-project.org Subject: Re: [R] naming vectors It is indeed an interesting behavior and I have no idea what you could do except what you did, though I would use: names(x) - rep(A, length(x)) But I don't really understand why you want to give the same name to all elements? There might be another way around depending on your goal Ivan Le 2/21/2011 15:44, Francois Rousseu a écrit : Hello R users I was trying to find a less annoying way of naming vectors than: x-1:10 names(x)[1:length(x)]-A So I tried: x-1:10 names(x)-A #but this gave only the first element named (as described in the help files) and x-1:10 names(x)[]-A #but this gave all elements named NA The curious thing with this last option is that if the same line is ran a second time, now the vector gets the name A for all elements, which is what is desired names(x)[]-A I'm guessing the first time the names attribute is created and the second time values are given to this attribute. But shouldn't we expect the elements to be all named on the first try with the given value? Cheers Francois [[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. -- 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/1525_8_1.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. [[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] Generating uniformly distributed correlated data.
one simple idea is to generate correlated normals (vector multivariate normal), and then use the cumulative distribution function F_i of component i such: F_i(X_i), which is uniform. Kjetil (this will not preserve tha value of the correlation coefficient, so you must experiment) On Mon, Feb 21, 2011 at 7:30 PM, Mike Marchywka marchy...@hotmail.com wrote: Date: Mon, 21 Feb 2011 15:53:26 +0100 From: erich.neuwi...@univie.ac.at To: marchy...@hotmail.com CC: soren.fau...@biology.au.dk; r-help@r-project.org Subject: Re: [R] Generating uniformly distributed correlated data. We want to generate a distribution on the unit square with the following properties * It is concentrated on a reasonable subset of the square, and the restricted distribution is uniform on this subset. * Both marginal distributions are uniform on the unit interval. * All horizontal and all vertical cross sections are sets of lines segments with the same total length If we find a geometric figure with these properties, we have solved the problem. So we define the distribution to be uniform on the following area: (it is distorted but should give the idea) x***/-/***x |**/-/| |*/-/*| |/-/**| |-/**/| |/**/-| |---/**/--| |--/**/---| |-/**/| |/**/-| |---/**/--| |--/**/---| |-/**/| |/**/-| |---/**/--| |--/**/---| |-/**/| |/**/-| |---/**/--| |--/**/---| |-/**/| |/**/-| |**/-/| |*/-/*| |/-/**| x***/-/***x There is the same number of stars in each horizontal row and each vertical column. So we define g(x1,x2)= 1 abs(x1-x2) = a or abs(x1-x2+1) = a or abs(x1-x2-1) = a 0 elsewhere The total area of the shape is 2*a. The admissible range for a is 0,1/2 therefore f(x1,x2)=g(x1,x2)/(2*a) is a density functions. This is where simple algebra comes in. This distribution has expected value 1/2 and variance 1/12 for both margins (uniform distribution), and it has covariance = (1-3*a+2*a2)/12 and correlation = 1 - 3*a + 2*a2 The inverse function of 1 - 3*2 + 2*a2 is (3-sqrt(1+8*r))/4 Therefore we can compute that our distribution with a=(3-sqrt(1+8*r))/4 will produce a given r. Ho do we create random numbers from this distribution? By using conditional densities. x1 is sampled from the uniform distribution, and for a give x1 we produce x2 by a uniform distribution on the along the vertical cross cut of the geometrical shape (which is either 1 or 2 intervals). And which is most easily implemented by using the modulo operator %%. This mechanism is NOT a convolution. Applying module after the addition makes it a nonconvolution. Adding independent random variables without doing anything further is a convolution, by applying a trimming operation, the convolution property gets lost. The thing inside the mod allows convolution, as I mentioned the effect of the mod is to move back the pieces that fall outside the desired range and they happen to restore the uniform distribution. I thought my explanation was simple and easy after the fact but not sure it would have motivated the original design too well. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Plot of set
Here is a solution using contour: x - y - seq(-1.5,1.5,length=100) z - outer(x, y, function(x,y) x^2+y^2) contour(x,y,z, levels=1) -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of . . Sent: Sunday, February 20, 2011 2:41 AM To: r-help@r-project.org Subject: [R] Plot of set I am in the situation where I have to make a two-dimential plot of a set. If I simplify my data it would be something along the lines of wanting to plot {x,y| x^2+y^2 = 1}. I am aware of the contour and persp plot, but cannot figure out how to convert one of those to draw the set. I have tried to google different ways of plotting in R but have not been able to find a method through that either. Thanks in advance Lise [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] wrong lines in auto.key xyplot
Hi all, I'm having a problem with the auto.key function in xyplot. I changed the symbols an lines styles using these commands trellis.par.set(superpose.symbol=list(pch=c(0,1,2,3,4,5,6,8,15,16))) trellis.par.set(superpose.symbol=list(col=c(rep(black,11 trellis.par.set(superpose.symbol=list(cex=c(rep(0.6,11 trellis.par.set(superpose.line=list(col=c(rep(black,11 trellis.par.set(superpose.line=list(lty=c(1,1,1,2,2,2,2,3,3,3,3))) xyplot(Dq~q , data =zq, groups=Weeks, type=o, auto.key=list(x=.7,y=.9,title=Weeks,cex.title=1, points=TRUE, lines=TRUE)) the graphic is showed with the parameters I changed and if I enter a show.settings() command the lines display as I changed, but in the legend the lines have any other style. What I am doing wrong? Any help would be greatly appreciated. Leonardo A. Saravia Instituto de Ciencias Universidad Nacional de General Sarmiento __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] J48 / Transform from numeric to nominal
Hi everyone, I am new to field of data mining as well as particularly using R respectively RWeka for writing my master thesis. I intend to create some specific J48 classification trees with the RWeka_classifiers_tree function. When I run the source code it says “cannot handle numeric class”. I therefore checked the arff-file and indeed there it says that the class variable is numeric although it only contains 0 and 1. In a next step I tried to Discretize my dataset but received the same error message. I googled the issue several times and also read about the filter function in WEKA but did not know how to use it and unfortunately did not find a proper solution. So – how can I transform my class variable from numeric to nominal / binary, I just don’t get it?! As I said, I am new to all of this and so appreciate anything little which helps! Pat -- Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.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] Building an array from matrix blocks
Thanks! On Mon, Feb 21, 2011 at 11:40 AM, rex.dw...@syngenta.com wrote: Well, you can lose B by just adding to X in the first for-loop, can't you? For (...) X - X + A[...] But if you want elegance, you could try: X = Reduce(+,lapply(1:(p+1), function(i) A[i:(n-p-1+i),i:(n-p-1+i)])) I imagine someone can be even more eleganter than this. rad -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Eduardo de Oliveira Horta Sent: Saturday, February 19, 2011 9:49 AM To: r-help Subject: [R] Building an array from matrix blocks Hello, I've googled for a while and couldn't find anything on this topic: say I have a matrix A and want to build matrices B1, B2,... using blocks from A (or equivalently an array B with B[,,i] being a block from A), and that I must sum the B[,,i]'s. I've come up with this rather non-elegant code: n = 6 p = 3 A - matrix(1:(n^2), n, n, byrow=TRUE) B - array(0, c(n-p, n-p, p+1)) for (i in 1:(p+1)) B[,,i] - A[i:(n-p-1+i), i:(n-p-1+i)] X - matrix(0, n-p, n-p) for (i in 1:(p+1)) X - X + B[,,i] A [,1] [,2] [,3] [,4] [,5] [,6] [1,] 1 2 3 4 5 6 [2,] 7 8 9 10 11 12 [3,] 13 14 15 16 17 18 [4,] 19 20 21 22 23 24 [5,] 25 26 27 28 29 30 [6,] 31 32 33 34 35 36 B , , 1 [,1] [,2] [,3] [1,] 1 2 3 [2,] 7 8 9 [3,] 13 14 15 , , 2 [,1] [,2] [,3] [1,] 8 9 10 [2,] 14 15 16 [3,] 20 21 22 , , 3 [,1] [,2] [,3] [1,] 15 16 17 [2,] 21 22 23 [3,] 27 28 29 , , 4 [,1] [,2] [,3] [1,] 22 23 24 [2,] 28 29 30 [3,] 34 35 36 X [,1] [,2] [,3] [1,] 46 50 54 [2,] 70 74 78 [3,] 94 98 102 Note that the blocks B[,,i] are obtained by sweeping the diagonal of A. I wonder if there is a better and faster way to achieve this using block matrix operations for instance. Actually what matters most for me is getting to the matrix X, so if it is possible to do this without having to construct the array B it would be ok as well... Interesting observation: system.time(for (j in 1:1) {X - matrix(0, n-p, n-p); for (i in 1:(p+1)) X - X + B[,,i]}) user system elapsed 0.27 0.00 0.26 system.time(for (j in 1:1) {X - apply(B,c(1,2),sum)}) user system elapsed 1.82 0.02 1.86 Thanks in advance, and best regards, Eduardo Horta sessionInfo() R version 2.11.1 (2010-05-31) x86_64-pc-mingw32 locale: [1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252 [3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C [5] LC_TIME=Portuguese_Brazil.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] Revobase_4.2.0 RevoScaleR_1.1-1 lattice_0.19-13 loaded via a namespace (and not attached): [1] grid_2.11.1 pkgXMLBuilder_1.0 revoIpe_1.0 tools_2.11.1 [5] XML_3.1-0 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. message may contain confidential information. If you are not the designated recipient, please notify the sender immediately, and delete the original and any copies. Any use of the message by you is prohibited. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] assign value to multiple objects with a given ls pattern
Dear R colleagues, This seems pretty straight forward but I have been banging my head on this for some time and can't seem to find a solution suppose I have something like a1-1; a2-2; a3-3; a4-4; b1-3; b2-4 I would like to quickly assign to objects with a certain pattern, e.g., those in ls(pattern=a) a specific value, e.g., 99, without having to assign each object at a time. is there a way I can do this within a for cycle? I have tested several eval and parse statements but with no success. Regards, Nuno Prista PhD student Instituto de Oceanografia Faculdade de Ciências da Universidade de Lisboa Campo Grande, Lisboa, 1749-016 Lisboa, Portugal __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] fitting logit to data
On Mon, Feb 21, 2011 at 12:13:09PM +0100, Sylvia Tippmann wrote: Hello, I'd like to fit a logit function to my data. The data is distributed like a logit (like in this plot on wikipedia http://en.wikipedia.org/wiki/File:Logit.png) but the values on the x-axis are not between 0 and 1. I don't think using a glm is the solution because I simply want to infer the parameters of the logit function (offset, compression, slope...), so I can apply it to all my values on x and get my value y. Two ideas: 1) scale your data so it does fit in [0,1] before fitting a glm 2) Use nls() to fit whatever function you find suitable cu Philipp -- Dr. Philipp Pagel Lehrstuhl für Genomorientierte Bioinformatik Technische Universität München Wissenschaftszentrum Weihenstephan Maximus-von-Imhof-Forum 3 85354 Freising, Germany http://webclu.bio.wzw.tum.de/~pagel/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Equivalent of log file in R?
Hi Tatyana, I think you are looking for ?sink Best, Ista On Mon, Feb 21, 2011 at 2:11 PM, Tatyana Deryugina tatya...@mit.edu wrote: Hi everyone, Is there a way to make R save the workspace output (just the results, not the objects themselves) as you go? I'm running analysis that takes a long time to run and I want to be able to interrupt it without losing all the output to date. Is there an alternative to putting save.image() commands after every couple lines of code? Best, Tatyana __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.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] J48 / Transform from numeric to nominal
Hi Patrick, You didn't say how exactly you tried to Discretize your variable, but have you tried ?factor ?as.character ? Best, Ista On Mon, Feb 21, 2011 at 3:34 PM, Patrick Skorupka patrick.skoru...@gmx.de wrote: Hi everyone, I am new to field of data mining as well as particularly using R respectively RWeka for writing my master thesis. I intend to create some specific J48 classification trees with the RWeka_classifiers_tree function. When I run the source code it says “cannot handle numeric class”. I therefore checked the arff-file and indeed there it says that the class variable is numeric although it only contains 0 and 1. In a next step I tried to Discretize my dataset but received the same error message. I googled the issue several times and also read about the filter function in WEKA but did not know how to use it and unfortunately did not find a proper solution. So – how can I transform my class variable from numeric to nominal / binary, I just don’t get it?! As I said, I am new to all of this and so appreciate anything little which helps! Pat -- Empfehlen Sie GMX DSL Ihren Freunden und Bekannten und wir belohnen Sie mit bis zu 50,- Euro! https://freundschaftswerbung.gmx.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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.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] Problem with writing a file in UTF-8
Thomas, I wasn't able to reproduce your finding. The last two characters in my 'out.txt' file were just as expected. But, I'm in an UTF-8 locale. Your locale affects the encoding of characters on your platform. If you're not in a UTF-8 locale, then characters are converted from your native encoding to UTF-8 (when you specify encoding=UTF-8). In the process of conversion, it's possible to lose information. You can test whether there is a loss (or a change rather) when R writes these characters like so: # what does űŁ look like in binary (hex)? raw_before - charToRaw(űŁ) # write 'out.txt' as before out - file(description=out.txt, open=w, encoding=UTF-8) write(x=űŁ, file=out) close(con=out) # read in the two characters out - file(description=out.txt, open=r, encoding=UTF-8) raw_after - charToRaw(readChar(con=out, nchars=2)) close(con=out) # compare the raw representations identical(raw_before, raw_after) This test passes on my machine. But, there's also the question of whether these characters made it onto R-help list unaltered. Also, please include the result of sessionInfo() in you subsequent messages. Best, Matt sessionInfo() R version 2.11.1 (2010-05-31) i686-pc-linux-gnu locale: [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C [3] LC_TIME=en_US.utf8LC_COLLATE=en_US.utf8 [5] LC_MONETARY=C LC_MESSAGES=en_US.utf8 [7] LC_PAPER=en_US.utf8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base On Thu, 2011-02-17 at 13:54 -0800, tpklein wrote: Hello, I am working with a data frame containg character strings with many special symbols from various European languages. When writing such character strings to a file using the UTF-8 encoding, some of them are converted in a strange way. See the following example, run in R 2.12.1 on Windows 7: out - file( description=out.txt, open=w, encoding=UTF-8) write( x=äöüßæűŁ, file=out ) close( con=out ) The last two symbols in the character string are converted to uL while all other characters are not changed (which is what I want). How to explain this? Does it have something to do with my locale? And is there a way to work around this problem? -- Any help would be greatly appreciated. Thomas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] assign value to multiple objects with a given ls pattern
Hi Nuno, Yes, you can do for(i in ls(pattern=a)) { assign(i, 99) } but honestly this is a bad idea. It will try to assign the value of 99 to any object in your workspace that contains an a, which sounds really scary to me. Better I think to use a list: ab.list - list(a1=1, a2=2, a3=3, a4=4, b1=3, b2=4) ab.list[grep(a, names(ab.list))] - 99 Or even just a named vector ab.vector - c(a1=1, a2=2, a3=3, a4=4, b1=3, b2=4) ab.vector[grep(a, names(ab.vector))] - 99 Best, Ista On Mon, Feb 21, 2011 at 4:22 PM, Nuno Prista nmpri...@fc.ul.pt wrote: Dear R colleagues, This seems pretty straight forward but I have been banging my head on this for some time and can't seem to find a solution suppose I have something like a1-1; a2-2; a3-3; a4-4; b1-3; b2-4 I would like to quickly assign to objects with a certain pattern, e.g., those in ls(pattern=a) a specific value, e.g., 99, without having to assign each object at a time. is there a way I can do this within a for cycle? I have tested several eval and parse statements but with no success. Regards, Nuno Prista PhD student Instituto de Oceanografia Faculdade de Ciências da Universidade de Lisboa Campo Grande, Lisboa, 1749-016 Lisboa, Portugal __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.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] Generating uniformly distributed correlated data.
On Feb 21, 2011, at 9:53 AM, Erich Neuwirth wrote: We want to generate a distribution on the unit square with the following properties * It is concentrated on a reasonable subset of the square, and the restricted distribution is uniform on this subset. * Both marginal distributions are uniform on the unit interval. * All horizontal and all vertical cross sections are sets of lines segments with the same total length If we find a geometric figure with these properties, we have solved the problem. So we define the distribution to be uniform on the following area: (it is distorted but should give the idea) x***/-/***x |**/-/| |*/-/*| |/-/**| |-/**/| |/**/-| |---/**/--| |--/**/---| |-/**/| |/**/-| |---/**/--| |--/**/---| |-/**/| |/**/-| |---/**/--| |--/**/---| |-/**/| |/**/-| |---/**/--| |--/**/---| |-/**/| |/**/-| |**/-/| |*/-/*| |/-/**| x***/-/***x There is the same number of stars in each horizontal row and each vertical column. I love it! I plotted the data that your method generated and got a plot with points in the regions you displayed. After pondering its curious pathology (three disjoint regions), I thought I could cure that pathology by flipping quadrants. I proceeded to do so but discovered that the pathology wasn't really cured but only concentrated at the ends and middle. Using your ASCII art, my version wuld look like this where the \\\ regions are double dense. y[x0.5 y 0.5] = 0.5 +abs(0.5-y[x0.5 y 0.5]) y[x0.5 y 0.5] = 0.5 -abs(0.5-y[x0.5 y 0.5]) plot(x,y) x-x |/*\\\| |---/***\\| |--/*\| |-/**/| |/**/-| |---/**/--| |--/**/---| |-/**/| |-|\\***/-| |-|\\\*/--| |-|---| |-*---| |/| |---/**\\\| |--/\\| |-/**\| |/**/-| |---/**/--| |--/**/---| |-/**/| |/**/-| |\*/--| |\\***/---| |/| \-x So it not only created a still slightly less pathological counterpart, but the correlation jumped from 0.5 to 0.95. It looks to be a promising basis for homework problems in probability courses, an experience I have never has the ?pleasure? to experience except during self-study to repair my (many) mathematical deficiencies. cor(x,y) [1] 0.9449256 -- David. So we define g(x1,x2)= 1 abs(x1-x2) = a or abs(x1-x2+1) = a or abs(x1-x2-1) = a 0 elsewhere The total area of the shape is 2*a. The admissible range for a is 0,1/2 therefore f(x1,x2)=g(x1,x2)/(2*a) is a density functions. This is where simple algebra comes in. This distribution has expected value 1/2 and variance 1/12 for both margins (uniform distribution), and it has covariance = (1-3*a+2*a2)/12 and correlation = 1 - 3*a + 2*a2 The inverse function of 1 - 3*2 + 2*a2 is (3-sqrt(1+8*r))/4 Therefore we can compute that our distribution with a=(3-sqrt(1+8*r))/4 will produce a given r. Ho do we create random numbers from this distribution? By using conditional densities. x1 is sampled from the uniform distribution, and for a give x1 we produce x2 by a uniform distribution on the along the vertical cross cut of the geometrical shape (which is either 1 or 2 intervals). And which is most easily implemented by using the modulo operator %%. This mechanism is NOT a convolution. Applying module after the addition makes it a nonconvolution. Adding independent random variables without doing anything further is a convolution, by applying a trimming operation, the convolution property gets lost. -- 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] assign value to multiple objects with a given ls pattern
Hi, This works for me: pat - ls(pattern=^a) ## I would anchor a to the beginning with ^ for safety! for (i in seq_along(pat))assign(pat[i], value=99) Or this with lapply: lapply(pat, FUN=function(x) assign(x, value=99, envir=.GlobalEnv)) See ?assign HTH, Ivan Le 2/21/2011 17:22, Nuno Prista a écrit : Dear R colleagues, This seems pretty straight forward but I have been banging my head on this for some time and can't seem to find a solution suppose I have something like a1-1; a2-2; a3-3; a4-4; b1-3; b2-4 I would like to quickly assign to objects with a certain pattern, e.g., those in ls(pattern=a) a specific value, e.g., 99, without having to assign each object at a time. is there a way I can do this within a for cycle? I have tested several eval and parse statements but with no success. Regards, Nuno Prista PhD student Instituto de Oceanografia Faculdade de Ciências da Universidade de Lisboa Campo Grande, Lisboa, 1749-016 Lisboa, Portugal __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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/1525_8_1.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.
[R] Generating uniformly distributed correlated data.
Hi list: Here is one approach that will generate two uniformly distributed variables with a correlation of 0.5 -- N - 1000 x - sample(1:9,N,replace=TRUE) uni - runif(N) y - (uni0.5)*x+(uni0.5)*sort(x) (y.freq - table(y) ) y 1 2 3 4 5 6 7 8 9 123 114 113 105 126 102 110 95 112 chisq.test(y.freq) Chi-squared test for given probabilities data: y.freq X-squared = 6.812, df = 8, p-value = 0.557 cor(x,y) [1] 0.5418051 It seems obvious that the correlation can be adjusted by changing 0.5 to r and 1-r, respectively in the assigment -- y - (uni0.5)*x+(uni0.5)*sort(x) It is worth reflecting about whether this algorithm reflects the real-world process you wish to simulate. Larry Hotchkiss On 2/21/2011 6:00 AM, r-help-requ...@r-project.org wrote: Generating uniformly distributed correlated data. Message: 1 Date: Sun, 20 Feb 2011 12:36:43 +0100 From: Enrico Schumannenricoschum...@yahoo.de To: =?iso-8859-1?Q?'S=C3=B8ren_Faurby'?= soren.fau...@biology.au.dk Cc:r-help@r-project.org Subject: Re: [R] Generating uniformly distributed correlated data. Message-ID:7C892818271C43E08DCFD8277CBD01CB@EnricosPC Content-Type: text/plain; charset=iso-8859-1 maybe this helps http://comisef.wikidot.com/tutorial:correlateduniformvariates regards enrico -Urspr?ngliche Nachricht- Von:r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von S??ren Faurby Gesendet: Sonntag, 20. Februar 2011 03:18 An:r-help@r-project.org Betreff: [R] Generating uniformly distributed correlated data. I wish to generate a vector of uniformly distributed data with a defined correlation to another vector The only function I have been able to find doing something similar is corgen from the library ecodist. The following code generates data with the desired correlation to the vector x but the resulting vector y is normal and not uniform distributed library(ecodist) x- runif(105) y- corgen(x=x, r=.5)$y Do anyone know a similar function generating uniform distributed data or a way of transforming y to the desired distribution while keeping the correlation between x and y Kind regards, Soren __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] assign value to multiple objects with a given ls pattern
If instead of having a1, a2, etc. as global variables you put them into a list then this becomes simple. The general rule is that if you ever want to do the same (or similar) think to a set of variable, then they should not have been separate variables, but part of a bigger one. Lists work well for this (there are other possibilities as well, but lists cover most of the cases). -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Nuno Prista Sent: Monday, February 21, 2011 9:22 AM To: r-help@R-project.org Subject: [R] assign value to multiple objects with a given ls pattern Dear R colleagues, This seems pretty straight forward but I have been banging my head on this for some time and can't seem to find a solution suppose I have something like a1-1; a2-2; a3-3; a4-4; b1-3; b2-4 I would like to quickly assign to objects with a certain pattern, e.g., those in ls(pattern=a) a specific value, e.g., 99, without having to assign each object at a time. is there a way I can do this within a for cycle? I have tested several eval and parse statements but with no success. Regards, Nuno Prista PhD student Instituto de Oceanografia Faculdade de Ciências da Universidade de Lisboa Campo Grande, Lisboa, 1749-016 Lisboa, Portugal __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] assign value to multiple objects with a given ls pattern
As I partially showed, I guess that the problem of assigning the value 99 to any object in the workspace can be dealt with a more precise regular expression. Maybe that would do: ls(pattern=^a[1-9]$) or ls(pattern=^a[0-9]+$) In any case, I agree that alternatives are better Ivan Le 2/21/2011 17:55, Ista Zahn a écrit : Hi Nuno, Yes, you can do for(i in ls(pattern=a)) { assign(i, 99) } but honestly this is a bad idea. It will try to assign the value of 99 to any object in your workspace that contains an a, which sounds really scary to me. Better I think to use a list: ab.list- list(a1=1, a2=2, a3=3, a4=4, b1=3, b2=4) ab.list[grep(a, names(ab.list))]- 99 Or even just a named vector ab.vector- c(a1=1, a2=2, a3=3, a4=4, b1=3, b2=4) ab.vector[grep(a, names(ab.vector))]- 99 Best, Ista On Mon, Feb 21, 2011 at 4:22 PM, Nuno Pristanmpri...@fc.ul.pt wrote: Dear R colleagues, This seems pretty straight forward but I have been banging my head on this for some time and can't seem to find a solution suppose I have something like a1-1; a2-2; a3-3; a4-4; b1-3; b2-4 I would like to quickly assign to objects with a certain pattern, e.g., those in ls(pattern=a) a specific value, e.g., 99, without having to assign each object at a time. is there a way I can do this within a for cycle? I have tested several eval and parse statements but with no success. Regards, Nuno Prista PhD student Instituto de Oceanografia Faculdade de Ciências da Universidade de Lisboa Campo Grande, Lisboa, 1749-016 Lisboa, Portugal __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- 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/1525_8_1.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] Problem with writing a file in UTF-8
This is asking FAR too much under Windows, which has no UTF-8 locales. In particular, cat() (on which write() is based) will convert to the native locale, even if you manage to input the string as an R UTF-8 string. And conversion is a OS service, so you are getting the conversion Windows sees as appropriate. The best way around this is to use a more capable OS. But you can do e.g. x - '\u0171\u0141' # ensure this really is űŁ writeLines(x, 'foo', useBytes=TRUE) # ensure no conversion On Mon, 21 Feb 2011, Matt Shotwell wrote: Thomas, I wasn't able to reproduce your finding. The last two characters in my 'out.txt' file were just as expected. But, I'm in an UTF-8 locale. Your locale affects the encoding of characters on your platform. If you're not in a UTF-8 locale, then characters are converted from your native encoding to UTF-8 (when you specify encoding=UTF-8). In the process of conversion, it's possible to lose information. You can test whether there is a loss (or a change rather) when R writes these characters like so: # what does űŁ look like in binary (hex)? raw_before - charToRaw(űŁ) # write 'out.txt' as before out - file(description=out.txt, open=w, encoding=UTF-8) write(x=űŁ, file=out) close(con=out) # read in the two characters out - file(description=out.txt, open=r, encoding=UTF-8) raw_after - charToRaw(readChar(con=out, nchars=2)) close(con=out) # compare the raw representations identical(raw_before, raw_after) This test passes on my machine. But, there's also the question of whether these characters made it onto R-help list unaltered. Also, please include the result of sessionInfo() in you subsequent messages. Best, Matt sessionInfo() R version 2.11.1 (2010-05-31) i686-pc-linux-gnu locale: [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C [3] LC_TIME=en_US.utf8LC_COLLATE=en_US.utf8 [5] LC_MONETARY=C LC_MESSAGES=en_US.utf8 [7] LC_PAPER=en_US.utf8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base On Thu, 2011-02-17 at 13:54 -0800, tpklein wrote: Hello, I am working with a data frame containg character strings with many special symbols from various European languages. When writing such character strings to a file using the UTF-8 encoding, some of them are converted in a strange way. See the following example, run in R 2.12.1 on Windows 7: out - file( description=out.txt, open=w, encoding=UTF-8) write( x=äöüßæűŁ, file=out ) close( con=out ) The last two symbols in the character string are converted to uL while all other characters are not changed (which is what I want). How to explain this? Does it have something to do with my locale? And is there a way to work around this problem? -- Any help would be greatly appreciated. Thomas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] output selectively change the font
Dear brainy R users, I need to output a matrix, with two colors , meaning some elements using different color I normally use write.table(table.m, file=table file name.csv, sep=,), how could I pass the index for the color ? Many thanks yan ** This email and any files transmitted with it are confide...{{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] OT: R Square Help (this debate again, i know!) and The Experimental Unit
Dieter (et. al.) I am weak and therefore yield to temptation... This is OT for R, so stop reading and discard now if you're looking for real R Help. (see also one inline coment below) Mount soapbox; begin rant / In addition to the points you made/alluded to, may I also suggest that confusion about the nature of The Experimental Unit results in a lot of garbage/non-replicable scientific results seemingly buttressed by officially sanctioned statistics. You can google the erm, but many of the results are not definitions, but examples from which one is (presumably) supposed to inductively infer the definition. Here is the one that I think is gfermane: Experimental Unit: The smallest division of the experimental material that can receive separate treatments. There is a brief but (imo) pertinent discussion of what this means in the context of food science here: http://ift.confex.com/ift/2005/techprogram/paper_27139.htm The importance of this idea -- never, insofar as I can tell, discussed in statistics texts -- is that it is the unit over which replication must occur for statistical calculations to provide scientifically meaningful estimates of experimental variability. Confusion or ignorance of the experimental unit means that statistically significant (or if you prefer, Bayesian versions thereof) results are based on pseudo-replicates that underestimate the true experimental variability and therefore lead to non-replicable results. A widespread example of this phenomenon with which I'm familiar occurs in animal experiments (think mice) in which several animals are housed together in a single cage, either for cost or animal care reasons (if the animals are social and need to live that way). So suppose one has, say 6 mice per cage, and one treats 2 cages = 12 mice with some sort of drug (e.g., these might be genetically engineered mice that express a human disease like diabetes,say) and 2 cages = 12 mice that are negative controls (receive a placebo). For logistical and perhaps scientific reasons all mice in a cage must receive the same treatment. So the experimental unit is the cage. The 6 mice in a cage are basically repeated measurements of the experimental unit.But have a look at the biological literature to see how such data are typically analyzed -- you'll most likely see 22 df for replicates. Of course mixed or other hierarchical models are out of the question with only 2 df for cage to cage variability. Do cage level effects really exist? Ask folks involved in such experiments about how a single overly aggressive animal (say) in a cage can skew results. To be fair, many scientists I know understand these issues, at least intuitively. That is, they are well aware how cage effects can screw things up. Nevertheless, they still worship at the P-value altar without understanding the nature of the bias. / end rant; dismount soapbox. Due to the nature of my comments, vigorous and even impolite disagreement is acceptable -- as are private, offlist fusillades. I will not try to defend myself on list, though I will publicly acknowledge any error. Cheers, Bert Surprisingly, it's mostly the not-so-top papers that cause problems here. When Lancet, New English or BMJ reject some statistical argument, they have good reasons. Oh? Data to support this assertion, please. Dieter -- Bert Gunter Genentech Nonclinical Biostatistics (But these are my own views, of course, not that of my organization). __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] difference in pairs ?
Dear all, I want to perform paired Wilcoxon signed ranks test on my data. I have pairs defined by ID and TIME variables. How can I calculate difference in variables q1, q2 in each pair? TIME ID q1 q2 1 1187 3 2 1 1706 3 3 1 1741 2 4 2 1187 3 2 2 1706 3 3 2 1741 2 4 Please, any clue! :) -- ** Vlatka Matkovic Puljic +32/ 485/ 453340 [[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] Interpreting the example given by Prof Frank Harrell in {Design} validate.cph
Thank you very much Prof Harrell! Sorry that I am new to this forum, and so ain't familiar with how to post message appropriately. I repeated the same procedure using a dataset from the {survival} package. This time I used the {rms} package, and 100 bootstrap samples: library(rms) library(survival) attach(colon) S-Surv(time,status) f-cph(S~factor(obstruct)+factor(perfor)+factor(adhere)+factor(differ)+factor(extent)+factor(node4),x=T,y=T,surv=T) # no stratification set.seed(110221) validate(f,method=b,B=100,dxy=T,pr=F) index.orig trainingtest optimism index.corrected n Dxy -0.2918 -0.2932 -0.2861 -0.0070 -0.2847 100 R20.1145 0.1191 0.1104 0.0088 0.1057 100 Slope 1. 1. 0.9626 0.0374 0.9626 100 D 0.0170 0.0178 0.0164 0.0014 0.0156 100 U-0.0002 -0.0002 0.0001 -0.0003 0.0001 100 Q 0.0172 0.0179 0.0162 0.0017 0.0155 100 g 0.5472 0.5590 0.5348 0.0242 0.5230 100 f2-cph(S~factor(obstruct)+factor(perfor)+factor(adhere)+factor(differ)+factor(extent)+factor(node4)+strat(rx),x=T,y=T,surv=T) # with stratification set.seed(110221) validate(f2,method=b,B=100,dxy=T,pr=F,u=30) index.orig training test optimism index.corrected n Dxy 0.1567 0.1966 0.1826 0.0140 0.1426 100 R20.1154 0.1191 0. 0.0081 0.1073 100 Slope 1. 1. 0.9720 0.0280 0.9720 100 D 0.0203 0.0210 0.0195 0.0015 0.0188 100 U-0.0002 -0.0002 0.0001 -0.0003 0.0001 100 Q 0.0205 0.0212 0.0193 0.0018 0.0186 100 g 0.5523 0.5591 0.5402 0.0189 0.5333 100 The same situation happened again. The Dxy's were all in opposite directions. In fact my case is even worse than these examples - the Dxy for non-stratified model was -0.54 but the Dxy for stratified model was almost +0.6; and the bootstrap validated R^2 was even negative!! But..why does this happen?? Thanks a lot, Vikki -- View this message in context: http://r.789695.n4.nabble.com/Interpreting-the-example-given-by-Prof-Frank-Harrell-in-Design-validate-cph-tp3316820p3317743.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] Conditional sum
I am still struggling (I'm an R novice). Basically I just want to sum the values per group if the year condition is met. I have the feeling that using a loop would work, but I am not really familiar with loops. Something like this? for(DF$C in 1:length(DF$C)) { DF-which(DF$yearDF[i,year]) DF$D-ave(DF$C,DF$group,FUN = function(x) sum(x)) } It doesn't work and probably looks awful, so can someone point me in the right direction? Thanks! M mathijsdevaan wrote: Dieter Menne wrote: In steps following the thinking order. You could shorten this considerably. I slightly changed you column names to more speakable ones. Dieter DF = data.frame(read.table(textConnection(group year C 1 b1 1999 0.25 2 c1 1999 0.25 3 d1 1999 0.25 4 a2 1999 0.25 5 c2 1999 0.25 6 d2 1999 0.25 7 a3 1999 0.25 8 b3 1999 0.25 9 d3 1999 0.25 10 a4 1999 0.25 11 b4 1999 0.25 12 c4 1999 0.25 13 b1 2001 0.5 14 a2 2001 0.5 15 b1 2004 0.33 16 c1 2004 0.33 17 a2 2004 0.33 18 c2 2004 0.33 19 a3 2004 0.33 20 b3 2004 0.33 21 d2 1980 0.4 22 a3 1980 0.4 23 b4 1981 0.4 24 c1 1981 0.4),head=TRUE)) by(DF,DF$group, FUN = function(x){ print(str(x)) }) # Looks like we should order... # Other solutions are possible, but ordering all first might (not tested) # be the most efficient way for large sets DF = DF[order(DF$group,DF$year),] # Let's try cumsum on each group by(DF,DF$group, FUN = function(x){ cumsum(x$C) }) # That's not exactly your defininition of prior # correct for first value by(DF,DF$group, FUN = function(x){ cumsum(x$C)-x$C }) # Now the data are in right order, make vector of result DF$D = unlist(by(DF,DF$group, FUN = function(x){ cumsum(x$C) })) # You could sort by row names now to restore the old order Thanks for the quick response, but it doesn't do the trick. There are two problems: 1. The ith value of the newly created variable DF$D also includes the ith value of DF$C (this problem is easily solved by DF$D = DF$D-DF$C.) 2. If group i in DF$group appears more than once in year t, the value of the second observation of that group exceeds (includes) the value of the first observation. Example (group b1 and a2 in 2001 are duplicated): DF = data.frame(read.table(textConnection(group year C 1 b1 1999 0.25 2 c1 1999 0.25 3 d1 1999 0.25 4 a2 1999 0.25 5 c2 1999 0.25 6 d2 1999 0.25 7 a3 1999 0.25 8 b3 1999 0.25 9 d3 1999 0.25 10 a4 1999 0.25 11 b4 1999 0.25 12 c4 1999 0.25 13 b1 2001 0.5 14 a2 2001 0.5 15 b1 2004 0.33 16 c1 2004 0.33 17 a2 2004 0.33 18 c2 2004 0.33 19 a3 2004 0.33 20 b3 2004 0.33 21 d2 1980 0.4 22 a3 1980 0.4 23 b4 1981 0.4 24 c1 1981 0.4 25 b1 2001 0.5 26 a2 2001 0.5),head=TRUE)) by(DF,DF$group, FUN = function(x){print(str(x))}) DF = DF[order(DF$group,DF$year),] by(DF,DF$group, FUN = function(x){cumsum(x$C)}) by(DF,DF$group, FUN = function(x){cumsum(x$C)-x$C}) DF$D = unlist(by(DF,DF$group, FUN = function(x){cumsum(x$C)})) DF$D = DF$D-DF$C -- View this message in context: http://r.789695.n4.nabble.com/Conditional-sum-tp3315163p3317573.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] Bootstraps standard error
Hi R-users, I've found the error In these rows: # Model (a) testtemp - lm.bp(doctorco~sex+age+income, prescrib~sex+age+income, data=bootdata) betafound - c(testtemp$beta,testtemp$beta3) results[i,] - betafound betafound must to be equal to: betafound - c(testtemp$beta1,testtemp$beta2,testtemp$beta3) ... Thanks a lot to everyone... -- View this message in context: http://r.789695.n4.nabble.com/Bootstraps-standard-error-tp3313322p3317675.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] panel data
Hello I have a question about how to regress panel data in R. What are the appropriate commands and preparations that need to be made when regressing panel data? /Andreas Otterstrom [[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] Species accumulation curves with differential sampling effort
Hello! I'm a PhD student working with coral reef fish diversity in Mexico. I want to do species accumulation curves but I have differential sampling effort for each sample. Do you know or have developed an R script that consider the differential effort of each sample? PRIMER and other programs use each pack of species as a replica without the possibility of telling the program that the first group of species (sample) was collected during a 30 minutes dive and the second group (sample) was taking after 60 minutes dive and so on. I would really appreciate any kind of help! Best regards, Vanessa Francisco [[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] NPMC - replacement has 0 rows (multiple comparisons)
On 2011-02-20 20:02, Karmatose wrote: I'm trying to include multiple variables in a non-parametric analysis (hah!). So far what I've managed to figure out is that the NPMC package from CRAN MIGHT be able to do what I need... Also look at packages nparcomp and coin (+ multcomp). Both use the formula interface. For the coin+multcomp combo look at the example at the bottom of the help page for kruskal_test. Regards, Mark. -- View this message in context: http://r.789695.n4.nabble.com/NPMC-replacement-has-0-rows-multiple-comparisons-tp3316788p3317629.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] (no subject)
What is plot.new? and how can i get it to work so i can load other data? library(splancs) area = 6*4 lambda = 1.5 N = rpois(1,lambda*area) u = runif(N,-2,4) v = runif(N,0,4) plot(u,v,asp=1) h = chull(u,v) h = c(h,h[1]) plot(u[h],v[h],1,asp=1) Error in plot.xy(xy, type, ...) : invalid plot type '1' plot(u[h],v[h],l,asp=1) points(u,v) Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet pts=as.points(u,v) pointmap(pts) hullpoly=as.points(u[h],v[h]) polymap(hullpolly,add=TRUE) Error in xy.coords(x, y) : object 'hullpolly' not found help(polymap) help(plot.net) No documentation for 'plot.net' in specified packages and libraries: you could try '??plot.net' help(plot.new) plot(u[h],v[h],l,asp=1) plot.new(u,v) Error in plot.new(u, v) : unused argument(s) (u, v) plot.new() points(u,v) Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet plot.new(u,v) Error in plot.new(u, v) : unused argument(s) (u, v) plot.new(xy.coords(x,y)) Error in plot.new(xy.coords(x, y)) : unused argument(s) (xy.coords(x, y)) plot.new(uv.coords(u,v)) Error in plot.new(uv.coords(u, v)) : unused argument(s) (uv.coords(u, v)) plot.new - function() + {} { } NULL plot.new - function() + { } { } NULL { for } Error: unexpected '}' in { for } area = 60*20 lambda = 2 N = rpois(1,lambda*area) u = runif(N,20,40) v = runif(N,-10,10) plot(u,v,asp=1) plot(u,v,asp=1) u = runif(N,20,40) v = runif(N,-10,10) plot(u,v,asp=1) plot(u,v,asp=1) u = runif(N,20,40) v = runif(N,-10,10) plot(u,v,asp=1) u = runif(N,20,40) v = runif(N,-10,10) plot(u,v,asp=1) h = chull(u,v) h = c(h,h[1]) plot(u[h],v[h],l,asp=1) points(u,v) Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet pts=as.points(u,v) pointmap(pts) hullpoly=as.points(u[h],v[h]) polymap(hullpolly,add=TRUE) Error in xy.coords(x, y) : object 'hullpolly' not found No help files found matching ‘hullpoly’ using fuzzy matching pointmap(as.points(hullpoly), add=TRUE) Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet hullpoly=as.points(u[h],v[h]) polymap(hullpoly$poly, add=TRUE) Error in hullpoly$poly : $ operator is invalid for atomic vectors polymap(hullpoly,add=TRUE) Error in polygon(poly, ...) : plot.new has not been called yet plot.new() NULL par(new=TRUE) Warning message: In par(new = TRUE) : calling par(new=TRUE) with no plot plot.new() NULL par(new=TRUE) Warning message: In par(new = TRUE) : calling par(new=TRUE) with no plot new.u=runif(50,20,40) new.v=ruinf(50,-10,10) Error: could not find function ruinf new.v=runif(50,-10,10) pts.in=pip(as.points(new.u,new.v),hullpoly,out=FALSE) pointmap(pts.in,col=red,add=TRUE) Error in plot.xy(xy.coords(x, y), type = type, ...) : plot.new has not been called yet __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] plot numerous functions in one figure with different values of x per function
To the more experienced R users, I am not a professional programmer so please excuse me if my questions seem naive. I have only begun using R to solve some problems and I'm already regretting it 1. I am trying to plot different functions in the same figure. The first function f(x)= sin(x)+(pi/4) , -2pi=x=2pi the second function g(x) = {sin(x), 0 = x = pi or −2pi = x = -pi {-pi/4, elsewhere my code is: x-seq(from=-2*pi,to=2*pi,length=1000) fx- (sin(x)+(pi/4)) plot(x,fx,type=l,lty=1) x2- seq(from=0,to=pi) x3- seq(from=-2*pi,to=-pi) gx-(sin(x2 | x3) + (-pi/4)) lines(x,gx,lty=2) Error in xy.coords(x, y) : 'x' and 'y' lengths differ it plots the first function but when I try to plot the second function it displays the error x,y coordinates differ. I assume this is because I am using different values for x in the first and second functions? any ideas will be appreciated. -- View this message in context: http://r.789695.n4.nabble.com/plot-numerous-functions-in-one-figure-with-different-values-of-x-per-function-tp3317784p3317784.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] question about generics
?InternalMethods ?S3groupGeneric ?S4groupGeneric -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Erin Hodgess Sent: Friday, February 18, 2011 10:45 PM To: R help Subject: [R] question about generics Dear R People: Is there a way to determine which functions are generics, please? I looked for something like is.Generic, but no luck. Thanks in advance! Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@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. message may contain confidential information. If you are not the designated recipient, please notify the sender immediately, and delete the original and any copies. Any use of the message by you is prohibited. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Mutiplying a data frame to a list
Hi R community, I have a question I'm sure is very simple for most of you. I have a list, with each element being a matrix and the names of the elements are numbers (like 1,3,...). I can extract the matrices and the names individually. Now, I want to multiply each of the names to the individual list matrices (after converting to numbers of course). I could use a for loop, but the very reason I have this list is that I was trying to avoid loops (using lapply). So, turning to one now could defeat the whole purpose. Thanks in advance, -- Thanks, Rohit Mob: 91 9819926213 [[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] wrong lines in auto.key xyplot
Hi all, I'm having a problem with the auto.key function in xyplot. This is simplified version of my data: q Weeks Dq -10 1 2.1122 1 1 1.9904 10 1 1.739 -10 3 2.5942 1 3 1.9714 10 3 1.8745 -10 5 2.5743 1 5 1.9523 10 5 1.7976 -10 7 2.4418 1 7 1.9741 10 7 1.8868 -10 9 2.3255 1 9 1.983 10 9 1.9242 -10 11 2.303 1 11 1.9847 10 11 1.9342 So I changed the symbols an lines styles and generated my graphic trellis.par.set(superpose.symbol=list(pch=c(0,1,2,3,4,5,6,8,15,16))) trellis.par.set(superpose.symbol=list(col=c(rep(black,11 trellis.par.set(superpose.symbol=list(cex=c(rep(0.6,11 trellis.par.set(superpose.line=list(col=c(rep(black,11 trellis.par.set(superpose.line=list(lty=c(1,1,1,2,2,2,2,3,3,3,3))) xyplot(Dq~q , data =zq, groups=Weeks, type=o, auto.key=list(x=.7,y=.9,title=Weeks,cex.title=1, points=TRUE, lines=TRUE)) the graphic showed perfectly, but in the legend the lines have any other style. What I am doing wrong? Any help would be greatly appreciated. Leonardo A. Saravia Instituto de Ciencias Universidad Nacional de General Sarmiento __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Equivalent of log file in R?
Thanks, Ista! I looked at sink() and it looks like it might work. However, it seems as though you need to use it with the print command. I have a lot of regression output that I would like to store in a log file. How do I use sink with that? Best, Tatyana --- Tatyana Deryugina MIT PhD Student, Department of Economics MIT Energy Initiative Energy Fellow (925) 349 - 8999 (cell) On Mon, Feb 21, 2011 at 11:23 AM, Ista Zahn iz...@psych.rochester.edu wrote: Hi Tatyana, I think you are looking for ?sink Best, Ista On Mon, Feb 21, 2011 at 2:11 PM, Tatyana Deryugina tatya...@mit.edu wrote: Hi everyone, Is there a way to make R save the workspace output (just the results, not the objects themselves) as you go? I'm running analysis that takes a long time to run and I want to be able to interrupt it without losing all the output to date. Is there an alternative to putting save.image() commands after every couple lines of code? Best, Tatyana __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.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] output selectively change the font
If I understand you correctly - you can add a column to the output table for your color variable?. Otherwise, if you need to write the *text* in a different color, that's probably something you want to do outside of R... Rob Tirrell On Mon, Feb 21, 2011 at 10:14, Yan Jiao y.j...@ucl.ac.uk wrote: Dear brainy R users, I need to output a matrix, with two colors , meaning some elements using different color I normally use write.table(table.m, file=table file name.csv, sep=,), how could I pass the index for the color ? Many thanks yan ** This email and any files transmitted with it are confide...{{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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] r-square for cluster
Dear forumities, It's seem that there is no straight forward way to calculate R2 of a cluster solution in R. So, I would like to know if I'm right when calculating a R2-like statistic for a given clustering solution. In fact, I have different cluster solution for a given set of data. I would like to know which cluster solution gives the highest R2. My data (5 variables) are scaled to a 0 mean and 1 std. This is the command lines I used to calculate R2 for 1 cluster solution: SSTot - (nrow(grid40km.datascale)-1)*sum(apply(grid40km.datascale,2,var)) # total sum of square SStot_grid40km - NULL for (i in 1:22) # there is 22 clusters { data_group - subset(grid40km.data,grid40km.cluster==i, select=c(X1, X2, X3, X4, X5)) SSgroup - (nrow(data_group-1)*sum(apply(data_group,2,var))) # SS for all variables for a given cluster SStot_grid40km=append(SStot_grid40km, SSgroup,after=length(SStot_grid40km)) } ssw_grid40km = sum(SStot_grid40km) #withinSS (??) as the sum of SS for all clusters ssbetween_grid40km = SSTot-ssw_grid40km RSQ_grid40km2 = ssbetween_grid40km/SSTot # R-square Am I right? Does this correspond to SAS's R2? Many thanks, Yan Ressources Naturelles Canada Service Canadien des Forêts - Centre de Foresterie des Laurentides 1055, rue du PEPS CP 10380, Succ. Ste-Foy Québec, QC, G1V 4C7 Tel. : +001 418 649-6859 Fax : +001 418 648-5849 email : yan.boulan...@nrcan.gc.ca [[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] Reg : help using nnet parameters
Hi R-helpers, I am using nnet package for Neural Network. I have understood almost all the basic parameters and the way they are used. I would like to know how to give the followinf parameters as input. 1.weights 2.wts 3.mask 4.contrasts 5.subset 6.For which kind of datasets we can set entropy and censored? Can any of you provide an example which has all these input parameters mentioned so that i can get a clear idea on this.I tried giving them as vectors, matrices .But since i do not know how they are used internally, i am unable to relate them to the results obtained.I am stuck here. Thanks in advance for your help. Regards, Raji -- View this message in context: http://r.789695.n4.nabble.com/Reg-help-using-nnet-parameters-tp3317616p3317616.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with writing a file in UTF-8
Windows is perfectly capable of handling UTF-8, but its native encoding is UTF-16LE. Applications on Windows are meant to work with text data in the UTF-16LE encoding. If it needs to be converted to or from another encoding then there are services that do this (which work). There are countless programs on Windows that are 100% Unicode compliant. I don't know how R holds text data, but perhaps it holds it as char* as do Python, Perl etc. and all the other such languages that have problems doing Unicode properly on Windows. Basically I don't buy the idea that Windows can't do Unicode. It's supported Unicode since NT was released back in 1991. That's 20 years ago now. It's just too easy to blame it on Windows but it doesn't ring true. David Heffernan. On Feb 21, 5:29 pm, Prof Brian Ripley rip...@stats.ox.ac.uk wrote: This is asking FAR too much under Windows, which has no UTF-8 locales. In particular, cat() (on which write() is based) will convert to the native locale, even if you manage to input the string as an R UTF-8 string. And conversion is a OS service, so you are getting the conversion Windows sees as appropriate. The best way around this is to use a more capable OS. But you can do e.g. x - '\u0171\u0141' # ensure this really is űŁ writeLines(x, 'foo', useBytes=TRUE) # ensure no conversion On Mon, 21 Feb 2011, Matt Shotwell wrote: Thomas, I wasn't able to reproduce your finding. The last two characters in my 'out.txt' file were just as expected. But, I'm in an UTF-8 locale. Your locale affects the encoding of characters on your platform. If you're not in a UTF-8 locale, then characters are converted from your native encoding to UTF-8 (when you specify encoding=UTF-8). In the process of conversion, it's possible to lose information. You can test whether there is a loss (or a change rather) when R writes these characters like so: # what does űŁ look like in binary (hex)? raw_before - charToRaw(űŁ) # write 'out.txt' as before out - file(description=out.txt, open=w, encoding=UTF-8) write(x=űŁ, file=out) close(con=out) # read in the two characters out - file(description=out.txt, open=r, encoding=UTF-8) raw_after - charToRaw(readChar(con=out, nchars=2)) close(con=out) # compare the raw representations identical(raw_before, raw_after) This test passes on my machine. But, there's also the question of whether these characters made it onto R-help list unaltered. Also, please include the result of sessionInfo() in you subsequent messages. Best, Matt sessionInfo() R version 2.11.1 (2010-05-31) i686-pc-linux-gnu locale: [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C [3] LC_TIME=en_US.utf8 LC_COLLATE=en_US.utf8 [5] LC_MONETARY=C LC_MESSAGES=en_US.utf8 [7] LC_PAPER=en_US.utf8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base On Thu, 2011-02-17 at 13:54 -0800, tpklein wrote: Hello, I am working with a data frame containg character strings with many special symbols from various European languages. When writing such character strings to a file using the UTF-8 encoding, some of them are converted in a strange way. See the following example, run in R 2.12.1 on Windows 7: out - file( description=out.txt, open=w, encoding=UTF-8) write( x=äöüßæűŁ, file=out ) close( con=out ) The last two symbols in the character string are converted to uL while all other characters are not changed (which is what I want). How to explain this? Does it have something to do with my locale? And is there a way to work around this problem? -- Any help would be greatly appreciated. Thomas __ r-h...@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595 __ r-h...@r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guidehttp://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] difference in pairs ?
Hi: Assuming dd is the name of your data frame, dd$diff - with(dd, q2 - q1) dd TIME ID q1 q2 diff 11 1187 3 2 -1 21 1706 3 30 31 1741 2 42 42 1187 3 2 -1 52 1706 3 30 62 1741 2 42 is one way to do it. HTH, Dennis On Mon, Feb 21, 2011 at 11:05 AM, Vlatka Matkovic Puljic v.matkovic.pul...@gmail.com wrote: Dear all, I want to perform paired Wilcoxon signed ranks test on my data. I have pairs defined by ID and TIME variables. How can I calculate difference in variables q1, q2 in each pair? TIME ID q1 q2 1 1187 3 2 1 1706 3 3 1 1741 2 4 2 1187 3 2 2 1706 3 3 2 1741 2 4 Please, any clue! :) -- ** Vlatka Matkovic Puljic +32/ 485/ 453340 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Equivalent of log file in R?
Hi Tatyana, Well, most things are implicitly printed. For the most part you should be able to just sink(file=my_R_log.txt) and write your r-code as you normally would. Anything that would usually be printed to the screen is instead sent to my_R_log.txt instead, including things that are implicitly printed. Note that you should do sink() when done to close the connection. Just give it a try and see if it does what you want. If not report back and tell us what you want that sink() is not doing for you. Best, Ista On Mon, Feb 21, 2011 at 6:26 PM, Tatyana Deryugina tatya...@mit.edu wrote: Thanks, Ista! I looked at sink() and it looks like it might work. However, it seems as though you need to use it with the print command. I have a lot of regression output that I would like to store in a log file. How do I use sink with that? Best, Tatyana --- Tatyana Deryugina MIT PhD Student, Department of Economics MIT Energy Initiative Energy Fellow (925) 349 - 8999 (cell) On Mon, Feb 21, 2011 at 11:23 AM, Ista Zahn iz...@psych.rochester.edu wrote: Hi Tatyana, I think you are looking for ?sink Best, Ista On Mon, Feb 21, 2011 at 2:11 PM, Tatyana Deryugina tatya...@mit.edu wrote: Hi everyone, Is there a way to make R save the workspace output (just the results, not the objects themselves) as you go? I'm running analysis that takes a long time to run and I want to be able to interrupt it without losing all the output to date. Is there an alternative to putting save.image() commands after every couple lines of code? Best, Tatyana __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.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] Species accumulation curves with differential sampling effort
On Feb 21, 2011, at 12:38 PM, Vanessa Francisco wrote: Hello! I'm a PhD student working with coral reef fish diversity in Mexico. Are you hiring? I want to do species accumulation curves but I have differential sampling effort for each sample. Do you know or have developed an R script that consider the differential effort of each sample? PRIMER ... not familiar with that package. and other programs use each pack of species as a replica without the possibility of telling the program that the first group of species (sample) was collected during a 30 minutes dive and the second group (sample) was taking after 60 minutes dive and so on. If you were using a glm model with a a log(poisson) link, then adding an offset term that was equal to log(time) should sensibly incorporate the information for the differential effort. I would really appreciate any kind of help! Best regards, Vanessa Francisco -- 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] Mutiplying a data frame to a list
Rohit- If I understand you correctly, and your list's name is mylist, then mapply('*',mylist,as.numeric(names(mylist))) will do what you want. In the future, please provide a reproducible example. - Phil Spector Statistical Computing Facility Department of Statistics UC Berkeley spec...@stat.berkeley.edu On Mon, 21 Feb 2011, Rohit Pandey wrote: Hi R community, I have a question I'm sure is very simple for most of you. I have a list, with each element being a matrix and the names of the elements are numbers (like 1,3,...). I can extract the matrices and the names individually. Now, I want to multiply each of the names to the individual list matrices (after converting to numbers of course). I could use a for loop, but the very reason I have this list is that I was trying to avoid loops (using lapply). So, turning to one now could defeat the whole purpose. Thanks in advance, -- Thanks, Rohit Mob: 91 9819926213 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.