Re: [R] Creating dataframe names on the fly?
On Fri, Mar 20, 2009 at 7:18 PM, science! karthik@gmail.com wrote: I am aware that it is easily possible to create var names on the fly. e.g. assign(paste(m,i,sep=),j) but is it possible to assign dataframes to variables created on the fly? e.g. If I have a dataframe called master and I wanted to subset parts of those data into separate dataframes, I could do: m1=subset(master,master$SAMPLE=='1') m2=subset(master,master$SAMPLE=='2') . but I would like to do this in a loop. Can someone give me suggestions on how to accomplish this? I tried assign(paste(m,i,sep=),subset(master,master$SAMPLE==i) with no success. Are you sure you really need to name these dataframes? Here's a workaround that I use for these cases. Create your new data frames and add them to a list, as in myframes - list(subset(master,master$SAMPLE=='1'), m2=subset(master,master$SAMPLE=='2')) Then when you want to use these things, you can get the first one as myframes[[1]] or myframes[[2]]. You can name the objects inside the list: names(myframes) - c(A,B) This is just as good as referring to them by name, in my experience. It also has the benefit that because your dataframes are in a list, then you can use features like lapply to do things for each dataset. I'm reading ?assign now, and it appears you can actually name these things. name - paste(fred,4,sep=) x - data.frame(py=rnorm(10)) assign(name,x) ls() [1] fred4 mname name x name [1] fred4 fred4 py 1 -1.04243477 2 -0.66475049 3 -0.08576428 4 0.64369356 5 -0.06828696 6 1.15710627 7 -2.45041700 8 0.40139655 9 0.27320936 10 -0.98028020 pj -- Paul E. Johnson Professor, Political Science 1541 Lilac Lane, Room 504 University of Kansas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Goodness of fit for negative binomial model
On Fri, Mar 20, 2009 at 8:03 PM, t c mudiver1...@yahoo.com wrote: Dear r list, I am using glm.nb in the MASS package to fit negative binomial models to data on manta ray abundance, and AICctab in the bbmle package to compare model IC. However, I need to test for the goodness of fit of the full model, and have not been able to find a Pearson's Chi Squared statistic in any of the output. Am I missing it somewhere? Is there a way to run the test using either chisq.test() or goodfit()? I would appreciate any suggestions on how to test for goodness of fit in negative binomial models. Thanks, Tim Clark I found myself wondering if the Chi Square you get from anova() is the Pearson one you want? (see ?anova.negbin). Just an example: library(MASS) example(glm.nb) anova(quine.nb3) Analysis of Deviance Table Model: Negative Binomial(1.9284), link: log Response: Days Terms added sequentially (first to last) Df Deviance Resid. Df Resid. Dev P(|Chi|) NULL 145272.291 Sex 11.705 144270.586 0.192 Sex:Age 6 30.202 138240.384 3.599e-05 Sex:Eth 2 20.461 136219.923 3.606e-05 Sex:Lrn 28.459 134211.465 0.015 Sex:Eth:Lrn 2 18.287 132193.178 1.069e-04 Sex:Age:Lrn 48.649 128184.529 0.070 Sex:Age:Eth 69.503 122175.025 0.147 Sex:Age:Eth:Lrn 47.572 118167.453 0.109 Warning message: In anova.negbin(quine.nb3) : tests made without re-estimating 'theta' That warning about re-estimating theta concerns me a bit. If that's not the correct Pearson statistic, I bet you can get what you need if you take the Pearson residuals and calculate whatever. I am looking at ?residuals.glm and I note you can get Pearson residuals. If you have a formula from a dusty old stats book with the formula, I bet you can get it done. pj -- Paul E. Johnson Professor, Political Science 1541 Lilac Lane, Room 504 University of Kansas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot and Boxplot in the same graph
On Fri, Mar 20, 2009 at 10:02 PM, johnhj jhar...@web.de wrote: Hii, Is it possible, to use the plot() funktion and the boxplot() funktion together ? I will plot a simple graph and additionally to the graph on certain places boxplots. I have imagined to plot the graph a little bit transparency and show in the same graph on certain places boxplots Is it possible to do it in this way ? greetings, johnh -- Run the boxplot first, then use points() or other subsidiary plot functions to add the points in the figure. y - rnorm(100) x - gl(2,50) boxplot(x,y) points(x,y) -- Paul E. Johnson Professor, Political Science 1541 Lilac Lane, Room 504 University of Kansas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] libRlapack.so not found
Whenever I try to load the Matrix package, I get the following error message: libRlapack.so: cannot open shared object file: No such file or directory A file with that name is indeed not on the hard disk. I am using the R version which comes with Ubuntu Hardy Heron LTS. Here is the output of R.Version(): R.Version() $platform [1] i486-pc-linux-gnu $arch [1] i486 $os [1] linux-gnu $system [1] i486, linux-gnu $status [1] $major [1] 2 $minor [1] 7.2 $year [1] 2008 $month [1] 08 $day [1] 25 $`svn rev` [1] 46428 $language [1] R $version.string [1] R version 2.7.2 (2008-08-25) -- Johannes Hüsing There is something fascinating about science. One gets such wholesale returns of conjecture mailto:johan...@huesing.name from such a trifling investment of fact. http://derwisch.wikidot.com (Mark Twain, Life on the Mississippi) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot and Boxplot in the same graph
Hi there. Try the add parameter in boxplot: add logical, if true *add* boxplot to current plot. On Sat, Mar 21, 2009 at 5:02 AM, johnhj jhar...@web.de wrote: Hii, Is it possible, to use the plot() funktion and the boxplot() funktion together ? I will plot a simple graph and additionally to the graph on certain places boxplots. I have imagined to plot the graph a little bit transparency and show in the same graph on certain places boxplots Is it possible to do it in this way ? greetings, johnh -- View this message in context: http://www.nabble.com/Plot-and-Boxplot-in-the-same-graph-tp22632355p22632355.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. -- -- My contact information: Tal Galili Phone number: 972-50-3373767 FaceBook: Tal Galili My Blogs: http://www.r-statistics.com/ http://www.talgalili.com http://www.biostatistics.co.il [[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] R: Multi-line texts in plots
mau...@alice.it wrote: Now that I have my list of flags with theri respective values (thanks to all those who posted their suggestions): Flags Values 1 TrendOff 0 2 MOdwt 1 3ZeroPadding 1 4 Step1HSOff 1 5 Step1NumHSOff 4 6 Step1NumHSOff 1 7Step1ExtOff 1 8 Step2HSOff 1 9 Step2NumHSOff 4 10 Step2NumHSOff 1 11 Step2ExtOff 1 12Step3HSOff 1 13 Step3NumHSOff 4 14 Step3NumHSOff 1 15 Step3ExtOff 1 16Step4HSOff 1 17 Step4NumHSOff 4 18 Step4NumHSOff 1 19 Step4ExtOff 1 The next step is to insert the above list in a composite plot made up of 4 quadrants. The top 2 quadrants are filled with a barplot, the bottom left quadrant is filled with a 2-tracks plot. I would like to place the flags list in the bottom right quadrant. Hi Maura, You can get a rather basicbox of text in the lower right quadrant by starting a plot: plot(1:10,axes=FALSE,type=n) and then just whacking the text in with boxed.labels in the plotrix package. boxed.labels(5,5, Flags Values 1 TrendOff 0 2 MOdwt 1 3ZeroPadding 1 4 Step1HSOff 1 5 Step1NumHSOff 4 6 Step1NumHSOff 1 7Step1ExtOff 1 8 Step2HSOff 1 9 Step2NumHSOff 4 10 Step2NumHSOff 1 11 Step2ExtOff 1 12Step3HSOff 1 13 Step3NumHSOff 4 14 Step3NumHSOff 1 15 Step3ExtOff 1 16Step4HSOff 1 17 Step4NumHSOff 4 18 Step4NumHSOff 1 19 Step4ExtOff 1,adj=0) Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Combining Sweave and fancyvrb
Andrew Ellis wrote: You cannot have \label in an S chunk, as R will not know what to do with it. Neither can you have \label in a verbatim environment, as it will simply be typeset verbatim. Actually, with your definition of Sinput \DefineVerbatimEnvironment{Sinput}{Verbatim} { commentchar=@, frame=lines, label=\textrm{\bf R code}, numbers=left, framesep=10pt, fontshape=sl, commandchars=\\\{\}} you can have \label{} in the verbatim environment. I haven't tried this but something like = help() # \label{line1} @ might work, and I believe there is a switch that suppresses the comments for Sweave -Michael __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] limiting simulated animal movement
Hi, I am trying to simulate animal movement in a gridded landscape made up of cells. At each time step (iteration), the animal moves from one cell to another in a random fashion. This is how I am simulating movement, where a and b are the x,y co-ordinates of the animal at the previous time step: for (i in 1:no.of.steps){ direction - sample(1:8, 1) if(direction == 1){ a - a b - b - 1} if(direction == 2){ a - a b - b + 1} if(direction == 3){ a - a - 1 b - b} if(direction == 4){ a - a + 1 b - b} if(direction == 5){ a - a - 1 b - b + 1} if(direction == 6){ a - a + 1 b - b + 1} if(direction == 7){ a - a + 1 b - b - 1} if(direction == 8){ a - a - 1 b - b - 1} The problem is 1. I want to limit animals to a pre-defined circular home range 2. I want to limit animals to the borders of the landscape itself I tried to limit animals to their home range using: if (sqrt((x - a)^2 + (y - b)^2) radius.range) { a - a[i-1] b - b[i-1] } Where x and y are co-ordinates for the centre of the home range But this is not working - giving NA values for x and y co-ordinates. Does anyone know what to do? Thanks and cheers, Umesh [[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] limiting simulated animal movement
On Sat, Mar 21, 2009 at 1:35 PM, Umesh Srinivasan umesh.sriniva...@gmail.com wrote: Hi, I am trying to simulate animal movement in a gridded landscape made up of cells. At each time step (iteration), the animal moves from one cell to another in a random fashion. This is how I am simulating movement, where a and b are the x,y co-ordinates of the animal at the previous time step: for (i in 1:no.of.steps){ direction - sample(1:8, 1) if(direction == 1){ a - a b - b - 1} if(direction == 2){ a - a b - b + 1} if(direction == 3){ a - a - 1 b - b} if(direction == 4){ a - a + 1 b - b} if(direction == 5){ a - a - 1 b - b + 1} if(direction == 6){ a - a + 1 b - b + 1} if(direction == 7){ a - a + 1 b - b - 1} if(direction == 8){ a - a - 1 b - b - 1} The problem is 1. I want to limit animals to a pre-defined circular home range 2. I want to limit animals to the borders of the landscape itself Before you can answer question 1 or two, you have to decide what the animal should do when it reaches the boundary. Options are a) it just stays where it is, and ignores the step which would lead utside the home range / simulated landscape, it could be reflected (like light from a mirror), or move along the border. In the case of the simulated landscape, there are other possibilities, but I don't think they are appropriate for your case. The next step is to define the cells which belong to the allowed range in which the animal is allowed to move (e.g. a matrix with 0, where it is not allowed, and 1 where it is). The next step is to let your animal start walking, as you are doing, and then check if the destination cell is 0 or 1. Then you can decide, if it is 0, what you want to do. You have to remember the cell from which it is walking, to be able to react accordingly. a function which returns the movement in x and the movement in y direction, would be the best approach. i.e (UNTESTED): nextStep - function() { dx - sample(c(-1, 0, 1), 1) dy - sample(c(-1, 0, 1), 1) ## if it does not move, try again ## this could be done more elegant, but it should work if(dx==0 dy==0) { d - nextStep() dx - d[1] dy - d[2] } d - c(dx, dy) names(d) - c(dx, dy) return(d) } Hope this helps, Rainer I tried to limit animals to their home range using: if (sqrt((x - a)^2 + (y - b)^2) radius.range) { a - a[i-1] b - b[i-1] } Where x and y are co-ordinates for the centre of the home range But this is not working - giving NA values for x and y co-ordinates. Does anyone know what to do? Thanks and cheers, Umesh [[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. -- Rainer M. Krug, Centre of Excellence for Invasion Biology, Stellenbosch University, South Africa __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] bargraph.CI change se for sd
Hi there, I am a beginner. I would like to change the error bars in the bargraph.CI function from the default (se) to (sd). The help file says ci.fun= function(x) c(fun(x)-se(x), fun(x)+se(x)) Is there a simple way of telling the function what (x) precisely is - I already define in in the of the bargraph.CI function and assume that is should be able to use that information. cheers, Herwig -- View this message in context: http://www.nabble.com/bargraph.CI-change-se-for-sd-tp22633770p22633770.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] Solved: [Fwd: Matching failure in merge()]
I've found where the problem was and a way to solve this problem: One dataset was encoded (and read) as UTF-8 and the other one was encoded (en read) as latin3 In this case, even if at the terminal you see the same characters, R states that the two elements are not equal. Don't know if this is the way it has to be, or this is a bug. Anyway, editing the second file (encoded as latin3) with OpenOffice calc, saving it as UTF-8 and reading it in R with encoding=UTF-8 solved the problem Agus Original Message Subject: Matching failure in merge() Date: Thu, 19 Mar 2009 20:04:48 +0100 From: Agustin Lobo agustin.l...@ija.csic.es Reply-To: agustin.l...@ija.csic.es To: r-help@r-project.org Hi! I've done a merging between 2 dataframes using merge(): delme - merge(miDUNS50peqB,Bnomscodmunicipis,by.x=POBLACION,by.y=NOMMUNI,all.x=T,sort=F) After realizing some problems in the resulting dataset, I've found that the problem was that, in some cases, there was no match between the by.x and the by.y elements, despite the fact that, apparently, such matching should exist. Specifically, I get no match for the cases in which both the by.x and the by.y variables are equal to SANT VICENÇ DELS HORTS. In the following example I select fields POBLACION and NOMMUNI in two cases for which both fields should be identical to SANT VICENÇ DELS HORTS and I get: (082634 is the municipality code for that town in Bnomscodmunicipis and 08620 is the postal code for that town in delme) x - Bnomscodmunicipis[Bnomscodmunicipis$CODMUN==082634,1][1] y - miDUNS50peqB[miDUNS50peqB$CODPOSTAL==08620,POBLACION][1] str(x) chr SANT VICENÇ DELS HORTS str(y) chr SANT VICENÇ DELS HORTS x==y [1] FALSE which I cannot understand. If I just cut and paste those values and run the equivalent logical operation: SANT VICENÇ DELS HORTS == SANT VICENÇ DELS HORTS [1] TRUE The problem is that the values for SANT VICENÇ DELS HORTS in the resulting merged dataframe are wrong. Any help with this issue would be greatly appreciated, I'm really astonished. I think it might involve an encoding problem with the non-ascii characters, but don't get to see it. I'm using R 2.8.1 on ubuntu 8.04 (in english; And R is in English too) Agus -- Dr. Agustin Lobo Institut de Ciencies de la Terra Jaume Almera (CSIC) LLuis Sole Sabaris s/n 08028 Barcelona Spain Tel. 34 934095410 Fax. 34 934110012 email: agustin.l...@ija.csic.es http://www.ija.csic.es/gt/obster -- Dr. Agustin Lobo Institut de Ciencies de la Terra Jaume Almera (CSIC) LLuis Sole Sabaris s/n 08028 Barcelona Spain Tel. 34 934095410 Fax. 34 934110012 email: agustin.l...@ija.csic.es http://www.ija.csic.es/gt/obster __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Retrieving Vertices Coordinates from SpatialPolygons
Dear List, I'm trying to use different R packages for my Teaching Assistantship classes. And I cam out to an (apparently) very simple problem. I would like to retrieve the vertices coordinate of a SpatialPolygon data. I know this is stored in the coords slot, but I can't get access to it! I tried to coerce the SpatialPolygon into a data.frame but it doesn't work. Want I want is just a list of x and y coordinates of my polygon vertices without doing the workflow in GRASS!!! Thanks very much! Enrico Crema --- Enrico R. Crema PhD Candidate Institute of Archaeology, UCL AHRC Centre for the Evolution of Cultural Diversity +44 7899093191 http://www.cecd.ucl.ac.uk/people/?go1=91 e.cr...@ucl.ac.uk enrico.cr...@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] oggetto gstat
Ciao a tutti ho appena iniziato ad utilizzare R per ora per attuare un'analisi geostatistica di dati. Volevo sapere come poter creare un oggetto gstat partendo da un file testo(che ho gia importato con read.table)e che contiene 3 colonne: x,y,value. Mi servirebbe far questo per costruire un variogramma. So che la domanda molto probabilmente per voi sara' banalevi ringrazio comunque, Giuseppe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Retrieving Vertices Coordinates from SpatialPolygons
If it is in an S4 slot then there should be an extraction function, possibly with an obvious name like coords(). Failing that you could offer the name of the package that you are using. Perhaps that would contain an example to be used for illustration. -- David Winsemius On Mar 21, 2009, at 8:33 AM, Enrico R. Crema wrote: Dear List, I'm trying to use different R packages for my Teaching Assistantship classes. And I cam out to an (apparently) very simple problem. I would like to retrieve the vertices coordinate of a SpatialPolygon data. I know this is stored in the coords slot, but I can't get access to it! I tried to coerce the SpatialPolygon into a data.frame but it doesn't work. Want I want is just a list of x and y coordinates of my polygon vertices without doing the workflow in GRASS!!! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] bargraph.CI change se for sd
Package name? Example code? -- On Mar 21, 2009, at 4:22 AM, herwig wrote: Hi there, I am a beginner. I would like to change the error bars in the bargraph.CI function from the default (se) to (sd). The help file says ci.fun= function(x) c(fun(x)-se(x), fun(x)+se(x)) Is there a simple way of telling the function what (x) precisely is - I already define in in the of the bargraph.CI function and assume that is should be able to use that information. cheers, Herwig -- David Winsemius, MD Heritage Laboratories 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] oggetto gstat
Hi Giuseppe, The language of this mailing list is English. Ciao a tutti ho appena iniziato ad utilizzare R per ora per attuare un'analisi geostatistica di dati. Volevo sapere come poter creare un oggetto gstat partendo da un file testo(che ho gia importato con read.table)e che contiene 3 colonne: x,y,value. Mi servirebbe far questo per costruire un variogramma. So che la domanda molto probabilmente per voi sara' banalevi ringrazio comunque, Giuseppe The details of how to create a gstat object are given in the help page of gstat that you can read after typing in the following commands: library(gstat) ?gstat It apparently contains an example as well on how to create and plot a variogram. HTH, Tobias __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] object gstat
dear all i have this dataset: x,y, datavalue dati[,c(1,2,5)] [,1] [, 2] [,3] [1,] 2.386 3.077 1.740 [2,] 2.544 1.972 1.335 [3,] 2.807 3.347 1.610 [4,] 4.308 1.933 2.150 [5,] 4.383 1.081 1.565 [6,] 3.244 4.519 1.145 [7,] 3.925 3.785 0.894 [8,] 2.116 3.498 0.525 [9,] 1.842 0.989 0.240 [10,] 1.709 1.843 0.625 [11,] 3.800 4.578 3.873 [12,] 2.699 1.199 1.425 [13,] 3.033 4.384 0.455 [14,] 4.232 1.588 1.025 [15,] 4.750 1.369 0.775 .. .. I want to create gstat object where x,y are location and datavalue are the misurement,.thank __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Retrieving Vertices Coordinates from SpatialPolygons
On Sat, Mar 21, 2009 at 12:33 PM, Enrico R. Crema e.cr...@ucl.ac.uk wrote: Dear List, I'm trying to use different R packages for my Teaching Assistantship classes. And I cam out to an (apparently) very simple problem. I would like to retrieve the vertices coordinate of a SpatialPolygon data. I know this is stored in the coords slot, but I can't get access to it! I tried to coerce the SpatialPolygon into a data.frame but it doesn't work. Want I want is just a list of x and y coordinates of my polygon vertices without doing the workflow in GRASS!!! There's not really such thing as a SpatialPolygon - there's only SpatialPolygons - so maybe you've got a SpatialPolygons object with only one feature in it.. str(thing) will help here. This is what I get if I str() something that is a SpatialPolygons object with only one feature in it: str(poly) Formal class 'SpatialPolygons' [package sp] with 4 slots ..@ polygons :List of 1 .. ..$ :Formal class 'Polygons' [package sp] with 5 slots .. .. .. ..@ Polygons :List of 1 .. .. .. .. ..$ :Formal class 'Polygon' [package sp] with 5 slots .. .. .. .. .. .. ..@ labpt : num [1:2] 1 10 .. .. .. .. .. .. ..@ area : num 1 .. .. .. .. .. .. ..@ hole : logi FALSE .. .. .. .. .. .. ..@ ringDir: int 1 .. .. .. .. .. .. ..@ coords : num [1:5, 1:2] 0.5 0.5 1.5 1.5 0.5 9.5 10.5 10.5 9.5 9.5 .. .. .. .. .. .. .. ..- attr(*, dimnames)=List of 2 .. .. .. .. .. .. .. .. ..$ : chr [1:5] s1 s1 s1 s1 ... .. .. .. .. .. .. .. .. ..$ : chr [1:2] x y .. .. .. ..@ plotOrder: int 1 .. .. .. ..@ labpt: num [1:2] 1 10 .. .. .. ..@ ID : chr g1 .. .. .. ..@ area : num 1 ..@ plotOrder : int 1 ..@ bbox : num [1:2, 1:2] 0.5 9.5 1.5 10.5 .. ..- attr(*, dimnames)=List of 2 .. .. ..$ : chr [1:2] r1 r2 .. .. ..$ : chr [1:2] min max ..@ proj4string:Formal class 'CRS' [package sp] with 1 slots .. .. ..@ projargs: chr NA I'll explain, stepping through the structure breadth first, and backwards: @proj4string is the coordinate reference system slot @bbox is the bounding box slot @plotOrder is the order to plot the polygons @polygons is the list of Polygons objects. @polygons[[1]] is the first (and in this case, only) feature. It is an object of class 'Polygons' (non-spatial, since there's no @proj4string in this part of the structure). @polygons[[...@polygons is the 'Polygons' slot of class 'Polygons', and is a list of rings that make up the feature. @polygons[[...@polygons[[1]] is an object of class 'Polygon'. @polygons[[...@polygons[[1]]@coords is the coordinates of the Polygon: p...@polygons[[1]]@polygons[[...@coords xy s1 0.5 9.5 s1 0.5 10.5 s1 1.5 10.5 s1 1.5 9.5 s1 0.5 9.5 It's complex because the SpatialPolygons class can hold multiple features (such as administrative subdivisions), and each feature can be made from multiple rings (islands, holes). It seems overkill when all you really want is to store a single simple closed polygon though! But now you know how to get it. There may be methods for some of these @slot calls. Personally, I forget this everytime, but str() is immensely useful. As is a copy of the Bivand/Pebesma/Gomez-Rubio book! Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Retrieving Vertices Coordinates from SpatialPolygons
This came up on R-sig-geo two days ago and this is what I said: I have the following code in ggplot2 for turning a SpatialPolygon into a regular data frame of coordinates. You'll need to load ggplot2, and then run fortify(yoursp). fortify.SpatialPolygonsDataFrame - function(shape, region = NULL) { attr - as.data.frame(shape) # If not specified, split into regions based on first variable in attributes if (is.null(region)) { region - names(attr)[1] message(Using , region, to define regions.) } # Figure out how polygons should be split up into the region of interest polys - split(as.numeric(row.names(attr)), attr[, region]) cp - polygons(shape) # Union together all polygons that make up a region try_require(c(gpclib, maptools)) unioned - unionSpatialPolygons(cp, invert(polys)) coords - fortify(unioned) coords$order - 1:nrow(coords) coords } fortify.SpatialPolygons - function(model, data, ...) { ldply(mo...@polygons, fortify) } fortify.Polygons - function(model, data, ...) { subpolys - mo...@polygons pieces - ldply(seq_along(subpolys), function(i) { df - fortify(subpolys[[mo...@plotorder[i]]]) df$piece - i df }) within(pieces,{ order - 1:nrow(pieces) id - mo...@id piece - factor(piece) group - interaction(id, piece) }) } fortify.Polygon - function(model, data, ...) { df - as.data.frame(mo...@coords) names(df) - c(long, lat) df$order - 1:nrow(df) df$hole - mo...@hole df } fortify.SpatialLinesDataFrame - function(model, data, ...) { ldply(mo...@lines, fortify) } fortify.Lines - function(model, data, ...) { lines - mo...@lines pieces - ldply(seq_along(lines), function(i) { df - fortify(lines[[i]]) df$piece - i df }) within(pieces,{ order - 1:nrow(pieces) id - mo...@id piece - factor(piece) group - interaction(id, piece) }) } fortify.Line - function(model, data, ...) { df - as.data.frame(mo...@coords) names(df) - c(long, lat) df$order - 1:nrow(df) df } Hadley On Sat, Mar 21, 2009 at 7:33 AM, Enrico R. Crema e.cr...@ucl.ac.uk wrote: Dear List, I'm trying to use different R packages for my Teaching Assistantship classes. And I cam out to an (apparently) very simple problem. I would like to retrieve the vertices coordinate of a SpatialPolygon data. I know this is stored in the coords slot, but I can't get access to it! I tried to coerce the SpatialPolygon into a data.frame but it doesn't work. Want I want is just a list of x and y coordinates of my polygon vertices without doing the workflow in GRASS!!! Thanks very much! Enrico Crema --- Enrico R. Crema PhD Candidate Institute of Archaeology, UCL AHRC Centre for the Evolution of Cultural Diversity +44 7899093191 http://www.cecd.ucl.ac.uk/people/?go1=91 e.cr...@ucl.ac.uk enrico.cr...@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. -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Bug with the col option in plot function
Thanks, David, utils::str(pdf.options()) returns exactly the same results as yours. The colormodel is set to rgb already. The reason I thought this is a bug is that the same plot function + col option works fine when pch=0 or other numbers, except for 1 or 16 (empty or solid circle) or any letter. Therefore, I have reason to believe that this is not something related to general plotting setting. And also I reproduced the same problem in different versions of R (both 2.4 and 2.8). Therefore, I donât think this is a problem with my specific R version. Heyi --- On Fri, 3/20/09, David Winsemius dwinsem...@comcast.net wrote: From: David Winsemius dwinsem...@comcast.net Subject: Re: [R] Bug with the col option in plot function To: xiaohey...@yahoo.com Cc: r-help@r-project.org Help r-help@r-project.org, R-SIG-Mac Mailing List r-sig-...@stat.math.ethz.ch Date: Friday, March 20, 2009, 7:45 PM Really belongs o R-SIG-Mac list and have copied it there. I cannot reproduce on my Mac. I get the same colors on the pdf file with that code as I do on the screen device. I have in in the past needed to set up a device before plotting: trellis.device(device=postscript, color = TRUE) ... but you are not using a trellis function or creating postscript. What does utils::str(pdf.options()) return? On mine I get this List of 15 $ width : num 7 $ height : num 7 $ onefile: logi TRUE $ family : chr Helvetica $ title : chr R Graphics Output $ fonts : NULL $ version: chr 1.4 $ paper : chr special $ encoding : chr default $ bg : chr transparent $ fg : chr black $ pointsize : num 12 $ pagecentre : logi TRUE $ colormodel : chr rgb $ useDingbats: logi TRUE Perhaps this could be a cure?: pdf.options(colormodel = rgb) You probably ought to update as well before raising the bug-flag. --David Winsemius, MD Heritage Laboratories West Hartford, CT sessionInfo() R version 2.8.1 Patched (2009-01-19 r47650) i386-apple-darwin9.6.0 locale: en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] splines stats graphics grDevices utils datasets methods base other attached packages: [1] termstrc_1.1Design_2.1-2Hmisc_3.5-2 survival_2.34-1 loaded via a namespace (and not attached): [1] cluster_1.11.12 grid_2.8.1 lattice_0.17-20 tools_2.8.1 On Mar 20, 2009, at 6:47 PM, heyi xiao wrote: I lose control on colors when I plot points with pch=1 or 16 (empty or solid circle) or any letter, say A. For example: x=runif(5) y=runif(5) pdf(plot.pdf) plot(x, y, type='p', pch=1, col = 1:5) #just black points plot(x, y, type='p', pch=0, col = 1:5) #points with different colors dev.off() This problem occurred for different versions of R under Mac OS X 10.4. not sure whether this is true for other operating systems. I used my most basic settings of R without any special package loaded. Any suggestions/ideas would be appreciated. sessionInfo() R version 2.8.0 (2008-10-20) powerpc-apple-darwin8.11.1 locale: C attached base packages: [1] stats graphics grDevices utils datasets methods base [[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] Retrieving Vertices Coordinates from SpatialPolygons
On Mar 21, 2009, at 10:31 AM, Barry Rowlingson wrote: On Sat, Mar 21, 2009 at 12:33 PM, Enrico R. Crema e.cr...@ucl.ac.uk wrote: Dear List, I'm trying to use different R packages for my Teaching Assistantship classes. And I cam out to an (apparently) very simple problem. I would like to retrieve the vertices coordinate of a SpatialPolygon data. I know this is stored in the coords slot, but I can't get access to it! I tried to coerce the SpatialPolygon into a data.frame but it doesn't work. Want I want is just a list of x and y coordinates of my polygon vertices without doing the workflow in GRASS!!! There's not really such thing as a SpatialPolygon - there's only SpatialPolygons - so maybe you've got a SpatialPolygons object with only one feature in it.. str(thing) will help here. This is what I get if I str() something that is a SpatialPolygons object with only one feature in it: str(poly) Formal class 'SpatialPolygons' [package sp] with 4 slots ..@ polygons :List of 1 .. ..$ :Formal class 'Polygons' [package sp] with 5 slots .. .. .. ..@ Polygons :List of 1 .. .. .. .. ..$ :Formal class 'Polygon' [package sp] with 5 slots .. .. .. .. .. .. ..@ labpt : num [1:2] 1 10 .. .. .. .. .. .. ..@ area : num 1 .. .. .. .. .. .. ..@ hole : logi FALSE .. .. .. .. .. .. ..@ ringDir: int 1 .. .. .. .. .. .. ..@ coords : num [1:5, 1:2] 0.5 0.5 1.5 1.5 0.5 9.5 10.5 10.5 9.5 9.5 .. .. .. .. .. .. .. ..- attr(*, dimnames)=List of 2 .. .. .. .. .. .. .. .. ..$ : chr [1:5] s1 s1 s1 s1 ... .. .. .. .. .. .. .. .. ..$ : chr [1:2] x y .. .. .. ..@ plotOrder: int 1 .. .. .. ..@ labpt: num [1:2] 1 10 .. .. .. ..@ ID : chr g1 .. .. .. ..@ area : num 1 ..@ plotOrder : int 1 ..@ bbox : num [1:2, 1:2] 0.5 9.5 1.5 10.5 .. ..- attr(*, dimnames)=List of 2 .. .. ..$ : chr [1:2] r1 r2 .. .. ..$ : chr [1:2] min max ..@ proj4string:Formal class 'CRS' [package sp] with 1 slots .. .. ..@ projargs: chr NA I'll explain, stepping through the structure breadth first, and backwards: @proj4string is the coordinate reference system slot @bbox is the bounding box slot @plotOrder is the order to plot the polygons @polygons is the list of Polygons objects. @polygons[[1]] is the first (and in this case, only) feature. It is an object of class 'Polygons' (non-spatial, since there's no @proj4string in this part of the structure). @polygons[[...@polygons is the 'Polygons' slot of class 'Polygons', and is a list of rings that make up the feature. @polygons[[...@polygons[[1]] is an object of class 'Polygon'. @polygons[[...@polygons[[1]]@coords is the coordinates of the Polygon: p...@polygons[[1]]@polygons[[...@coords xy s1 0.5 9.5 s1 0.5 10.5 s1 1.5 10.5 s1 1.5 9.5 s1 0.5 9.5 It's complex because the SpatialPolygons class can hold multiple features (such as administrative subdivisions), and each feature can be made from multiple rings (islands, holes). It seems overkill when all you really want is to store a single simple closed polygon though! But now you know how to get it. There may be methods for some of these @slot calls. The last example on the following page suggests to me that there is a coordinates function for this class, although I do not see it mentioned in the body of the class description: http://finzi.psych.upenn.edu/R/library/sp/html/SpatialPolygons-class.html Personally, I forget this everytime, but str() is immensely useful. As is a copy of the Bivand/Pebesma/Gomez-Rubio book! Barry David Winsemius, MD Heritage Laboratories 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] Generalized Extreme Value Distribution (LMOM package) and Frechet Distribution
Hi, The package evd most functions that one would need for analysis of Extreme Values so you should consider giving it a try. By the way your vector of numerical values is not valid; there are a couple of values with repeated decimal point separators. Regards, Christos Argyropoulos University of Pittsburgh _ ! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 avoid switching on input type?
Hi, I need some help improving this ugly code I wrote. I would like to shift forward a zoo object, matrix, ts, or list by shift items (default 1) and fill the holes with 0's. The code below works, but it looks ugly. I could write a function lag.zerofill() which calls the two functions below depending on the class() of the item passed in, but that feels very unlike R. What is the proper way to write this code so that it works for all input types? Is a switch depending on the input type really necessary? I am hoping the answer is no. Thanks in advance. - Ken # --- require( zoo ); inp - c( 5, 9, 4, 2, 1 ); inp2 - c( 6, 6, 0, 4, 2 ); inp.zoo - zoo( cbind( inp, inp2 ), as.Date(2003-02-01) + (0:(length(inp)-1))); lag.zerofill.list - function( m, shift=1, ...) { c( rep(0,shift), m[-((length(m)-shift+1):length(m))] ); } lag.zerofill.zoo - function( m, shift=1, ...) { k - rbind( m[1:shift,], lag(m,-(shift))); k[1:shift,] - 0; k; } lag.zerofill.list( inp ) # works ok lag.zerofill.zoo( inp.zoo ) # works ok -- View this message in context: http://www.nabble.com/How-to-avoid-switching-on-input-type--tp22637249p22637249.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 Can I Concatenate Every Row in a Data Frame with Every Other Row?
I have a data frame with roughly 500 rows and 120 variables. I would like to generate a new data frame that will include one row for each PAIR of rows in the original data frame and will include all 120 + 120 = 240 variables from the two rows. I need only one row for each pair, not two rows. Thus the new data frame will contain 500 x 499 / 2 = 124,750 rows. Is there an easy way to do this with R? Thanks in advance, Don Macnaughton __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 Can I Concatenate Every Row in a Data Frame with Every Other Row?
Try this: x - data.frame(a=1:100, b=100:1, c=sample(100)) # assume even number of rows: bind the even/odd together even - seq(nrow(x)) %% 2 new.x - cbind(x[even==1,], x[even==0,]) head(new.x) a b c a.1 b.1 c.1 1 1 100 69 2 99 60 3 3 98 24 4 97 26 5 5 96 71 6 95 43 7 7 94 17 8 93 70 9 9 92 10 10 91 79 11 11 90 56 12 89 50 On Sat, Mar 21, 2009 at 12:01 PM, Donald Macnaughton don...@matstat.com wrote: I have a data frame with roughly 500 rows and 120 variables. I would like to generate a new data frame that will include one row for each PAIR of rows in the original data frame and will include all 120 + 120 = 240 variables from the two rows. I need only one row for each pair, not two rows. Thus the new data frame will contain 500 x 499 / 2 = 124,750 rows. Is there an easy way to do this with R? Thanks in advance, Don Macnaughton __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How Can I Concatenate Every Row in a Data Frame with Every Other Row?
On 21/03/2009 12:01 PM, Donald Macnaughton wrote: I have a data frame with roughly 500 rows and 120 variables. I would like to generate a new data frame that will include one row for each PAIR of rows in the original data frame and will include all 120 + 120 = 240 variables from the two rows. I need only one row for each pair, not two rows. Thus the new data frame will contain 500 x 499 / 2 = 124,750 rows. Is there an easy way to do this with R? Probably the easiest is to generate row indices for each pair, e.g. n - nrow(mydata) row1 - rep(1:n, n) row2 - rep(1:n, each=n) keep - row1 row2 big - cbind(mydata[row1[keep],], mydata[row2[keep],]) With a simple example mydata - data.frame(a=1:3, b=letters[1:3]) mydata a b 1 1 a 2 2 b 3 3 c this produces big a b a b 1 1 a 2 b 1.1 1 a 3 c 2 2 b 3 c __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Can not replicate estimates with rScreen function from ROSSI Bayesian Statistics and Marketing
Hi R-users, I have the following problem: I am trying to learn something about bayes methodology and started paying around bayesm package, but could not replicate the Conjunctive model's estimates as they appear in Rossi et al Bayesian Statistics and Marketing, 2005, JWS, pages 264-265, Table CS4.4. I have downloaded in my working directory the documents from http://faculty.chicagobooth.edu/peter.rossi/research/bsm.html and then i have sourced the functions 2 times: one with 1000 MCMC iterations (i simply sourced without any kind of modifications) and one with 4000 iterations (i have modified in the source code the number of iterations to 4000 instead of the defaulted value 1000, and changed the name out into out2). Can anyone tell me what am I doing wrong, and why don't i get the same estimates? Do i need more iterations or other modifications in the source code? Thank you very much and have a great day ahead! PS: I have no problem replicating the estimates of the BANK EXAMPLE in the A.3 HIERARCHICAL BAYES MODELING – AN EXAMPLE pages 303- 322 Eugen. source(C:\\Documents and Settings\\Administrator\\My Documents\\rScreen.R) source(C:\\Documents and Settings\\Administrator\\My Documents\\run screening rules.R) t(matrix(apply(out$betadraw[,,500:1000],2,mean),ncol=18)) [,1] [1,] -1.832448426 [2,] -0.355615613 [3,] -1.210309206 [4,] -0.052342073 [5,] 0.182849361 [6,] 0.350787951 [7,] 0.598865166 [8,] -0.186233704 [9,] 0.652014888 [10,] -0.625699004 [11,] 0.469491733 [12,] 0.921956623 [13,] 1.304895684 [14,] -0.003796531 [15,] 0.680552062 [16,] 0.693060152 [17,] 0.881657248 [18,] 0.004990399 t(matrix(apply(out2$betadraw[,,3000:4000],2,mean),ncol=18)) [,1] [1,] -1.21287139 [2,] 0.30380276 [3,] -0.44522457 [4,] 0.12716930 [5,] 0.18397110 [6,] 0.36007492 [7,] 0.66189078 [8,] -0.17114451 [9,] 0.71097740 [10,] -0.32130846 [11,] 0.52676240 [12,] 0.84596696 [13,] 1.22110159 [14,] -0.02148484 [15,] 0.44813543 [16,] 0.47782513 [17,] 0.65008370 [18,] 0.01589271 sessionInfo() R version 2.8.1 (2008-12-22) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] bayesm_2.2-2 loaded via a namespace (and not attached): [1] tools_2.8.1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 Can I Concatenate Every Row in a Data Frame with Every Other Row?
I hacked at a bit differently than Duncan. See if these help pages and this example point another way: ?combn ?[ df - data.frame(a = 1:4, b=LETTERS[1:4]) n - nrow(df) cbind(df[combn(1:n,2)[1,],], df[combn(1:n,2)[2,],] ) a b a b 1 1 A 2 B 1.1 1 A 3 C 1.2 1 A 4 D 2 2 B 3 C 2.1 2 B 4 D 3 3 C 4 D -- David Winsemius On Mar 21, 2009, at 12:01 PM, Donald Macnaughton wrote: I have a data frame with roughly 500 rows and 120 variables. I would like to generate a new data frame that will include one row for each PAIR of rows in the original data frame and will include all 120 + 120 = 240 variables from the two rows. I need only one row for each pair, not two rows. Thus the new data frame will contain 500 x 499 / 2 = 124,750 rows. Is there an easy way to do this with R? David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Forestplot () box size question
Hi All, I have been able to modify the x-axis to start at zero by adding xlow and xhigh parameters; that was pretty simple. I have been unable to find the location of the code that would turn off the information weighting of the box size (I have smaller randomized trials getting less weight than a much larger non-randomized trial). The function is forestplot() from rmeta. Thanks for any help. Gerard Slightly modified working function with data and a call follows: fplot=function (labeltext, mean, lower, upper, align = NULL, is.summary = FALSE, clip = c(-Inf, Inf), xlab = , zero = 1, graphwidth = unit(3,inches), col = meta.colors(), xlog = FALSE, xticks = NULL, xlow=0, xhigh, digitsize, ...) { require(grid) || stop(`grid' package not found) require(rmeta) || stop(`rmeta' package not found) drawNormalCI - function(LL, OR, UL, size) { size = 0.75 * size clipupper - convertX(unit(UL, native), npc, valueOnly = TRUE) 1 cliplower - convertX(unit(LL, native), npc, valueOnly = TRUE) 0 box - convertX(unit(OR, native), npc, valueOnly = TRUE) clipbox - box 0 || box 1 if (clipupper || cliplower) { ends - both lims - unit(c(0, 1), c(npc, npc)) if (!clipupper) { ends - first lims - unit(c(0, UL), c(npc, native)) } if (!cliplower) { ends - last lims - unit(c(LL, 1), c(native, npc)) } grid.lines(x = lims, y = 0.5, arrow = arrow(ends = ends, length = unit(0.05, inches)), gp = gpar(col = col$lines)) if (!clipbox) grid.rect(x = unit(OR, native), width = unit(size, snpc), height = unit(size, snpc), gp = gpar(fill = col$box, col = col$box)) } else { grid.lines(x = unit(c(LL, UL), native), y = 0.5, gp = gpar(col = col$lines)) grid.rect(x = unit(OR, native), width = unit(size, snpc), height = unit(size, snpc), gp = gpar(fill = col$box, col = col$box)) if ((convertX(unit(OR, native) + unit(0.5 * size, lines), native, valueOnly = TRUE) UL) (convertX(unit(OR, native) - unit(0.5 * size, lines), native, valueOnly = TRUE) LL)) grid.lines(x = unit(c(LL, UL), native), y = 0.5, gp = gpar(col = col$lines)) } } drawSummaryCI - function(LL, OR, UL, size) { grid.polygon(x = unit(c(LL, OR, UL, OR), native), y = unit(0.5 + c(0, 0.5 * size, 0, -0.5 * size), npc), gp = gpar(fill = col$summary, col = col$summary)) } plot.new() widthcolumn - !apply(is.na(labeltext), 1, any) nc - NCOL(labeltext) labels - vector(list, nc) if (is.null(align)) align - c(l, rep(r, nc - 1)) else align - rep(align, length = nc) nr - NROW(labeltext) is.summary - rep(is.summary, length = nr) for (j in 1:nc) { labels[[j]] - vector(list, nr) for (i in 1:nr) { if (is.na(labeltext[i, j])) next x - switch(align[j], l = 0, r = 1, c = 0.5) just - switch(align[j], l = left, r = right, c = center) labels[[j]][[i]] - textGrob(labeltext[i, j], x = x, just = just, gp = gpar(fontface = if (is.summary[i]) bold else plain, col = rep(col$text, length = nr)[i])) } } colgap - unit(3, mm) colwidths - unit.c(max(unit(rep(1, sum(widthcolumn)), grobwidth, labels[[1]][widthcolumn])), colgap) if (nc 1) { for (i in 2:nc) colwidths - unit.c(colwidths, max(unit(rep(1, sum(widthcolumn)), grobwidth, labels[[i]][widthcolumn])), colgap) } colwidths - unit.c(colwidths, graphwidth) pushViewport(viewport(layout = grid.layout(nr + 1, nc * 2 + 1, widths = colwidths, heights = unit(c(rep(1, nr), 0.5), lines cwidth - (upper - lower) #xrange - c(max(min(lower, na.rm = TRUE), clip[1]), min(max(upper, na.rm = TRUE), clip[2])) xrange - c(xlow,xhigh) info - 1/cwidth info - info/max(info[!is.summary], na.rm = TRUE) info[is.summary] - 1 for (j in 1:nc) { for (i in 1:nr) { if (!is.null(labels[[j]][[i]])) { pushViewport(viewport(layout.pos.row = i, layout.pos.col = 2 * j - 1)) grid.draw(labels[[j]][[i]]) popViewport() } } } pushViewport(viewport(layout.pos.col = 2 * nc + 1, xscale = xrange)) grid.lines(x = unit(zero, native), y = 0:1, gp = gpar(col = col$zero)) if (xlog) { if (is.null(xticks)) { ticks - pretty(exp(xrange))
Re: [R] Forestplot () box size question
If you look at the original code (or at the help page), you should see a boxsize parameter. If you set that to 1 in the call you get boxes all the same size. Presumably that could be modified to suit your needs. You seem to have removed that section of the code. The two lines with that parameter are: if (!is.null(boxsize)) info - rep(boxsize, length = length(info)) -- David Winsemius, MD Heritage Laboratories West Hartford, CT On Mar 21, 2009, at 1:03 PM, Gerard Smits wrote: Hi All, I have been able to modify the x-axis to start at zero by adding xlow and xhigh parameters; that was pretty simple. I have been unable to find the location of the code that would turn off the information weighting of the box size (I have smaller randomized trials getting less weight than a much larger non-randomized trial). The function is forestplot() from rmeta. Thanks for any help. Gerard Slightly modified working function with data and a call follows: fplot=function (labeltext, mean, lower, upper, align = NULL, is.summary = FALSE, clip = c(-Inf, Inf), xlab = , zero = 1, graphwidth = unit(3,inches), col = meta.colors(), xlog = FALSE, xticks = NULL, xlow=0, xhigh, digitsize, ...) { require(grid) || stop(`grid' package not found) require(rmeta) || stop(`rmeta' package not found) drawNormalCI - function(LL, OR, UL, size) { size = 0.75 * size clipupper - convertX(unit(UL, native), npc, valueOnly = TRUE) 1 cliplower - convertX(unit(LL, native), npc, valueOnly = TRUE) 0 box - convertX(unit(OR, native), npc, valueOnly = TRUE) clipbox - box 0 || box 1 if (clipupper || cliplower) { ends - both lims - unit(c(0, 1), c(npc, npc)) if (!clipupper) { ends - first lims - unit(c(0, UL), c(npc, native)) } if (!cliplower) { ends - last lims - unit(c(LL, 1), c(native, npc)) } grid.lines(x = lims, y = 0.5, arrow = arrow(ends = ends, length = unit(0.05, inches)), gp = gpar(col = col $lines)) if (!clipbox) grid.rect(x = unit(OR, native), width = unit(size, snpc), height = unit(size, snpc), gp = gpar(fill = col$box, col = col$box)) } else { grid.lines(x = unit(c(LL, UL), native), y = 0.5, gp = gpar(col = col$lines)) grid.rect(x = unit(OR, native), width = unit(size, snpc), height = unit(size, snpc), gp = gpar(fill = col$box, col = col$box)) if ((convertX(unit(OR, native) + unit(0.5 * size, lines), native, valueOnly = TRUE) UL) (convertX(unit(OR, native) - unit(0.5 * size, lines), native, valueOnly = TRUE) LL)) grid.lines(x = unit(c(LL, UL), native), y = 0.5, gp = gpar(col = col$lines)) } } drawSummaryCI - function(LL, OR, UL, size) { grid.polygon(x = unit(c(LL, OR, UL, OR), native), y = unit(0.5 + c(0, 0.5 * size, 0, -0.5 * size), npc), gp = gpar(fill = col$summary, col = col$summary)) } plot.new() widthcolumn - !apply(is.na(labeltext), 1, any) nc - NCOL(labeltext) labels - vector(list, nc) if (is.null(align)) align - c(l, rep(r, nc - 1)) else align - rep(align, length = nc) nr - NROW(labeltext) is.summary - rep(is.summary, length = nr) for (j in 1:nc) { labels[[j]] - vector(list, nr) for (i in 1:nr) { if (is.na(labeltext[i, j])) next x - switch(align[j], l = 0, r = 1, c = 0.5) just - switch(align[j], l = left, r = right, c = center) labels[[j]][[i]] - textGrob(labeltext[i, j], x = x, just = just, gp = gpar(fontface = if (is.summary[i]) bold else plain, col = rep(col$text, length = nr)[i])) } } colgap - unit(3, mm) colwidths - unit.c(max(unit(rep(1, sum(widthcolumn)), grobwidth, labels[[1]][widthcolumn])), colgap) if (nc 1) { for (i in 2:nc) colwidths - unit.c(colwidths, max(unit(rep(1, sum(widthcolumn)), grobwidth, labels[[i]] [widthcolumn])), colgap) } colwidths - unit.c(colwidths, graphwidth) pushViewport(viewport(layout = grid.layout(nr + 1, nc * 2 + 1, widths = colwidths, heights = unit(c(rep(1, nr), 0.5), lines cwidth - (upper - lower) #xrange - c(max(min(lower, na.rm = TRUE), clip[1]), min(max(upper, na.rm = TRUE), clip[2])) xrange - c(xlow,xhigh) info - 1/cwidth info - info/max(info[!is.summary], na.rm = TRUE) info[is.summary] - 1 for (j in 1:nc) { for (i in 1:nr) { if (!is.null(labels[[j]][[i]])) {
Re: [R] How to avoid switching on input type?
Create an S3 generic lag.zerofill and then define methods for each class: lag.zerofill - function(x, k = 1, ...) UseMethod(lag.zerofill) lag.zerofill.zoo - function(x, k, ...) { m - merge(x, lag(x, k), fill = 0) structure(m[, -(1:ncol(x))], dimnames = list(NULL, colnames(x))) } # lag.zerofill.list - ... # test lag.zerofill(inp.zoo, -1) Running the above gives (last line shown only): lag.zerofill(inp.zoo, -1) inp inp2 2003-02-01 00 2003-02-02 56 2003-02-03 96 2003-02-04 40 2003-02-05 24 On Sat, Mar 21, 2009 at 11:47 AM, Ken-JP kfmf...@gmail.com wrote: Hi, I need some help improving this ugly code I wrote. I would like to shift forward a zoo object, matrix, ts, or list by shift items (default 1) and fill the holes with 0's. The code below works, but it looks ugly. I could write a function lag.zerofill() which calls the two functions below depending on the class() of the item passed in, but that feels very unlike R. What is the proper way to write this code so that it works for all input types? Is a switch depending on the input type really necessary? I am hoping the answer is no. Thanks in advance. - Ken # --- require( zoo ); inp - c( 5, 9, 4, 2, 1 ); inp2 - c( 6, 6, 0, 4, 2 ); inp.zoo - zoo( cbind( inp, inp2 ), as.Date(2003-02-01) + (0:(length(inp)-1))); lag.zerofill.list - function( m, shift=1, ...) { c( rep(0,shift), m[-((length(m)-shift+1):length(m))] ); } lag.zerofill.zoo - function( m, shift=1, ...) { k - rbind( m[1:shift,], lag(m,-(shift))); k[1:shift,] - 0; k; } lag.zerofill.list( inp ) # works ok lag.zerofill.zoo( inp.zoo ) # works ok -- View this message in context: http://www.nabble.com/How-to-avoid-switching-on-input-type--tp22637249p22637249.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] Forestplot () box size question
Hi David, I just checked to make sure I had the latest version. I see no boxsize option in the forestplot function parameters or any other place in the code. function (labeltext, mean, lower, upper, align = NULL, is.summary = FALSE, clip = c(-Inf, Inf), xlab = , zero = 0, graphwidth = unit(2, inches), col = meta.colors(), xlog = FALSE, xticks = NULL, ...) { Thanks, Gerard At 10:32 AM 3/21/2009, David Winsemius wrote: if (!is.null(boxsize)) info - rep(boxsize, length = length(info)) [[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] Forestplot () box size question
Latest version is a tad non-specific. The help page for (my) package rmeta, version 2.15 (download and compiled today) says: Usage forestplot(labeltext, mean, lower, upper, align = NULL, is.summary = FALSE, clip = c(-Inf, Inf), xlab = , zero = 0, graphwidth = unit(2, inches), col = meta.colors(), xlog = FALSE, xticks=NULL, boxsize=NULL,...) -- sessionInfo() R version 2.8.1 Patched (2009-01-19 r47650) i386-apple-darwin9.6.0 locale: en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] grid stats graphics grDevices utils datasets methods base other attached packages: [1] rmeta_2.15 zoo_1.5-5 loaded via a namespace (and not attached): [1] lattice_0.17-20 tools_2.8.1 -- David Winsemius, MD Heritage Laboratories West Hartford, CT On Mar 21, 2009, at 2:01 PM, Gerard Smits wrote: Hi David, I just checked to make sure I had the latest version. I see no boxsize option in the forestplot function parameters or any other place in the code. function (labeltext, mean, lower, upper, align = NULL, is.summary = FALSE, clip = c(-Inf, Inf), xlab = , zero = 0, graphwidth = unit(2, inches), col = meta.colors(), xlog = FALSE, xticks = NULL, ...) { Thanks, Gerard At 10:32 AM 3/21/2009, David Winsemius wrote: if (!is.null(boxsize)) info - rep(boxsize, length = length(info)) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Forestplot () box size question
Hi David, I did a general package update, but it must not have been quite as complete as I had hoped. I will make sure I download 2.15 and go from there. Thanks for you help. Gerard At 11:10 AM 3/21/2009, David Winsemius wrote: Latest version is a tad non-specific. The help page for (my) package rmeta, version 2.15 (download and compiled today) says: Usage forestplot(labeltext, mean, lower, upper, align = NULL, is.summary = FALSE, clip = c(-Inf, Inf), xlab = , zero = 0, graphwidth = unit(2, inches), col = meta.colors(), xlog = FALSE, xticks=NULL, boxsize=NULL,...) -- sessionInfo() R version 2.8.1 Patched (2009-01-19 r47650) i386-apple-darwin9.6.0 locale: en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] grid stats graphics grDevices utils datasets methods base other attached packages: [1] rmeta_2.15 zoo_1.5-5 loaded via a namespace (and not attached): [1] lattice_0.17-20 tools_2.8.1 -- David Winsemius, MD Heritage Laboratories West Hartford, CT On Mar 21, 2009, at 2:01 PM, Gerard Smits wrote: Hi David, I just checked to make sure I had the latest version. I see no boxsize option in the forestplot function parameters or any other place in the code. function (labeltext, mean, lower, upper, align = NULL, is.summary = FALSE, clip = c(-Inf, Inf), xlab = , zero = 0, graphwidth = unit(2, inches), col = meta.colors(), xlog = FALSE, xticks = NULL, ...) { Thanks, Gerard At 10:32 AM 3/21/2009, David Winsemius wrote: if (!is.null(boxsize)) info - rep(boxsize, length = length(info)) [[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] Is this sample size big enough to test for statisti cal significance?
J S yulya258 at hotmail.com writes: Is this sample size large enough to study differences between two groups of the populations? Q1: do the body temperatures differ between the two groups of the overwintering turtles juveniles and adults? One group (adults) has 6 turtles Second group (juveniles) has 1 turtle. There are 3 replications, i.e. the experiment was repeated over the three years, but using different turtles. We had about 130 observations (daily body temperature) per each turtle per year. -- This is not a count problem, where you often can tell the numbers required without knowing the characteristics of your result set, but a continuous variable is involved. Without knowing at least approximately the statistics of the body temperature everything is possible. Dieter __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Forestplot () box size question
I have tried several sites (2 in Ca and also Australia) and find only version 2.14. Which site did you pull 2.15 from? Thanks At 11:10 AM 3/21/2009, David Winsemius wrote: Latest version is a tad non-specific. The help page for (my) package rmeta, version 2.15 (download and compiled today) says: Usage forestplot(labeltext, mean, lower, upper, align = NULL, is.summary = FALSE, clip = c(-Inf, Inf), xlab = , zero = 0, graphwidth = unit(2, inches), col = meta.colors(), xlog = FALSE, xticks=NULL, boxsize=NULL,...) -- sessionInfo() R version 2.8.1 Patched (2009-01-19 r47650) i386-apple-darwin9.6.0 locale: en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] grid stats graphics grDevices utils datasets methods base other attached packages: [1] rmeta_2.15 zoo_1.5-5 loaded via a namespace (and not attached): [1] lattice_0.17-20 tools_2.8.1 -- David Winsemius, MD Heritage Laboratories West Hartford, CT On Mar 21, 2009, at 2:01 PM, Gerard Smits wrote: Hi David, I just checked to make sure I had the latest version. I see no boxsize option in the forestplot function parameters or any other place in the code. function (labeltext, mean, lower, upper, align = NULL, is.summary = FALSE, clip = c(-Inf, Inf), xlab = , zero = 0, graphwidth = unit(2, inches), col = meta.colors(), xlog = FALSE, xticks = NULL, ...) { Thanks, Gerard At 10:32 AM 3/21/2009, David Winsemius wrote: if (!is.null(boxsize)) info - rep(boxsize, length = length(info)) [[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] Problem with zoo and rbind() converting matrix to vector
require( zoo ) inp - c( 5, 9, 4, 2, 1 ); m - zoo( cbind( inp ), as.Date(2003-02-01) + (0:(length(inp)-1))); dim( m ) # [1] 5 1 dim( m[1,,drop=FALSE] ) # [1] 1 1 - ok dim( lag( m, -1 )) # [1] 4 1 - ok dim( rbind( m[1,,drop=FALSE], lag(m,-1) )) # NULL - converted from zoo matrix to zoo vector!?!? # any way to keep the last line as a zoo matrix??? -- View this message in context: http://www.nabble.com/Problem-with-zoo-and-rbind%28%29-converting-matrix-to-vector-tp22638959p22638959.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] Forestplot () box size question
I use the CMU site. I think it is US PA #1 or some such. I suppose the fact that I am using a Mac could affect that but I am guessing not. I also found a copy of the 2.14 docs and boxsize was a parameter in that version as well. -- David Winsemius On Mar 21, 2009, at 2:24 PM, Gerard Smits wrote: I have tried several sites (2 in Ca and also Australia) and find only version 2.14. Which site did you pull 2.15 from? Thanks At 11:10 AM 3/21/2009, David Winsemius wrote: Latest version is a tad non-specific. The help page for (my) package rmeta, version 2.15 (download and compiled today) says: Usage forestplot(labeltext, mean, lower, upper, align = NULL, is.summary = FALSE, clip = c(-Inf, Inf), xlab = , zero = 0, graphwidth = unit(2, inches), col = meta.colors(), xlog = FALSE, xticks=NULL, boxsize=NULL,...) -- sessionInfo() R version 2.8.1 Patched (2009-01-19 r47650) i386-apple-darwin9.6.0 locale: en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] grid stats graphics grDevices utils datasets methods base other attached packages: [1] rmeta_2.15 zoo_1.5-5 loaded via a namespace (and not attached): [1] lattice_0.17-20 tools_2.8.1 -- David Winsemius, MD Heritage Laboratories West Hartford, CT On Mar 21, 2009, at 2:01 PM, Gerard Smits wrote: Hi David, I just checked to make sure I had the latest version. I see no boxsize option in the forestplot function parameters or any other place in the code. function (labeltext, mean, lower, upper, align = NULL, is.summary = FALSE, clip = c(-Inf, Inf), xlab = , zero = 0, graphwidth = unit(2, inches), col = meta.colors(), xlog = FALSE, xticks = NULL, ...) { Thanks, Gerard At 10:32 AM 3/21/2009, David Winsemius wrote: if (!is.null(boxsize)) info - rep(boxsize, length = length(info)) David Winsemius, MD Heritage Laboratories West Hartford, CT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with zoo and rbind() converting matrix to vector
On Mar 21, 2009, at 2:31 PM, Ken-JP wrote: require( zoo ) inp - c( 5, 9, 4, 2, 1 ); m - zoo( cbind( inp ), as.Date(2003-02-01) + (0:(length(inp)-1))); dim( m ) # [1] 5 1 dim( m[1,,drop=FALSE] ) # [1] 1 1 - ok dim( lag( m, -1 )) # [1] 4 1 - ok dim( rbind( m[1,,drop=FALSE], lag(m,-1) )) # NULL - converted from zoo matrix to zoo vector!?!? # any way to keep the last line as a zoo matrix??? Are you sure that apply dim() is a valid method of testing for zoo-ness? as.zoo(rbind(m[1,,drop=FALSE], lag(m,-1) )) 2003-02-01 2003-02-02 2003-02-03 2003-02-04 2003-02-05 5 5 9 4 2 dim(as.zoo(rbind(m[1,,drop=FALSE], lag(m,-1) ))) NULL is.zoo(as.zoo(rbind(m[1,,drop=FALSE], lag(m,-1) ))) [1] TRUE c(m[1,,drop=FALSE], lag(m,-1) ) 2003-02-01 2003-02-02 2003-02-03 2003-02-04 2003-02-05 5 5 9 4 2 str(c(m[1,,drop=FALSE], lag(m,-1) )) ‘zoo’ series from 2003-02-01 to 2003-02-05 Data: num [1:5] 5 5 9 4 2 Index: Class 'Date' num [1:5] 12084 12085 12086 12087 12088 dim(c(m[1,,drop=FALSE], lag(m,-1) )) NULL merge(c(m[1,,drop=FALSE], lag(m,-1) )) 2003-02-01 2003-02-02 2003-02-03 2003-02-04 2003-02-05 5 5 9 4 2 dim(merge(c(m[1,,drop=FALSE], lag(m,-1) ))) NULL str(merge(c(m[1,,drop=FALSE], lag(m,-1) ))) ‘zoo’ series from 2003-02-01 to 2003-02-05 Data: num [1:5] 5 5 9 4 2 Index: Class 'Date' num [1:5] 12084 12085 12086 12087 12088 David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Fisher test problem
Hi, I noted a discrepancy between R and openepi when I ran a fisher test with the same matrix. In R: a=matrix(c(1,2,6,17), nrow=2) a [,1] [,2] [1,]16 [2,]2 17 fisher.test(a, conf.int=T) Fisher's Exact Test for Count Data data: a p-value = 1 alternative hypothesis: true odds ratio is not equal to 1 95 percent confidence interval: 0.02061498 31.73691924 sample estimates: odds ratio 1.396646 But in openepi the P value is 1.25. (In another instance too for other sets of data, I had got a p value of 1 in 3 instances for a prop.test when I got 3 other answers on a friend's stata software with the same data. ) I'm using R on Ubuntu Intrepid. Is there anything I'm doing wrong? Any other packages I have to install? Thanks in advance Viju Moses __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Creating dataframe names on the fly?
On Fri, Mar 20, 2009 at 8:18 PM, science! karthik@gmail.com wrote: I am aware that it is easily possible to create var names on the fly. e.g. assign(paste(m,i,sep=),j) but is it possible to assign dataframes to variables created on the fly? e.g. If I have a dataframe called master and I wanted to subset parts of those data into separate dataframes, I could do: m1=subset(master,master$SAMPLE=='1') m2=subset(master,master$SAMPLE=='2') . but I would like to do this in a loop. Can someone give me suggestions on how to accomplish this? Assuming this is a good idea (a priori I am sceptical), the following works just fine. What problems did you run into? master - data.frame(a=sample(3,8,replace=TRUE),b=rnorm(8)) for (i in 1:3) assign(paste(m,i,sep=),subset(master,a==i)) m1 a b 1 1 0.01395752 3 1 0.58781916 4 1 2.30619952 m2 a b 5 2 -0.21210500 7 2 -1.12641675 8 2 0.01753290 m3 a b 2 3 -0.957271 6 3 2.035773 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fisher test problem
Viju Moses, Are you sure you got a P-value of 1.25 ? Since P-value could only be between 0 to 1... Tal On Sat, Mar 21, 2009 at 9:17 PM, Viju Moses vijumo...@gmail.com wrote: Hi, I noted a discrepancy between R and openepi when I ran a fisher test with the same matrix. In R: a=matrix(c(1,2,6,17), nrow=2) a [,1] [,2] [1,]16 [2,]2 17 fisher.test(a, conf.int=T) Fisher's Exact Test for Count Data data: a p-value = 1 alternative hypothesis: true odds ratio is not equal to 1 95 percent confidence interval: 0.02061498 31.73691924 sample estimates: odds ratio 1.396646 But in openepi the P value is 1.25. (In another instance too for other sets of data, I had got a p value of 1 in 3 instances for a prop.test when I got 3 other answers on a friend's stata software with the same data. ) I'm using R on Ubuntu Intrepid. Is there anything I'm doing wrong? Any other packages I have to install? Thanks in advance Viju Moses __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- -- My contact information: Tal Galili Phone number: 972-50-3373767 FaceBook: Tal Galili My Blogs: http://www.r-statistics.com/ http://www.talgalili.com http://www.biostatistics.co.il [[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] Fisher test problem
Let me ask you: What degree of credibility should be accorded a WWW application that delivers a p-value of 1.25? If the answer is not immediately and glaringly obvious, then tell us, what sort of axioms of probability are you working with? -- David Winsemius On Mar 21, 2009, at 3:17 PM, Viju Moses wrote: Hi, I noted a discrepancy between R and openepi when I ran a fisher test with the same matrix. In R: a=matrix(c(1,2,6,17), nrow=2) a [,1] [,2] [1,]16 [2,]2 17 fisher.test(a, conf.int=T) Fisher's Exact Test for Count Data data: a p-value = 1 alternative hypothesis: true odds ratio is not equal to 1 95 percent confidence interval: 0.02061498 31.73691924 sample estimates: odds ratio 1.396646 But in openepi the P value is 1.25. (In another instance too for other sets of data, I had got a p value of 1 in 3 instances for a prop.test when I got 3 other answers on a friend's stata software with the same data. ) I'm using R on Ubuntu Intrepid. Is there anything I'm doing wrong? Any other packages I have to install? Thanks in advance Viju Moses __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Heritage Laboratories 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 Can I Concatenate Every Row in a Data Frame with Every Other Row?
On Sat, Mar 21, 2009 at 12:01 PM, I wrote: I have a data frame with roughly 500 rows and 120 variables. I would like to generate a new data frame that will include one row for each PAIR of rows in the original data frame and will include all 120 + 120 = 240 variables from the two rows. I need only one row for each pair, not two rows. Thus the new data frame will contain 500 x 499 / 2 = 124,750 rows. Is there an easy way to do this with R? Thanks in advance, Don Macnaughton I thank David Wisemius, Duncan Murdoch, and Jim Holtman for their helpful replies. Jim wrote What is the problem that you are trying to solve? This work is for a client whose son was accused of cheating on a multiple choice exam. One can investigate this matter statistically by computing the number of matching answers to questions on the exam between all pairs of students. Of course under the null hypothesis of no cheating the number of matching answers has a certain distribution, which allows one to reject the null hypothesis if the number of matching answers is unduly large for a particular pair. (The distribution is generally taken with respect to the average number of correct answers in a given pair because the more correct answers, the more matches can be expected under the null hypothesis.) Wesolowsky (2000) discusses some of the statistical and ethical aspects of this exercise. Don Macnaughton REFERENCE Wesolowsky, G. O. 2000. Detecting excessive similarity in answers on multiple choice exams. _Journal of Applied Statistics,_ 27, 909-921. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] macro in a loop
Hi there, Thanks for your time in advance. I am trying to read in multiple files. For example, data.1940 - read.table(c:/data/1940.csv,header=TRUE,sep=,) data.1950 - read.table(c:/data/1950.csv,header=TRUE,sep=,) data.1960 - read.table(c:/data/1960.csv,header=TRUE,sep=,) How can I write a loop to read the data? I was trying to use the following year-c(1940,1950,1960) for (j in 1:3){ data.year[j] - read.table(c:/data/year[j] .csv,header=TRUE,sep=,) } But it is obviously wrong, as the marco is not proctected. I have been googling around for a while but haven't succeeded in finding any solutions. Thanks again for your help. Le __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] macro in a loop
Dear Le, Try this: year-c(1940,1950,1960) for (i in y) assign(paste(data.,i,sep=), read.table(c:/data/i.csv,header=TRUE,sep=,)) data.1940 data.1950 data.1960 See ?assign for more details. HTH, Jorge On Sat, Mar 21, 2009 at 3:53 PM, Le Wang ruser...@gmail.com wrote: Hi there, Thanks for your time in advance. I am trying to read in multiple files. For example, data.1940 - read.table(c:/data/1940.csv,header=TRUE,sep=,) data.1950 - read.table(c:/data/1950.csv,header=TRUE,sep=,) data.1960 - read.table(c:/data/1960.csv,header=TRUE,sep=,) How can I write a loop to read the data? I was trying to use the following year-c(1940,1950,1960) for (j in 1:3){ data.year[j] - read.table(c:/data/year[j] .csv,header=TRUE,sep=,) } But it is obviously wrong, as the marco is not proctected. I have been googling around for a while but haven't succeeded in finding any solutions. Thanks again for your help. Le __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] macro in a loop
Hi again, My bad. Below solution had a typo :(Here is the correct one: year-c(1940,1950,1960) for (i in y) assign(paste(data.,i,sep=), read.table(paste(c:/data/,i,.csv,sep=),header=TRUE,sep=,)) HTH, Jorge On Sat, Mar 21, 2009 at 4:01 PM, Jorge Ivan Velez jorgeivanve...@gmail.comwrote: Dear Le, Try this: year-c(1940,1950,1960) for (i in y) assign(paste(data.,i,sep=), read.table(c:/data/i.csv,header=TRUE,sep=,)) data.1940 data.1950 data.1960 See ?assign for more details. HTH, Jorge On Sat, Mar 21, 2009 at 3:53 PM, Le Wang ruser...@gmail.com wrote: Hi there, Thanks for your time in advance. I am trying to read in multiple files. For example, data.1940 - read.table(c:/data/1940.csv,header=TRUE,sep=,) data.1950 - read.table(c:/data/1950.csv,header=TRUE,sep=,) data.1960 - read.table(c:/data/1960.csv,header=TRUE,sep=,) How can I write a loop to read the data? I was trying to use the following year-c(1940,1950,1960) for (j in 1:3){ data.year[j] - read.table(c:/data/year[j] .csv,header=TRUE,sep=,) } But it is obviously wrong, as the marco is not proctected. I have been googling around for a while but haven't succeeded in finding any solutions. Thanks again for your help. Le __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] macro in a loop
Sorry. Not sure what you mean by macro not protected. ?paste ?assign Perhaps: filelist - paste(c:\\data\\, year,.csv, sep=) filelist [1] c:\\data\\1940.csv c:\\data\\1950.csv c:\\data\\1960.csv for (i in filelist) { assign( paste(data., year[i], sep=) , read.table( file=i, , header=TRUE, sep=,) ) } On Mar 21, 2009, at 3:53 PM, Le Wang wrote: Hi there, Thanks for your time in advance. I am trying to read in multiple files. For example, data.1940 - read.table(c:/data/1940.csv,header=TRUE,sep=,) data.1950 - read.table(c:/data/1950.csv,header=TRUE,sep=,) data.1960 - read.table(c:/data/1960.csv,header=TRUE,sep=,) How can I write a loop to read the data? I was trying to use the following year-c(1940,1950,1960) for (j in 1:3){ data.year[j] - read.table(c:/data/year[j] .csv,header=TRUE,sep=,) } But it is obviously wrong, as the marco is not proctected. I have been googling around for a while but haven't succeeded in finding any solutions. Thanks again for your help. Le David Winsemius, MD Heritage Laboratories 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] macro in a loop
R does not directly support macros and I don't think that that is what you meant. Also we probably want to put the data frames in a list so we can easily operate over all of them later. (If these are time series also see read.zoo in the zoo package.) setwd(c:/data) filenames - paste(year, csv, sep = .) DFlist - sapply(filenames, read.csv, simplify = FALSE) On Sat, Mar 21, 2009 at 3:53 PM, Le Wang ruser...@gmail.com wrote: Hi there, Thanks for your time in advance. I am trying to read in multiple files. For example, data.1940 - read.table(c:/data/1940.csv,header=TRUE,sep=,) data.1950 - read.table(c:/data/1950.csv,header=TRUE,sep=,) data.1960 - read.table(c:/data/1960.csv,header=TRUE,sep=,) How can I write a loop to read the data? I was trying to use the following year-c(1940,1950,1960) for (j in 1:3){ data.year[j] - read.table(c:/data/year[j] .csv,header=TRUE,sep=,) } But it is obviously wrong, as the marco is not proctected. I have been googling around for a while but haven't succeeded in finding any solutions. Thanks again for your help. Le __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Looking for program for sample size determination
we have some initial data from our field sampling. From the means and variances, we see your sampling field is much heterogeneous (not uniform). We are looking for a R program for sampling size determination. Right now, we are not good enough to write a whole R program, so please help. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] macro in a loop
data.year[j] - read.table(paste(c:/data/,year[j],.csv,sep=''),header=T,sep=,) should do it. Le Wang wrote: Hi there, Thanks for your time in advance. I am trying to read in multiple files. For example, data.1940 - read.table(c:/data/1940.csv,header=TRUE,sep=,) data.1950 - read.table(c:/data/1950.csv,header=TRUE,sep=,) data.1960 - read.table(c:/data/1960.csv,header=TRUE,sep=,) How can I write a loop to read the data? I was trying to use the following year-c(1940,1950,1960) for (j in 1:3){ data.year[j] - read.table(c:/data/year[j] .csv,header=TRUE,sep=,) } But it is obviously wrong, as the marco is not proctected. I have been googling around for a while but haven't succeeded in finding any solutions. Thanks again for your help. Le __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Looking for program for sample size determination
The MBESS package has many sample size functions. Hmisc has bpower and cpower . The pwr package has some simple power functions. ss.fromdata.pois {package::ssanv} asypow package I worry that beginners in statistics will get their hands on some package or function that gives them a pleasing answer when the problem is not really the one for which that function was designed. I would encourage you to consider building a sufficiently complex simulation to adequately represent the problem at hand. -- David Winsemius On Mar 21, 2009, at 4:20 PM, Qianfeng Li wrote: we have some initial data from our field sampling. From the means and variances, we see your sampling field is much heterogeneous (not uniform). We are looking for a R program for sampling size determination. Right now, we are not good enough to write a whole R program, so please help. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] factor with numeric names
Hi all, I have a pretty basic question about categorical variables but I can't seem to be able to find answer so I am hoping someone here can help. I found that if the factor names are all in numbers, fitting the model in lm would return labels that are not very recognizable. # Example: let's just assume that we want to fit this model fit - lm(height ~ age + Seed, data=Loblolly) # See the category names are all mangled up here fit Call: lm(formula = height ~ age + Seed, data = Loblolly) Coefficients: (Intercept) age Seed.L Seed.Q Seed.C Seed^4 -1.31240 2.59052 4.86941 0.87307 0.37894 -0.46853 Seed^5 Seed^6 Seed^7 Seed^8 Seed^9 Seed^10 0.55237 0.39659 -0.06507 0.35074 -0.83442 0.42085 Seed^11 Seed^12 Seed^13 0.53906 -0.29803 -0.77254 One possible solution I found is to rename the categorical variables seed.str - paste(S, Loblolly$Seed, sep=) seed.str - factor(seed.str) fit - lm(height ~ age + seed.str, data=Loblolly) fit Call: lm(formula = height ~ age + seed.str, data = Loblolly) Coefficients: (Intercept) age seed.strS303 seed.strS305 seed.strS307 -0.43012.59050.86001.8683 -1.9183 seed.strS309 seed.strS311 seed.strS315 seed.strS319 seed.strS321 0.5350 -1.5933 -0.8867 -0.3650 -2.0350 seed.strS323 seed.strS325 seed.strS327 seed.strS329 seed.strS331 0.3067 -1.3233 -2.6400 -2.9333 -2.2267 Now it is actually possible to see which one is which, but is kind of lame. Can someone point me to a more elegant solution? Thank you so much. Saiwing Yeung __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] macro in a loop
COnsider the use of a 'list': dataYear - lapply(c(1940, 1950, 1960), function(.file){ read.table(paste(c:/data/, .file, '.csv', sep=''), header=TRUE, sep=',') }) The you can access your data: dataYear[['1940']] or dataYear$1940 On Sat, Mar 21, 2009 at 3:53 PM, Le Wang ruser...@gmail.com wrote: Hi there, Thanks for your time in advance. I am trying to read in multiple files. For example, data.1940 - read.table(c:/data/1940.csv,header=TRUE,sep=,) data.1950 - read.table(c:/data/1950.csv,header=TRUE,sep=,) data.1960 - read.table(c:/data/1960.csv,header=TRUE,sep=,) How can I write a loop to read the data? I was trying to use the following year-c(1940,1950,1960) for (j in 1:3){ data.year[j] - read.table(c:/data/year[j] .csv,header=TRUE,sep=,) } But it is obviously wrong, as the marco is not proctected. I have been googling around for a while but haven't succeeded in finding any solutions. Thanks again for your help. Le __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] factor with numeric names
Dear Saiwing Yeung, You appear to be using orthogonal-polynomial contrasts (generated by contr.poly) for Seed, which suggests that Seed is either an ordered factor or that you've assigned these contrasts to it. Because Seed has 14 levels, you end up fitting an degree-13 polynomial. If Seed is indeed an ordered factor and you want to use contr.treatment instead then you could, e.g., set Loblolly$Seed - as.factor(Loblolly$Seed). (If I'm right about Seed being an ordered factor, your solution worked because it changed Seed to a factor, not because it used non-numeric level names.) I hope this helps, John -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Saiwing Yeung Sent: March-21-09 5:02 PM To: r-help@r-project.org Subject: [R] factor with numeric names Hi all, I have a pretty basic question about categorical variables but I can't seem to be able to find answer so I am hoping someone here can help. I found that if the factor names are all in numbers, fitting the model in lm would return labels that are not very recognizable. # Example: let's just assume that we want to fit this model fit - lm(height ~ age + Seed, data=Loblolly) # See the category names are all mangled up here fit Call: lm(formula = height ~ age + Seed, data = Loblolly) Coefficients: (Intercept) age Seed.L Seed.Q Seed.C Seed^4 -1.31240 2.59052 4.86941 0.87307 0.37894 -0.46853 Seed^5 Seed^6 Seed^7 Seed^8 Seed^9 Seed^10 0.55237 0.39659 -0.06507 0.35074 -0.83442 0.42085 Seed^11 Seed^12 Seed^13 0.53906 -0.29803 -0.77254 One possible solution I found is to rename the categorical variables seed.str - paste(S, Loblolly$Seed, sep=) seed.str - factor(seed.str) fit - lm(height ~ age + seed.str, data=Loblolly) fit Call: lm(formula = height ~ age + seed.str, data = Loblolly) Coefficients: (Intercept) age seed.strS303 seed.strS305 seed.strS307 -0.43012.59050.86001.8683 -1.9183 seed.strS309 seed.strS311 seed.strS315 seed.strS319 seed.strS321 0.5350 -1.5933 -0.8867 -0.3650 -2.0350 seed.strS323 seed.strS325 seed.strS327 seed.strS329 seed.strS331 0.3067 -1.3233 -2.6400 -2.9333 -2.2267 Now it is actually possible to see which one is which, but is kind of lame. Can someone point me to a more elegant solution? Thank you so much. Saiwing Yeung __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] replying to old thread
If you come across an archived thread that you would like to reply to, how do you reply to it without starting a new thread? Joe Boyer Statistical Sciences Renaissance Bldg 510, 3233-D Mail Stop RN0320 8-275-3661 cell: (610) 209-8531 [[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] for transfer function model
hi i need to use R to make a transfer function model. i searched online for so long for a code. there is no result. anyone help would be appreciated. altho the best situation is that if anyone has done the same kind of work b4? if yes, pls upload ur work as an example. bill _ Chat with the whole group, and bring everyone together. [[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] factor with numeric names
Hi Saiwing, If all you are asking is how to rename a factor vector, the easiest way would be to use: levels(Loblolly$Seed) - c( a vector of level names you would like to use for the factor - separated by commas) If you are asking how to make your output look better, I am not sure I have an idea (except for using summary(fit) - but I guess that is not what you mean) Best, Tal On Sat, Mar 21, 2009 at 11:02 PM, Saiwing Yeung saiw...@berkeley.eduwrote: Hi all, I have a pretty basic question about categorical variables but I can't seem to be able to find answer so I am hoping someone here can help. I found that if the factor names are all in numbers, fitting the model in lm would return labels that are not very recognizable. # Example: let's just assume that we want to fit this model fit - lm(height ~ age + Seed, data=Loblolly) # See the category names are all mangled up here fit Call: lm(formula = height ~ age + Seed, data = Loblolly) Coefficients: (Intercept) age Seed.L Seed.Q Seed.C Seed^4 -1.31240 2.59052 4.86941 0.87307 0.37894 -0.46853 Seed^5 Seed^6 Seed^7 Seed^8 Seed^9 Seed^10 0.55237 0.39659 -0.06507 0.35074 -0.83442 0.42085 Seed^11 Seed^12 Seed^13 0.53906 -0.29803 -0.77254 One possible solution I found is to rename the categorical variables seed.str - paste(S, Loblolly$Seed, sep=) seed.str - factor(seed.str) fit - lm(height ~ age + seed.str, data=Loblolly) fit Call: lm(formula = height ~ age + seed.str, data = Loblolly) Coefficients: (Intercept) age seed.strS303 seed.strS305 seed.strS307 -0.43012.59050.86001.8683 -1.9183 seed.strS309 seed.strS311 seed.strS315 seed.strS319 seed.strS321 0.5350 -1.5933 -0.8867 -0.3650 -2.0350 seed.strS323 seed.strS325 seed.strS327 seed.strS329 seed.strS331 0.3067 -1.3233 -2.6400 -2.9333 -2.2267 Now it is actually possible to see which one is which, but is kind of lame. Can someone point me to a more elegant solution? Thank you so much. Saiwing Yeung __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- -- My contact information: Tal Galili Phone number: 972-50-3373767 FaceBook: Tal Galili My Blogs: http://www.r-statistics.com/ http://www.talgalili.com http://www.biostatistics.co.il [[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] bargraph.CI change se for sd
Sorry about forgetting that. Package sciplot Simple example code: This code plots the standard error on the bars; I would like to replace that by the standard deviation bargraph.CI(peptide, surface, group=adjunct,data = y) David Winsemius wrote: Package name? Example code? -- On Mar 21, 2009, at 4:22 AM, herwig wrote: Hi there, I am a beginner. I would like to change the error bars in the bargraph.CI function from the default (se) to (sd). The help file says ci.fun= function(x) c(fun(x)-se(x), fun(x)+se(x)) Is there a simple way of telling the function what (x) precisely is - I already define in in the of the bargraph.CI function and assume that is should be able to use that information. cheers, Herwig -- David Winsemius, MD Heritage Laboratories 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. -- View this message in context: http://www.nabble.com/bargraph.CI-change-se-for-sd-tp22633770p22639845.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] Fisher test accuracy in doubt
Hi, I noted a discrepancy between R and openepi when I ran a fisher test with the same matrix. In R: a=matrix(c(1,2,6,17), nrow=2) a [,1] [,2] [1,]16 [2,]2 17 fisher.test(a, conf.int=T) Fisher's Exact Test for Count Data data: a p-value = 1 alternative hypothesis: true odds ratio is not equal to 1 95 percent confidence interval: 0.02061498 31.73691924 sample estimates: odds ratio 1.396646 But in openepi the P value is 1.25. (In another instance too for other sets of data, I had got a p value of 1 in 3 instances for a prop.test when I got 3 other answers on a friend's stata software with the same data. ) I'm using R on Ubuntu Intrepid. Is there anything I'm doing wrong? Any other packages I have to install? Thanks in advance -- View this message in context: http://www.nabble.com/Fisher-test-accuracy-in-doubt-tp22639239p22639239.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] bargraph.CI change se for sd
library(sciplot) bargraph.CI(peptide, surface, group=adjunct,data = y) Error in eval(substitute(subset), envir = data) : object y not found #groan, ... why can't people offer a workable example? data(ToothGrowth) # se as default bargraph.CI(x.factor = dose, response = len, data = ToothGrowth) # create desired function bargraph.CI(x.factor = dose, response = len, data = ToothGrowth, ci.fun= function(x) c(mean(x)-sd(x), mean(x) + sd(x)) ) QED On Mar 21, 2009, at 4:09 PM, herwig wrote: Sorry about forgetting that. Package sciplot Simple example code: This code plots the standard error on the bars; I would like to replace that by the standard deviation bargraph.CI(peptide, surface, group=adjunct,data = y) David Winsemius wrote: Package name? Example code? -- On Mar 21, 2009, at 4:22 AM, herwig wrote: Hi there, I am a beginner. I would like to change the error bars in the bargraph.CI function from the default (se) to (sd). The help file says ci.fun= function(x) c(fun(x)-se(x), fun(x)+se(x)) Is there a simple way of telling the function what (x) precisely is - I already define in in the of the bargraph.CI function and assume that is should be able to use that information. cheers, Herwig -- David Winsemius, MD Heritage Laboratories 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. -- View this message in context: http://www.nabble.com/bargraph.CI-change-se-for-sd-tp22633770p22639845.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 Heritage Laboratories 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] Problem with zoo and rbind() converting matrix to vector
On Sat, 21 Mar 2009, Ken-JP wrote: require( zoo ) inp - c( 5, 9, 4, 2, 1 ); m - zoo( cbind( inp ), as.Date(2003-02-01) + (0:(length(inp)-1))); dim( m ) # [1] 5 1 dim( m[1,,drop=FALSE] ) # [1] 1 1 - ok dim( lag( m, -1 )) # [1] 4 1 - ok dim( rbind( m[1,,drop=FALSE], lag(m,-1) )) # NULL - converted from zoo matrix to zoo vector!?!? # any way to keep the last line as a zoo matrix??? This was a problem in the rbind() method, I've just commited a fix to the devel-version on R-Forge. Thanks for the report, Z -- View this message in context: http://www.nabble.com/Problem-with-zoo-and-rbind%28%29-converting-matrix-to-vector-tp22638959p22638959.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] Fisher test accuracy in doubt
On Sat, Mar 21, 2009 at 2:03 PM, joker77 vijumo...@gmail.com wrote: Hi, I noted a discrepancy between R and openepi when I ran a fisher test with the same matrix. In R: a=matrix(c(1,2,6,17), nrow=2) a [,1] [,2] [1,] 1 6 [2,] 2 17 fisher.test(a, conf.int=T) Fisher's Exact Test for Count Data data: a p-value = 1 alternative hypothesis: true odds ratio is not equal to 1 95 percent confidence interval: 0.02061498 31.73691924 sample estimates: odds ratio 1.396646 But in openepi the P value is 1.25. (In another instance too for other sets of data, I had got a p value of 1 in 3 instances for a prop.test when I got 3 other answers on a friend's stata software with the same data. ) Given that a p-value is between 0 and 1, I would rather think that openEpi's accuracy is in doubt. Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with zoo and rbind() converting matrix to vector
Thank you for your reply, but I am still confused. Let me clarify... ...my problem isn't with zoo-ness per se. With zoo objects, there appears to be zoo-matrices and zoo-vectors. My problem is this - I start with a zoo-matrix: x - m[1,,drop=FALSE] x inp 2003-02-01 5 is.matrix( x ) [1] TRUE and another zoo-matrix: y - lag(m,-1) y inp 2003-02-02 5 2003-02-03 9 2003-02-04 4 2003-02-05 2 is.matrix( y ) [1] TRUE and somehow, when I rbind() them together, I get a zoo-vector: z - rbind( x, y ) z 2003-02-01 2003-02-02 2003-02-03 2003-02-04 2003-02-05 5 5 9 4 2 is.matrix( z ) [1] FALSE is.zoo( z ) [1] TRUE Yes, I realize that x, y, and z are still zoo's (as they should be). But the part I can't resolve is, z has turned into a zoo-vector. Unfortunately, none of the 3 solutions you gave are zoo-matrices: is.matrix( as.zoo(rbind(m[1,,drop=FALSE], lag(m,-1) )) ) [1] FALSE is.matrix( c(m[1,,drop=FALSE], lag(m,-1) ) ) [1] FALSE is.matrix( merge(c(m[1,,drop=FALSE], lag(m,-1) )) ) [1] FALSE I was using dim() as a indirect test for matrices where I could be using is.matrix() to be more explicit; before this, I did not know if is.matrix() would work on a zoo-matrix. Now, I know! It seems to me that I need to write a specialized version of my function for vectors (whether a plain vector or a zoo vector) and another version for matrices (whether a plain matrix or a zoo matrix). Luckily, I am only dealing with 2d matrices. But I don't know if I can avoid using really ugly class-based code testing for is.zoo(m) and is.matrix(m), etc... ...but even worse, my code works for a multi-column 2d zoo matrices, but not for a single-column 2d zoo matrix. Gabor Grothendieck mentioned in another thread that if I use S3 generics on zoo, I can avoid using a switch on zoo and non-zoo types. But unfortunately, his example, like mine, only works on a multi-column zoo-matrix, but fails on a single-column zoo-matrix (gets converted to a zoo-vector). So I don't have a solution yet. I am still trying to write something which will take a: 1. vector and return a vector 2. single-column matrix and return a single-column matrix 3. multi-column matrix and return a multi-column matrix 4.-6. zoo versions of 1.-3. I think solutions for 1, 3, 4, and 6 have been posted, but it is not clear to me how I should handle 2 and the zoo-version of 2 yet. -- View this message in context: http://www.nabble.com/Problem-with-zoo-and-rbind%28%29-converting-matrix-to-vector-tp22638959p22641961.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with zoo and rbind() converting matrix to vector
Hi Achim, That was a very quick reply/fix that got posted in between my reading and my response. I have downloaded your fix from: svn checkout svn://r-forge.r-project.org/svnroot/zoo for the HEAD revision and confirmed that it works as expected - I tested using the code I posted in the first message. I really appreciate your response and fix. Thank you. Regards, Ken -- View this message in context: http://www.nabble.com/Problem-with-zoo-and-rbind%28%29-converting-matrix-to-vector-tp22638959p22642095.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] package sowas
I cannot find sowas package by Douglas Mauran in CRAN packages list- On which platforms does sowas run ? Has anybody used such a package at all ? hHank you very much, Maura tutti i telefonini TIM! [[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] plotting two variables with a third used for color
On 2009-March-20 , at 16:23 , David Winsemius wrote: On Mar 20, 2009, at 3:55 PM, Altaweel, Mark R. wrote: I have a problem where I have two columns of data that I can simply plot using: plot(wV[0:15,3],wY[0:15,3]). Perhaps: plot(wV[0:15,3],wY[0:15,3], col = ifelse(wY[0:15,3]0, blue,red) ) And you could look into the package ggplot2 which gives you a legend and is well suited for these things. # quick version: qplot(wV[0:15,3], wY[0:15,3], colour=ifelse(wY[0:15,3]0,0,0)) # more explicit version, using a data.frame dat = data.frame(v=wV[0:15,3], y=wY[0:15,3], sign=ifelse(wY[0:15,3]0,0,0)) ggplot(data=dat) + geom_point(aes(x=v,y=y,colour=sign)) JiHO --- http://jo.irisson.free.fr/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot and Boxplot in the same graph
On 2009-March-20 , at 23:02 , johnhj wrote: Is it possible, to use the plot() funktion and the boxplot() funktion together ? I will plot a simple graph and additionally to the graph on certain places boxplots. I have imagined to plot the graph a little bit transparency and show in the same graph on certain places boxplots If you don't mind letting got the base graphics in R, you can look into http://had.co.nz/ggplot2/ The representations you are interested in are geom_jitter and geom_boxplot and in the help page of geom_jitter there is an example of specifically what you just asked: http://had.co.nz/ggplot2/geom_jitter.html look at the end. As for transparency, you can use geom_boxplot(fill=alpha(white,0.5)) for example. JiHO --- http://jo.irisson.free.fr/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fisher test problem
I tried the OpenEpi, the p-value of 1.25 is due to the fact that the one tailed p-value is 0.62. The two tailed p-value then is 0.62 * 2 = 1.25. OpenEpi is not clever enough to ceiling the p-value to 1. CH On Sun, Mar 22, 2009 at 3:43 AM, David Winsemius dwinsem...@comcast.net wrote: Let me ask you: What degree of credibility should be accorded a WWW application that delivers a p-value of 1.25? If the answer is not immediately and glaringly obvious, then tell us, what sort of axioms of probability are you working with? -- David Winsemius On Mar 21, 2009, at 3:17 PM, Viju Moses wrote: Hi, I noted a discrepancy between R and openepi when I ran a fisher test with the same matrix. In R: a=matrix(c(1,2,6,17), nrow=2) a [,1] [,2] [1,] 1 6 [2,] 2 17 fisher.test(a, conf.int=T) Fisher's Exact Test for Count Data data: a p-value = 1 alternative hypothesis: true odds ratio is not equal to 1 95 percent confidence interval: 0.02061498 31.73691924 sample estimates: odds ratio 1.396646 But in openepi the P value is 1.25. (In another instance too for other sets of data, I had got a p value of 1 in 3 instances for a prop.test when I got 3 other answers on a friend's stata software with the same data. ) I'm using R on Ubuntu Intrepid. Is there anything I'm doing wrong? Any other packages I have to install? Thanks in advance Viju Moses __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Heritage Laboratories 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. -- CH Chan Research Assistant - KWH http://www.macgrass.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] macro in a loop
Thank you all for the help! Le On Sat, Mar 21, 2009 at 4:23 PM, Pankaj Chopra pcho...@ncsu.edu wrote: data.year[j] - read.table(paste(c:/data/,year[j],.csv,sep=''),header=T,sep=,) should do it. Le Wang wrote: Hi there, Thanks for your time in advance. I am trying to read in multiple files. For example, data.1940 - read.table(c:/data/1940.csv,header=TRUE,sep=,) data.1950 - read.table(c:/data/1950.csv,header=TRUE,sep=,) data.1960 - read.table(c:/data/1960.csv,header=TRUE,sep=,) How can I write a loop to read the data? I was trying to use the following year-c(1940,1950,1960) for (j in 1:3){ data.year[j] - read.table(c:/data/year[j] .csv,header=TRUE,sep=,) } But it is obviously wrong, as the marco is not proctected. I have been googling around for a while but haven't succeeded in finding any solutions. Thanks again for your help. Le __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] package sowas
You must go to his website because it is not on CRAN. I have built it on mac osx by installing it with R CMD install. This should work on other unix platforms. Stephen Sefick On Sat, Mar 21, 2009 at 9:26 PM, mau...@alice.it wrote: I cannot find sowas package by Douglas Mauran in CRAN packages list- On which platforms does sowas run ? Has anybody used such a package at all ? hHank you very much, Maura tutti i telefonini TIM! [[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. -- Stephen Sefick Let's not spend our time and resources thinking about things that are so little or so large that all they really do for us is puff us up and make us feel like gods. We are mammals, and have not exhausted the annoying little problems of being mammals. -K. Mullis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fisher test problem
by definition, the one tailed p-value has to be = 0.5 so there is still something wrong with your OpenEpi calc. Most likely it's calculating the 2 tailed p-value and then mistakenly multiplying by 2. For example: A) Suppose you are testing Ho: u = u_0 H1 u u_0 and your t-stat was -0.3 Then prob( T t_0) = 0.62 so your pvalue would be 0.62. B) Instead, suppose you are testing Ho: u = u_0 H1 u != u_0 and your t-stat was -0.3. Then, one calculates, prob(T t_0 = -.3) = .31 and then multiplies by 2 ( because the test is 2 sided ) so the pvalue is still 0.62. So, it's probably doing the first case andf them multiplying it by 2 which is incorrect. Also, no offense intended but it's dangerous to use these things unless the understanding is there. In fact, it can be dangerous to use them even when the understanding is there !!! Peter Daalgard's book or John Verzani's book are probably decent recommendations to read for the above kind of thing but an introduction to statistical testing textbook is probably most useful. I can't think of a title at the moment. On Sat, Mar 21, 2009 at 9:07 PM, C.H. wrote: I tried the OpenEpi, the p-value of 1.25 is due to the fact that the one tailed p-value is 0.62. The two tailed p-value then is 0.62 * 2 = 1.25. OpenEpi is not clever enough to ceiling the p-value to 1. CH On Sun, Mar 22, 2009 at 3:43 AM, David Winsemius dwinsem...@comcast.net wrote: Let me ask you: What degree of credibility should be accorded a WWW application that delivers a p-value of 1.25? If the answer is not immediately and glaringly obvious, then tell us, what sort of axioms of probability are you working with? -- David Winsemius On Mar 21, 2009, at 3:17 PM, Viju Moses wrote: Hi, I noted a discrepancy between R and openepi when I ran a fisher test with the same matrix. In R: a=matrix(c(1,2,6,17), nrow=2) a [,1] [,2] [1,] 1 6 [2,] 2 17 fisher.test(a, conf.int=T) Fisher's Exact Test for Count Data data: a p-value = 1 alternative hypothesis: true odds ratio is not equal to 1 95 percent confidence interval: 0.02061498 31.73691924 sample estimates: odds ratio 1.396646 But in openepi the P value is 1.25. (In another instance too for other sets of data, I had got a p value of 1 in 3 instances for a prop.test when I got 3 other answers on a friend's stata software with the same data. ) I'm using R on Ubuntu Intrepid. Is there anything I'm doing wrong? Any other packages I have to install? Thanks in advance Viju Moses __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Heritage Laboratories 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. -- CH Chan Research Assistant - KWH http://www.macgrass.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] data analysis. R
so i am having this question what should i do if the give data file (.txt) has 4 columns, but different lengths? how can i read them in R? any idea for the following problem? Gas consumption (1000 cubic feet) was measured before and after insulation was put into a house. We are interested in looking at the effect of insulation on gas consumption. The average outside temperature (degrees celcius) was also measured. The data are included in the file insulation.txt. (a) Determine if insulation in the house effects the average gas consumption. (b) How much extra gas is used when there is no insulation? Provide an interval estimate as well as a point estimate. heres the content in insulation.txt (u can just copy and paste it to the notepad so can be read in R) Before insulAfter insul. tempgas tempgas -0.87.2-0.74.8 -0.76.90.84.6 0.46.41.04.7 2.56.01.44.0 2.95.81.54.2 3.25.81.64.2 3.65.62.34.1 3.94.72.54.0 4.25.82.53.5 4.35.23.13.2 5.44.93.93.9 6.04.94.03.5 6.04.34.03.7 6.04.44.23.5 6.24.54.33.5 6.34.64.63.7 6.93.74.73.5 7.03.94.93.4 7.44.24.93.7 7.54.04.94.0 7.53.95.03.6 7.63.55.33.7 8.04.06.22.8 8.53.67.13.0 9.13.17.22.8 10.2 2.67.52.6 8.02.7 8.72.8 8.81.3 9.71.5 thx and any ideas would help. -- View this message in context: http://www.nabble.com/data-analysis.-R-tp22641912p22641912.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] Fisher test problem
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of C.H. Sent: Saturday, March 21, 2009 7:07 PM To: r-help@r-project.org Subject: Re: [R] Fisher test problem I tried the OpenEpi, the p-value of 1.25 is due to the fact that the one tailed p-value is 0.62. The two tailed p-value then is 0.62 * 2 = 1.25. OpenEpi is not clever enough to ceiling the p-value to 1. CH But that just shows that OpenEpi is incorrect, because the two-tailed probability is not 2 times a one-tailed probability (there are two of them and they are not symmetrical). To calculate a two-tailed test, one needs to calculate the probability for each table that is as extreme or more extreme than the observed table and take the sum (including the probabiility of the observed table). Hope this is helpful, Dan Daniel Nordlund Bothell, WA USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Percentage variance
Dear Members, Simple questions, I am a beginner with R. What is the function for percentage variance? A function that replaces: (final value-Initial value/Initial value)*100 Thank You. H. __ [[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] data analysis. R
If the input file has a separator other than a space (e.g., tabs or commas) then you can read it is and the missing data will be NAs and you can decide how to handle it. If it does not have a separator, then maybe you can read it in with read.fwf. Otherwise when you read it in, you can tell the system to 'fill' the missing data, but you don't really know what columns that might be in. So you have some choices; you are able to read in data that may have different lengths in the columns, but if it is ill-structured, it may be difficult to determine how to handle the missing data. On Sat, Mar 21, 2009 at 8:13 PM, UBC cheong0...@hotmail.com wrote: so i am having this question what should i do if the give data file (.txt) has 4 columns, but different lengths? how can i read them in R? any idea for the following problem? Gas consumption (1000 cubic feet) was measured before and after insulation was put into a house. We are interested in looking at the effect of insulation on gas consumption. The average outside temperature (degrees celcius) was also measured. The data are included in the file insulation.txt. (a) Determine if insulation in the house effects the average gas consumption. (b) How much extra gas is used when there is no insulation? Provide an interval estimate as well as a point estimate. heres the content in insulation.txt (u can just copy and paste it to the notepad so can be read in R) Before insul After insul. temp gas temp gas -0.8 7.2 -0.7 4.8 -0.7 6.9 0.8 4.6 0.4 6.4 1.0 4.7 2.5 6.0 1.4 4.0 2.9 5.8 1.5 4.2 3.2 5.8 1.6 4.2 3.6 5.6 2.3 4.1 3.9 4.7 2.5 4.0 4.2 5.8 2.5 3.5 4.3 5.2 3.1 3.2 5.4 4.9 3.9 3.9 6.0 4.9 4.0 3.5 6.0 4.3 4.0 3.7 6.0 4.4 4.2 3.5 6.2 4.5 4.3 3.5 6.3 4.6 4.6 3.7 6.9 3.7 4.7 3.5 7.0 3.9 4.9 3.4 7.4 4.2 4.9 3.7 7.5 4.0 4.9 4.0 7.5 3.9 5.0 3.6 7.6 3.5 5.3 3.7 8.0 4.0 6.2 2.8 8.5 3.6 7.1 3.0 9.1 3.1 7.2 2.8 10.2 2.6 7.5 2.6 8.0 2.7 8.7 2.8 8.8 1.3 9.7 1.5 thx and any ideas would help. -- View this message in context: http://www.nabble.com/data-analysis.-R-tp22641912p22641912.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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fisher test problem
markleeds at verizon.net writes: by definition, the one tailed p-value has to be = 0.5 so there is still something wrong with your OpenEpi calc. Most likely it's calculating the 2 tailed p-value and then mistakenly multiplying by 2. For example: For what it's worth, Fisher's exact test with alternative=greater (true odds ratio is 1) does give 0.6273 in R. (Why does a one-tailed test have to have p=0.5? The probability that a test statistic is greater than some null-hypothesis value can be anywhere between 0 and 1 ...) It is a 1-tailed test, but (as has been pointed out) multiplying it by 2 without truncating at 1 is wrong. Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Percentage variance
One that you could write yourself: percVar - function(init, final) (final - init) / init * 100 On Sat, Mar 21, 2009 at 9:43 PM, Hadil Eshtayah hesht...@yahoo.ca wrote: Dear Members, Simple questions, I am a beginner with R. What is the function for percentage variance? A function that replaces: (final value-Initial value/Initial value)*100 Thank You. H. __ [[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. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fisher test problem
thanks ben: i think my example makes sense but my terminology of one tailed two tailed was wrong or flipped or whatever. in fact, that's why i gave the example. i wasn't remembering the terminology because it's been too long since i stepped in a classroom ( 8 years ). On Sat, Mar 21, 2009 at 10:42 PM, Ben Bolker wrote: markleeds at verizon.net writes: by definition, the one tailed p-value has to be = 0.5 so there is still something wrong with your OpenEpi calc. Most likely it's calculating the 2 tailed p-value and then mistakenly multiplying by 2. For example: For what it's worth, Fisher's exact test with alternative=greater (true odds ratio is 1) does give 0.6273 in R. (Why does a one-tailed test have to have p=0.5? The probability that a test statistic is greater than some null-hypothesis value can be anywhere between 0 and 1 ...) It is a 1-tailed test, but (as has been pointed out) multiplying it by 2 without truncating at 1 is wrong. Ben Bolker __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fisher test problem
Thanks berwin. See what I sent to Ben. I better start looking up my stat textbooks or going back to class before I start using stat terms. You guys are on top of things . On Sat, Mar 21, 2009 at 10:50 PM, Berwin A Turlach wrote: G'day Mark, On Sat, 21 Mar 2009 22:08:21 -0500 (CDT) markle...@verizon.net wrote: by definition, the one tailed p-value has to be = 0.5 Can you point me to such a definition? I was not aware that this is the case. :) And your example: A) Suppose you are testing Ho: u = u_0 H1 u u_0 and your t-stat was -0.3 Then prob( T t_0) = 0.62 so your pvalue would be 0.62. seems to contradict your statement. A one sided-test, hence a one-tailed p-value, which yields a p-value larger than 0.5. But, perhaps, we are just using different terminology. Cheers, Berwin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] data analysis. R
This works with the example. If the real data is different it may not work. To run the example below just copy and paste it into R. To run with the real data replace textConnection(Lines) with insulation.txt everywhere. Lines - Before insulAfter insul. tempgas tempgas -0.87.2-0.74.8 -0.76.90.84.6 0.46.41.04.7 2.56.01.44.0 2.95.81.54.2 3.25.81.64.2 3.65.62.34.1 3.94.72.54.0 4.25.82.53.5 4.35.23.13.2 5.44.93.93.9 6.04.94.03.5 6.04.34.03.7 6.04.44.23.5 6.24.54.33.5 6.34.64.63.7 6.93.74.73.5 7.03.94.93.4 7.44.24.93.7 7.54.04.94.0 7.53.95.03.6 7.63.55.33.7 8.04.06.22.8 8.53.67.13.0 9.13.17.22.8 10.2 2.67.52.6 8.02.7 8.72.8 8.81.3 9.71.5 nfld - count.fields(textConnection(Lines)) data.lines - readLines(textConnection(Lines)) data.lines - ifelse(nfld == 2, paste(NA NA, data.lines), data.lines) my.data - read.table(textConnection(data.lines), header = TRUE, skip = 1) On Sat, Mar 21, 2009 at 8:13 PM, UBC cheong0...@hotmail.com wrote: so i am having this question what should i do if the give data file (.txt) has 4 columns, but different lengths? how can i read them in R? any idea for the following problem? Gas consumption (1000 cubic feet) was measured before and after insulation was put into a house. We are interested in looking at the effect of insulation on gas consumption. The average outside temperature (degrees celcius) was also measured. The data are included in the file insulation.txt. (a) Determine if insulation in the house effects the average gas consumption. (b) How much extra gas is used when there is no insulation? Provide an interval estimate as well as a point estimate. heres the content in insulation.txt (u can just copy and paste it to the notepad so can be read in R) Before insul After insul. temp gas temp gas -0.8 7.2 -0.7 4.8 -0.7 6.9 0.8 4.6 0.4 6.4 1.0 4.7 2.5 6.0 1.4 4.0 2.9 5.8 1.5 4.2 3.2 5.8 1.6 4.2 3.6 5.6 2.3 4.1 3.9 4.7 2.5 4.0 4.2 5.8 2.5 3.5 4.3 5.2 3.1 3.2 5.4 4.9 3.9 3.9 6.0 4.9 4.0 3.5 6.0 4.3 4.0 3.7 6.0 4.4 4.2 3.5 6.2 4.5 4.3 3.5 6.3 4.6 4.6 3.7 6.9 3.7 4.7 3.5 7.0 3.9 4.9 3.4 7.4 4.2 4.9 3.7 7.5 4.0 4.9 4.0 7.5 3.9 5.0 3.6 7.6 3.5 5.3 3.7 8.0 4.0 6.2 2.8 8.5 3.6 7.1 3.0 9.1 3.1 7.2 2.8 10.2 2.6 7.5 2.6 8.0 2.7 8.7 2.8 8.8 1.3 9.7 1.5 thx and any ideas would help. -- View this message in context: http://www.nabble.com/data-analysis.-R-tp22641912p22641912.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] data analysis. R
On Sat, Mar 21, 2009 at 5:13 PM, UBC cheong0...@hotmail.com wrote: so i am having this question what should i do if the give data file (.txt) has 4 columns, but different lengths? how can i read them in R? any idea for the following problem? Gas consumption (1000 cubic feet) was measured before and after insulation was put into a house. We are interested in looking at the effect of insulation on gas consumption. The average outside temperature (degrees celcius) was also measured. The data are included in the file insulation.txt. (a) Determine if insulation in the house effects the average gas consumption. (b) How much extra gas is used when there is no insulation? Provide an interval estimate as well as a point estimate. heres the content in insulation.txt (u can just copy and paste it to the notepad so can be read in R) Before insul After insul. temp gas temp gas -0.8 7.2 -0.7 4.8 -0.7 6.9 0.8 4.6 0.4 6.4 1.0 4.7 2.5 6.0 1.4 4.0 2.9 5.8 1.5 4.2 3.2 5.8 1.6 4.2 3.6 5.6 2.3 4.1 3.9 4.7 2.5 4.0 4.2 5.8 2.5 3.5 4.3 5.2 3.1 3.2 5.4 4.9 3.9 3.9 6.0 4.9 4.0 3.5 6.0 4.3 4.0 3.7 6.0 4.4 4.2 3.5 6.2 4.5 4.3 3.5 6.3 4.6 4.6 3.7 6.9 3.7 4.7 3.5 7.0 3.9 4.9 3.4 7.4 4.2 4.9 3.7 7.5 4.0 4.9 4.0 7.5 3.9 5.0 3.6 7.6 3.5 5.3 3.7 8.0 4.0 6.2 2.8 8.5 3.6 7.1 3.0 9.1 3.1 7.2 2.8 10.2 2.6 7.5 2.6 8.0 2.7 8.7 2.8 8.8 1.3 9.7 1.5 thx and any ideas would help. Dude- really? This is just a funky-format version of the whiteside data found in the MASS package: library(MASS) whiteside See the posting guide (http://www.r-project.org/posting-guide.html), especially the section on homework questions. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.