Re: [R] Finicky factor comparison operators
MIchael - Thanks for your insight. I think I see where you're going with this. To make '==' comparisons for subsetting against an ordered factor, I've had to create a lookup table for all possible values I'd ever want to compare against (all dates covered by the quarters in question, in this case) that maps into the ordered factors values. This is wrapped by a function that returns an ordered factor, which allows me to write: /(opps$close_quarter == which.quarter.end(2010-10-20)/ Otherwise if I try to create an ordered factor from the constant just for the purposes of comparison, the error tells me that ordered factors from different sources cannot be compared: /(opps$close_quarter == factor(2007-10-20, ordered=T) Error in Ops.factor(factor(2007-10-30, ordered = T), quarter.factors[1, 2]) : level sets of factors are different/ That makes sense, since internally factors are integers -- enums in other terms. But what I want to avoid -- and what I don't see as necessary is explicitly coercing the terms to a common representation that mimics their print form: /as.character(2007-10-20)== as.character(factor(2007-10-20, ordered=T)) / I don't think there should be confusion since the conversion to print form is obvious -- but it does conflict with the conversion rules for creating vectors by c(): /c(2011-10-20, factor(2007-10-20, ordered=T)) [1] 2011-10-20 1 / where the factor is converted to its internal enum representation, then to a character. Having given this some more thought to what motivated the original question, one could use which() to invert the factor's levels vector: /which(2008-04-30 == levels(quarter.factors[,2])) [1] 3 / Its still not clear to me what exactly are the implicit conversion rules for factors. Cheers -jm / -- View this message in context: http://r.789695.n4.nabble.com/Finicky-factor-comparison-operators-tp4400377p4403352.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] ggplot rank stack bar automatically.
df - structure(c(106487, 495681, 1597442, 2452577, 2065141, 2271925, 4735484, 3555352, 8056040, 4321887, 2463194, 347566, 621147, 1325727, 1123492, 800368, 761550, 1359737, 1073726, 36, 53, 141, 41538, 64759, 124160, 69942, 74862, 323543, 247236, 112059, 16595, 37028, 153249, 427642, 1588178, 2738157, 2795672, 2265696, 11951, 33424, 62469, 74720, 166607, 404044, 426967, 38972, 361888, 1143671, 1516716, 160037, 354804, 996944, 1716374, 1982735, 3615225, 4486806, 3037122, 17, 54, 55, 210, 312, 358, 857, 350, 7368, 8443, 6286, 1750, 7367, 14092, 28954, 80779, 176893, 354939, 446792, 3, 69911, 53144, 29169, 18005, 11704, 13363, 18028, 46547, 14574, 8954, 2483, 14693, 25467, 25215, 41254, 46237, 98263, 185986), .Dim = c(19, 5), .Dimnames = list(c(1820-30, 1831-40, 1841-50, 1851-60, 1861-70, 1871-80, 1881-90, 1891-00, 1901-10, 1911-20, 1921-30, 1931-40, 1941-50, 1951-60, 1961-70, 1971-80, 1981-90, 1991-00, 2001-06), c(Europe, Asia, Americas, Africa, Oceania))) df.m - melt(df) df.m - rename(df.m, c(X1 = Period, X2 = Region)) df.m - transform(df.m, Period = reorder(Period, -1*value)) ggplot(df.m, aes(x = Period, y = value/1e+06, fill = Region)) + geom_bar(stat = identity, position = stack) = levels(df.m$Period) [1] 1820-30 1831-40 1841-50 1851-60 1861-70 1871-80 1881-90 [8] 1891-00 1901-10 1911-20 1921-30 1931-40 1941-50 1951-60 [15] 1961-70 1971-80 1981-90 1991-00 2001-06 = I think after reordering, the levels changed, but the fact was nothing has got change _!!! I found I have many commands happen like this. especially drawing graph...ordering doesn't work... [[elided Yahoo spam]] it is crazy, R teases me. -- View this message in context: http://r.789695.n4.nabble.com/ggplot-rank-stack-bar-automatically-tp4391042p4403442.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] Basic advice for a poLCA newbie
Hi everyone / poLCA gurus, I'm facing a problem regarding conditional dependence and poLCA. Using a few data sets composed of only 1's and 2's, i'm able to do a latent class analysis for independent data columns using poLCA. The commands I use to do this are something like, bcs = read.csv(data.csv, header=T); response = data.frame(bcs[0:5]); names(response) attach(response) f = cbind(A,B,C,D,E)~1 poLCA(f,data=response, nclass=2); However, my question is, how must I modify this for conditional dependence ? assuming that some columns are dependent or each other, and that instead of just 1 and 2, dependent columns have been merged and may bear values 1,2,3 or 4, how should I modify the above command for latent class analysis ? Please advice... -- Thanks and Best Regards, Suranga [[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] Non-parametric test for repeated measures and post-hoc single comparisons in R?
Thanks, I got it! (And I think I should have googled what replicated means!) However, then Bortz, Lienert, Boehnke are imprecise, if not wrong: Der Friedman-Test setzt voraus, dass die N Individuen wechselseitig unabhängig sind, dass also nicht etwa ein und dasselbe Individuum zweimal oder mehrmals im Untersuchungsplan auftritt (p. 271). Which I (hope to) translate: The Friedman test requires the N individuals to be reciprocally independent, which means that one individual cannot occur twice or more times in the research design. *S* On 19.02.12 22:04, peter dalgaard wrote: Repeated measures means that you have multiple measurements on the same individual. Usually, the same person measured at different time points. So if you have N individuals and T times, then you can place your observations in an N*T layout. In this layout, you can have 1 observation per cell or R 1 observations. In the former case, the design is referred to as unreplicated. Got it? -pd On Feb 19, 2012, at 19:25 , saschav...@gmail.com wrote: Some attribute x from 17 individuals was recorded repeatedly on 6 time points using a Likert scale with 7 distractors. Which statistical test(s) can I apply to check whether the changes along the 6 time points were significant? set.seed( 123 ) x- matrix( sample( 1:7, 17*6, repl=T ), nrow = 17, byrow = TRUE, dimnames = list(1:17, paste( 'T', 1:6, sep='' )) ) I found the Friedman test and the Quade test for testing the overall hypothesis. friedman.test( x ) quade.test( x ) However, the R help files, my text books (Bortz, Lienert and Boehnke, 2008; Köhler, Schachtel and Voleske, 2007; both German), and the Wikipedia texts differ in what they propose as requirements for the tests. R says that data need to be unreplicated. I read 'unreplicated' as 'not-repeated', but is that right? If so, the example, in contrast, in friedman.test() appears to use indeed repeated measures. Yet, Wikipedia says the contrary that is to say the test is good especially if data represents repeated measures. The text books say either (in the same paragraph, which is very confusing). What is right? In addition, what would be an appropriate test for post-hoc single comparisons for the indication which column differs from others significantly? Bortz, Lienert, Boehnke (2008). Verteilungsfreie Methoden in der Biostatistik. Berlin: Springer Köhler, Schachtel, Voleske (2007). Biostatistik: Eine Einführung für Biologen und Agrarwissenschaftler. Berlin: Springer -- Sascha Vieweg, saschav...@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. -- Sascha Vieweg, saschav...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Run function several times changing only one argument - without a loop
Dear people, I created a plot which looks like this: Ee1-matrix(c(88,86,74,62,41),ncol=5) colnames(Ee1)-c(Lehrer,Lehrerinnen,Klassenkollegen,Klassenkolleginnen,Geschwister) par(las=1) par(mar=c(5,13,4,2)) barplot(Ee1,horiz=T,col=grey85,border=NA,xlim=c(0,100),axes=F) axis(2,pos=10, tick=T, tcl=F, labels=F,col=white) axis(2,pos=20, tick=T, tcl=F, labels=F,col=white) axis(2,pos=30, tick=T, tcl=F, labels=F,col=white) axis(2,pos=40, tick=T, tcl=F, labels=F,col=white) axis(2,pos=50, tick=T, tcl=F, labels=F,col=white) axis(2,pos=60, tick=T, tcl=F, labels=F,col=white) axis(2,pos=70, tick=T, tcl=F, labels=F,col=white) axis(2,pos=80, tick=T, tcl=F, labels=F,col=white) axis(2,pos=90, tick=T, tcl=F, labels=F,col=white) Now I would like to shorten the whole thing - namely use only one step to create the 9 axes without having to use a loop. In general, I would be interested if there is a way to use a function several times changing only one argument, without having to use a loop. Does anyone know how to do that. Marion [[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 on lattice barchart ploting
Hi friends, I have following data and would like to plot this with barchart() availble with lattice package. RsID Freqs Genotype AAA 63.636 1/1 AAA 32.727 1/2 AAA 3.636 2/2 BBB 85.965 2/2 BBB 14.035 2/1 CCC 63.158 1/1 CCC 21.053 1/2 CCC 15.789 2/2 DDD 26.786 2/2 DDD 46.429 2/1 DDD 26.786 1/1 EEE 32.759 2/2 EEE 43.103 2/1 EEE 24.138 1/1 EEE 37.931 1/1 EEE 51.724 1/2 EEE 10.345 2/2 FFF 23.214 2/2 FFF 53.571 2/1 FFF 23.214 1/1 GGG 46.552 1/1 GGG 44.828 1/2 GGG 8.621 2/2 HHH 65.517 2/2 HHH 32.759 2/1 HHH 1.724 1/1 Following is the code which I have written to get the plot. barchart(Genotype~Freqs | RsID, data=gDataFr,layout=c(4,6), main=Genotype Frequency, ylab=Genotype, xlab=Frequency, scales=list(x=list(alternating=c(1, 1, 1))), panel=function(x,y,...){ panel.fill(col=white) panel.grid(-1,0,lty=3,col=black) panel.barchart(x,y,col=c(blue,green,red),...) } ) but in plot, x-axis scale ranges from 0 to 30 though I have Freq column values in range of 0 to 100. I have tried many ways to get x-axis scale to 0 to 100, including xlim=c(1:100), but still bars in plot are not propotional to the range 0 to 100. hence can somebody let me know how get bars in the plot propotional to x-axis range 0 to 100? Regards, mlsc [[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] Run function several times changing only one argument - without a loop
Hi Marion, is all you want the white vertical lines? Then try abline(v = seq(10, 90, by = 10), col = white) instead of your axis commands. Regards, Enrico Am 20.02.2012 11:04, schrieb Marion Wenty: Dear people, I created a plot which looks like this: Ee1-matrix(c(88,86,74,62,41),ncol=5) colnames(Ee1)-c(Lehrer,Lehrerinnen,Klassenkollegen,Klassenkolleginnen,Geschwister) par(las=1) par(mar=c(5,13,4,2)) barplot(Ee1,horiz=T,col=grey85,border=NA,xlim=c(0,100),axes=F) axis(2,pos=10, tick=T, tcl=F, labels=F,col=white) axis(2,pos=20, tick=T, tcl=F, labels=F,col=white) axis(2,pos=30, tick=T, tcl=F, labels=F,col=white) axis(2,pos=40, tick=T, tcl=F, labels=F,col=white) axis(2,pos=50, tick=T, tcl=F, labels=F,col=white) axis(2,pos=60, tick=T, tcl=F, labels=F,col=white) axis(2,pos=70, tick=T, tcl=F, labels=F,col=white) axis(2,pos=80, tick=T, tcl=F, labels=F,col=white) axis(2,pos=90, tick=T, tcl=F, labels=F,col=white) Now I would like to shorten the whole thing - namely use only one step to create the 9 axes without having to use a loop. In general, I would be interested if there is a way to use a function several times changing only one argument, without having to use a loop. Does anyone know how to do that. Marion [[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. -- Enrico Schumann Lucerne, Switzerland http://nmof.net/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] overlay of two sets of boxplots
Hello, I am new to R and currently have the following problem: I have successfully loaded my data in R which consists of two numeric columns (LI_F and female) and one character column (Strain). So far I can plot two different set of boxplots for each of the numeric columns plotted by the groups of the character column and the commands look like that: boxplot(LI_F~Strain, ylab=LI_F, xlab=Strain, data=pain) boxplot(female~Strain, ylab=female, xlab=Strain, data=pain) How can I overlay the two set of boxplots (preferably in different colors), so that I can compare them one by one, meaning two boxplots corresponding to the same character in Strain are directly above each other? I have tried a lot of things and would greatly appreciate your help. Best, Mirjam [[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] Sorting strings
Hi all, I am having difficulties to understand how R sort strings: If I do R) sort(c(X.,X0B)) [1] X. X0B So for me, as far as lexicographic order is concerned I can add whatever to the end, the order will remain the same, but : R) sort(c(X.Z,X0B.Z)) [1] X0B.Z X.Z Can somebody give me a trick for the order to become lexicographic ? -- View this message in context: http://r.789695.n4.nabble.com/Sorting-strings-tp4403696p4403696.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] apply with as function ifelse with 2 logical conditions
Hi all, I have a question concerning using several conditions in an ifelse function used as the function in apply. I want to create a new value with the function ifelse ‘ object which can be coerced to logical mode “test[n,] 1 test[n-1,]==0” With n I mean the row. I don’t know how I could do this without a loop. I want to avoid the usage of loops and was thinking about apply. This was what I was thinking about: test-data.frame(C=c(0,0,0,0,5,2,0,0,0,15,12,10,6,0,0,0),B=c(0,0,0,0,9,6,2,0,0,24,20,16,2,0,0,0),F=c(0,0,0,0,6,5,1,0,0,18,16,12,10,5,1,0)) test.b-test[-(nrow(test)),] test.2b-rbind(0,test.b) result-as.data.frame(apply(test,M=2,function(x)ifelse((test1test.2b==0),1,0))) But I get 3 times the amount of rows than that I want… what I should achieve: test.result-data.frame(C=c(0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0),B=c(0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0),F=c(0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0)) Has someone a suggestions about what I’m doing wrong? Many thanks, Nerak -- View this message in context: http://r.789695.n4.nabble.com/apply-with-as-function-ifelse-with-2-logical-conditions-tp4403637p4403637.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] Run function several times changing only one argument - without a loop
Hi Marion, you can either use any of the *apply-functions or vectorize your function (which internally uses mapply): par(las=1) par(mar=c(5,13,4,2)) barplot(Ee1,horiz=T,col=grey85,border=NA,xlim=c(0,100),axes=F) #using sapply invisible(sapply((1:9)*10,function(x)axis(2,pos=x,tick=T, tcl=F, labels=F,col=white))) #using Vectorize barplot(Ee1,horiz=T,col=grey85,border=NA,xlim=c(0,100),axes=F) vaxis-Vectorize(axis,pos) invisible(vaxis(2,pos=(1:9)*10, tick=T, tcl=F, labels=F,col=white)) Cheers! Am 20.02.2012 11:04, schrieb Marion Wenty: Dear people, I created a plot which looks like this: Ee1-matrix(c(88,86,74,62,41),ncol=5) colnames(Ee1)-c(Lehrer,Lehrerinnen,Klassenkollegen,Klassenkolleginnen,Geschwister) par(las=1) par(mar=c(5,13,4,2)) barplot(Ee1,horiz=T,col=grey85,border=NA,xlim=c(0,100),axes=F) axis(2,pos=10, tick=T, tcl=F, labels=F,col=white) axis(2,pos=20, tick=T, tcl=F, labels=F,col=white) axis(2,pos=30, tick=T, tcl=F, labels=F,col=white) axis(2,pos=40, tick=T, tcl=F, labels=F,col=white) axis(2,pos=50, tick=T, tcl=F, labels=F,col=white) axis(2,pos=60, tick=T, tcl=F, labels=F,col=white) axis(2,pos=70, tick=T, tcl=F, labels=F,col=white) axis(2,pos=80, tick=T, tcl=F, labels=F,col=white) axis(2,pos=90, tick=T, tcl=F, labels=F,col=white) Now I would like to shorten the whole thing - namely use only one step to create the 9 axes without having to use a loop. In general, I would be interested if there is a way to use a function several times changing only one argument, without having to use a loop. Does anyone know how to do that. Marion [[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. -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 -- Pflichtangaben gemäß Gesetz über elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG): Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; Gerichtsstand: Hamburg Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting strings
On Mon, Feb 20, 2012 at 02:18:42AM -0800, statquant2 wrote: Hi all, I am having difficulties to understand how R sort strings: If I do R) sort(c(X.,X0B)) [1] X. X0B So for me, as far as lexicographic order is concerned I can add whatever to the end, the order will remain the same, but : Hi. This neednot be true for strings of different length. For example ab abc become by concatenation with z abcz abz Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] chisq.test vs manual calculation - why are different results produced?
Hello, I am trying to fit gamma, negative exponential and inverse power functions to a dataset, and then test whether the fit of each curve is good. To do this I have been advised to calculate predicted values for bins of data (I have grouped a continuous range of distances into 1km bins), and then apply a chi-squared test. Example: data - data.frame(distance=c(1,2,3,4,5,6,7), observed=c(43,13,10,6,2,1), predicted=c(28, 18, 10, 5 ,3, 1, 1)) chisq.test(data$observed, data$predicted) Which gives: Pearson's Chi-squared test data: data$observed and data$predicted X-squared = 35, df = 25, p-value = 0.0882 Warning message: In chisq.test(data$observed, data$predicted) : Chi-squared approximation may be incorrect I understand this is due to having observed/predicted values of less than five, however I am interested to know firstly why R uses such a large number of degrees of freedom (when by my understanding there should only be 4 df), and secondly whether using the following manual calculation is therefore inappropriate - X2 - sum(((data$observed - data$predicted)^2)/data$predicted) 1-pchisq(X2,4) [1] 0.04114223 If chi-squared is unsuitable, what other test can I use to determine whether my observed and predicted data come from the same distribution? The frequently recommended fisher's test doesn't seem to be any more appropriate as it requires values of greater than 5 for contingency tables larger than 2 x 2. Thanks for your help. Louise [[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] installing the package Rcplex
On 20.02.2012 01:54, David Winsemius wrote: On Feb 19, 2012, at 7:45 PM, zheng wei wrote: I did not know this before. I installed it as you suggested. what to do next? Read the Installation Manual? And don't forget this is a source package for which no CRAN Windows binary exists, hence it may be not that straightforward to get it done and you wil have to read the INSTALL file from the source package carefully. 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] GTK+
On 19.02.2012 18:58, Idielle Walters wrote: Hi I am struggling to install GTK+ for Windows 7. RGtk2 needs this package to load. Does anybody know of a installation file that works? See the ReadMe for Windows binary packages. For the current R-reelase this is http://cran.r-project.org/bin/windows/contrib/2.14/ReadMe and find that - Package RGtk2 requires an an installation of Gtk+ aka Gtk2 = 2.20. For 32-bit R, version 2.20 or later from http://www.gtk.org/download/win32.php, e.g. http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/2.22/gtk+-bundle_2.22.0-20101016_win32.zip For 64-bit R, version 2.20 or later from http://www.gtk.org/download/win64.php, e.g. http://ftp.gnome.org/pub/gnome/binaries/win64/gtk+/2.22/gtk+-bundle_2.22.0-20101016_win64.zip In each case, unpack the zip file in a suitable empty directory and put the 'bin' directory in your path. NB: the 32-bit and 64-bit distributions contain DLLs of the same names, and so you must ensure that you have the 32-bit version in your path when running 32-bit R and the 64-bit version when running 64-bit R - and the error messages you get with the wrong version are confusing. Uwe Ligges __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting strings
Petr Savicky savi...@cs.cas.cz wrote in message news:20120220105153.gc21...@cs.cas.cz... On Mon, Feb 20, 2012 at 02:18:42AM -0800, statquant2 wrote: Hi all, I am having difficulties to understand how R sort strings: If I do R) sort(c(X.,X0B)) [1] X. X0B So for me, as far as lexicographic order is concerned I can add whatever to the end, the order will remain the same, but : Hi. This neednot be true for strings of different length. For example ab abc become by concatenation with z abcz abz Petr Savicky. That's not the explanation in this case. The OP isn't telling us everything. I get [R version 2.14.1 Platform: i386-pc-mingw32/i386 (32-bit)]: sort(c(X.,X0B)) [1] X. X0B sort(c(X.Z,X0B.Z)) [1] X.Z X0B.Z KJ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Problems with installation of lsa package
Hi everybody! First of all, I would like to point that I am newebie in using R. The issue is that I need to install lsa package in R. In theory, I have downloaded and installed all necessary packages to run lsa library, but when I am going to load it I get this message: library(lsa)Loading required package: SnowballError : .onLoad failed in loadNamespace() for 'Snowball', details: call: NULL error: .onLoad failed in loadNamespace() for 'rJava', details: call: stop(No CurrentVersion entry in ', key, '! Try re-installing Java and make sure R and Java have matching architectures.) error: objeto 'key' no encontradoError: package Snowball could not be loaded I have already installed Snowball and rJava, but there is no way to load lsa library. Any idea? Thank you in advance. Best, AJ [[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] GTK
I am struggling to install GTK+ for Windows 7. RGtk2 needs this package to load. Does anybody know of a installation file that works? GTK+ is automatically installed when you install the RGtk2 package (you'll be asked about it during installation). As of R-2.14.1, it is installed under the R tree, so if you had write access when installing R itself, you should have no problem. HTH, Yvonnick Noel University of Brittany, Rennes 2 France __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] apply with as function ifelse with 2 logical conditions
On 20-02-2012, at 10:40, Nerak wrote: Hi all, I have a question concerning using several conditions in an ifelse function used as the function in apply. I want to create a new value with the function ifelse ‘ object which can be coerced to logical mode “test[n,] 1 test[n-1,]==0” With n I mean the row. I don’t know how I could do this without a loop. I want to avoid the usage of loops and was thinking about apply. This was what I was thinking about: test-data.frame(C=c(0,0,0,0,5,2,0,0,0,15,12,10,6,0,0,0),B=c(0,0,0,0,9,6,2,0,0,24,20,16,2,0,0,0),F=c(0,0,0,0,6,5,1,0,0,18,16,12,10,5,1,0)) test.b-test[-(nrow(test)),] test.2b-rbind(0,test.b) result-as.data.frame(apply(test,M=2,function(x)ifelse((test1test.2b==0),1,0))) You are not using the argument x in the ifelse. For every column (you have 3) you are evaluating the ifelse condition. But I get 3 times the amount of rows than that I want… what I should achieve: test.result-data.frame(C=c(0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0),B=c(0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0),F=c(0,0,0,0,1,0,0,0,0,1,0,0,0,0,0,0)) Has someone a suggestions about what I’m doing wrong? Simplify. You don't need apply. This'll do it result - ifelse((test1) (test.2b==0),1,0) Berend __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting strings
See ?Comparison, which holds some warnings about what to expect when sorting strings. Am 20.02.2012 11:51, schrieb Petr Savicky: On Mon, Feb 20, 2012 at 02:18:42AM -0800, statquant2 wrote: Hi all, I am having difficulties to understand how R sort strings: If I do R) sort(c(X.,X0B)) [1] X. X0B So for me, as far as lexicographic order is concerned I can add whatever to the end, the order will remain the same, but : Hi. This neednot be true for strings of different length. For example ab abc become by concatenation with z abcz abz Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Enrico Schumann Lucerne, Switzerland http://nmof.net/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting strings
Ok so it changed from 2.12.2 to 2.14.1 ?? Can somebody tell me how to modify my sort or whatever to get the save resilt that I would get in 2.14.1 ? Cheers -- View this message in context: http://r.789695.n4.nabble.com/Sorting-strings-tp4403696p4403858.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to determine a subset of a binary strings?
Hi, I need some neat ways of determing a subset of binary strings. For example, x=c(0,0,1), y=c(0,1,1), z=c(0,1,0). So x is a subset of y and z is also a subset of y, but x is not a subset of z. I tried to search R functions and packages but no hits. Any ideas? Best, Jing -- Jing Tang, PhD Senior Researcher Finnish Institute of Molecular Medicine (FIMM) FI-00014 University of Helsinki Finland [[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] How to inset a cell into a matrix?
hi i'm facing a problem How to inset a cell into a matrix? for example i have a matrix: 332 244 332244 665 332 665332 785 785 785665 i want to covert the matrix like this: 02440244 332 332332332 6650665665 785785 785 0 i find the minimum value from the 1st row, if any value greater than that, i will inset a 0 in that column and move the whole column down. but how to inset a cell? -- View this message in context: http://r.789695.n4.nabble.com/How-to-inset-a-cell-into-a-matrix-tp4403887p4403887.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] Time taken to process a file after a socket connection was made
Hello R people, I have created a '.csv' file of 100 rows by 20 columns whose each cell contains a random numbers between 0 1, thru a Java program. Once that is created a signal (just a letter) is send to the port of a socket connection at localhost, which was earlier started by an R session. Now the R reads the '.csv' file into a data frame and calculates the average of 2000 numbers. This mean value was then written to the socket connection and Java received that successfully. The duration of this processing at R session took 1 min 03 seconds. My question : Is the time duration of 63 seconds OK for only this set of activities or it should be less? If so how it can be reduced? Point to be noted that both the Java and R were running on the same PC and the 62 seconds were consumed for the readLines command. Thanks and regards. Aniruddha. =-=-= Notice: The information contained in this e-mail message and/or attachments to it may contain confidential or privileged information. If you are not the intended recipient, any dissemination, use, review, distribution, printing or copying of the information contained in this e-mail message and/or attachments to it are strictly prohibited. If you have received this communication in error, please notify us by reply e-mail or telephone and immediately and permanently delete the message and any attachments. Thank you [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Run function several times changing only one argument - without a loop
Hi Enrico, Yes, you were right, I just wanted to draw white vertical lines and with your command it's much simpler. Thanks a lot! Hi Eik, I learned a lot from your tips about sapply and Vectorize! I had only used apply, lapply and mapply but not yet sapply. I find the Vectorize function very fascinating: being able to change a function - this is something I hadn't come accross yet. By checking out the command invisible I also learned a new command. Thank you very much! Marion Hi Marion, is all you want the white vertical lines? Then try abline(v = seq(10, 90, by = 10), col = white) instead of your axis commands. Regards, Enrico 2012/2/20 Eik Vettorazzi e.vettora...@uke.de Hi Marion, you can either use any of the *apply-functions or vectorize your function (which internally uses mapply): par(las=1) par(mar=c(5,13,4,2)) barplot(Ee1,horiz=T,col=grey85,border=NA,xlim=c(0,100),axes=F) #using sapply invisible(sapply((1:9)*10,function(x)axis(2,pos=x,tick=T, tcl=F, labels=F,col=white))) #using Vectorize barplot(Ee1,horiz=T,col=grey85,border=NA,xlim=c(0,100),axes=F) vaxis-Vectorize(axis,pos) invisible(vaxis(2,pos=(1:9)*10, tick=T, tcl=F, labels=F,col=white)) Cheers! Am 20.02.2012 11:04, schrieb Marion Wenty: Dear people, I created a plot which looks like this: Ee1-matrix(c(88,86,74,62,41),ncol=5) colnames(Ee1)-c(Lehrer,Lehrerinnen,Klassenkollegen,Klassenkolleginnen,Geschwister) par(las=1) par(mar=c(5,13,4,2)) barplot(Ee1,horiz=T,col=grey85,border=NA,xlim=c(0,100),axes=F) axis(2,pos=10, tick=T, tcl=F, labels=F,col=white) axis(2,pos=20, tick=T, tcl=F, labels=F,col=white) axis(2,pos=30, tick=T, tcl=F, labels=F,col=white) axis(2,pos=40, tick=T, tcl=F, labels=F,col=white) axis(2,pos=50, tick=T, tcl=F, labels=F,col=white) axis(2,pos=60, tick=T, tcl=F, labels=F,col=white) axis(2,pos=70, tick=T, tcl=F, labels=F,col=white) axis(2,pos=80, tick=T, tcl=F, labels=F,col=white) axis(2,pos=90, tick=T, tcl=F, labels=F,col=white) Now I would like to shorten the whole thing - namely use only one step to create the 9 axes without having to use a loop. In general, I would be interested if there is a way to use a function several times changing only one argument, without having to use a loop. Does anyone know how to do that. Marion [[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. -- Eik Vettorazzi Institut für Medizinische Biometrie und Epidemiologie Universitätsklinikum Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790 -- Pflichtangaben gemäß Gesetz über elektronische Handelsregister und Genossenschaftsregister sowie das Unternehmensregister (EHUG): Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; Gerichtsstand: Hamburg Vorstandsmitglieder: Prof. Dr. Guido Sauter (Vertreter des Vorsitzenden), Dr. Alexander Kirstein, Joachim Prölß, Prof. Dr. Dr. Uwe Koch-Gromus [[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] proto: make a parameter persist
I like it better. Thanks! Ben On Fri, Feb 17, 2012 at 11:38 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: On Sat, Feb 18, 2012 at 12:44 AM, Ben quant ccqu...@gmail.com wrote: The code below works as expected but: Using the proto package, is this the best way to 1) make a parameter persist if the parameter is passed in with a value, 2) allow for calling the bias() function without a parameter assignment, 3) have the x2 value initialize as 5? Thanks for your feedback. Giving the proto package a test beat and establishing some templates for myself. oo - proto(expr = {x = c(10, 20, 15, 19, 17) x2 = 5 # so x2 initializes as 5, but can be overwritten with param assignment bias - function(.,x2=.$x2) { # x2=.$x2 so no default param is needed .$x2 = x2 # so x2 persists in the env .$x - .$x + x2 } }) o = oo$proto() o$x # [1] 10 20 15 19 17 o$x2 #[1] 5 o$bias(x2 = 100) o$x2 # [1] 100 o$x # [1] 110 120 115 119 117 This is not very different from what you have already but here it is for comparison. Note that the with(...) line has the same meaning as .$x - .$x + .$x2 : oo - proto( x = c(10, 20, 15, 19, 17), x2 = 5, bias = function(., x2) { if (!missing(x2)) .$x2 - x2 with(., x - x + x2) } ) -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Triangular Test
Hello, I would like to perform triangular test for clinical trial with R. can you help me please ? Jan [[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 determine a subset of a binary strings?
On 20-02-2012, at 14:15, jing tang wrote: Hi, I need some neat ways of determing a subset of binary strings. For example, x=c(0,0,1), y=c(0,1,1), z=c(0,1,0). So x is a subset of y and z is also a subset of y, but x is not a subset of z. I tried to search R functions and packages but no hits. Any ideas? x - c(0,0,1) y - c(0,1,1) z - c(0,1,0) any(x y) any(z y) any(x z) Berend __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] coxme: model simplification using LR-test?
Summary of the query: update does not work on a coxme object I ran into this bug myself 2 days ago -- I rarely use update() so hadn't encountered it before. The problem is that coxme breaks the formula into fixed and random portions, and this confuses the default method for formula. Solution: add the following function: formula.coxme - function(x, ...) x$call$formula This method will be included in my next update of coxme. Terry Therneau __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Finicky factor comparison operators
On Feb 20, 2012, at 1:45 AM, johnmark wrote: MIchael - Thanks for your insight. I think I see where you're going with this. To make '==' comparisons for subsetting against an ordered factor, I've had to create a lookup table for all possible values I'd ever want to compare against (all dates covered by the quarters in question, in this case) that maps into the ordered factors values. This is wrapped by a function that returns an ordered factor, which allows me to write: /(opps$close_quarter == which.quarter.end(2010-10-20)/ Otherwise if I try to create an ordered factor from the constant just for the purposes of comparison, the error tells me that ordered factors from different sources cannot be compared: /(opps$close_quarter == factor(2007-10-20, ordered=T) Error in Ops.factor(factor(2007-10-30, ordered = T), quarter.factors[1, 2]) : level sets of factors are different/ Actually it is telling you that you cannot compare ordered factors which have different levels. That makes perfect sense for the same reasons that you are not allowed to compare Dates to ordered factors. If the factors from different sources had the same levels you should have succeeded. z - factor(LETTERS[3:1], ordered = TRUE) z3 - factor(LETTERS[1:3] , ordered=TRUE) z[2] == z3[2] [1] TRUE That makes sense, since internally factors are integers -- enums in other terms. But what I want to avoid -- and what I don't see as necessary is explicitly coercing the terms to a common representation that mimics their print form: /as.character(2007-10-20)== as.character(factor(2007-10-20, ordered=T)) / I don't think there should be confusion since the conversion to print form is obvious -- but it does conflict with the conversion rules for creating vectors by c(): /c(2011-10-20, factor(2007-10-20, ordered=T)) [1] 2011-10-20 1 / where the factor is converted to its internal enum representation, then to a character. That just an example of the need to use as.character when converting data out of factor class. Having given this some more thought to what motivated the original question, one could use which() to invert the factor's levels vector: /which(2008-04-30 == levels(quarter.factors[,2])) [1] 3 / Its still not clear to me what exactly are the implicit conversion rules for factors. In your last case you are comparing a character to a character value and getting the expected result. (Since levels(quarter.factors) is NOT a factor.) You should also succeed when testing equality between ordered factor and character types. You have still not provided an example for testing so this may suffice. z - factor(LETTERS[3:1], ordered = TRUE) z == A [1] FALSE FALSE TRUE You should be able to assemble a list of valid candidate (character) values with levels(fac). Or if you want them in factor representation then use unique(fac). -- 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] Help on lattice barchart ploting
On Feb 20, 2012, at 5:34 AM, MLSC wrote: Hi friends, I have following data and would like to plot this with barchart() availble with lattice package. RsID Freqs Genotype AAA 63.636 1/1 AAA 32.727 1/2 AAA 3.636 2/2 BBB 85.965 2/2 BBB 14.035 2/1 CCC 63.158 1/1 CCC 21.053 1/2 CCC 15.789 2/2 DDD 26.786 2/2 DDD 46.429 2/1 DDD 26.786 1/1 EEE 32.759 2/2 EEE 43.103 2/1 EEE 24.138 1/1 EEE 37.931 1/1 EEE 51.724 1/2 EEE 10.345 2/2 FFF 23.214 2/2 FFF 53.571 2/1 FFF 23.214 1/1 GGG 46.552 1/1 GGG 44.828 1/2 GGG 8.621 2/2 HHH 65.517 2/2 HHH 32.759 2/1 HHH 1.724 1/1 Following is the code which I have written to get the plot. barchart(Genotype~Freqs | RsID, data=gDataFr,layout=c(4,6), main=Genotype Frequency, ylab=Genotype, xlab=Frequency, scales=list(x=list(alternating=c(1, 1, 1))), panel=function(x,y,...){ panel.fill(col=white) panel.grid(-1,0,lty=3,col=black) panel.barchart(x,y,col=c(blue,green,red),...) } ) but in plot, x-axis scale ranges from 0 to 30 though I have Freq column values in range of 0 to 100. I have tried many ways to get x-axis scale to 0 to 100, including xlim=c(1:100), but still bars in plot are not propotional to the range 0 to 100. hence can somebody let me know how get bars in the plot propotional to x-axis range 0 to 100? Check the class of Genotype. I do not see what you are describing when I create a dataset from your example. I suspect you had implicit coercion of your Genotype column to factor class. Or that you recognized that and forgot to tell us that you made the newbie error of using as.numeric() without first converting using as.character() from factor. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to determine a subset of a binary strings?
Hi Jing, I am not sure I got your definition of a subset right, but maybe this helps. Regards, Enrico x - c(0,0,1) y - c(0,1,1) z - c(0,1,0) ## is x a 'subset' of y? isSubset - function(x, y) { x - as.logical(x) y - as.logical(y) all(y[x] == TRUE) } isSubset(x, y) isSubset(z, y) isSubset(x, z) ## create all subsets exampleVec - c(0,1,1,0,1) fun - function(t) if (t) 0:1 else 0 expand.grid(lapply(as.list(exampleVec), fun)) Am 20.02.2012 14:15, schrieb jing tang: Hi, I need some neat ways of determing a subset of binary strings. For example, x=c(0,0,1), y=c(0,1,1), z=c(0,1,0). So x is a subset of y and z is also a subset of y, but x is not a subset of z. I tried to search R functions and packages but no hits. Any ideas? Best, Jing -- Jing Tang, PhD Senior Researcher Finnish Institute of Molecular Medicine (FIMM) FI-00014 University of Helsinki Finland [[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. -- Enrico Schumann Lucerne, Switzerland http://nmof.net/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Run function several times changing only one argument - without a loop
On Feb 20, 2012, at 5:04 AM, Marion Wenty wrote: Dear people, I created a plot which looks like this: Ee1-matrix(c(88,86,74,62,41),ncol=5) colnames(Ee1)- c (Lehrer ,Lehrerinnen,Klassenkollegen,Klassenkolleginnen,Geschwister) par(las=1) par(mar=c(5,13,4,2)) barplot(Ee1,horiz=T,col=grey85,border=NA,xlim=c(0,100),axes=F) axis(2,pos=10, tick=T, tcl=F, labels=F,col=white) axis(2,pos=20, tick=T, tcl=F, labels=F,col=white) axis(2,pos=30, tick=T, tcl=F, labels=F,col=white) axis(2,pos=40, tick=T, tcl=F, labels=F,col=white) axis(2,pos=50, tick=T, tcl=F, labels=F,col=white) axis(2,pos=60, tick=T, tcl=F, labels=F,col=white) axis(2,pos=70, tick=T, tcl=F, labels=F,col=white) axis(2,pos=80, tick=T, tcl=F, labels=F,col=white) axis(2,pos=90, tick=T, tcl=F, labels=F,col=white) Now I would like to shorten the whole thing - namely use only one step to create the 9 axes without having to use a loop. See if grid() is helpful: barplot(Ee1,horiz=T,col=grey85,border=NA,xlim=c(0,100),axes=F) grid(nx=9, ny=NA, col=white) Somehow using axis to draw elements inside a graph seems wrong, especially when you are using it for what is basically side-effect as you have been attempting. Could also have used abline which accepts a vector for its v argument. barplot(Ee1,horiz=T,col=grey85,border=NA,xlim=c(0,100),axes=F) abline(v=seq(10,90,by=10), col=white) In general, I would be interested if there is a way to use a function several times changing only one argument, without having to use a loop. A large number of functions will offer that facility using seq() as the functional input argument. Does anyone know how to do that. Marion [[alternative HTML version deleted]] You might consider working in the settings for your mail client. I know that gmail offers that option. -- 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] chisq.test vs manual calculation - why are different results produced?
On Feb 20, 2012, at 5:57 AM, Louise Mair wrote: Hello, I am trying to fit gamma, negative exponential and inverse power functions to a dataset, and then test whether the fit of each curve is good. To do this I have been advised to calculate predicted values for bins of data (I have grouped a continuous range of distances into 1km bins), and then apply a chi-squared test. Example: data - data.frame(distance=c(1,2,3,4,5,6,7), observed=c(43,13,10,6,2,1), predicted=c(28, 18, 10, 5 ,3, 1, 1)) There's an error with that code. chisq.test(data$observed, data$predicted) Which gives: Pearson's Chi-squared test data: data$observed and data$predicted X-squared = 35, df = 25, p-value = 0.0882 Warning message: In chisq.test(data$observed, data$predicted) : Chi-squared approximation may be incorrect I understand this is due to having observed/predicted values of less than five, however I am interested to know firstly why R uses such a large number of degrees of freedom (when by my understanding there should only be 4 df), and secondly whether using the following manual calculation is therefore inappropriate - Read the help page Details section end of second paragraph. You probably wanted: chisq.test(cbind(data$observed, data$predicted)) X2 - sum(((data$observed - data$predicted)^2)/data$predicted) 1-pchisq(X2,4) [1] 0.04114223 If chi-squared is unsuitable, what other test can I use to determine whether my observed and predicted data come from the same distribution? The frequently recommended fisher's test doesn't seem to be any more appropriate as it requires values of greater than 5 for contingency tables larger than 2 x 2. Thanks for your help. Louise [[alternative HTML version deleted]] Plain text is requested as the mail format. 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] Sorting strings
I did, but this does not give the answer to my question... Anybody knows how to tweack the behaviour of sort or how to do ? -- View this message in context: http://r.789695.n4.nabble.com/Sorting-strings-tp4403696p4404091.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] Reporting Kaplan-Meier / Cox-Proportional Hazard Standard Error, km.coxph.plot, survfit.object
The 10% rule does not provide a unique answer. Should it apply to the cumulative probability, its logarithm, or log-log (log hazard scale)? Many studies are too small to achieve 10% at any time point. I think it is more traditional (but not without bias) to stop where fewer than 10 subjects are still being followed. There's room for many other choices though. Sometimes I think that the curve should go to the max but be accompanied by confidence bands. Frank Paul Johnston wrote What is the best way to report the standard error when publishing Kaplan-Meier plots? In my field (Vascular Surgery), practitioners loosely refer to the 10% error cutoff as the point at which to stop drawing the KM curve. I am interpreting this as the *standard error of the cumulative hazard*, although I'm having a difficult time finding some guidelines about this (perhaps I am not searching the correct terms or references). My KM figures contain typically two curves that I am comparing using the logrank test. Inspecting the ?survfit.object yields the std.err field that gives the standard error for each timepoint on the curve. Is it recommended that I just name the timepoint at which the standard error exceeds 0.1 in the figure legend? For example, The standard error exceeds 10% at time points beyond 394 days. I have seen this strategy in other publications. What is your approach? Thanks for your help, PCJ __ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/Reporting-Kaplan-Meier-Cox-Proportional-Hazard-Standard-Error-km-coxph-plot-survfit-object-tp4403045p4404200.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help on lattice barchart ploting
I do not see the restricted range that you report. There is probably some masking as David pointed out. Try again in a fresh R session with --vanilla. You probably want three additional arguments. update(.Last.value, xlim=c(0, 100), between=list(x=1, y=1), origin = 0) to the barchart function call. The origin=0 makes the bars start at 0, not at the left margin of the panel. The between visually separates the panels. If you want the values 0 and 100 to appear on the x-axis, then you will need to use xlim=x(-5, 105) On Mon, Feb 20, 2012 at 5:34 AM, MLSC mlscm...@gmail.com wrote: Hi friends, I have following data and would like to plot this with barchart() availble with lattice package. RsID Freqs Genotype AAA 63.636 1/1 AAA 32.727 1/2 AAA 3.636 2/2 BBB 85.965 2/2 BBB 14.035 2/1 CCC 63.158 1/1 CCC 21.053 1/2 CCC 15.789 2/2 DDD 26.786 2/2 DDD 46.429 2/1 DDD 26.786 1/1 EEE 32.759 2/2 EEE 43.103 2/1 EEE 24.138 1/1 EEE 37.931 1/1 EEE 51.724 1/2 EEE 10.345 2/2 FFF 23.214 2/2 FFF 53.571 2/1 FFF 23.214 1/1 GGG 46.552 1/1 GGG 44.828 1/2 GGG 8.621 2/2 HHH 65.517 2/2 HHH 32.759 2/1 HHH 1.724 1/1 Following is the code which I have written to get the plot. barchart(Genotype~Freqs | RsID, data=gDataFr,layout=c(4,6), main=Genotype Frequency, ylab=Genotype, xlab=Frequency, scales=list(x=list(alternating=c(1, 1, 1))), panel=function(x,y,...){ panel.fill(col=white) panel.grid(-1,0,lty=3,col=black) panel.barchart(x,y,col=c(blue,green,red),...) } ) but in plot, x-axis scale ranges from 0 to 30 though I have Freq column values in range of 0 to 100. I have tried many ways to get x-axis scale to 0 to 100, including xlim=c(1:100), but still bars in plot are not propotional to the range 0 to 100. hence can somebody let me know how get bars in the plot propotional to x-axis range 0 to 100? Regards, mlsc [[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.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting strings
I don't *think* it's version specific, but rather it depends on your (still unstated) locale, as the documentation goes to great lengths to point out. Change that and you might see different behaviors. Michael On Mon, Feb 20, 2012 at 8:55 AM, statquant2 statqu...@gmail.com wrote: I did, but this does not give the answer to my question... Anybody knows how to tweack the behaviour of sort or how to do ? -- View this message in context: http://r.789695.n4.nabble.com/Sorting-strings-tp4403696p4404091.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Confused: Inconsistent result?
This is copy paste from my session: xyz-as.vector(c(ls(),as.matrix(lapply(ls(),class dim(xyz)-c(length(xyz)/2,2) allobj-function(){ + xyz-as.vector(c(ls(),as.matrix(lapply(ls(),class; + dim(xyz)-c(length(xyz)/2,2); + return(xyz) + } xyz [,1] [,2] [1,] a character [2,] aa character [3,] abc character [4,] AirPassengers character [5,] allobj character [6,] allObjects character [7,] allObjects2 character [8,] arrayFromAPL character [9,] classes character [10,] myCharVector character [11,] myDateVector character [12,] myNumericVector character [13,] newArrayFromAPL character [14,] obj character [15,] objClass character [16,] x character [17,] xyz character [18,] y character allobj() [,1] [,2] As far as I can see, the function allobj has the same expressions as those executed from the command line. Why are the results different? [[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] stats on transitions from one state to another
Folks, I'm trying to get stats from a matrix for each transition from one state to another. I have a matrix x as below. structure(c(0, 2, 2, 2, 0, 0, 0, 1, 1, 1, 1, 2, 2, 1, 1, 1, 0, 0, 2, 2, 0.21, -0.57, -0.59, 0.16, -1.62, 0.18, -0.81, -0.19, -0.76, 0.74, -1.51, 2.79, 0.41, 1.63, -0.86, -0.81, 0.39, -1.38, 0.06, 0.84, 0.51, -1, -1.29, 2.15, 0.39, 0.78, 0.85, 1.18, 1.66, 0.9, -0.94, -1.29, -0.23, -0.92, -0.21, 1.02, -0.77, -0.68, -0.33, 0.04), .Dim = c(20L, 3L), .Dimnames = list(NULL, c(State, V1, V2))) Is it possible to get, say, mean values of each variable in state 1 when the previous state was 0, in state 2 when the previous state was 0, and so on with all available transitions between states 0, 1, 2? In the above case, mean of V1 in state 2 when previous state was 0 would be mean(c(-0.57, -0.59, 0.16, 0.06, 0.84)) = -0.02 while the mean of V1 in state 0 when previous state was 2 would be: mean(c(1.62, 0.18, -0.81)) = 0.33 If I try something like by(x[, 2:3], x[, 1], FUN = colMeans) I get the means for each state. I'm not sure how to get the split by transition? Thanks, Murali __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Confused: Inconsistent result?
On Feb 20, 2012, at 10:07 AM, Ajay Askoolum wrote: This is copy paste from my session: xyz-as.vector(c(ls(),as.matrix(lapply(ls(),class dim(xyz)-c(length(xyz)/2,2) allobj-function(){ + xyz-as.vector(c(ls(),as.matrix(lapply(ls(),class; + dim(xyz)-c(length(xyz)/2,2); + return(xyz) + } xyz [,1] [,2] [1,] a character [2,] aa character [3,] abc character [4,] AirPassengers character [5,] allobj character [6,] allObjects character [7,] allObjects2 character [8,] arrayFromAPLcharacter [9,] classes character [10,] myCharVectorcharacter [11,] myDateVectorcharacter [12,] myNumericVector character [13,] newArrayFromAPL character [14,] obj character [15,] objClasscharacter [16,] x character [17,] xyz character [18,] y character allobj() [,1] [,2] As far as I can see, the function allobj has the same expressions as those executed from the command line. Why are the results different? The ls function looks only in the local environment if not supplied with specific directions about where to look. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Confused: Inconsistent result?
Sorry, just checked it and you need to add .GlobalEnv to both ls() calls. Michael On Mon, Feb 20, 2012 at 10:17 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: Short answer, environments -- ls() looks (by default) in its current environment, which is not the same as the global environment when being called inside a function. This would (I think) give the same answer but I haven't checked it. : allobj-function(){ + xyz-as.vector(c(ls(.GlobalEnv),as.matrix(lapply(ls(),class; + dim(xyz)-c(length(xyz)/2,2); + return(xyz) + } On Mon, Feb 20, 2012 at 10:07 AM, Ajay Askoolum aa2e...@yahoo.co.uk wrote: This is copy paste from my session: xyz-as.vector(c(ls(),as.matrix(lapply(ls(),class dim(xyz)-c(length(xyz)/2,2) allobj-function(){ + xyz-as.vector(c(ls(),as.matrix(lapply(ls(),class; + dim(xyz)-c(length(xyz)/2,2); + return(xyz) + } xyz [,1] [,2] [1,] a character [2,] aa character [3,] abc character [4,] AirPassengers character [5,] allobj character [6,] allObjects character [7,] allObjects2 character [8,] arrayFromAPL character [9,] classes character [10,] myCharVector character [11,] myDateVector character [12,] myNumericVector character [13,] newArrayFromAPL character [14,] obj character [15,] objClass character [16,] x character [17,] xyz character [18,] y character allobj() [,1] [,2] As far as I can see, the function allobj has the same expressions as those executed from the command line. Why are the results different? [[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] Confused: Inconsistent result?
Short answer, environments -- ls() looks (by default) in its current environment, which is not the same as the global environment when being called inside a function. This would (I think) give the same answer but I haven't checked it. : allobj-function(){ + xyz-as.vector(c(ls(.GlobalEnv),as.matrix(lapply(ls(),class; + dim(xyz)-c(length(xyz)/2,2); + return(xyz) + } On Mon, Feb 20, 2012 at 10:07 AM, Ajay Askoolum aa2e...@yahoo.co.uk wrote: This is copy paste from my session: xyz-as.vector(c(ls(),as.matrix(lapply(ls(),class dim(xyz)-c(length(xyz)/2,2) allobj-function(){ + xyz-as.vector(c(ls(),as.matrix(lapply(ls(),class; + dim(xyz)-c(length(xyz)/2,2); + return(xyz) + } xyz [,1] [,2] [1,] a character [2,] aa character [3,] abc character [4,] AirPassengers character [5,] allobj character [6,] allObjects character [7,] allObjects2 character [8,] arrayFromAPL character [9,] classes character [10,] myCharVector character [11,] myDateVector character [12,] myNumericVector character [13,] newArrayFromAPL character [14,] obj character [15,] objClass character [16,] x character [17,] xyz character [18,] y character allobj() [,1] [,2] As far as I can see, the function allobj has the same expressions as those executed from the command line. Why are the results different? [[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] Computing plot size in Sweave
Sometimes you want to compute the physical size of a plot based on data. In R itself this is no problem. But is there a way to compute the values of height and width in S-weave, say: graph,fig=TRUE,height=xx,width=yy= where xx and yy are computed and not physically written in the document? Bendix __ Bendix Carstensen Senior Statistician Epidemiology Steno Diabetes Center A/S Niels Steensens Vej 2-4 DK-2820 Gentofte Denmark +45 44 43 87 38 (direct) +45 30 75 87 38 (mobile) b...@steno.dkhttp://BendixCarstensen.com www.steno.dk This e-mail (including any attachments) is intended for ...{{dropped:8}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Confused: Inconsistent result?
Hi This is copy paste from my session: xyz-as.vector(c(ls(),as.matrix(lapply(ls(),class dim(xyz)-c(length(xyz)/2,2) allobj-function(){ + xyz-as.vector(c(ls(),as.matrix(lapply(ls(),class; + dim(xyz)-c(length(xyz)/2,2); + return(xyz) + } xyz [,1] [,2] [1,] a character [2,] aa character [3,] abc character [4,] AirPassengers character [5,] allobj character [6,] allObjects character [7,] allObjects2 character [8,] arrayFromAPLcharacter [9,] classes character [10,] myCharVectorcharacter [11,] myDateVectorcharacter [12,] myNumericVector character [13,] newArrayFromAPL character [14,] obj character [15,] objClasscharacter [16,] x character [17,] xyz character [18,] y character allobj() [,1] [,2] As far as I can see, the function allobj has the same expressions as those executed from the command line. Why are the results different? Probably due to environment handling. Do you really want to check if ls behaves as is intended and that it produces character vector? Or your intention is a little bit more ambitious and you want to know what objects do you have? If the later, I recommend to use this function: function (pos = 1, pattern, order.by) { napply - function(names, fn) sapply(names, function(x) fn(get(x, pos = pos))) names - ls(pos = pos, pattern = pattern) obj.class - napply(names, function(x) as.character(class(x))[1]) obj.mode - napply(names, mode) obj.type - ifelse(is.na(obj.class), obj.mode, obj.class) obj.size - napply(names, object.size) obj.dim - t(napply(names, function(x) as.numeric(dim(x))[1:2])) vec - is.na(obj.dim)[, 1] (obj.type != function) obj.dim[vec, 1] - napply(names, length)[vec] out - data.frame(obj.type, obj.size, obj.dim) names(out) - c(Type, Size, Rows, Columns) if (!missing(order.by)) out - out[order(out[[order.by]]), ] out } [[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] stats on transitions from one state to another
On Feb 20, 2012, at 10:11 AM, murali.me...@avivainvestors.com wrote: Folks, I'm trying to get stats from a matrix for each transition from one state to another. I have a matrix x as below. structure(c(0, 2, 2, 2, 0, 0, 0, 1, 1, 1, 1, 2, 2, 1, 1, 1, 0, 0, 2, 2, 0.21, -0.57, -0.59, 0.16, -1.62, 0.18, -0.81, -0.19, -0.76, 0.74, -1.51, 2.79, 0.41, 1.63, -0.86, -0.81, 0.39, -1.38, 0.06, 0.84, 0.51, -1, -1.29, 2.15, 0.39, 0.78, 0.85, 1.18, 1.66, 0.9, -0.94, -1.29, -0.23, -0.92, -0.21, 1.02, -0.77, -0.68, -0.33, 0.04), .Dim = c(20L, 3L), .Dimnames = list(NULL, c(State, V1, V2))) Is it possible to get, say, mean values of each variable in state 1 when the previous state was 0, in state 2 when the previous state was 0, and so on with all available transitions between states 0, 1, 2? In the above case, mean of V1 in state 2 when previous state was 0 would be mean(c(-0.57, -0.59, 0.16, 0.06, 0.84)) = -0.02 while the mean of V1 in state 0 when previous state was 2 would be: mean(c(1.62, 0.18, -0.81)) = 0.33 If I try something like by(x[, 2:3], x[, 1], FUN = colMeans) I get the means for each state. I'm not sure how to get the split by transition? Add an extra column of previous states: and tabulate: sss -cbind(sss, c(NA, sss[,State][-nrow(sss)]) ) table(sss[,State], sss[,4]) 0 1 2 0 3 1 1 1 1 5 1 2 2 1 4 The requested means for V1 by transition types: tapply(sss[,V1], INDEX=interaction(sss[,State], sss[,4]), mean) 0.01.02.00.11.12.10.21.22.2 -0.670 -0.190 -0.255 0.390 -0.640 2.790 -1.620 1.630 0.205 The counts on which those means are based: tapply(sss[,V1], INDEX=interaction(sss[,State], sss[,4]), length) 0.0 1.0 2.0 0.1 1.1 2.1 0.2 1.2 2.2 3 1 2 1 5 1 1 1 4 -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to resample matrices to test for the robustness of their correlation
Thank you Chuck, Here is the head of my data set (tjornres): Fish.1 Fish.2 MORPHO DIET 1 1 20.03768 0.1559250 2 1 30.05609 0.7897060 3 1 40.03934 0.4638010 4 1 50.03363 0.1200480 5 1 60.05629 0.4390760 6 1 80.08366 0.1866750 7 1 90.04892 0.0988235 8 1 10 0.04427 0.2637140 MORPHO and DIET refer to the morphological and diet distances between fish 1 and fish 2. My original data set has over 2400 pairs of fish. My goal is to resample this dataste by selecting only 435. I would like to do this 999 times and get a distribution of the correlation coefficients MORPHO~DIET. I went on and wrote this code: head(tjornres) essayres = tjornres # copy of the data R = 999 # the number of replicates cor.values = numeric(R) # store the data for (i in 1:R) { # loop + group1 = sample(essayres, size=435, replace=F) + group2 = sample(essayres, size=435, replace=F) + cor.values[i] = cor.test(group1,group2)$cor + } I have a syntax error in this code. Also if I run one resampling, sample(essayres, size=435, replace=F), I get this error message: Error in `[.data.frame`(x, .Internal(sample(length(x), size, replace, : cannot take a sample larger than the population when 'replace = FALSE'. Does anyone know why this code is not working? Are there any other ways to resample (without replacement) ? Thank you for your help, -- View this message in context: http://r.789695.n4.nabble.com/How-to-resample-matrices-to-test-for-the-robustness-of-their-correlation-tp4397915p4404337.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to determine a subset of a binary strings?
On Mon, Feb 20, 2012 at 03:15:53PM +0200, jing tang wrote: Hi, I need some neat ways of determing a subset of binary strings. For example, x=c(0,0,1), y=c(0,1,1), z=c(0,1,0). So x is a subset of y and z is also a subset of y, but x is not a subset of z. I tried to search R functions and packages but no hits. Any ideas? Hi. Try this all(x = y) # [1] TRUE all(z = y) # [1] TRUE all(x = z) # [1] FALSE Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting strings
On Mon, Feb 20, 2012 at 05:55:30AM -0800, statquant2 wrote: I did, but this does not give the answer to my question... Anybody knows how to tweack the behaviour of sort or how to do ? Hi. Try this Sys.setlocale(LC_COLLATE, C) This comes from ?locale and reads there Sys.setlocale(LC_COLLATE, C) # turn off locale-specific sorting, # usually See also ?sort The sort order for character vectors will depend on the collating sequence of the locale in use: see ‘Comparison’. ?Comparison Comparison of strings in character vectors is lexicographic within the strings using the collating sequence of the locale in use: see ‘locales’. The collating sequence of locales such as ‘en_US’ is normally different from ‘C’ (which should use ASCII) and can be surprising. Beware of making _any_ assumptions about the collation order: ... Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting strings
Hello, statquant2 wrote Ok so it changed from 2.12.2 to 2.14.1 ?? Can somebody tell me how to modify my sort or whatever to get the save resilt that I would get in 2.14.1 ? Cheers I don't know about 2.12.2 but for 2.12.0 I get: R.version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 12.0 year 2010 month 10 day15 svn rev53317 language R version.string R version 2.12.0 (2010-10-15) sort(c(X.,X0B)) [1] X. X0B sort(c(X.Z,X0B.Z)) [1] X.Z X0B.Z And the same for 2.14.1: R.version _ platform i386-pc-mingw32 [... deleted...] version.string R version 2.14.1 (2011-12-22) sort(c(X.,X0B)) [1] X. X0B sort(c(X.Z,X0B.Z)) [1] X.Z X0B.Z Could it be OS related? Rui Barradas. -- View this message in context: http://r.789695.n4.nabble.com/Sorting-strings-tp4403696p4404267.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] Metafor: Moderator variables for each study arm
Hello, I am trying to do a meta-analysis where each study has two arms, similar to the BCG data set. However, follow-up duration was different for each study arm, so I would like to fit a model that uses the length of follow-up in each arm as a moderator. Is this possible? For example, if this was the BCG data, each study would have 2 follow up variables: 1 for the treatment group, and 1 for the control group. thanks for the help, Faiz . __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Column wise matrix multiplication
Hi all, I am trying to multiply each column of a matrix such to have a unique resulting vector with length equal to the number of rows of the original matrix. In short I would like to do what prod(.) function in Matlab does, i.e. A -matrix(c(1:10),5,2) V = A[,1]*A[,2] Thank you Graziano [[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] Sorting strings
Ok I have : R) str(R.Version()) List of 13 $ platform : chr x86_64-unknown-linux-gnu $ arch : chr x86_64 $ os: chr linux-gnu $ system: chr x86_64, linux-gnu $ status: chr $ major : chr 2 $ minor : chr 12.2 $ year : chr 2011 $ month : chr 02 $ day : chr 25 $ svn rev : chr 54585 $ language : chr R $ version.string: chr R version 2.12.2 (2011-02-25) R) sort(c(X.,X0B)) [1] X. X0B R) sort(c(X.Z,X0B.Z)) [1] X0B.Z X.Z I am using a linux redHat $ uname -a Linux 2.6.18-238.9.1.el5 #1 SMP Fri Mar 18 12:42:39 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux -- View this message in context: http://r.789695.n4.nabble.com/Sorting-strings-tp4403696p4404298.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] FW: Problems with R
Dears, I am a new R user and I am trying to analyze my data sets, R gives me a default when I type in the regression formula as following: fit1=gamlss(tot_remun_revenue$tot_remun.y~tot_remun_revenue$revenue.x,family=NO) Fehler in model.frame.default(formula = tot_remun_revenue$tot_remun.y ~ : ungültiger Typ (NULL) für die Variable 'tot_remun_revenue$tot_remun.y' Is there anything wrong in my data set, as the instruction is directly copied from lectures I had about R? Attached please find the data set as .csv. Best regards and thanks in advance! Thorsten Poellinger__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Column wise matrix multiplication
Try apply(A, 1, prod) I hope it helps. Best, Dimitris On 2/20/2012 4:21 PM, Graziano Mirata wrote: Hi all, I am trying to multiply each column of a matrix such to have a unique resulting vector with length equal to the number of rows of the original matrix. In short I would like to do what prod(.) function in Matlab does, i.e. A-matrix(c(1:10),5,2) V = A[,1]*A[,2] Thank you Graziano [[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] stats on transitions from one state to another
On 20-02-2012, at 16:11, murali.me...@avivainvestors.com murali.me...@avivainvestors.com wrote: Folks, I'm trying to get stats from a matrix for each transition from one state to another. I have a matrix x as below. structure(c(0, 2, 2, 2, 0, 0, 0, 1, 1, 1, 1, 2, 2, 1, 1, 1, 0, 0, 2, 2, 0.21, -0.57, -0.59, 0.16, -1.62, 0.18, -0.81, -0.19, -0.76, 0.74, -1.51, 2.79, 0.41, 1.63, -0.86, -0.81, 0.39, -1.38, 0.06, 0.84, 0.51, -1, -1.29, 2.15, 0.39, 0.78, 0.85, 1.18, 1.66, 0.9, -0.94, -1.29, -0.23, -0.92, -0.21, 1.02, -0.77, -0.68, -0.33, 0.04), .Dim = c(20L, 3L), .Dimnames = list(NULL, c(State, V1, V2))) Is it possible to get, say, mean values of each variable in state 1 when the previous state was 0, in state 2 when the previous state was 0, and so on with all available transitions between states 0, 1, 2? In the above case, mean of V1 in state 2 when previous state was 0 would be mean(c(-0.57, -0.59, 0.16, 0.06, 0.84)) = -0.02 What do you mean by previous state. I do this x - cbind(c(NA, x[,State][-nrow(x)]), x) colnames(x)[1] - State.prev x State.prev StateV1V2 [1,] NA 0 0.21 0.51 [2,] 0 2 -0.57 -1.00 [3,] 2 2 -0.59 -1.29 [4,] 2 2 0.16 2.15 [5,] 2 0 -1.62 0.39 [6,] 0 0 0.18 0.78 [7,] 0 0 -0.81 0.85 [8,] 0 1 -0.19 1.18 [9,] 1 1 -0.76 1.66 [10,] 1 1 0.74 0.90 [11,] 1 1 -1.51 -0.94 [12,] 1 2 2.79 -1.29 [13,] 2 2 0.41 -0.23 [14,] 2 1 1.63 -0.92 [15,] 1 1 -0.86 -0.21 [16,] 1 1 -0.81 1.02 [17,] 1 0 0.39 -0.77 [18,] 0 0 -1.38 -0.68 [19,] 0 2 0.06 -0.33 [20,] 2 2 0.84 0.04 The mean of V1 in state 2 when the previous state is 0 would be in my interpretation mean(c(-0.57, 0.06)) while the mean of V1 in state 0 when previous state was 2 would be: mean(c(1.62, 0.18, -0.81)) = 0.33 Your second case would be the mean of -1.62 Berend __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting strings
It seems OS-dependent. I got different results when trying it on windows xp and Redhat linux. R.version _ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 9.1 year 2009 month 06 day26 svn rev48839 language R version.string R version 2.9.1 (2009-06-26) sort(c(X.,X0B)) [1] X. X0B sort(c(X.Z,X0B.Z)) [1] X.Z X0B.Z R.version _ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 9.1 year 2009 month 06 day26 svn rev48839 language R version.string R version 2.9.1 (2009-06-26) sort(c(X.,X0B)) [1] X. X0B sort(c(X.Z,X0B.Z)) [1] X0B.Z X.Z On 2012-2-20 23:27, statquant2 wrote: Ok I have : R) str(R.Version()) List of 13 $ platform : chr x86_64-unknown-linux-gnu $ arch : chr x86_64 $ os: chr linux-gnu $ system: chr x86_64, linux-gnu $ status: chr $ major : chr 2 $ minor : chr 12.2 $ year : chr 2011 $ month : chr 02 $ day : chr 25 $ svn rev : chr 54585 $ language : chr R $ version.string: chr R version 2.12.2 (2011-02-25) R) sort(c(X.,X0B)) [1] X. X0B R) sort(c(X.Z,X0B.Z)) [1] X0B.Z X.Z I am using a linux redHat $ uname -a Linux 2.6.18-238.9.1.el5 #1 SMP Fri Mar 18 12:42:39 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux -- View this message in context: http://r.789695.n4.nabble.com/Sorting-strings-tp4403696p4404298.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting strings
On Mon, Feb 20, 2012 at 04:56:21PM +0100, Petr Savicky wrote: On Mon, Feb 20, 2012 at 05:55:30AM -0800, statquant2 wrote: I did, but this does not give the answer to my question... Anybody knows how to tweack the behaviour of sort or how to do ? Hi. Try this Sys.setlocale(LC_COLLATE, C) This comes from ?locale and reads there This is not in ?locale, but in ?locales Sys.setlocale(LC_COLLATE, C) # turn off locale-specific sorting, # usually This in the example section at the end. Try also to see Sys.getlocale() Relevant can also be LC_CTYPE Sys.setlocale(LC_CTYPE, C) Hope this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting strings
Sorry, just made a mistake. This is the result from windows xp. sort(c(X.,X0B)) [1] X. X0B sort(c(X.Z,X0B.Z)) [1] X.Z X0B.Z R.version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 13.0 year 2011 month 04 day13 svn rev55427 language R version.string R version 2.13.0 (2011-04-13) On 2012-2-21 0:13, De-Jian Zhao wrote: It seems OS-dependent. I got different results when trying it on windows xp and Redhat linux. R.version _ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 9.1 year 2009 month 06 day26 svn rev48839 language R version.string R version 2.9.1 (2009-06-26) sort(c(X.,X0B)) [1] X. X0B sort(c(X.Z,X0B.Z)) [1] X.Z X0B.Z R.version _ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 9.1 year 2009 month 06 day26 svn rev48839 language R version.string R version 2.9.1 (2009-06-26) sort(c(X.,X0B)) [1] X. X0B sort(c(X.Z,X0B.Z)) [1] X0B.Z X.Z On 2012-2-20 23:27, statquant2 wrote: Ok I have : R) str(R.Version()) List of 13 $ platform : chr x86_64-unknown-linux-gnu $ arch : chr x86_64 $ os: chr linux-gnu $ system: chr x86_64, linux-gnu $ status: chr $ major : chr 2 $ minor : chr 12.2 $ year : chr 2011 $ month : chr 02 $ day : chr 25 $ svn rev : chr 54585 $ language : chr R $ version.string: chr R version 2.12.2 (2011-02-25) R) sort(c(X.,X0B)) [1] X. X0B R) sort(c(X.Z,X0B.Z)) [1] X0B.Z X.Z I am using a linux redHat $ uname -a Linux 2.6.18-238.9.1.el5 #1 SMP Fri Mar 18 12:42:39 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux -- View this message in context: http://r.789695.n4.nabble.com/Sorting-strings-tp4403696p4404298.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] FW: Problems with R
On Feb 20, 2012, at 10:26 AM, Thorsten Pöllinger wrote: Dears, I am a new R user and I am trying to analyze my data sets, R gives me a default when I type in the regression formula as following: fit1=gamlss(tot_remun_revenue$tot_remun.y~tot_remun_revenue $revenue.x,family=NO) Most regression functions work best with a data argument and then a formula that uses just column names. Fehler in model.frame.default(formula = tot_remun_revenue $tot_remun.y ~ : ungültiger Typ (NULL) für die Variable 'tot_remun_revenue $tot_remun.y' Is there anything wrong in my data set, as the instruction is directly copied from lectures I had about R? Attached please find the data set as .csv. Best regards and thanks in advance! Thorsten Poellinger You mailer probably did not properly indicate that the .csv file was an acceptable file type. You may want to send a followup after renaming the file to somthing.txt before attaching,... and you should include the data input commands you used. -- 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] Non-parametric test for repeated measures and post-hoc single comparisons in R?
No, the authors are correct: the individuals (i.e. the 17 individuals) you have need to be independent (i.e. no correlation between them, let alone any individual running through your temporal experiment more than once, as indicated in the citation), while the *observations* are of course dependent as they are within the same subject (individual -- they have the same subject effect). Think of Friedman as a non-parametric 2-way ANOVA with one of the factors being subject; observations of the same subject are dependent, but once you include the subject effect, the errors are assumed to be independent (which implies that subjects need to be independent and should, e.g., not work on the assessment together). The imprecision is in your interpretation of individuals vs. observations. HTH, Michael -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of saschav...@gmail.com Sent: Montag, 20. Februar 2012 09:59 To: peter dalgaard Cc: r-help@r-project.org Subject: Re: [R] Non-parametric test for repeated measures and post-hoc single comparisons in R? Thanks, I got it! (And I think I should have googled what replicated means!) However, then Bortz, Lienert, Boehnke are imprecise, if not wrong: Der Friedman-Test setzt voraus, dass die N Individuen wechselseitig unabhängig sind, dass also nicht etwa ein und dasselbe Individuum zweimal oder mehrmals im Untersuchungsplan auftritt (p. 271). Which I (hope to) translate: The Friedman test requires the N individuals to be reciprocally independent, which means that one individual cannot occur twice or more times in the research design. *S* On 19.02.12 22:04, peter dalgaard wrote: Repeated measures means that you have multiple measurements on the same individual. Usually, the same person measured at different time points. So if you have N individuals and T times, then you can place your observations in an N*T layout. In this layout, you can have 1 observation per cell or R 1 observations. In the former case, the design is referred to as unreplicated. Got it? -pd On Feb 19, 2012, at 19:25 , saschav...@gmail.com wrote: Some attribute x from 17 individuals was recorded repeatedly on 6 time points using a Likert scale with 7 distractors. Which statistical test(s) can I apply to check whether the changes along the 6 time points were significant? set.seed( 123 ) x- matrix( sample( 1:7, 17*6, repl=T ), nrow = 17, byrow = TRUE, dimnames = list(1:17, paste( 'T', 1:6, sep='' )) ) I found the Friedman test and the Quade test for testing the overall hypothesis. friedman.test( x ) quade.test( x ) However, the R help files, my text books (Bortz, Lienert and Boehnke, 2008; Köhler, Schachtel and Voleske, 2007; both German), and the Wikipedia texts differ in what they propose as requirements for the tests. R says that data need to be unreplicated. I read 'unreplicated' as 'not-repeated', but is that right? If so, the example, in contrast, in friedman.test() appears to use indeed repeated measures. Yet, Wikipedia says the contrary that is to say the test is good especially if data represents repeated measures. The text books say either (in the same paragraph, which is very confusing). What is right? In addition, what would be an appropriate test for post-hoc single comparisons for the indication which column differs from others significantly? Bortz, Lienert, Boehnke (2008). Verteilungsfreie Methoden in der Biostatistik. Berlin: Springer Köhler, Schachtel, Voleske (2007). Biostatistik: Eine Einführung für Biologen und Agrarwissenschaftler. Berlin: Springer -- Sascha Vieweg, saschav...@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. -- Sascha Vieweg, saschav...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] coxme: model simplification using LR-test?
Many thanks for the suggestion. I tried it already, but as I've never wrote a function, I had no luck. If it's not asked too much, maybe you or somebody else could help me getting the code for the function right. Regards Simon Am 20/02/2012 14:52, schrieb Terry Therneau: Summary of the query: update does not work on a coxme object I ran into this bug myself 2 days ago -- I rarely use update() so hadn't encountered it before. The problem is that coxme breaks the formula into fixed and random portions, and this confuses the default method for formula. Solution: add the following function: formula.coxme- function(x, ...) x$call$formula This method will be included in my next update of coxme. Terry Therneau -- Simon Tragust Animal Ecology I University of Bayreuth __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting strings
On 2012-2-20 23:15, Rui Barradas wrote: Could it be OS related? Yes, it seems. I tried it on my local windows xp and redhat linux server, and got different results. Hope it will be fixed in the future versions. Maybe we should keep alert to check whether the results are consistent when transferring our code from one platform to another. sort(c(X.,X0B)) [1] X. X0B sort(c(X.Z,X0B.Z)) [1] X0B.Z X.Z R.version _ platform x86_64-unknown-linux-gnu arch x86_64 os linux-gnu system x86_64, linux-gnu status major 2 minor 9.1 year 2009 month 06 day26 svn rev48839 language R version.string R version 2.9.1 (2009-06-26) sort(c(X.,X0B)) [1] X. X0B sort(c(X.Z,X0B.Z)) [1] X.Z X0B.Z R.version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 13.0 year 2011 month 04 day13 svn rev55427 language R version.string R version 2.13.0 (2011-04-13) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] overlay of two sets of boxplots
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. At a rough guess you may want to have a look at the mfrow in ?par but without some sample data and a bit more information about what you need it is difficult to suggest more. By the way dput (see ?dput) is a handy way to supply a sample data set here. John Kane Kingston ON Canada -Original Message- From: ap...@neuro.mpg.de Sent: Mon, 20 Feb 2012 10:27:11 + To: r-help@r-project.org Subject: [R] overlay of two sets of boxplots Hello, I am new to R and currently have the following problem: I have successfully loaded my data in R which consists of two numeric columns (LI_F and female) and one character column (Strain). So far I can plot two different set of boxplots for each of the numeric columns plotted by the groups of the character column and the commands look like that: boxplot(LI_F~Strain, ylab=LI_F, xlab=Strain, data=pain) boxplot(female~Strain, ylab=female, xlab=Strain, data=pain) How can I overlay the two set of boxplots (preferably in different colors), so that I can compare them one by one, meaning two boxplots corresponding to the same character in Strain are directly above each other? I have tried a lot of things and would greatly appreciate your help. Best, Mirjam [[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. Receive Notifications of Incoming Messages Easily monitor multiple email accounts access them with a click. Visit http://www.inbox.com/notifier and check it out! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting strings
On 20-Feb-2012 Petr Savicky wrote: On Mon, Feb 20, 2012 at 05:55:30AM -0800, statquant2 wrote: I did, but this does not give the answer to my question... Anybody knows how to tweack the behaviour of sort or how to do ? Hi. Try this Sys.setlocale(LC_COLLATE, C) This comes from ?locale and reads there Sys.setlocale(LC_COLLATE, C) # turn off locale-specific sorting, # usually See also ?sort The sort order for character vectors will depend on the collating sequence of the locale in use: see 'Comparison'. ?Comparison Comparison of strings in character vectors is lexicographic within the strings using the collating sequence of the locale in use: see 'locales'. The collating sequence of locales such as 'en_US' is normally different from 'C' (which should use ASCII) and can be surprising. Beware of making _any_ assumptions about the collation order: ... Hope this helps. Petr Savicky. I've been following this thread with interest. I had begun composing a reply on similar lines to Petr's above, but put it on one side while waiting to see how the thread would evolve. In view of the tangle of mixed experiences reported by different users, I now wonder whether we should have something like lc_collate as a specific parameter for sort(), e.g. so that one can set, for a particular sorting operation, sort(c(X.,X0B),lc_collate=C) without affecting the system LC_COLLATE setting (i.e. the change takes effect only within the execution of that sort() command). Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 20-Feb-2012 Time: 17:16:47 This message was sent by 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] ggplot rank stack bar automatically.
Hi, That is not what I get. After running your code I get levels(df.m$Period) [1] 1991-00 1901-10 1981-90 2001-06 1911-20 1881-90 1971-80 [8] 1921-30 1891-00 1961-70 1871-80 1851-60 1951-60 1861-70 [15] 1841-50 1941-50 1831-40 1931-40 1820-30 this is my version info: sessionInfo() R version 2.14.1 (2011-12-22) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.9.0 reshape_0.8.4 plyr_1.7.1 loaded via a namespace (and not attached): [1] colorspace_1.1-1 dichromat_1.2-4digest_0.5.1 grid_2.14.1 [5] MASS_7.3-16memoise_0.1munsell_0.3proto_0.3-9.2 [9] RColorBrewer_1.0-5 reshape2_1.2.1 scales_0.1.0 stringr_0.6 what is yours? Best, Ista On Sunday, February 19, 2012 11:59:30 PM vd3000 wrote: df - structure(c(106487, 495681, 1597442, 2452577, 2065141, 2271925, 4735484, 3555352, 8056040, 4321887, 2463194, 347566, 621147, 1325727, 1123492, 800368, 761550, 1359737, 1073726, 36, 53, 141, 41538, 64759, 124160, 69942, 74862, 323543, 247236, 112059, 16595, 37028, 153249, 427642, 1588178, 2738157, 2795672, 2265696, 11951, 33424, 62469, 74720, 166607, 404044, 426967, 38972, 361888, 1143671, 1516716, 160037, 354804, 996944, 1716374, 1982735, 3615225, 4486806, 3037122, 17, 54, 55, 210, 312, 358, 857, 350, 7368, 8443, 6286, 1750, 7367, 14092, 28954, 80779, 176893, 354939, 446792, 3, 69911, 53144, 29169, 18005, 11704, 13363, 18028, 46547, 14574, 8954, 2483, 14693, 25467, 25215, 41254, 46237, 98263, 185986), .Dim = c(19, 5), .Dimnames = list(c(1820-30, 1831-40, 1841-50, 1851-60, 1861-70, 1871-80, 1881-90, 1891-00, 1901-10, 1911-20, 1921-30, 1931-40, 1941-50, 1951-60, 1961-70, 1971-80, 1981-90, 1991-00, 2001-06), c(Europe, Asia, Americas, Africa, Oceania))) df.m - melt(df) df.m - rename(df.m, c(X1 = Period, X2 = Region)) df.m - transform(df.m, Period = reorder(Period, -1*value)) ggplot(df.m, aes(x = Period, y = value/1e+06, fill = Region)) + geom_bar(stat = identity, position = stack) = levels(df.m$Period) [1] 1820-30 1831-40 1841-50 1851-60 1861-70 1871-80 1881-90 [8] 1891-00 1901-10 1911-20 1921-30 1931-40 1941-50 1951-60 [15] 1961-70 1971-80 1981-90 1991-00 2001-06 = I think after reordering, the levels changed, but the fact was nothing has got change _!!! I found I have many commands happen like this. especially drawing graph...ordering doesn't work... [[elided Yahoo spam]] it is crazy, R teases me. -- View this message in context: http://r.789695.n4.nabble.com/ggplot-rank-stack-bar-automatically-tp4391042 p4403442.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help updating package rJava (on ubuntu)
Simon, Thanks alot for the further clarification. As i said some where in my lengthy explanation - i don't what of the myriad steps were needed, only that they were performed and i now have an up-to-date rJava. Next time (actually coming up soon) i'll certainly be following the couple simple steps you suggest. Also good to know that Java 1.7 can be used with the latest R (which is all i intend to install). Thanks again for the follow up, Karl On 02/20/2012 03:37 AM, Simon Urbanek wrote: On Feb 19, 2012, at 4:31 PM, Karl Brand wrote: Hi Hasan, Success. For myself and FWIW to other useR's here's how i spent the sunny half of my sunday to achieve it :/ Many thanks for your and Simon's input, FWIW you should not need to set any custom settings if you system is properly configured (if you use Java 1.7 you may need R 2.14.0 or higher which works around some bugs in 1.7 binaries). On Debian/Ubuntu you just install your favorite JDK (Sun/Oracle or OpenJDK) and use 'sudo update-alternatives --config java' or 'sudo update-java-alternatives' (depending on the age of your system) to select the right one. The fact you you had to tweak PATH means that something is seriously broken or you did setup the alternatives configuration correctly. Cheers, Simon Karl Since: $ javac -version returned nothing i believe you (and Simon) were right, i.e, it (and JDK) were missing on my system. Furthermore: $ sudo R CMD javareconf Java interpreter : /usr/bin/java Java version : 1.6.0_23 Java home path : /usr/lib/jvm/java-6-openjdk/jre Java compiler: not present Java headers gen.: Java archive tool: Java library path: $(JAVA_HOME)/lib/amd64/server:$(JAVA_HOME)/lib/amd64:$(JAVA_HOME)/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib/jni:/lib:/usr/lib JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -L$(JAVA_HOME)/lib/amd64 -L$(JAVA_HOME)/../lib/amd64 -L/usr/java/packages/lib/amd64 -L/usr/lib/jni -L/lib -L/usr/lib -ljvm JNI cpp flags: Updating Java configuration in /etc/R Done. Some things are clearly absent i.e., Java compiler: not present Java headers gen.: Java archive tool: Now i have: $ javac -version javac 1.6.0_23 $ sudo R CMD javareconf Java interpreter : /usr/bin/java Java version : 1.6.0_23 Java home path : /usr/lib/jvm/java-6-openjdk/jre Java compiler: /usr/bin/javac Java headers gen.: /usr/bin/javah Java archive tool: /usr/bin/jar Java library path: $(JAVA_HOME)/lib/amd64/server:$(JAVA_HOME)/lib/amd64:$(JAVA_HOME)/../lib/amd64:/usr/java/packages/lib/amd64:/usr/lib/jni:/lib:/usr/lib JNI linker flags : -L$(JAVA_HOME)/lib/amd64/server -L$(JAVA_HOME)/lib/amd64 -L$(JAVA_HOME)/../lib/amd64 -L/usr/java/packages/lib/amd64 -L/usr/lib/jni -L/lib -L/usr/lib -ljvm JNI cpp flags: -I$(JAVA_HOME)/../include Updating Java configuration in /etc/R Done. Certainly i don't know exactly what was needed to achieve this. BUT - for posterities sake, this is what i did: ## purge and reinstall openjdk-6-jdk which turned outwasn't installed! ## how this can be when i have a /usr/lib/jvm/java-6-openjdk full of ## files i don't understand. Moreover since i had the previosu version ## of rJava running fine!!! $ sudo apt-get purge openjdk-6-jdk snip Package openjdk-6-jdk is not installed, so not removed 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded. ## install openjdk-6-jdk $ sudo apt-get install openjdk-6-jdk ## Per- http://ubuntuforums.org/showthread.php?t=1491846 ## added 2 entries to /etc/bash.bashrc file $ gksudo gedit /etc/bash.bashrc ## entries were: export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/jre export PATH=$PATH:$JAVA_HOME/bin ## note the addition of /jre for JAVA_HOME per- ## http://stackoverflow.com/questions/3311940/r-rjava-package-install-failing saved bash.bashrc file then reloaded $ source /etc/bash.bashrc ## confirmed $ echo $JAVA_HOME /usr/lib/jvm/java-6-openjdk/jre ## configured java $ sudo R CMD javareconf I was then able to update rJava in a new R-session. Also note that per- http://stackoverflow.com/questions/3311940/r-rjava-package-install-failing $ apt-get install r-cran-rjava did NOT enable me to update my rJava. Unless i buggered up something else along the way :/ On 02/18/2012 10:20 PM, Hasan Diwan wrote: On 18 February 2012 13:13, Karl Brandk.br...@erasmusmc.nl wrote: Thanks for yout fast response. Thing is - i managed to get Version 0.9-1 installed and fully functional. And $ locate jdk returns too many entries to post here, so i'm pretty sure its on the machine. What you want to look for is javac, not jdk. On my ubuntu system, this is to be found at /usr/lib/jvm/java-6-openjdk-i386/bin/javac So i'd like to know how i can ensure it's registered in R. This i have no idea how to do. I simply don't have enough R and linux experience. Also the thread i mentioned http://stackoverflow.com/questions/3311940/r-rjava-package-install-failing seems to be about pointing R at the right location of certain
Re: [R] coxme: model simplification using LR-test?
On Feb 20, 2012, at 11:41 AM, Simon Tragust wrote: Many thanks for the suggestion. I tried it already, it means .. what exactly? but as I've never wrote a function, I had no luck. no luck means ... what? If it's not asked too much, maybe you or somebody else could help me getting the code for the function right. He gave you a perfectly formed function. Were you thinking you had to fill in some blanks? Not so. That ... is a meaningful construct in R. It says to take whatever arguments follow and pass them on to the next function. So when you enter this at the console: m-coxme(Surv(day,status) ~ condition*infection + (1|infection/population), data=all) formula.coxme- function(x, ...) x$call$formula m1-update(m, ~.-condition:infection) what happens? -- david. Am 20/02/2012 14:52, schrieb Terry Therneau: Summary of the query: update does not work on a coxme object I ran into this bug myself 2 days ago -- I rarely use update() so hadn't encountered it before. The problem is that coxme breaks the formula into fixed and random portions, and this confuses the default method for formula. Solution: add the following function: formula.coxme- function(x, ...) x$call$formula This method will be included in my next update of coxme. Terry Therneau 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] Computing plot size in Sweave
I guess that is not possible with Sweave, but it is possible in the knitr package (an alternative to Sweave). You can set opts_knit$set(eval.opts = c('fig.height', 'fig.width')) so that these two options will be evaluated as R expressions (e.g. fig.height=x means it takes value from a variable x). Note width/height have been renamed to fig.width/fig.height in knitr. See http://yihui.name/knitr/ Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Mon, Feb 20, 2012 at 9:15 AM, BXC (Bendix Carstensen) b...@steno.dk wrote: Sometimes you want to compute the physical size of a plot based on data. In R itself this is no problem. But is there a way to compute the values of height and width in S-weave, say: graph,fig=TRUE,height=xx,width=yy= where xx and yy are computed and not physically written in the document? Bendix __ Bendix Carstensen Senior Statistician Epidemiology Steno Diabetes Center A/S Niels Steensens Vej 2-4 DK-2820 Gentofte Denmark +45 44 43 87 38 (direct) +45 30 75 87 38 (mobile) b...@steno.dk http://BendixCarstensen.com www.steno.dk This e-mail (including any attachments) is intended for ...{{dropped:8}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Column wise matrix multiplication
On 20-Feb-2012 Graziano Mirata wrote: Hi all, I am trying to multiply each column of a matrix such to have a unique resulting vector with length equal to the number of rows of the original matrix. In short I would like to do what prod(.) function in Matlab does, i.e. A -matrix(c(1:10),5,2) V = A[,1]*A[,2] Thank you Graziano The Matlab prod(A,2) function computes the products along the rows of the matrix A and returns the result as a column vector, of length equal to the number of rows in A, which seems to be what you describe. Your code above does this for your 2-column example, but the result is a simple R vector which is not an array (and in particular is not a column vector): A[,1]*A[,2] # [1] 6 14 24 36 50 dim(A[,1]*A[,2]) # NULL For a matrix A with arbitrary number of columns, if you wanted the row sums rather than the row products, you could use the R function rowSums(): rowSums(A) # [1] 7 9 11 13 15 This is still a dimensionless simple R vector: dim(rowSums(A)) # NULL Unfortunately, there seems to be no equivalent for products (e.g. rowProds). But you can define one: rowProds - function(X){ apply(X,1,FUN=prod) } rowProds(A) # [1] 6 14 24 36 50 Even then, the result is a simple R vector, without dimensions: dim(rowProds(A)) # NULL If you need an array (row) vector then you can apply t(): t(rowProds(A)) # [,1] [,2] [,3] [,4] [,5] # [1,]6 14 24 36 50 or t(t()) for a column vector: t(t(rowProds(A))) # [,1] # [1,]6 # [2,] 14 # [3,] 24 # [4,] 36 # [5,] 50 Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 20-Feb-2012 Time: 17:54:13 This message was sent by 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] How to change the objective function of quantile regression?
Dear all, I need to run a quantile regression but considering a different objective function to be minimized: instead of finding the parameters that minimize rho(t) = u*(t - I(u0)), I need to find the parameters beta that minimize a sum of two rho functions rho(t1) = u1*(t1 - I(u10)) and rho(t2) = u2*(t2 - I(u20)) where t1 and t2 are different quantile levels and u1 = y1 - b'x1 and u2 = y2 - b'x2. y1 and x1 are response variable and regressors, respectively, that will be weighted by t1 and similar for t2. The problem is that I do not know how to change the function rq() in R because it only accepts two arguments, y and x. In my case, I think I also have two arguments, that is x - rbind(x1,x2) and y - rbind(y1,y2) , but I need to split the residuals to be minimized, weighting u1 by t1 and u2 by t2. I am trying my best, but I cannot do it. Does anybody have any suggestion? I appreciate any kind of suggestion and help. All the best, Nathalie [[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] Disabling shell access through system() possible?
Hi! I'm deploying R behind a web-app on a linux-server and I don't want to grant the users shell access through the system() function for security reasons. Is there any safe way to deny a user access to the function? I tried a) alter the function in the R-Sources before compiling them. Doesn't seem to work because system() is apparently needed during the build. b) Redefine system() in the global Rprofile. Leads to of course to some warning messages at any session start and feels generally kludgy and unsafe. Best Regards M.W. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sorting strings
NICE DDE It solves my problem ! Awesome stuff -- View this message in context: http://r.789695.n4.nabble.com/Sorting-strings-tp4403696p4404424.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to How to compare the concordance index between two nomograms with R
I have got two kinds of nomogram for the same data set analyzed by Cox regression. My question is how to compare the concordance index between these two nomograms with R? -- View this message in context: http://r.789695.n4.nabble.com/how-to-How-to-compare-the-concordance-index-between-two-nomograms-with-R-tp4404488p4404488.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] Time Series - Trend Line
How can I had a trend line to my plot? My data looks like this: Date=seq(as.Date(1910/1/1), as.Date(1920/1/1), day) Values=runif(length(Date), min=-5, max=5) dataset=data.frame(Values,as.Date(Date)) I just want to add a linear trend line to this plot(dataset,col=rgb(1,0,0,1/8),cex=0.5,pch=19) -- View this message in context: http://r.789695.n4.nabble.com/Time-Series-Trend-Line-tp4404582p4404582.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] overlay of two sets of boxplots
Hello John, Thanks for your fast answer. I will try to be clearer and more detailed this time. At the moment I am importing a dataframe like below as a '.csv file'. I want to generate a boxplot for M and F values grouped by X whereby boxplots for M and F should be above or very close to each other. Please see attachment for example figure. Till now I have tried a code that looks like the one below the frame (I found it in the graph help of R for boxes close to each other): X MF Exp1-90.0273224 -77.66531714 Exp1-73.-96.36363636 Exp1-98.24561404-91.57848325 Exp1-65.2173913 -59.18367347 Exp1-98.7654321 -92.42424242 Exp1-96.42857143-89.25925926 Exp2-84.61538462 -47.36842105 Exp2-43.63636364 -22.37762238 Exp2-47.5 -33. Exp2-55.49450549-66.6667 boxplot( formula = F~Strain, data= pain, boxwex = 0.25, at = 1:38 - 0.1, subset =supp== F, col = red, xlab= Strain, ylab= F ) boxplot( formula = M~Strain, data= pain, boxwex = 0.25, at = 1:38 + 0.1, subset =supp== M, col = orange, add = TRUE ) ...but I did cannot find anywhere what supp means and R cannot read it. I hope this is explained ok. Any kind of answer would help! Best Mirjam -Original Message- From: John Kane [mailto:jrkrid...@inbox.com] Sent: Monday, February 20, 2012 6:00 PM To: Mirjam Appel; r-help@r-project.org Subject: RE: [R] overlay of two sets of boxplots PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. At a rough guess you may want to have a look at the mfrow in ?par but without some sample data and a bit more information about what you need it is difficult to suggest more. By the way dput (see ?dput) is a handy way to supply a sample data set here. John Kane Kingston ON Canada -Original Message- From: ap...@neuro.mpg.de Sent: Mon, 20 Feb 2012 10:27:11 + To: r-help@r-project.org Subject: [R] overlay of two sets of boxplots Hello, I am new to R and currently have the following problem: I have successfully loaded my data in R which consists of two numeric columns (LI_F and female) and one character column (Strain). So far I can plot two different set of boxplots for each of the numeric columns plotted by the groups of the character column and the commands look like that: boxplot(LI_F~Strain, ylab=LI_F, xlab=Strain, data=pain) boxplot(female~Strain, ylab=female, xlab=Strain, data=pain) How can I overlay the two set of boxplots (preferably in different colors), so that I can compare them one by one, meaning two boxplots corresponding to the same character in Strain are directly above each other? I have tried a lot of things and would greatly appreciate your help. Best, Mirjam [[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. Receive Notifications of Incoming Messages Easily monitor multiple email accounts access them with a click. Visit http://www.inbox.com/notifier and check it out! overlayed boxplots.pdf Description: overlayed boxplots.pdf __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] overlay of two sets of boxplots
On Feb 20, 2012, at 1:59 PM, Mirjam Appel wrote: Hello John, Thanks for your fast answer. I will try to be clearer and more detailed this time. At the moment I am importing a dataframe like below as a '.csv file'. I want to generate a boxplot for M and F values grouped by X whereby boxplots for M and F should be above or very close to each other. Please see attachment for example figure. Till now I have tried a code that looks like the one below the frame (I found it in the graph help of R for boxes close to each other): I think you must have missed the spot in whatever example code you are following for your homework task where they reshaped this data so that it was in long format. Go back into your text and read it more carefully and if it's not clear, then pose further questions to your instructor. X MF Exp1-90.0273224 -77.66531714 Exp1-73.-96.36363636 Exp1-98.24561404-91.57848325 Exp1-65.2173913 -59.18367347 Exp1-98.7654321 -92.42424242 Exp1-96.42857143-89.25925926 Exp2-84.61538462 -47.36842105 Exp2-43.63636364 -22.37762238 Exp2-47.5 -33. Exp2-55.49450549-66.6667 boxplot( formula = F~Strain, data= pain, boxwex = 0.25, at = 1:38 - 0.1, subset =supp== F, Clearly the strain variable was created in the process of reshaping and the supp variable as well. -- david. col = red, xlab= Strain, ylab= F ) boxplot( formula = M~Strain, data= pain, boxwex = 0.25, at = 1:38 + 0.1, subset =supp== M, col = orange, add = TRUE ) ...but I did cannot find anywhere what supp means and R cannot read it. I hope this is explained ok. Any kind of answer would help! Best Mirjam -Original Message- From: John Kane [mailto:jrkrid...@inbox.com] Sent: Monday, February 20, 2012 6:00 PM To: Mirjam Appel; r-help@r-project.org Subject: RE: [R] overlay of two sets of boxplots PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. At a rough guess you may want to have a look at the mfrow in ?par but without some sample data and a bit more information about what you need it is difficult to suggest more. By the way dput (see ?dput) is a handy way to supply a sample data set here. John Kane Kingston ON Canada -Original Message- From: ap...@neuro.mpg.de Sent: Mon, 20 Feb 2012 10:27:11 + To: r-help@r-project.org Subject: [R] overlay of two sets of boxplots Hello, I am new to R and currently have the following problem: I have successfully loaded my data in R which consists of two numeric columns (LI_F and female) and one character column (Strain). So far I can plot two different set of boxplots for each of the numeric columns plotted by the groups of the character column and the commands look like that: boxplot(LI_F~Strain, ylab=LI_F, xlab=Strain, data=pain) boxplot(female~Strain, ylab=female, xlab=Strain, data=pain) How can I overlay the two set of boxplots (preferably in different colors), so that I can compare them one by one, meaning two boxplots corresponding to the same character in Strain are directly above each other? I have tried a lot of things and would greatly appreciate your help. Best, Mirjam [[alternative HTML version deleted]] 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] Disabling shell access through system() possible?
On Mon, Feb 20, 2012 at 06:17:23PM +0100, li...@mwoywod.de wrote: Hi! I'm deploying R behind a web-app on a linux-server and I don't want to grant the users shell access through the system() function for security reasons. Is there any safe way to deny a user access to the function? Hi. Disabling system() is not sufficient. The user may call directly .Internal(system(, )) Other dangerous things may be opening connections with write access or manipulation with files. In particular, pipe() can also run a command. It could be better to run R under a user name with restricted permissions. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] JGR Segmentation fault
The http://mxcl.github.com/homebrew/ Homebrew package manager is an exelent way to manage packages like R on osx. I highly recommend it to any developer. I am hoping there are others in the R community that are interested in getting this working too. Does anyone else run a Homebrew install of R? If so have you been able to get JGR / Deducer running? -- View this message in context: http://r.789695.n4.nabble.com/JGR-Segmentation-fault-tp4401260p4404821.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] error with persp()- increasing 'x' and 'y' values expected
I want to use persp to graph my data and it keeps giving me the error increasing 'x' and 'y' values expected, even though my data is in increasing order with respect to x and y. Here is the code I'm currently using: bob= scan (SBA3dataTaxonB.txt,what=char) labels = bob[1:3] bob=bob[-c(1,2,3)] bob=as.numeric(bob) bob=array(bob,dim=c(3, length(bob)/3)) bob=t(bob) data.frame(bob) - bob bob = bob[order(bob[,1], bob[,3]),] persp(bob[,1], bob[,3], bob[,2], log=bob[,1]) The first few lines of the txt file SBA3dataTaxonB.txt look like this: variableTaxonB central 10 19 0.002 10 25 0.002 10 26 0.002 1 17 0.002 1 23 0.002 1 16 0.002 0.1 48 0.002 0.1 47 0.002 0.1 57 0.002 10 15 0.004 10 22 0.004 10 22 0.004 1 21 0.004 1 22 0.004 1 27 0.004 0.1 73 0.004 0.1 62 0.004 Can anyone help me figure out why I am getting this error? And also a possible solution would be greatly appreciated. -Thanks, Amanda -- View this message in context: http://r.789695.n4.nabble.com/error-with-persp-increasing-x-and-y-values-expected-tp4404834p4404834.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] overlay of two sets of boxplots
Does something like the code below give you want you want? It requires the ggplot2 package so you will likely have to install it. John Kane Kingston ON Canada # sample data converted using dput xx - structure(list(X = c(Exp1, Exp1, Exp1, Exp1, Exp1, Exp1, Exp2, Exp2, Exp2, Exp2), M = c(-90.0273224, -73., -98.24561404, -65.2173913, -98.7654321, -96.42857143, -84.61538462, -43.63636364, -47.5, -55.49450549), F = c(-77.66531714, -96.36363636, -91.57848325, -59.18367347, -92.42424242, -89.25925926, -47.36842105, -22.37762238, -33., -66.6667)), .Names = c(X, M, F), class = data.frame, row.names = c(NA, -10L)) # melt data using reshape --automatically loads with ggplot2 library(ggplot2) mm - melt(xx, id=X) ggplot(mm, aes(variable, value, fill=variable)) + geom_boxplot() + opts(legend.position=none) + facet_grid(. ~ X) -Original Message- From: ap...@neuro.mpg.de Sent: Mon, 20 Feb 2012 18:59:49 + To: jrkrid...@inbox.com, r-help@r-project.org Subject: RE: [R] overlay of two sets of boxplots Hello John, Thanks for your fast answer. I will try to be clearer and more detailed this time. At the moment I am importing a dataframe like below as a '.csv file'. I want to generate a boxplot for M and F values grouped by X whereby boxplots for M and F should be above or very close to each other. Please see attachment for example figure. Till now I have tried a code that looks like the one below the frame (I found it in the graph help of R for boxes close to each other): X MF Exp1 -90.0273224 -77.66531714 Exp1 -73.-96.36363636 Exp1 -98.24561404-91.57848325 Exp1 -65.2173913 -59.18367347 Exp1 -98.7654321 -92.42424242 Exp1 -96.42857143-89.25925926 Exp2 -84.61538462 -47.36842105 Exp2 -43.63636364 -22.37762238 Exp2 -47.5 -33. Exp2 -55.49450549-66.6667 boxplot( formula = F~Strain, data= pain, boxwex = 0.25, at = 1:38 - 0.1, subset =supp== F, col = red, xlab= Strain, ylab= F ) boxplot( formula = M~Strain, data= pain, boxwex = 0.25, at = 1:38 + 0.1, subset =supp== M, col = orange, add = TRUE ) ...but I did cannot find anywhere what supp means and R cannot read it. I hope this is explained ok. Any kind of answer would help! Best Mirjam -Original Message- From: John Kane [mailto:jrkrid...@inbox.com] Sent: Monday, February 20, 2012 6:00 PM To: Mirjam Appel; r-help@r-project.org Subject: RE: [R] overlay of two sets of boxplots PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. At a rough guess you may want to have a look at the mfrow in ?par but without some sample data and a bit more information about what you need it is difficult to suggest more. By the way dput (see ?dput) is a handy way to supply a sample data set here. John Kane Kingston ON Canada -Original Message- From: ap...@neuro.mpg.de Sent: Mon, 20 Feb 2012 10:27:11 + To: r-help@r-project.org Subject: [R] overlay of two sets of boxplots Hello, I am new to R and currently have the following problem: I have successfully loaded my data in R which consists of two numeric columns (LI_F and female) and one character column (Strain). So far I can plot two different set of boxplots for each of the numeric columns plotted by the groups of the character column and the commands look like that: boxplot(LI_F~Strain, ylab=LI_F, xlab=Strain, data=pain) boxplot(female~Strain, ylab=female, xlab=Strain, data=pain) How can I overlay the two set of boxplots (preferably in different colors), so that I can compare them one by one, meaning two boxplots corresponding to the same character in Strain are directly above each other? I have tried a lot of things and would greatly appreciate your help. Best, Mirjam [[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. Receive Notifications of Incoming Messages Easily monitor multiple email accounts access them with a click. Visit http://www.inbox.com/notifier and check it out! Share photos screenshots in seconds... TRY FREE IM TOOLPACK at http://www.imtoolpack.com/default.aspx?rc=if1 Works in all emails, instant messengers, blogs,
Re: [R] error with persp()- increasing 'x' and 'y' values expected
On Feb 20, 2012, at 2:15 PM, adick wrote: I want to use persp to graph my data and it keeps giving me the error increasing 'x' and 'y' values expected, even though my data is in increasing order with respect to x and y. Do you have missing entries? (Running your data fragment through your code produces the same error.) You may want to use rep with each and times arguments to construct a regular grid and then population the missing entries in matrix with NA's. Here is the code I'm currently using: bob= scan (SBA3dataTaxonB.txt,what=char) labels = bob[1:3] bob=bob[-c(1,2,3)] bob=as.numeric(bob) bob=array(bob,dim=c(3, length(bob)/3)) bob=t(bob) data.frame(bob) - bob bob = bob[order(bob[,1], bob[,3]),] persp(bob[,1], bob[,3], bob[,2], log=bob[,1]) Any way The z argument to `persp` is supposed to be a matrix of dimension == length(x)*length(y): ?matrix The first few lines of the txt file SBA3dataTaxonB.txt look like this: variableTaxonB central 10 19 0.002 10 25 0.002 10 26 0.002 1 17 0.002 1 23 0.002 1 16 0.002 0.1 48 0.002 0.1 47 0.002 0.1 57 0.002 10 15 0.004 10 22 0.004 10 22 0.004 1 21 0.004 1 22 0.004 1 27 0.004 0.1 73 0.004 0.1 62 0.004 Can anyone help me figure out why I am getting this error? And also a possible solution would be greatly appreciated. -Thanks, Amanda -- View this message in context: http://r.789695.n4.nabble.com/error-with-persp-increasing-x-and-y-values-expected-tp4404834p4404834.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Computing plot size in Sweave
On Feb 20, 2012, at 9:15 AM, BXC (Bendix Carstensen) wrote: Sometimes you want to compute the physical size of a plot based on data. In R itself this is no problem. But is there a way to compute the values of height and width in S-weave, say: graph,fig=TRUE,height=xx,width=yy= where xx and yy are computed and not physically written in the document? Bendix Bendix, By default, Sweave.sty sets: \setkeys{Gin}{width=0.8\textwidth} which modifies the default \includegraphics LaTeX command auto-generated during Sweave processing. This means that irrespective of the 'height' and 'width' arguments in the figure chunk header, which do control the size of the PDF/EPS files created, the actual size of the graphic as included in the resultant document will ALWAYS be 80% of the current text width and the height will be scaled accordingly. In general, if you wanted to control the actual height and width of the figure in the resultant document, you could set: FigureChunkName,include=false,echo=false,fig=true,height=YourHeight,width=YourWidth= Plot Code Here @ \begin{figure}[tbp] \centering \includegraphics{RnwFileName-FigureChunkName} \caption[LOF Caption]{Some Longer Caption} \end{figure} 'RnwFileName' is the name of your working .Rnw Sweave file and 'FigureChunkName' is the name of the figure chunk and as a result, the graphic file name being created by Sweave, separated by the hyphen ('-'). By setting the 'include' option to false, Sweave does not auto-generate the \includegraphics line with the width=0.8\textwidth argument, and you then explicitly include it in the LaTeX code following the figure chunk. The plot file(s) would then be created with the height and width parameters in the figure chunk header and the resultant document will have a figure of the size you desire, overriding the default behavior. In my .Rnw files, I actually set: \usepackage[nogin]{Sweave} in my preamble, which overrides the default 'Gin' behavior. Then the height and width parameters in the figure chunks are reflected in the resultant document, but of course, I need to explicitly pre-define those. If you want to calculate the figure's height and width at run-time, I suspect that the only way to do that would be to have your R code generate all of the LaTeX code output at runtime as well. So something like the following: CodeChunkName,echo=false= # Plot Size Calculations Here Height - ResultOfCalcs Width - ResultOfCalcs pdf(MyPlotFileName.pdf, height = Height, width = Width) Plot Code Here dev.off() cat(\\begin{figure}[tbp]\n) cat(\\centering\n) cat(\\includegraphics{MyPlotFileName}\n) cat(\\caption[LOF Caption]{Some Longer Caption}\n) cat(\\end{figure}\n) @ The result of the cat() function calls will be to output the included character vectors to the .tex file being created by Sweave at run-time. So you are using R in a normal code chunk to generate LaTeX code. If you need an EPS file either in place of the PDF (because you are using postscript stuff like pstricks) or in addition to the PDF, you can replace the pdf() call with postscript() or run a second iteration of the plotting code using postscript()/dev.off() as well. HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Column wise matrix multiplication
[See at end] On 20-Feb-2012 Ted Harding wrote: On 20-Feb-2012 Graziano Mirata wrote: Hi all, I am trying to multiply each column of a matrix such to have a unique resulting vector with length equal to the number of rows of the original matrix. In short I would like to do what prod(.) function in Matlab does, i.e. A -matrix(c(1:10),5,2) V = A[,1]*A[,2] Thank you Graziano The Matlab prod(A,2) function computes the products along the rows of the matrix A and returns the result as a column vector, of length equal to the number of rows in A, which seems to be what you describe. Your code above does this for your 2-column example, but the result is a simple R vector which is not an array (and in particular is not a column vector): A[,1]*A[,2] # [1] 6 14 24 36 50 dim(A[,1]*A[,2]) # NULL For a matrix A with arbitrary number of columns, if you wanted the row sums rather than the row products, you could use the R function rowSums(): rowSums(A) # [1] 7 9 11 13 15 This is still a dimensionless simple R vector: dim(rowSums(A)) # NULL Unfortunately, there seems to be no equivalent for products (e.g. rowProds). But you can define one: rowProds - function(X){ apply(X,1,FUN=prod) } rowProds(A) # [1] 6 14 24 36 50 Even then, the result is a simple R vector, without dimensions: dim(rowProds(A)) # NULL If you need an array (row) vector then you can apply t(): t(rowProds(A)) # [,1] [,2] [,3] [,4] [,5] # [1,]6 14 24 36 50 or t(t()) for a column vector: t(t(rowProds(A))) # [,1] # [1,]6 # [2,] 14 # [3,] 24 # [4,] 36 # [5,] 50 Ted. - Further to the above: I have managed to track down a function rowProds in the matrixStats package: http://finzi.psych.upenn.edu/R/library/matrixStats/html/rowProds.html http://www.stats.bris.ac.uk/R/web/packages/matrixStats/matrixStats.pdf Note that: Details Internally the product is calculated via the logarithmic transform, treating zeros and negative values specially. In view of this, which strikes me as potentially getting close to thin ice, plus the overhead of loading a whole package just for one function, it may be more straightforward (and perhaps safer) to define one's own function (as above). Also (see the PDF reference manual) it is apparently work in progress and also has dependencies on other packages: see the description at http://www.stats.bris.ac.uk/R/web/packages/matrixStats/index.html Ted. - E-Mail: (Ted Harding) ted.hard...@wlandres.net Date: 20-Feb-2012 Time: 21:33:25 This message was sent by 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] Time Series - Trend Line
This isn't being plotted with any special time series methods (because it's not a time-based object here) so ?abline will work. Michael On Mon, Feb 20, 2012 at 12:14 PM, anaraster rrast...@gmail.com wrote: How can I had a trend line to my plot? My data looks like this: Date=seq(as.Date(1910/1/1), as.Date(1920/1/1), day) Values=runif(length(Date), min=-5, max=5) dataset=data.frame(Values,as.Date(Date)) I just want to add a linear trend line to this plot(dataset,col=rgb(1,0,0,1/8),cex=0.5,pch=19) -- View this message in context: http://r.789695.n4.nabble.com/Time-Series-Trend-Line-tp4404582p4404582.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] counting characters starting point
I have three character strings represented below as seq1, seq2, and seq3. Each string has a reference character different from the other. Thus, for seq1, the reference character is U, seq2, S (3rd S from left where A is leftmost character) and for seq3 Y. seq1 = PQRTUWXYseq2 = AQSDSSDHRSseq3 = EEZYJKFFBHO I wish to generate a 3 by 26 matrix where 3 represent seq1, seq2, seq3 and 26 the letters of the alphabet in order. A matrix entry should correspond to the number of characters from the reference character to the said character. We would consider characters to the left of the reference character to have a negative value and characters to the right a positive value. In addition, if a character appears more than once, we would consider the lowest of the counts. The output for seq1, seq2, seq3 shown below where 99 indicates missing. A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 99 99 99 99 99 99 99 99 99 99 99 99 99 99 99 -4 -3 -2 99 0 99 99 1 2 3 99 -5 99 99 -2 99 99 99 1 99 99 99 99 99 99 99 -4 99 2 0 99 99 99 99 99 99 99 99 5 99 99 2 3 99 6 99 1 2 99 99 99 7 99 99 99 99 99 99 99 99 99 0 -1 Could someone help me with a code on how to implement this.Thank you in advance for your helpJN [[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] slope in curves - how to compare?
Hello, Is there any formula or way to compare slopes of different functions? If we fit 2 functions in our data, and we have 2 slope parameters, how can we compare these slopes? Plotting y=5x and y=exp(5x) in which slope is equal to 5 in both of them.. doesn't seem that it makes sense to compare them. Maybe what I ask is basic statistics.. but you may be aware of some formula that could allow comparisons. best, John [[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 How to compare the concordance index between two nomograms with R
A nomogram is a graphical device for displaying a model. Please try again with your question. If you also wrote me privately earlier today please choose one mode of communication. Thanks Frank lijundfgd wrote I have got two kinds of nomogram for the same data set analyzed by Cox regression. My question is how to compare the concordance index between these two nomograms with R? - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/how-to-How-to-compare-the-concordance-index-between-two-nomograms-with-R-tp4404488p4405372.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] Computing plot size in Sweave
Yes, with the old good cat() and results=tex, you can do anything. It is just so unnatural. Why must a simple task like setting the size of a plot involve with so much coding work? % complete knitr code setup, include=FALSE= opts_knit$set(eval.opts = c('fig.height', 'fig.width')) my.height = 6; my.width = 7 @ use-my-size, fig.height=my.height, fig.height=my.height, out.width=.8\textwidth= plot(rnorm(100)) @ No cats are involved here. Besides, cat() is hard-coded; you have to remember to change the filename when your label is changed, and I do not mind writing pdf()/dev.off() once, but what if I have a hundred plots in the document -- five hundred cats jumping around? And you also want to hide them in the backyard so the readers won't see them. Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Mon, Feb 20, 2012 at 3:34 PM, Marc Schwartz marc_schwa...@me.com wrote: On Feb 20, 2012, at 9:15 AM, BXC (Bendix Carstensen) wrote: Sometimes you want to compute the physical size of a plot based on data. In R itself this is no problem. But is there a way to compute the values of height and width in S-weave, say: graph,fig=TRUE,height=xx,width=yy= where xx and yy are computed and not physically written in the document? Bendix Bendix, By default, Sweave.sty sets: \setkeys{Gin}{width=0.8\textwidth} which modifies the default \includegraphics LaTeX command auto-generated during Sweave processing. This means that irrespective of the 'height' and 'width' arguments in the figure chunk header, which do control the size of the PDF/EPS files created, the actual size of the graphic as included in the resultant document will ALWAYS be 80% of the current text width and the height will be scaled accordingly. In general, if you wanted to control the actual height and width of the figure in the resultant document, you could set: FigureChunkName,include=false,echo=false,fig=true,height=YourHeight,width=YourWidth= Plot Code Here @ \begin{figure}[tbp] \centering \includegraphics{RnwFileName-FigureChunkName} \caption[LOF Caption]{Some Longer Caption} \end{figure} 'RnwFileName' is the name of your working .Rnw Sweave file and 'FigureChunkName' is the name of the figure chunk and as a result, the graphic file name being created by Sweave, separated by the hyphen ('-'). By setting the 'include' option to false, Sweave does not auto-generate the \includegraphics line with the width=0.8\textwidth argument, and you then explicitly include it in the LaTeX code following the figure chunk. The plot file(s) would then be created with the height and width parameters in the figure chunk header and the resultant document will have a figure of the size you desire, overriding the default behavior. In my .Rnw files, I actually set: \usepackage[nogin]{Sweave} in my preamble, which overrides the default 'Gin' behavior. Then the height and width parameters in the figure chunks are reflected in the resultant document, but of course, I need to explicitly pre-define those. If you want to calculate the figure's height and width at run-time, I suspect that the only way to do that would be to have your R code generate all of the LaTeX code output at runtime as well. So something like the following: CodeChunkName,echo=false= # Plot Size Calculations Here Height - ResultOfCalcs Width - ResultOfCalcs pdf(MyPlotFileName.pdf, height = Height, width = Width) Plot Code Here dev.off() cat(\\begin{figure}[tbp]\n) cat(\\centering\n) cat(\\includegraphics{MyPlotFileName}\n) cat(\\caption[LOF Caption]{Some Longer Caption}\n) cat(\\end{figure}\n) @ The result of the cat() function calls will be to output the included character vectors to the .tex file being created by Sweave at run-time. So you are using R in a normal code chunk to generate LaTeX code. If you need an EPS file either in place of the PDF (because you are using postscript stuff like pstricks) or in addition to the PDF, you can replace the pdf() call with postscript() or run a second iteration of the plotting code using postscript()/dev.off() as well. HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] slope in curves - how to compare?
Hi John, What do you mean by 'compare'? y = exp(5x) could equally be said: y = exp(x)^5 so no, the slopes of those two lines are not the same or are only equal when you take the natural logarithm of y (log_{e}(y) = log_{e}(5x). They specify _completely_ different relationships between x and y; so what are you hoping to accomplish? Cheers, Josh On Mon, Feb 20, 2012 at 2:32 PM, John Kohr illuminati...@hotmail.com wrote: Hello, Is there any formula or way to compare slopes of different functions? If we fit 2 functions in our data, and we have 2 slope parameters, how can we compare these slopes? Plotting y=5x and y=exp(5x) in which slope is equal to 5 in both of them.. doesn't seem that it makes sense to compare them. Maybe what I ask is basic statistics.. but you may be aware of some formula that could allow comparisons. best, John [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] prediction for linear mixed model
Hi, I am wondering if we can make prediction on a linear mixed model by lmer() from lme4 package? Specifically I am fitting a very simple glmer() with binomial family distribution, and want to see if I can get the predicted probability like that in regular logistic regression? fit-glmer(y~x+(1|id),dat,family=binomial) where y is the response variable (0, 1), and x is a continuous variable. I would like to get a predicted probability at a given value of x. Many thanks John [[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] Call R from C
Dear All, I am new to calling R in C. I want to call sample R function in C. i.e. I want to do a sample equivalent to n - c(1:10) p - seq(0,10,length.out= 10) sample(n,size = 1, prob = p, replace = FALSE) how can I call this function directly in C? any help would be great, thanks, nitin [[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] bigmemory not really parallel
Hi, all, I have a really big matrix that I want to run k-means on. I tried: data - read.big.memory('mydata.csv',type='double',backingfile='mydata.bin',descriptorfile='mydata.desc') I'm using doMC to register multicore. library(doMC) registerDoMC(cores=8) ans-bigkmeans(data,k) In system monitor, it seems only one thread running R. Is there anything I did wrong? Thanks in advance for any suggestions. Best, Lishu [[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] Call R from C
Hi, On Mon, Feb 20, 2012 at 6:15 PM, nitin kumar nit...@gmail.com wrote: Dear All, I am new to calling R in C. I want to call sample R function in C. i.e. I want to do a sample equivalent to n - c(1:10) p - seq(0,10,length.out= 10) sample(n,size = 1, prob = p, replace = FALSE) how can I call this function directly in C? Perhaps the RInside package can help? http://cran.r-project.org/web/packages/RInside/index.html http://dirk.eddelbuettel.com/code/rinside.html HTH, -steve -- Steve Lianoglou Graduate Student: Computational Systems Biology | Memorial Sloan-Kettering Cancer Center | Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] question on axis labels
Hi All, I'm trying to label my plot axis with times (HH:MM) that correspond to a numeric index (values 0:6) for my time variable. I'd like to plot 08:00, 12:00, and so on, instead of 0 through 6. I have used the following line of code: axis(1, 0:6, labels=c(08:00, 12:00, 16:00, 20:00, 24:00, 04:00, 08:00), cex=0.8) [I've used both the 0:6 and at=c(0:6), with no effect.] My labels come out with a 0 - 6, location dependent, superimposed over my colon in my HH:MM string. So 08:00 looks like 08000, 12:00 looks like 12100. Any way of suppressing the at locations? I'm using version 2.14.0 on a mac My program pulls in the following packages (not sure relevant): require (Hmisc) require (lattice) require (gplots) Thanks for any suggestions, Gerard __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] question on axis labels
This works for me: plot(0:6, runif(7), xaxt=n) axis(1, at=0:6, labels=c(08:00, 12:00, 16:00, 20:00, 24:00, 04:00, 08:00), cex=0.8) You need the xaxt=n in the plot statement, and the correct form is at=0:6 Sarah On Mon, Feb 20, 2012 at 6:39 PM, Gerard Smits g_sm...@verizon.net wrote: Hi All, I'm trying to label my plot axis with times (HH:MM) that correspond to a numeric index (values 0:6) for my time variable. I'd like to plot 08:00, 12:00, and so on, instead of 0 through 6. I have used the following line of code: axis(1, 0:6, labels=c(08:00, 12:00, 16:00, 20:00, 24:00, 04:00, 08:00), cex=0.8) [I've used both the 0:6 and at=c(0:6), with no effect.] My labels come out with a 0 - 6, location dependent, superimposed over my colon in my HH:MM string. So 08:00 looks like 08000, 12:00 looks like 12100. Any way of suppressing the at locations? I'm using version 2.14.0 on a mac My program pulls in the following packages (not sure relevant): require (Hmisc) require (lattice) require (gplots) Thanks for any suggestions, Gerard -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to print km square in the form of km2
Hello, This is Elaine. I am drawing a plot with x-axis label with km square as the unit. Now I want to print km square in the form of km2 and output 2 as the uppercase. Please kindly help suggest command to show the uppercase. Thank you. Elaine [[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] question on axis labels
Worked like a charm! Thanks for your help. Gerard On Feb 20, 2012, at 3:52 PM, Sarah Goslee wrote: This works for me: plot(0:6, runif(7), xaxt=n) axis(1, at=0:6, labels=c(08:00, 12:00, 16:00, 20:00, 24:00, 04:00, 08:00), cex=0.8) You need the xaxt=n in the plot statement, and the correct form is at=0:6 Sarah On Mon, Feb 20, 2012 at 6:39 PM, Gerard Smits g_sm...@verizon.net wrote: Hi All, I'm trying to label my plot axis with times (HH:MM) that correspond to a numeric index (values 0:6) for my time variable. I'd like to plot 08:00, 12:00, and so on, instead of 0 through 6. I have used the following line of code: axis(1, 0:6, labels=c(08:00, 12:00, 16:00, 20:00, 24:00, 04:00, 08:00), cex=0.8) [I've used both the 0:6 and at=c(0:6), with no effect.] My labels come out with a 0 - 6, location dependent, superimposed over my colon in my HH:MM string. So 08:00 looks like 08000, 12:00 looks like 12100. Any way of suppressing the at locations? I'm using version 2.14.0 on a mac My program pulls in the following packages (not sure relevant): require (Hmisc) require (lattice) require (gplots) Thanks for any suggestions, Gerard -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to print km square in the form of km2
On 21/02/12 12:54, Elaine Kuo wrote: Hello, This is Elaine. I am drawing a plot with x-axis label with km square as the unit. Now I want to print km square in the form of km2 and output 2 as the uppercase. Please kindly help suggest command to show the uppercase. When you say as [the] uppercase I *think* you mean as a superscript. Assuming that I am correct in my supposition, you can achieve what you want via the syntax shown in the following example: plot(1:10,ylab=y,xlab=expression(plain(km)^2)) For details on how you do this sort of thing in general see: ?plotmath Be warned --- it's tricky! I find that I always need to experiment quite a lot before I get it right. Experimentation is cheap, but. HTH cheers, Rolf Turner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] bootstrap in time dependent Cox model
Dear R-list, I am wondering how to perform a bootstrap in R for the weighted time dependent Cox model (Andersen–Gill format, with multiple observations from each patients) to obtain the bootstrap standard error of the treatment effect. Below is an example dataset. Would 'censboot' be appropriate to use in this context? Any suggestions/references/direction to R-package will be highly appreciated. Thanks Ehsan ### dataset = read.csv(http://stat.ubc.ca/~e.karim/dataset2.csv;) head(dataset) # (tx = treatment, weight = IPTW) id tx enter exit event weight 1 1 0 01 0 1.037136 2 1 0 12 0 1.299079 3 1 0 23 0 1.352642 4 1 1 34 0 1.245575 5 1 0 45 0 1.360458 6 1 0 56 0 1.236780 time.dep.weighted.cox = coxph(Surv(enter, exit, event) ~ tx + cluster(id), robust = TRUE, data = dataset, weights = weight) time.dep.weighted.cox coef exp(coef) se(coef) robust se zp tx -0.2 0.819 0.22 0.25 -0.798 0.42 Likelihood ratio test=0.83 on 1 df, p=0.361 n= 9626, number of events= 81 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.