Re: [R] Installing package in windows 7
You probably need to get your users permissions (in win 7) set properly... Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Wed, Jan 19, 2011 at 8:26 PM, radagast haseeb.mah...@gmail.com wrote: Hi all, I was trying to install a package called ei from this http://gking.harvard.edu/eiR link . With GCC, r-base-dev and some other R package dependencies installed it works perfect in my Ubuntu Linux system. Now I am trying to install the same in Windows 7 environment. So far my setup is as follows, 1. R installed in home folder (c:\Users\username\R-2.12.1\R. It is set to run as administrator, and the R folder is writable. 2. My working directory is (c:\Users\username\Documents) 3. Rtool is installed in (c:\Rtools) Having this setup, 4. I tried to install it by the command, install.packages(ei,repos=http://r.iq.harvard.edu;) This command gives me the following error message. --- Installing package(s) into C:\Users\username\Documents/R/win-library/2.12 (as lib is unspecified) Warning message: In getDependencies(pkgs, dependencies, available, lib) : package ei is not available --- After that I have decided to have a try to install it from a local zip file, so I proceeded in the following way, 5. I have downloaded the package ei_0.938.tar.gz, untar it and make a zip file from that. I placed it into my work directory. 6. I opened the terminal (Run cmd), went to the work directory and tried to run the command R COM INSTALL ei --- It shows me the following error message, C:\Users\username\DocumentsR COM INSTALL ei 'R' is not recognized as an internal or external command, operable program or batch file. --- I am not sure what should I do now. Is there anyone to help? _ Rdgst. -- View this message in context: http://r.789695.n4.nabble.com/Installing-package-in-windows-7-tp3225439p3225439.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] adding text to y-axis per row of panels (lattice)
Dear all, Being a newbie to R, I've trawled through many old posts on this list looking for a solution to my problem, but unfortunately couldn't quite figure it out myself. I'd be very grateful if someone here on this list could perhaps help me out. I have a lattice plot with several panels and would like to add some text next to the y-axis on the right hand side of each row of panels. This text should help the reader to interpret the value ranges of the y-axis: so the range between -1 and 1 (in between the two reference lines) should e.g. labelled balanced, the rest of the positive scale as too high, and the rest of the negative scale as too low. The text should be printed in parallel to the y-axis. If this was a base graphic plot, I'd use mtext, but I'm not sure how to get to the same results when using lattice. Here is some example data: library(lattice) varx - c(1:4,1:4,1:4,1:4) vary - c(2,2,1.5,0.3,1,2,3,4,-1,-0.5,3,-1,-1,-0.5,1,-3) condvar - c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4) exampledata -data.frame(cbind(varx,vary,condvar)) exampledata xyplot(vary~varx|condvar, type=o,data=exampledata, scales=list(alternating=F,x=list(at=c(1,2,3,4)), y=list(at=c(-3,-1,0,1,3))), panel=function(x,y,...){ panel.abline(h=-1) panel.abline(h=1) panel.xyplot(x,y,...) }) Any help is greatly appreciated! EH __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] subsets
Dear R people Could you please help. Basically, there are two variables in my data set. Each patient ('id') may have one or more diseases ('diagnosis'). It looks like id diagnosis 1 ah 2 ah 2 ihd 2 im 3 ah 3 stroke 4 ah 4 ihd 4 angina 5 ihd .. Q: How to make three data sets: 1. Patients with ah and ihd 2. Patients with ah but no ihd 3. Patients with ihd but no ah? If you have any ideas could just guide what should I look for. Is a subset or aggregate, or loops, or something else??? I am a bit lost. (F1 F1 F1 !!!:) Thank you __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] reading in time series
This is causing me great consternation, and I've spent too much time floundering around on it. My data is in the form of columns in Excel, with the first column being in m/dd/ hh:mm format. The spreadsheet is complicated (headers, merged cells, lines w/o data); so I've tried various ways of exporting the data into a text file for the R processing - CSV, spaced, etc. For example: 3/23/2010 20:55 -0.10655 -0.121454561 -0.12032 -0.111680001 -0.122429997 3/23/2010 21:25 -0.099166997 -0.114189997 -0.11287 -0.104647976 -0.114720002 . . - or - 3/23/2010 20:55, -0.10655, -0.121454561, -0.12032, -0.111680001, -0.122429997 3/23/2010 21:25, -0.099166997, -0.114189997, -0.11287, -0.104647976, -0.114720002 . . I can't seem to get R to recognize this data as a time/data column in m/dd/ hh:mm format followed by columns of data. There was a post on an analogous topic a couple of years ago, but none of the proposed (and quite complicated) solutions seemed to work for me. Anyone know how to handle this? -- View this message in context: http://r.789695.n4.nabble.com/reading-in-time-series-tp3225481p3225481.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] Problems with ecodist
Dear Dr.Goslee and anyone may intrested in matrix manipulate, I am using your ecodist to do mantel and partial mantel test, I have locality data and shape variation data, and the two distance matrixs are given as belowings. When I run the analysis, it is always report that the matrix is not square, but I didn't know what's wrong with my data. Would you please help me on this. I am quite new to R. Thanks. distancematrix - as.matrix(read.table(test1.txt)) distancematrix1 - as.matrix(read.table(test2.txt)) distancematrix1 Loc1 Loc2 Loc3 Loc4 Loc5 Loc6 Loc7 Loc8 Loc9Loc10 Loc11 Loc12 Loc1 0.000 2293.8671 2180.7127 7563.934 2494.5049 2522.3946 5953.609 2511.5994 2047.683 4448.721 3180.844 3112.6798 Loc2 2293.8670. 443.2497 9831.220 472.2009 397.4316 8213.580 1114.9120 2087.877 6723.807 2407.192 1314.6927 Loc3 2180.713 443.24970. 9620.263 915.4497 836.5849 8001.565 708.1212 2377.024 6627.808 2818.822 1063.8092 Loc4 7563.934 9831.2199 9620.2627 0.000 10057.8311 10085.8054 1619.041 9639.4505 8967.156 3482.672 10046.113 10253.9565 Loc5 2494.505 472.2009 915.4497 10057.831 0. 112.6242 8448.063 1569.7006 1846.755 6845.471 1983.525 1670.4862 Loc6 2522.395 397.4316 836.5849 10085.805 112.6242 0. 8473.279 1473.1610 1951.517 6897.051 2092.925 1558.8962 Loc7 5953.609 8213.5803 8001.5652 1619.041 8448.0626 8473.27890.000 8034.9093 7447.264 2171.838 8568.467 8654.3923 Loc8 2511.599 1114.9120 708.1212 9639.451 1569.7006 1473.1610 8034.909 0. 3064.747 6870.287 3518.951 631.5406 Loc9 2047.683 2087.8774 2377.0240 8967.156 1846.7549 1951.5175 7447.264 3064.74660.000 5528.956 1182.826 3397.4896 Loc10 4448.721 6723.8068 6627.8081 3482.672 6845.4709 6897.0513 2171.838 6870.2865 5528.9560.000 6572.264 7497.8614 Loc11 3180.844 2407.1921 2818.8222 10046.113 1983.5246 2092.9254 8568.467 3518.9508 1182.826 6572.264 0.000 3647.8307 Loc12 3112.680 1314.6927 1063.8092 10253.957 1670.4862 1558.8962 8654.392 631.5406 3397.490 7497.861 3647.831 0. distancematrix sample1 sample2 sample3 sample4 sample5 sample6 sample7 sample8 sample9 sample10 sample11 sample12 sample1 0. 0.0229 0.0258 0.0394 0.0295 0.0337 0.0269 0.0345 0.0314 0.0418 0.0577 0.0853 sample2 0.0229 0. 0.0219 0.0373 0.0337 0.0352 0.0320 0.0310 0.0275 0.0508 0.0533 0.0739 sample3 0.0258 0.0219 0. 0.0349 0.0375 0.0332 0.0309 0.0233 0.0246 0.0522 0.0539 0.0748 sample4 0.0394 0.0373 0.0349 0. 0.0590 0.0514 0.0356 0.0321 0.0354 0.0737 0.0365 0.0652 sample5 0.0295 0.0337 0.0375 0.0590 0. 0.0311 0.0482 0.0474 0.0401 0.0331 0.0726 0.0931 sample6 0.0337 0.0352 0.0332 0.0514 0.0311 0. 0.0406 0.0362 0.0363 0.0429 0.0708 0.0903 sample7 0.0269 0.0320 0.0309 0.0356 0.0482 0.0406 0. 0.0359 0.0370 0.0536 0.0625 0.0888 sample8 0.0345 0.0310 0.0233 0.0321 0.0474 0.0362 0.0359 0. 0.0267 0.0649 0.0498 0.0662 sample9 0.0314 0.0275 0.0246 0.0354 0.0401 0.0363 0.0370 0.0267 0. 0.0569 0.0583 0.0693 sample10 0.0418 0.0508 0.0522 0.0737 0.0331 0.0429 0.0536 0.0649 0.0569 0. 0.0919 0.1150 sample11 0.0577 0.0533 0.0539 0.0365 0.0726 0.0708 0.0625 0.0498 0.0583 0.0919 0. 0.0601 sample12 0.0853 0.0739 0.0748 0.0652 0.0931 0.0903 0.0888 0.0662 0.0693 0.1150 0.0601 0. mantel(distancematrix~distancematrix1) error mantel(distancematrix ~ distancematrix1) : Matrix not square. -- View this message in context: http://r.789695.n4.nabble.com/Problems-with-ecodist-tp3225480p3225480.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] subsets
Hi! I think you should read the intro to R, as well as ?[ and ?subset. It should help you to understand. Let's say your data is in a data.frame called df: # 1. ah and ihd df_ah_ihd - df[df$diagnosis==ah | df$diagnosis==ihd, ] ## the | is the boolean OR (you want one OR the other). Note the last comma #2. ah df_ah - df[df$diagnosis==ah, ] #3. ihd df_ihd - df[df$diagnosis==ihd, ] You could do the same using subset() if you feel better with this function. HTH, Ivan Le 1/20/2011 09:53, Den a écrit : Dear R people Could you please help. Basically, there are two variables in my data set. Each patient ('id') may have one or more diseases ('diagnosis'). It looks like id diagnosis 1 ah 2 ah 2 ihd 2 im 3 ah 3 stroke 4 ah 4 ihd 4 angina 5 ihd .. Q: How to make three data sets: 1. Patients with ah and ihd 2. Patients with ah but no ihd 3. Patients with ihd but no ah? If you have any ideas could just guide what should I look for. Is a subset or aggregate, or loops, or something else??? I am a bit lost. (F1 F1 F1 !!!:) Thank you __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] fix sign of a coefficient in formula
Dear R users experts, I'd like to create a model using lm (or glm) under some constraints of how coefficients for each component could look like (sort of a range of coefficients that should be allowed). So let's go for an example : model=lm(age ~ eyecolor + height, data=inputdata) So let's suppose that R pops out a model with positive estimates for the coefficients eyecolor and height, I have to use them as is. But however, if I'd like to produce a model that follows that behaviour : age = A*eyecolor - B*height having A0 and B0 how can I achieve that? I read about offsets, but I just know the range of the coefficient, but not the exact value and doing something like that offset(seq(-1,0,0.01)*height) doesn't seem to work in lm. Thanks in advance for any hint! Best regards. -- Peter Schmidtke PhD Student Dept. Physical Chemistry Faculty of Pharmacy University of Barcelona __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Installing package in windows 7
On Thu, 20 Jan 2011, Tal Galili wrote: You probably need to get your users permissions (in win 7) set properly... I see no evidence that is the issue That site seems to be offering only source packages. So in Windows you need install.packages(ei,repos=http://r.iq.harvard.edu;, type='source') This can be done without Rtools in R = 2.12.0. Note though that it depends on other packages mvtnorm, msm, tmvtnorm, ellipse, plotrix, MASS, ucminf, cubature, mnormt, foreach and those have dependencies (at least iterators), so I would install them from CRAN first (MASS should already be there). Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Wed, Jan 19, 2011 at 8:26 PM, radagast haseeb.mah...@gmail.com wrote: Hi all, I was trying to install a package called ei from this http://gking.harvard.edu/eiR link . With GCC, r-base-dev and some other R package dependencies installed it works perfect in my Ubuntu Linux system. Now I am trying to install the same in Windows 7 environment. So far my setup is as follows, 1. R installed in home folder (c:\Users\username\R-2.12.1\R. It is set to run as administrator, and the R folder is writable. 2. My working directory is (c:\Users\username\Documents) 3. Rtool is installed in (c:\Rtools) Having this setup, 4. I tried to install it by the command, install.packages(ei,repos=http://r.iq.harvard.edu;) This command gives me the following error message. --- Installing package(s) into ?C:\Users\username\Documents/R/win-library/2.12? (as ?lib? is unspecified) Warning message: In getDependencies(pkgs, dependencies, available, lib) : package ?ei? is not available --- After that I have decided to have a try to install it from a local zip file, so I proceeded in the following way, 5. I have downloaded the package ei_0.938.tar.gz, untar it and make a zip file from that. I placed it into my work directory. 6. I opened the terminal (Run cmd), went to the work directory and tried to run the command R COM INSTALL ei --- It shows me the following error message, C:\Users\username\DocumentsR COM INSTALL ei 'R' is not recognized as an internal or external command, operable program or batch file. --- I am not sure what should I do now. Is there anyone to help? _ Rdgst. -- View this message in context: http://r.789695.n4.nabble.com/Installing-package-in-windows-7-tp3225439p3225439.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Using a list as multidimensional indexer
Hello list. Another 'puzzle' for which I don't have a clean solution. Say I have a multidimensional object, e.g.: Mm-matrix(1:6, nrow=2, dimnames=list(c(a,b), c(g,h,i))) And on the other hand I have a list Ind-list(b,g) This holds, for each dimension, an indexer for that dimension. Now I would like to get the element pointed at by the list. The obvious solutions don't seem to work, and I can't seem to get do.call to call the indexer ('[') on my multidimensional object. Any suggestions? Thanks in advance, Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using a list as multidimensional indexer
On Thu, 20 Jan 2011, Nick Sabbe wrote: Hello list. Another 'puzzle' for which I don't have a clean solution. Say I have a multidimensional object, e.g.: Mm-matrix(1:6, nrow=2, dimnames=list(c(a,b), c(g,h,i))) And on the other hand I have a list Ind-list(b,g) This holds, for each dimension, an indexer for that dimension. Now I would like to get the element pointed at by the list. The obvious solutions don't seem to work, and I can't seem to get do.call to call the indexer ('[') on my multidimensional object. Any suggestions? do.call(`[`, c(quote(Mm), Ind)) [1] 2 do.call(`[`, c(list(Mm), Ind)) [1] 2 gives Mm[b, g] [1] 2 The first refers to the object by name, the second uses it directly. Thanks in advance, Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] fix sign of a coefficient in formula
Fitting a linear model with constraints is a completely different task from fitting one without -- and it is the fit you want to constrain, not the formula. See CRAN package nnls to fit a linear model with sign constraints. If you have range constraints you can use nls(algorithm=port) since 'non-linear' here subsumes 'linear'. In your simple case you can also use some convex optimization theory to know that if the unconstrained solution has either A 0 or B 0 then a solution constrained by A = 0 and B = 0 has either A=0 or B=0 or both, so try those and see which fits best. On Thu, 20 Jan 2011, Peter Schmidtke wrote: Dear R users experts, I'd like to create a model using lm (or glm) under some constraints of how coefficients for each component could look like (sort of a range of coefficients that should be allowed). So let's go for an example : model=lm(age ~ eyecolor + height, data=inputdata) So let's suppose that R pops out a model with positive estimates for the coefficients eyecolor and height, I have to use them as is. But however, if I'd like to produce a model that follows that behaviour : age = A*eyecolor - B*height having A0 and B0 Note that in general that will not have an optimal solution. You need A = 0 and B = 0. Also, that differs from your R formula, which has an intercept and the opposite sign for 'height'. how can I achieve that? I read about offsets, but I just know the range of the coefficient, but not the exact value and doing something like that offset(seq(-1,0,0.01)*height) doesn't seem to work in lm. It should work and do what it is documented to do, just not what you want. Thanks in advance for any hint! Best regards. -- Peter Schmidtke PhD Student Dept. Physical Chemistry Faculty of Pharmacy University of Barcelona -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Using a list as multidimensional indexer
Hm. I got somewhat further: Ind2-list(Mm,b,g) do.call([,Ind2) Seems to work. However, now I need it one step beyond: in fact, my actual multidimensional object holds one dimension more than my list holds indexes. i.e.: I want the equivalent of Mm[a,]. I tried some variants of Ind3-list(Mm,b,NULL) do.call([, Ind3) But all of these return integer(0). So the actual new question is: how do I pass a 'missing' argument through a do.call? Thanks for any pointers, Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Nick Sabbe Sent: donderdag 20 januari 2011 11:05 To: r-help@r-project.org Subject: [R] Using a list as multidimensional indexer Hello list. Another 'puzzle' for which I don't have a clean solution. Say I have a multidimensional object, e.g.: Mm-matrix(1:6, nrow=2, dimnames=list(c(a,b), c(g,h,i))) And on the other hand I have a list Ind-list(b,g) This holds, for each dimension, an indexer for that dimension. Now I would like to get the element pointed at by the list. The obvious solutions don't seem to work, and I can't seem to get do.call to call the indexer ('[') on my multidimensional object. Any suggestions? Thanks in advance, Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] spacing of color key in filled.contour
On 01/20/2011 09:19 AM, claudia tebaldi wrote: Hi all I'm plotting colored contour maps using filled.contour. My levels are very unevenly spaced, with, say, high resolution in the small numbers but ranges that can be an order of magnitude or two larger in absolute value compared to where the action takes place. Aside from transforming the data, is there a way to control the color spacing in the key to the right of the map? Right now I get most of the key length taken up by a couple of colors and the rest all squeezed into thin slices, which also creates a problem with the fourth axis labels getting drawn on top of one another. Hi Claudia, You can roll your own color key with the color.legend function in plotrix. Just specify the colors you want in rect.col and the labels in legend. 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] subsets
I don't think Ivan's solution meets the OP's needs. I think you could do it using %in% and the approriate logical operations e.g. aDF - data.frame(id=c(1,2,2,2,3,3,4,4,4,5), diagnosis=c(ah, ah, ihd, im, ah, stroke, ah, ihd, angina, ihd)) aDF[with(aDF,(id %in% id[diagnosis==ah]) (id %in% id[diagnosis==ihd])),] aDF[with(aDF,(id %in% id[diagnosis==ah]) !(id %in% id[diagnosis==ihd])),] aDF[with(aDF,!(id %in% id[diagnosis==ah]) (id %in% id[diagnosis==ihd])),] That starts to feel a bit fiddly for me. You might want to look at package sqldf. HTH Keith J -- Ivan Calandra ivan.calan...@uni-hamburg.de wrote in message news:4d37fbea.5070...@uni-hamburg.de... Hi! I think you should read the intro to R, as well as ?[ and ?subset. It should help you to understand. Let's say your data is in a data.frame called df: # 1. ah and ihd df_ah_ihd - df[df$diagnosis==ah | df$diagnosis==ihd, ] ## the | is the boolean OR (you want one OR the other). Note the last comma #2. ah df_ah - df[df$diagnosis==ah, ] #3. ihd df_ihd - df[df$diagnosis==ihd, ] You could do the same using subset() if you feel better with this function. HTH, Ivan Le 1/20/2011 09:53, Den a écrit : Dear R people Could you please help. Basically, there are two variables in my data set. Each patient ('id') may have one or more diseases ('diagnosis'). It looks like id diagnosis 1 ah 2 ah 2 ihd 2 im 3 ah 3 stroke 4 ah 4 ihd 4 angina 5 ihd .. Q: How to make three data sets: 1. Patients with ah and ihd 2. Patients with ah but no ihd 3. Patients with ihd but no ah? If you have any ideas could just guide what should I look for. Is a subset or aggregate, or loops, or something else??? I am a bit lost. (F1 F1 F1 !!!:) Thank you __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] subsets
Try this: lapply(list(c('ah', 'ihd'), 'ah', 'ihd'), function(x)subset(aDF, diagnosis == x)) On Thu, Jan 20, 2011 at 6:53 AM, Den d.kazakiew...@gmail.com wrote: Dear R people Could you please help. Basically, there are two variables in my data set. Each patient ('id') may have one or more diseases ('diagnosis'). It looks like id diagnosis 1 ah 2 ah 2 ihd 2 im 3 ah 3 stroke 4 ah 4 ihd 4 angina 5 ihd .. Q: How to make three data sets: 1. Patients with ah and ihd 2. Patients with ah but no ihd 3. Patients with ihd but no ah? If you have any ideas could just guide what should I look for. Is a subset or aggregate, or loops, or something else??? I am a bit lost. (F1 F1 F1 !!!:) Thank you __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot2, geom_hline and facet_grid
Thank you. That seems to work - also on my much larger data set. I'm not sure I understand why it has to be defined as a factor, but if it works... Sandy Dennis Murphy wrote: Hi Sandy: I can reproduce your problem given the data provided. When I change ecd_rhythm from character to factor, it works as you intended. str(lvefeg) List of 4 ### Interesting... $ cvd_basestudy: chr [1:10] CBP05J02 CBP05J02 CBP05J02 CBP05J02 ... $ ecd_rhythm : chr [1:10] AF AF AF AF ... $ fixed_time : num [1:10] 30.9 33.2 32.6 32.1 30.9 ... $ variable_time: num [1:10] 29.4 32 30.3 33.7 28.3 ... - attr(*, row.names)= int [1:10] 1 2 3 4 5 6 7 9 10 11 class(lvefeg) [1] cast_dfdata.frame lvefeg$ecd_rhythm - factor(lvefeg$ecd_rhythm) p - qplot((variable_time + fixed_time) /2 , variable_time - fixed_time, data = lvefeg, geom='point') p p + facet_grid(ecd_rhythm ~ .) + geom_hline(yintercept=0) Does that work on your end? (And thank you for the reproducible example. Using dput() allows us to see what you see, which is very helpful.) HTH, Dennis On Wed, Jan 19, 2011 at 1:30 PM, Small Sandy (NHS Greater Glasgow Clyde) [1]sandy.sm...@nhs.net wrote: Hi Still having problems in that when I use geom_hline and facet_grid together I get two extra empty panels A reproducible example can be found at: [2]https://gist.github.com/786894 Sandy Small From: [3]h.wick...@gmail.com [[4]h.wick...@gmail.com] On Behalf Of Hadley Wickham [[5]had...@rice.edu] Sent: 19 January 2011 15:11 To: Small Sandy (NHS Greater Glasgow Clyde) Cc: [6]r-help@r-project.org Subject: Re: [R] ggplot2, geom_hline and facet_grid Hi Sandy, It's difficult to know what's going wrong without a small reproducible example ([7]https://github.com/hadley/devtools/wiki/Reproducibility) - could you please provide one? You might also have better luck with an email directly to the ggplot2 mailing list. Hadley On Wed, Jan 19, 2011 at 2:57 AM, Sandy Small [8]sandy.sm...@nhs.net wrote: Having upgraded to R version 2.12.1 I still have the same problem: The combination of facet_grid and geom_hline produce (for me) 4 panels of which two are empty of any data or lines (labelled 1 and 2). Removing either the facet_grid or the geom_hline gives me the result I would then expect. I have tried forcing the rhythm to be a factor Anyone have any ideas? Sandy Dennis Murphy wrote: Hi: The attached plot comes from the following code: g - ggplot(data =f, aes(x = (variable_time + fixed_time)/2, y variable_time - fixed_time)) g + geom_point() + geom_hline(yintercept =) + facet_grid(ecd_rhythm ~ .) Is this what you were expecting? sessionInfo() R version 2.12.1 Patched (2010-12-18 r53869) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=glish_United States.1252 [2] LC_CTYPE=glish_United States.1252 [3] LC_MONETARY=glish_United States.1252 [4] LC_NUMERIC=nbsp; [5] LC_TIME=glish_United States.1252 attached base packages: [1] splines stats graphics grDevices utils datasets grid [8] methods base other attached packages: [1] data.table_1.5.1 doBy_4.2.2 R2HTML_2.2 contrast_0.13 [5] Design_2.3-0 Hmisc_3.8-3 survival_2.36-2 sos_1.3-0 [9] brew_1.0-4 lattice_0.19-17 ggplot2_0.8.9proto_0.3-8 [13] reshape_0.8.3plyr_1.4 loaded via a namespace (and not attached): [1] cluster_1.13.2 digest_0.4.2 Matrix_0.999375-46 reshape2_1.1 [5] stringr_0.4tools_2.12.1 HTH, Dennis On Tue, Jan 18, 2011 at 1:46 AM, Small Sandy (NHS Greater Glasgow Clyde) [9]sandy.sm...@nhs.net [10]ailto:sandy.sm...@nhs.net%22 wrote: Hi I have a long data set on which I want to do Bland-Altman style plots for each rhythm type Using ggplot2, when I use geom_hline with facet_grid I get an extra set of empty panels. I can't get it to do it with the Diamonds data supplied with the package so here is a (much abbreviated) example: lvexs cvd_basestudy ecd_rhythm fixed_time variable_time 1 CBP05J02 AF30.9000 29.4225 2 CBP05J02 AF33.1700 32.0350 3 CBP05J02 AF32.5700 30.2775 4 CBP05J02 AF32.0550 33.7275 5 CBP05J02 SINUS30.9175 28.3475 6 CBP05J02 SINUS30.5725 29.7450 7 CBP05J02 SINUS33.
[R] puzzled with plotmath
Dear all, I'm puzzled with matrix indices in plotmath. I'm plotting matrix elements: Z [i, i], and I'd like to put that as label. I'll describe what I want and what I get in LaTeX-notation. The output should look like Z_{i, i}, and my first try was plot (1, 1, ylab = expression (Z[i, i])) That, however, gives me Z_{i} (no comma, no second i) although the expression looks OK to me: a - expression (Z[i, i]) a [[1]] Z[i, i] str (as.list (a [[1]])) List of 4 $ : symbol [ $ : symbol Z $ : symbol i $ : symbol i I'm able to tweak the ouput looking as I want: plot (1, 1, ylab = expression (Z[i][, ][i])) which is, however, logically very far from what I want to express. What am I missing? I'm almost sure this has been discussed before, but I can't find it: can anyone point me to good search terms? Is it possible to search for the terms being close to each other in RSiteSearch and/or RSeek? I get lots of introductory documents as they point to plotmath and discuss matrices... Thanks a lot for your help, Claudia -- Claudia Beleites Dipartimento dei Materiali e delle Risorse Naturali Università degli Studi di Trieste Via Alfonso Valerio 6/a I-34127 Trieste phone: +39 0 40 5 58-37 68 email: cbelei...@units.it __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] puzzled with plotmath II
sorry, I forgot my sessionInfo: please see below. Original Message Subject: puzzled with plotmath Date: Thu, 20 Jan 2011 12:48:18 +0100 From: Claudia Beleites cbelei...@units.it To: R Help r-help@r-project.org Dear all, I'm puzzled with matrix indices in plotmath. I'm plotting matrix elements: Z [i, i], and I'd like to put that as label. I'll describe what I want and what I get in LaTeX-notation. The output should look like Z_{i, i}, and my first try was plot (1, 1, ylab = expression (Z[i, i])) That, however, gives me Z_{i} (no comma, no second i) although the expression looks OK to me: a - expression (Z[i, i]) a [[1]] Z[i, i] str (as.list (a [[1]])) List of 4 $ : symbol [ $ : symbol Z $ : symbol i $ : symbol i I'm able to tweak the ouput looking as I want: plot (1, 1, ylab = expression (Z[i][, ][i])) which is, however, logically very far from what I want to express. What am I missing? I'm almost sure this has been discussed before, but I can't find it: can anyone point me to good search terms? Is it possible to search for the terms being close to each other in RSiteSearch and/or RSeek? I get lots of introductory documents as they point to plotmath and discuss matrices... Thanks a lot for your help, Claudia sessionInfo () R version 2.12.1 (2010-12-16) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C LC_TIME=en_US.utf8 [4] LC_COLLATE=en_US.utf8 LC_MONETARY=C LC_MESSAGES=en_US.utf8 [7] LC_PAPER=en_US.utf8 LC_NAME=C LC_ADDRESS=C [10] LC_TELEPHONE=CLC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] grid stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.8.8 proto_0.3-8 reshape_0.8.3 plyr_1.2.1 loaded via a namespace (and not attached): [1] digest_0.4.2 tools_2.12.1 -- Claudia Beleites Dipartimento dei Materiali e delle Risorse Naturali Università degli Studi di Trieste Via Alfonso Valerio 6/a I-34127 Trieste phone: +39 0 40 5 58-37 68 email: cbelei...@units.it __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problems with ecodist
Hi, If you read the help for mantel, it says that the data must be either vectors of dissimilarities or objects of class dist. Since you are reading in your data as full symmetric matrices, you have two options: mantel(as.dist(distancematrix) ~ as.dist(distancematrix1)) mantelr pval1 pval2 pval3 llim.2.5% ulim.97.5% 0.07596818 0.2910 0.7100 0.7300 -0.02049799 0.22440245 mantel(lower(distancematrix) ~ lower(distancematrix1)) mantelr pval1 pval2 pval3 llim.2.5% ulim.97.5% 0.07596818 0.3140 0.6870 0.7400 -0.03329888 0.20299330 Sarah On Thu, Jan 20, 2011 at 3:03 AM, deyan g...@ioz.ac.cn wrote: Dear Dr.Goslee and anyone may intrested in matrix manipulate, I am using your ecodist to do mantel and partial mantel test, I have locality data and shape variation data, and the two distance matrixs are given as belowings. When I run the analysis, it is always report that the matrix is not square, but I didn't know what's wrong with my data. Would you please help me on this. I am quite new to R. Thanks. distancematrix - as.matrix(read.table(test1.txt)) distancematrix1 - as.matrix(read.table(test2.txt)) distancematrix1 Loc1 Loc2 Loc3 Loc4 Loc5 Loc6 Loc7 Loc8 Loc9 Loc10 Loc11 Loc12 Loc1 0.000 2293.8671 2180.7127 7563.934 2494.5049 2522.3946 5953.609 2511.5994 2047.683 4448.721 3180.844 3112.6798 Loc2 2293.867 0. 443.2497 9831.220 472.2009 397.4316 8213.580 1114.9120 2087.877 6723.807 2407.192 1314.6927 Loc3 2180.713 443.2497 0. 9620.263 915.4497 836.5849 8001.565 708.1212 2377.024 6627.808 2818.822 1063.8092 Loc4 7563.934 9831.2199 9620.2627 0.000 10057.8311 10085.8054 1619.041 9639.4505 8967.156 3482.672 10046.113 10253.9565 Loc5 2494.505 472.2009 915.4497 10057.831 0. 112.6242 8448.063 1569.7006 1846.755 6845.471 1983.525 1670.4862 Loc6 2522.395 397.4316 836.5849 10085.805 112.6242 0. 8473.279 1473.1610 1951.517 6897.051 2092.925 1558.8962 Loc7 5953.609 8213.5803 8001.5652 1619.041 8448.0626 8473.2789 0.000 8034.9093 7447.264 2171.838 8568.467 8654.3923 Loc8 2511.599 1114.9120 708.1212 9639.451 1569.7006 1473.1610 8034.909 0. 3064.747 6870.287 3518.951 631.5406 Loc9 2047.683 2087.8774 2377.0240 8967.156 1846.7549 1951.5175 7447.264 3064.7466 0.000 5528.956 1182.826 3397.4896 Loc10 4448.721 6723.8068 6627.8081 3482.672 6845.4709 6897.0513 2171.838 6870.2865 5528.956 0.000 6572.264 7497.8614 Loc11 3180.844 2407.1921 2818.8222 10046.113 1983.5246 2092.9254 8568.467 3518.9508 1182.826 6572.264 0.000 3647.8307 Loc12 3112.680 1314.6927 1063.8092 10253.957 1670.4862 1558.8962 8654.392 631.5406 3397.490 7497.861 3647.831 0. distancematrix sample1 sample2 sample3 sample4 sample5 sample6 sample7 sample8 sample9 sample10 sample11 sample12 sample1 0. 0.0229 0.0258 0.0394 0.0295 0.0337 0.0269 0.0345 0.0314 0.0418 0.0577 0.0853 sample2 0.0229 0. 0.0219 0.0373 0.0337 0.0352 0.0320 0.0310 0.0275 0.0508 0.0533 0.0739 sample3 0.0258 0.0219 0. 0.0349 0.0375 0.0332 0.0309 0.0233 0.0246 0.0522 0.0539 0.0748 sample4 0.0394 0.0373 0.0349 0. 0.0590 0.0514 0.0356 0.0321 0.0354 0.0737 0.0365 0.0652 sample5 0.0295 0.0337 0.0375 0.0590 0. 0.0311 0.0482 0.0474 0.0401 0.0331 0.0726 0.0931 sample6 0.0337 0.0352 0.0332 0.0514 0.0311 0. 0.0406 0.0362 0.0363 0.0429 0.0708 0.0903 sample7 0.0269 0.0320 0.0309 0.0356 0.0482 0.0406 0. 0.0359 0.0370 0.0536 0.0625 0.0888 sample8 0.0345 0.0310 0.0233 0.0321 0.0474 0.0362 0.0359 0. 0.0267 0.0649 0.0498 0.0662 sample9 0.0314 0.0275 0.0246 0.0354 0.0401 0.0363 0.0370 0.0267 0. 0.0569 0.0583 0.0693 sample10 0.0418 0.0508 0.0522 0.0737 0.0331 0.0429 0.0536 0.0649 0.0569 0. 0.0919 0.1150 sample11 0.0577 0.0533 0.0539 0.0365 0.0726 0.0708 0.0625 0.0498 0.0583 0.0919 0. 0.0601 sample12 0.0853 0.0739 0.0748 0.0652 0.0931 0.0903 0.0888 0.0662 0.0693 0.1150 0.0601 0. mantel(distancematrix~distancematrix1) error mantel(distancematrix ~ distancematrix1) : Matrix not square. -- View this message in context: http://r.789695.n4.nabble.com/Problems-with-ecodist-tp3225480p3225480.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Sarah Goslee http://www.stringpage.com http://www.astronomicum.com
Re: [R] puzzled with plotmath II
Try plot (1, 1, ylab = expression (Z[list(i,i)])) Hth -- Gerrit Original Message Subject: puzzled with plotmath Date: Thu, 20 Jan 2011 12:48:18 +0100 From: Claudia Beleites cbelei...@units.it To: R Help r-help@r-project.org Dear all, I'm puzzled with matrix indices in plotmath. I'm plotting matrix elements: Z [i, i], and I'd like to put that as label. I'll describe what I want and what I get in LaTeX-notation. The output should look like Z_{i, i}, and my first try was plot (1, 1, ylab = expression (Z[i, i])) That, however, gives me Z_{i} (no comma, no second i) although the expression looks OK to me: a - expression (Z[i, i]) a [[1]] Z[i, i] str (as.list (a [[1]])) List of 4 $ : symbol [ $ : symbol Z $ : symbol i $ : symbol i I'm able to tweak the ouput looking as I want: plot (1, 1, ylab = expression (Z[i][, ][i])) which is, however, logically very far from what I want to express. What am I missing? I'm almost sure this has been discussed before, but I can't find it: can anyone point me to good search terms? Is it possible to search for the terms being close to each other in RSiteSearch and/or RSeek? I get lots of introductory documents as they point to plotmath and discuss matrices... Thanks a lot for your help, Claudia sessionInfo () R version 2.12.1 (2010-12-16) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C LC_TIME=en_US.utf8 [4] LC_COLLATE=en_US.utf8 LC_MONETARY=C LC_MESSAGES=en_US.utf8 [7] LC_PAPER=en_US.utf8 LC_NAME=C LC_ADDRESS=C [10] LC_TELEPHONE=CLC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] grid stats graphics grDevices utils datasets methods base other attached packages: [1] ggplot2_0.8.8 proto_0.3-8 reshape_0.8.3 plyr_1.2.1 loaded via a namespace (and not attached): [1] digest_0.4.2 tools_2.12.1 -- Claudia Beleites Dipartimento dei Materiali e delle Risorse Naturali Università degli Studi di Trieste Via Alfonso Valerio 6/a I-34127 Trieste phone: +39 0 40 5 58-37 68 email: cbelei...@units.it __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Loading wordnet in R
On 18.01.2011 07:42, fayazvf wrote: I ve installed wordnet 2.1 and R 2.11.0 on windows 7. Whenver i try to load wordnet in R, i get an error initDict() FALSE cannot find wordnet 'dict' directory, Please set the WNHOME variable to its parent. I have tried setting WNHOME to C:\Program Files (x86)\WordNet\2.1\dict,C:\\Program Files (x86)\\WordNet\\2.1\\dict,C:Program Files (x86)WordNet2.1dict. None of them helps. Please help me out. Thanks in advance. 1. WNHOME is supposed to be the environment variable set in your opearting system (not an R variable). 2. You should set it to the parent of dict rather than dict. If you want to do that from R, use Sys.setenv(WNHOME = C:\\Program Files (x86)\\WordNet\\2.1) Best, Uwe Ligges __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Generating time progressing line for Google Earth
Dear, I am trying to visualise a time-progressing line (it's supposed to represent spread patterns) using brew package and Google Earth. The idea is to have a function which takes start and end point geographic coordinates, as well as number of intervals to chop the path up, and returns the collection of points segmenting this line. Unfortunately my calculations fail for large distances, as the generated lines are nowhere near being straigth (run the code to see the example). My R code so far: #---LIBS---# library(brew) ### #---GREAT CIRCULAR DISTANCE---# ### #degrees to radians Radians - function (degree) { radian = degree * (pi/180.0) return(radian) } #radians to degrees Degrees - function (radian) { degree = radian * (180.0/pi) return(degree) } # Calculates the distance between two points using the # Spherical Law of Cosines gcd.slc - function(lon1, lat1, lon2, lat2) { R = 6371.0 # Earth mean radius [km] lon1 = Radians(lon1) lat1 = Radians(lat1) lon2 = Radians(lon2) lat2 = Radians(lat2) d = acos(sin(lat1)*sin(lat2) + cos(lat1)*cos(lat2) * cos(lon2-lon1)) * R return(d) # Distance in km } #---PROGRESSING LINE---# GenerateLineSegments - function(start_point.Long, start_point.Lat, end_point.Long, end_point.Lat, numberOfIntervals) { coords - matrix(NA, numberOfIntervals, 2) full_distance = gcd.slc(lat1 = start_point.Lat, lon1 = start_point.Long, lat2 = end_point.Lat, lon2 = end_point.Long) distance_slice = full_distance / numberOfIntervals for(i in 1 : numberOfIntervals) { distance = i * distance_slice ang_dist = distance / 6371.0 lon_1 = Radians(start_point.Long); lat_1 = Radians(start_point.Lat); lat_2 = Radians(end_point.Lat); lon_diff = Radians(end_point.Long - start_point.Long); # First calculate the bearing bearing = atan2( sin(lon_diff) * cos(lat_2), (cos(lat_1) * sin(lat_2)) - (sin(lat_1) * cos(lat_2) * cos(lon_diff)) ); # Then use the bearing and the start point to find the destination new_lat_rad = asin(sin(lat_1) * cos(ang_dist) + cos(lat_1) * sin(ang_dist) * cos(bearing)); new_lon_rad = lon_1 + atan2( sin(bearing) * sin(ang_dist) * cos(lat_1), cos(ang_dist) - sin(lat_1) * sin(lat_2) ); # Convert from radians to degrees new_lat = Degrees(new_lat_rad); new_lon = Degrees(new_lon_rad); coords[i, 2] = new_lat coords[i, 1] = new_lon } return(coords) } ### #---BREWING KML---# ### #A 39.5-4.5 #E 44.75 -107.5 startLong = -4.5 startLat = 39.5 endLong = -107.5 endLat = 44.75 numberOfIntervals = 100 coords - GenerateLineSegments(startLong, startLat, endLong, endLat, numberOfIntervals) coords - as.data.frame(coords) names(coords) - c(Long, Lat) seg - data.frame(matrix(NA, nrow(coords) - 1, 5)) names(seg) - c(x, y, xend, yend, segment) for (i in 1 : (nrow(coords) - 1 ) ) { seg[i, ]$x = coords[i, ]$Long seg[i, ]$y = coords[i, ]$Lat seg[i, ]$xend = coords[i + 1, ]$Long seg[i, ]$yend = coords[i + 1, ]$Lat seg[i, ]$segment = paste(i) } #seg brew(file = LinesTemplate.xml, output = RKMLoutput.kml ) ...and the kml template file to be used with brewer: ?xml version=1.0 encoding=utf-8 ? kml xmlns=http://www.opengis.net/kml/2.2; Document Foldernamelines/name % for(i in 1:nrow(seg)){ % Placemark TimeSpan begin%= paste(1980+i, 01, 01, sep=-)%/begin /TimeSpan name%=paste(seg$x[i], ,, seg$y[i], : , seg$xend[i], ,, seg$yend[i], sep=)%/name StyleLineStylecolor7f9b/colorwidth3.5/width/LineStyle/Style LineString tessellate1/tessellate coordinates%=seg[i,]$x%, %=seg[i,]$y%, 0.0 %=seg[i,]$xend%, %=seg[i,]$yend%, 0.0 /coordinates/LineString /Placemark % } % /Folder /Document/kml What is going wrong here? -- while(!succeed) { try(); } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] puzzled with plotmath for matrix indices
Gerrit, thanks viele Grüße nach Oberhessen :-) plot (1, 1, ylab = expression (Z[list(i,i)])) though that cannot be evaluated, either (due to [ not knowing what to do with an index list) for future searches: probably the easiest cheat is, of course, plot (1, 1, ylab = expression (Z[i, i])) Anyways, I put the how to into the R Wiki page on plotmath. And I suggest that it should be mentioned in the plotmath help = email to r-devel. Claudia -- Claudia Beleites Dipartimento dei Materiali e delle Risorse Naturali Università degli Studi di Trieste Via Alfonso Valerio 6/a I-34127 Trieste phone: +39 0 40 5 58-37 68 email: cbelei...@units.it __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] puzzled with plotmath for matrix indices
On 20.01.2011 14:08, Claudia Beleites wrote: Gerrit, thanks viele Grüße nach Oberhessen :-) plot (1, 1, ylab = expression (Z[list(i,i)])) though that cannot be evaluated, either (due to [ not knowing what to do with an index list) Works for me with a recent R version. for future searches: probably the easiest cheat is, of course, plot (1, 1, ylab = expression (Z[i, i])) which is less convenient since you could not replace i by a dynamically calculated number, for example. Best, Uwe Ligges Anyways, I put the how to into the R Wiki page on plotmath. And I suggest that it should be mentioned in the plotmath help = email to r-devel. Claudia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] reading in time series
Is this what you are trying to do: x - read.table(textConnection(3/23/2010 20:55, -0.10655, -0.121454561, -0.12032, -0.111680001,-0.122429997 + 3/23/2010 21:25, -0.099166997, -0.114189997, -0.11287, -0.104647976,-0.114720002), sep = ',', as.is = TRUE) closeAllConnections() x V1V2 V3 V4 V5 V6 1 3/23/2010 20:55 -0.106560 -0.1214546 -0.12030 -0.1116800 -0.12243 2 3/23/2010 21:25 -0.099167 -0.1141900 -0.11288 -0.1046480 -0.11472 str(x) 'data.frame': 2 obs. of 6 variables: $ V1: chr 3/23/2010 20:55 3/23/2010 21:25 $ V2: num -0.1066 -0.0992 $ V3: num -0.121 -0.114 $ V4: num -0.12 -0.113 $ V5: num -0.112 -0.105 $ V6: num -0.122 -0.115 # convert to POSIXct x$V1 - as.POSIXct(x$V1, format = %m/%d/%Y %H:%M) x V1V2 V3 V4 V5 V6 1 2010-03-23 20:55:00 -0.106560 -0.1214546 -0.12030 -0.1116800 -0.12243 2 2010-03-23 21:25:00 -0.099167 -0.1141900 -0.11288 -0.1046480 -0.11472 str(x) 'data.frame': 2 obs. of 6 variables: $ V1: POSIXct, format: 2010-03-23 20:55:00 2010-03-23 21:25:00 $ V2: num -0.1066 -0.0992 $ V3: num -0.121 -0.114 $ V4: num -0.12 -0.113 $ V5: num -0.112 -0.105 $ V6: num -0.122 -0.115 On Thu, Jan 20, 2011 at 3:04 AM, tluedeke tlued...@excite.com wrote: This is causing me great consternation, and I've spent too much time floundering around on it. My data is in the form of columns in Excel, with the first column being in m/dd/ hh:mm format. The spreadsheet is complicated (headers, merged cells, lines w/o data); so I've tried various ways of exporting the data into a text file for the R processing - CSV, spaced, etc. For example: 3/23/2010 20:55 -0.10655 -0.121454561 -0.12032 -0.111680001 -0.122429997 3/23/2010 21:25 -0.099166997 -0.114189997 -0.11287 -0.104647976 -0.114720002 . . - or - 3/23/2010 20:55, -0.10655, -0.121454561, -0.12032, -0.111680001, -0.122429997 3/23/2010 21:25, -0.099166997, -0.114189997, -0.11287, -0.104647976, -0.114720002 . . I can't seem to get R to recognize this data as a time/data column in m/dd/ hh:mm format followed by columns of data. There was a post on an analogous topic a couple of years ago, but none of the proposed (and quite complicated) solutions seemed to work for me. Anyone know how to handle this? -- View this message in context: http://r.789695.n4.nabble.com/reading-in-time-series-tp3225481p3225481.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 Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] puzzled with plotmath II
On 2011-01-20 04:09, Gerrit Eichner wrote: Try plot (1, 1, ylab = expression (Z[list(i,i)])) Hth -- Gerrit Original Message Subject: puzzled with plotmath Date: Thu, 20 Jan 2011 12:48:18 +0100 From: Claudia Beleitescbelei...@units.it To: R Helpr-help@r-project.org Dear all, I'm puzzled with matrix indices in plotmath. I'm plotting matrix elements: Z [i, i], and I'd like to put that as label. I'll describe what I want and what I get in LaTeX-notation. The output should look like Z_{i, i}, and my first try was plot (1, 1, ylab = expression (Z[i, i])) That, however, gives me Z_{i} (no comma, no second i) although the expression looks OK to me: a- expression (Z[i, i]) a [[1]] Z[i, i] str (as.list (a [[1]])) List of 4 $ : symbol [ $ : symbol Z $ : symbol i $ : symbol i I'm able to tweak the ouput looking as I want: plot (1, 1, ylab = expression (Z[i][, ][i])) which is, however, logically very far from what I want to express. What am I missing? I'm almost sure this has been discussed before, but I can't find it: can anyone point me to good search terms? Is it possible to search for the terms being close to each other in RSiteSearch and/or RSeek? I get lots of introductory documents as they point to plotmath and discuss matrices... [snip] Claudia, Look for 'comma-separated list' on the help page!! It will lead you directly to Gerrit's solution. I would put a space in front of the first 'i' with expression(Z[list(~i,i)]) or you can build it all up in pieces: expression(Z[~i*,~i]) Peter Ehlers __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] reading in time series
You have to tell R that a column has date/time content. Here is an example: test-3/23/2010 20:55 #this is your format as.POSIXct(test, format=%m/%d/%Y %H:%M) #with the format parameter you tell R how to interpret your data ___ Moritz Grenke http://www.360mix.de __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Saving a webpage, when content is generated by javascript
Hi to all members of this group, how can i download a webpage using R (html), which is generated using javasript when trying to open that webpage in the browser? When i try to save the page as text file i get only some java code inside, not the actual data. When opening website in the browser and saving the page in txt file everything works fine, so seems like i need to emulate browser request inside R code. Thanks -- View this message in context: http://r.789695.n4.nabble.com/Saving-a-webpage-when-content-is-generated-by-javascript-tp3225505p3225505.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] subsets
Hello Den, your problem is not as it may seem so Ivan's suggestion is only a partial answer. I see that each patient can have more then one diagnosis and I take that you want to isolate patients based on particular conditions. Thus, simply looking for ah or idh as Ivan suggests will yield patients which can have either of those but not necessarily patients that have both. Instead, what one must do is apply the condition to the whole set of diagnosis associated with each patient. I think that its done best with the aggregate function. This function splits the data according to some factor (in our case it will be the patient id) and performs a routine on each subset (in our case it will be a condition test): ids - aggregate(diagnosis ~ id, df, function(x) ah %in% x ihd %in% x) ids - aggregate(diagnosis ~ id, df, function(x) ah %in% x !ihd %in% x) ids - aggregate(diagnosis ~ id, df, function(x) ! ah %in% x ihd %in% x) Now, ids will contain a data frame like: id diagnosis 1 TRUE 2 FALSE 3 FALSE ... which shows which patients have the set of diagnoses you asked for. You can then apply these patients to the original data by something like: subset(df, id %in% subset(ids, diagnosis == TRUE)$id) this will extract only patients from the 'ids' data frame for which the diagnosis applies and then extract the associated diagnosis sets from the original 'df' data frame. Hope it helps, Taras On Jan 20, 2011, at 9:53 , Den wrote: Dear R people Could you please help. Basically, there are two variables in my data set. Each patient ('id') may have one or more diseases ('diagnosis'). It looks like iddiagnosis 1 ah 2 ah 2 ihd 2 im 3 ah 3 stroke 4 ah 4 ihd 4 angina 5 ihd .. Q: How to make three data sets: 1. Patients with ah and ihd 2. Patients with ah but no ihd 3. Patients with ihd but no ah? If you have any ideas could just guide what should I look for. Is a subset or aggregate, or loops, or something else??? I am a bit lost. (F1 F1 F1 !!!:) Thank you __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] selecting predictors for model from dataframe
Dear all, I think I have a rather strange question, but I'd like to give it a try: I want to perform a simulation numerous times, thats why I can't do it by hand. I sample a small dataset from a very large one, and use backward selection to select significant predictors for some arbitrary outcome variable Y. These predictors are to be placed in a model, and regression coefficients estimated in a new small dataset. This is what I got: #First I sample a small dataset from the large one, lrm is logistic regression from the Design package (as is the command fastbw) fsubset=lrm(Ysub~X1sub+X2sub+X3sub+X4sub, data=dsubset1) variables[i]=as.vector(fastbw(fsubset, rule=p, type=individual, sls=0.5)[2]) variables=unlist(variables[i]) #So my variables are the significant ones. #Below is the sampling of the testset, in which I want to estimate a model, but the only predictors in the model should be the ones I found to be significant. dderiveset=sample(patnr, 50, replace=FALSE) dderiveset=d[dderiveset,] colnames(dderiveset)=c(pat, X1d, X2d, X3d, X4d, Yd) attach(dderiveset) #Now in this new set of data, I want to build a model, but only using the coefficients that were significant #in the fsubset model, thus from variables I've tried everything and anything, even building logical expression within the model, but this was not accepted. Best regards, Sander van Kuijk [[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] puzzled with plotmath for matrix indices
On 01/20/2011 02:11 PM, Uwe Ligges wrote: On 20.01.2011 14:08, Claudia Beleites wrote: Gerrit, thanks viele Grüße nach Oberhessen :-) plot (1, 1, ylab = expression (Z[list(i,i)])) though that cannot be evaluated, either (due to [ not knowing what to do with an index list) Works for me with a recent R version. Sorry, my comment wasn't clear: sure it produces the desired output, what I meant is: Z [,1] [,2] [1,]13 [2,]24 i - 2 eval (expression (Z[list(i,i)])) Error in Z[list(i, i)] : invalid subscript type 'list' whereas: eval (expression (Z[i,i])) [1] 4 (and of course all the text-based solutions also lack the beauty of the expression actually meaning in R what the output looks like) for future searches: probably the easiest cheat is, of course, plot (1, 1, ylab = expression (Z[i, i])) which is less convenient since you could not replace i by a dynamically calculated number, for example. good point. Thanks, I learn a lot here :-) Claudia -- Claudia Beleites Dipartimento dei Materiali e delle Risorse Naturali Università degli Studi di Trieste Via Alfonso Valerio 6/a I-34127 Trieste phone: +39 0 40 5 58-37 68 email: cbelei...@units.it __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] subsets
I did try it. It gave me [[1]] id diagnosis 1 1ah 5 3ah 7 4ah 8 4 ihd 10 5 ihd [[2]] id diagnosis 1 1ah 2 2ah 5 3ah 7 4ah [[3]] id diagnosis 3 2 ihd 8 4 ihd 10 5 ihd Which isn't what the OP asked for Q: How to make three data sets: 1. Patients with ah and ihd id diagnosis 2 2ah 3 2 ihd 4 2im 7 4ah 8 4 ihd 9 4angina 2. Patients with ah but no ihd id diagnosis 1 1ah 5 3ah 6 3stroke 3. Patients with ihd but no ah? id diagnosis 10 5 ihd Regards, KJ - Henrique Dallazuanna www...@gmail.com wrote in message news:aanlktikqnw_hntdyxdrj+ytyqf6tghlmh0qsleouf...@mail.gmail.com... Try this: lapply(list(c('ah', 'ihd'), 'ah', 'ihd'), function(x)subset(aDF, diagnosis == x)) On Thu, Jan 20, 2011 at 6:53 AM, Den d.kazakiew...@gmail.com wrote: Dear R people Could you please help. Basically, there are two variables in my data set. Each patient ('id') may have one or more diseases ('diagnosis'). It looks like id diagnosis 1 ah 2 ah 2 ihd 2 im 3 ah 3 stroke 4 ah 4 ihd 4 angina 5 ihd .. Q: How to make three data sets: 1. Patients with ah and ihd 2. Patients with ah but no ihd 3. Patients with ihd but no ah? If you have any ideas could just guide what should I look for. Is a subset or aggregate, or loops, or something else??? I am a bit lost. (F1 F1 F1 !!!:) Thank you __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] subsets
Hi Taras, Indeed, I've overlooked the problem. Anyway, I'm not sure I would have been able to give a complete answer like you did! Ivan Le 1/20/2011 11:05, Taras Zakharko a écrit : Hello Den, your problem is not as it may seem so Ivan's suggestion is only a partial answer. I see that each patient can have more then one diagnosis and I take that you want to isolate patients based on particular conditions. Thus, simply looking for ah or idh as Ivan suggests will yield patients which can have either of those but not necessarily patients that have both. Instead, what one must do is apply the condition to the whole set of diagnosis associated with each patient. I think that its done best with the aggregate function. This function splits the data according to some factor (in our case it will be the patient id) and performs a routine on each subset (in our case it will be a condition test): ids- aggregate(diagnosis ~ id, df, function(x) ah %in% x ihd %in% x) ids- aggregate(diagnosis ~ id, df, function(x) ah %in% x !ihd %in% x) ids- aggregate(diagnosis ~ id, df, function(x) ! ah %in% x ihd %in% x) Now, ids will contain a data frame like: id diagnosis 1 TRUE 2 FALSE 3 FALSE ... which shows which patients have the set of diagnoses you asked for. You can then apply these patients to the original data by something like: subset(df, id %in% subset(ids, diagnosis == TRUE)$id) this will extract only patients from the 'ids' data frame for which the diagnosis applies and then extract the associated diagnosis sets from the original 'df' data frame. Hope it helps, Taras On Jan 20, 2011, at 9:53 , Den wrote: Dear R people Could you please help. Basically, there are two variables in my data set. Each patient ('id') may have one or more diseases ('diagnosis'). It looks like id diagnosis 1 ah 2 ah 2 ihd 2 im 3 ah 3 stroke 4 ah 4 ihd 4 angina 5 ihd .. Q: How to make three data sets: 1. Patients with ah and ihd 2. Patients with ah but no ihd 3. Patients with ihd but no ah? If you have any ideas could just guide what should I look for. Is a subset or aggregate, or loops, or something else??? I am a bit lost. (F1 F1 F1 !!!:) Thank you __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- Ivan CALANDRA PhD Student University of Hamburg Biozentrum Grindel und Zoologisches Museum Abt. Säugetiere Martin-Luther-King-Platz 3 D-20146 Hamburg, GERMANY +49(0)40 42838 6231 ivan.calan...@uni-hamburg.de ** http://www.for771.uni-bonn.de http://webapp5.rrz.uni-hamburg.de/mammals/eng/1525_8_1.php __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Installing package in windows 7
Prof. Brian Ripley and Tal Galili, Thanks for your replies. I cannot make the *install.packages(ei,repos=http://r.iq.harvard.edu;, type='source')* command work. Alternatively, I can find the way (thanks to stackoverflow guys) I can install that file from a local repo. For the sake of record, I am summarizing the steps here, 1. Install R in root or home directory. Avoid Program Files directory. If you install it there then make sure you are running R in administrative privilege. 2. Install Rtools. During the installation please select package authoring installation. Then in Select additional Tasks, check both fields, ie. Edit the system path, Save version number 2.xx 3. Add path of R in the environment variable. To do that, right click the My Computer icon Properties Advanced system settings Environment variables find path and click edit add the following line c:\R-2.12.1\bin\i386; (depending on the location you installed your R, you should edit the above line accordingly) After clicking ok, close all the terminals opened and then open a new terminal and type - path. It should give you an output including the following - PATH=c:\Rtools\bin; c:\Rtools\perl\bin; c:\Rtools\MinGW\bin; c:\Rtools\MinGW64\bin;c:\R-2.12.1\bin\i386; Depending on the software installed you will find other inputs, but the above are what you need. 4. Download the required package. Open a dos prompt. Go to the download directory and put the following command, R CMD INSTALL ei_0.938.tar.gz It will ask the dependencies Tal Galili mentioned. Install the dependencies. Try the command again. It should work then. Kind regards. On Thu, Jan 20, 2011 at 11:02 AM, Prof Brian Ripley rip...@stats.ox.ac.ukwrote: On Thu, 20 Jan 2011, Tal Galili wrote: You probably need to get your users permissions (in win 7) set properly... I see no evidence that is the issue That site seems to be offering only source packages. So in Windows you need install.packages(ei,repos=http://r.iq.harvard.edu;, type='source') This can be done without Rtools in R = 2.12.0. Note though that it depends on other packages mvtnorm, msm, tmvtnorm, ellipse, plotrix, MASS, ucminf, cubature, mnormt, foreach and those have dependencies (at least iterators), so I would install them from CRAN first (MASS should already be there). Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Wed, Jan 19, 2011 at 8:26 PM, radagast haseeb.mah...@gmail.com wrote: Hi all, I was trying to install a package called ei from this http://gking.harvard.edu/eiR link . With GCC, r-base-dev and some other R package dependencies installed it works perfect in my Ubuntu Linux system. Now I am trying to install the same in Windows 7 environment. So far my setup is as follows, 1. R installed in home folder (c:\Users\username\R-2.12.1\R. It is set to run as administrator, and the R folder is writable. 2. My working directory is (c:\Users\username\Documents) 3. Rtool is installed in (c:\Rtools) Having this setup, 4. I tried to install it by the command, install.packages(ei,repos=http://r.iq.harvard.edu;) This command gives me the following error message. --- Installing package(s) into ?C:\Users\username\Documents/R/win-library/2.12? (as ?lib? is unspecified) Warning message: In getDependencies(pkgs, dependencies, available, lib) : package ?ei? is not available --- After that I have decided to have a try to install it from a local zip file, so I proceeded in the following way, 5. I have downloaded the package ei_0.938.tar.gz, untar it and make a zip file from that. I placed it into my work directory. 6. I opened the terminal (Run cmd), went to the work directory and tried to run the command R COM INSTALL ei --- It shows me the following error message, C:\Users\username\DocumentsR COM INSTALL ei 'R' is not recognized as an internal or external command, operable program or batch file. --- I am not sure what should I do now. Is there anyone to help? _ Rdgst. -- View this message in context: http://r.789695.n4.nabble.com/Installing-package-in-windows-7-tp3225439p3225439.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list
Re: [R] subsets
On Thu, Jan 20, 2011 at 10:53:01AM +0200, Den wrote: Dear R people Could you please help. Basically, there are two variables in my data set. Each patient ('id') may have one or more diseases ('diagnosis'). It looks like iddiagnosis 1 ah 2 ah 2 ihd 2 im 3 ah 3 stroke 4 ah 4 ihd 4 angina 5 ihd .. Q: How to make three data sets: 1. Patients with ah and ihd 2. Patients with ah but no ihd 3. Patients with ihd but no ah? This may be understood as a two step procedure: 1. Split the id into disjoint groups according the above criteria. 2. Split the data cases into the groups from step 1. If this is what you want, then function table() may be used to collect information on each id. df - structure(list(id = c(1L, 2L, 2L, 2L, 3L, 3L, 4L, 4L, 4L, 5L), diagnosis = structure(c(1L, 1L, 3L, 4L, 1L, 5L, 1L, 3L, 2L, 3L), .Label = c(ah, angina, ihd, im, stroke), class = factor)), .Names = c(id, diagnosis), class = data.frame, row.names = c(NA, -10L)) tab - table(df$id, df$diag) Then, for example, the data cases for 2. Patients with ah but no ihd may be obtained sel - tab[, ah] != 0 tab[, ihd] == 0 ah.noihd - dimnames(tab)[[1]][sel] # [1] 1 3 df[df$id %in% ah.noihd, ] # id diagnosis # 1 1ah # 5 3ah # 6 3stroke I hope, this helps. Petr Savicky. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] calculation correlation and p-values of genes using rcorr function
Hi I want to do correlation of genes but I need to know p-values to construct netwrok based on correlation. But I,m getting too many zero for some reasons. I read one paper and they did analysed their data by :: 1- R values 2-P-values 3-Spearman p values - FDR corrected (Bejamini-Hochberg) Do yopu think I,m following same procedure for that or its possible I can get all three in one go and output file with all these analysis? libray(HMISC) 1- calculation correlation and p-values of genes using rcorr function rashid=rcorr(t(x),type=pearson) 2- Spearman p values - FDR corrected (Bejamini-Hochberg) (p-values adjustment) round(p.adjust(x), 3) round(p.adjust(x,BH), 3) and also I want to extract with p-vale .80 Any help would be nice !! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] puzzled with plotmath for matrix indices
Claudia, Mittelhessen! ;-) thanks viele Grüße nach Oberhessen :-) plot (1, 1, ylab = expression (Z[list(i,i)])) though that cannot be evaluated, either (due to [ not knowing what to do with an index list) Something is missing; this last sentence of yours appears to be not complete, does it? Regarding Uwe's remark and Peter's nice aesthetic suggestion: plot( 1, 1, xlab = substitute( Z[list(~i, j)], list( i = 1, j = 2))) should solve both problems. This does work even in R as old as 2.7.1 (and, of course, for a more recent version as Uwe already stated). Best regards / Beste Grüße -- Gerrit__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] subsets
On 2011-01-20 02:05, Taras Zakharko wrote: Hello Den, your problem is not as it may seem so Ivan's suggestion is only a partial answer. I see that each patient can have more then one diagnosis and I take that you want to isolate patients based on particular conditions. Thus, simply looking for ah or idh as Ivan suggests will yield patients which can have either of those but not necessarily patients that have both. Instead, what one must do is apply the condition to the whole set of diagnosis associated with each patient. I think that its done best with the aggregate function. This function splits the data according to some factor (in our case it will be the patient id) and performs a routine on each subset (in our case it will be a condition test): ids- aggregate(diagnosis ~ id, df, function(x) ah %in% x ihd %in% x) ids- aggregate(diagnosis ~ id, df, function(x) ah %in% x !ihd %in% x) ids- aggregate(diagnosis ~ id, df, function(x) ! ah %in% x ihd %in% x) Now, ids will contain a data frame like: id diagnosis 1 TRUE 2 FALSE 3 FALSE ... which shows which patients have the set of diagnoses you asked for. You can then apply these patients to the original data by something like: subset(df, id %in% subset(ids, diagnosis == TRUE)$id) this will extract only patients from the 'ids' data frame for which the diagnosis applies and then extract the associated diagnosis sets from the original 'df' data frame. Hope it helps, Taras Here's a tidy version using the plyr package: require(plyr) df1 - ddply(df, .(id), summarize, has.both = (ah %in% diagnosis) (ihd %in% diagnosis), has.only.ah = (ah %in% diagnosis) !(ihd %in% diagnosis), has.only.ihd = !(ah %in% diagnosis) (ihd %in% diagnosis) ) Further processing on the columns of df1 is straightforward. Peter Ehlers On Jan 20, 2011, at 9:53 , Den wrote: Dear R people Could you please help. Basically, there are two variables in my data set. Each patient ('id') may have one or more diseases ('diagnosis'). It looks like id diagnosis 1 ah 2 ah 2 ihd 2 im 3 ah 3 stroke 4 ah 4 ihd 4 angina 5 ihd .. Q: How to make three data sets: 1. Patients with ah and ihd 2. Patients with ah but no ihd 3. Patients with ihd but no ah? If you have any ideas could just guide what should I look for. Is a subset or aggregate, or loops, or something else??? I am a bit lost. (F1 F1 F1 !!!:) Thank you __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] MCMC object indexing
Robinson, David G drobin at sandia.gov writes: I have an mcmc object and I'm trying to plot the quantiles of the variables - and not as a function of the iterations as in cumuplot. I cannot seem to find the right combination of indexing to access the variables; after which I'm sure I can plot all the statistics I could hope for. Any hints for accessing the mcmc object would be appreciated. =Dave A reproducible example would be very useful. In general I find that I can just index an mcmc object as though it were a matrix, e.g.: z - cbind(a=runif(20),b=runif(20),c=runif(20)) library(coda) m - mcmc(data=z) t(apply(m,2,quantile,c(0.025,0.975))) If that sort of thing doesn't work for you, please post an example of what doesn't work ... 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] Odp: Relative frequency on a character vector
Hi, On Tue, Jan 18, 2011 at 3:48 PM, ADias diasan...@gmail.com wrote: I have done like this to get the result I need more directly A-c(Tell me how many different letter this vector has?) prop.table(table(strsplit(A,))) ? a c d e f h i l m n o r s t 0.16 0.02 0.04 0.02 0.02 0.14 0.04 0.06 0.04 0.06 0.04 0.04 0.04 0.06 0.04 0.10 T v w y 0.02 0.02 0.02 0.02 two questios: 1) is there a direct way of making capital T the same as lower case t? See ?chartr for character case conversion. 2) And can I avoid on the strslipt function to exclude the ? and the spaces between words? I know I can do: x-table(strsplit(A, )) ] x a c d e f h i l m n o r s t T v w y 2 1 1 7 2 3 2 3 2 2 2 3 2 5 1 1 1 1 My question is always to find out if there's a more direct way of doing this? Seems pretty direct to me... what exactly are you looking for? Regards, A.Dias -- View this message in context: http://r.789695.n4.nabble.com/Relative-frequency-on-a-character-vector-tp3221319p3223966.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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] CCF and missing values.
On 2011-01-19 08:48, Paul Ossenbruggen wrote: Hi, I have missing values in my time series. na.action = na.pass works for acf and pacf. Why do I get the following error for the ccf? ts(matrix(c(dev$u[1:10],dev$q[1:10]),ncol=2),start=1,freq=1) Time Series: Start = 1 End = 10 Frequency = 1 Series 1 Series 2 1 68.0 138.4615 2 70.0 355.5556 3 68.76000 304.3200 4 68.0 231.4286 5 69.74194 357.4963 6 NA NA 7 67.45455 174.8697 8 66.0 144. 9 73.5 287.6471 10 70.0 172.6027 ccf(x = ts.data[,1], y = ts.data[,2], na.action = na.pass, ylab = CCF) Error in na.fail.default(as.ts(x)) : missing values in object I can see two possible solutions: 1. Use na.action = na.contiguous (see ?na.contiguous) 2. Modify ccf(). Make a copy and replace the line acf.out - acf(X, lag.max = lag.max, plot = FALSE, type = type) with acf.out - acf(X, lag.max = lag.max, plot = FALSE, type = type, na.action = na.action) I think this may be a bug in ccf(). Peter Ehlers __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] puzzled with plotmath II
Peter, Look for 'comma-separated list' on the help page!! Yes, seeing the solution I also understand why list is the solution. The special meaning of list () in plotmath was only in my passive vocabulary - and after this discussion I think it is upgraded to active ;-) I have to admit that my coming from matlab (as opposed to lisp) still catches me once in a while: though I was aware that I would somehow need to change the tree of the expression, I went astray because c() still feels to me the more basic function to put things together than list (). A second aspect that put me a bit off the track is that both create expressions that do have a meaning but don't mean in R what I want to express: Z [c(a, b)] is meaningful, but not the same as Z [a, b] Z [list (a, b)] is syntactically correct, but `[.matrix` doesn't accept lists for parameter i) Anyways, thanks a lot for the patience everyone: problem is solved, solutions (including bquote) are to be found in the Wiki, and instead of creating more fuss by unclear emails I'll fetch a coffee before I go on plotting my confusion matrix elements... Claudia -- Claudia Beleites Dipartimento dei Materiali e delle Risorse Naturali Università degli Studi di Trieste Via Alfonso Valerio 6/a I-34127 Trieste phone: +39 0 40 5 58-37 68 email: cbelei...@units.it __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Obtaining a quadratic function igven three points on a curve
Hello I would like to obtain the coefficients for a quadratic function (ax^2 + bx + c) given three sets of points on the quadratic curve. For instance: Y X 0.1595290 0.5 0.773019 1 1 Is there a function in R to obtain the a, b and c ceofficients? Thanks Barth PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Bandwidth - Kernel Density Estimation
Dear R helpers I am having recovery rates as given below and I am trying to estimate the Loss Given Default (LGD) and for this I am using Kernel Density estimation method. recovery_rates = c(0.61,0.12,0.10,0.68,0.87,0.19,0.84,0.81,0.87,0.54,0.08,0.65,0.91, 0.56,0.52,0.30,0.41,0.24,0.66,0.35,0.36,0.64,0.55,0.43,0.36,0.28,0.89,0.11,0.23,0.07, 0.66,0.67,0.48,0.86,0.94,0.86,0.00,0.03,0.95,0.65,0.48,0.79,0.96,0.34,0.68,0.33,0.49, 0.79,0.89,0.04,0.05,0.83,0.88,0.64,0.15,0.67,0.43,0.40,0.37,0.61,0.18,0.24,0.41,0.97, 0.82,0.11,0.53,0.80,0.71,0.31,0.70,0.00,0.90,0.88,0.15,0.49,0.54,0.89,0.07,0.09,0.34, 0.20,0.73,0.37,0.94,0.49,0.40,0.55,0.68,0.89,0.00,0.42,0.94,0.06,0.53,0.46,0.11,0.96, 0.41,0.69) I need to find out the bandwidth and I have two ways of doing it as # as per the stats package bw1 = bw.nrd0(recovery_rates) # which gives me bw1 = 0.1050780 # as per the KernSmooth package bw2 = dpik(recovery_rates) # which gives bw2 = 0.1027932 I am bit confused which bandwidth is to be used. Is it that statistics package deal with univariate data while KernSmooth deals with multivariate data? Also, whenever I need to read some package, I download the respective package.zip file, but I couldn't get the zip file pertaining to statistics package. Kindly guide Regards Amelia [[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] Obtaining a quadratic function igven three points on a curve
Hi Barth, Here is an option fitting a linear model toa second order polynomial and extracting the coefficients. The Intercept corresponds to c in your email, then poly(...)1 to b and poly(...)2 to a. dat - read.table(textConnection( Y X 0.159529 0 0.5 0.773019 1 1), header = TRUE) closeAllConnections() coef(lm(Y ~ poly(X, 2), data = dat)) # For details see: ?poly ?lm ?coef Hope this helps, Josh On Thu, Jan 20, 2011 at 6:42 AM, Barth B. Riley bbri...@chestnut.org wrote: Hello I would like to obtain the coefficients for a quadratic function (ax^2 + bx + c) given three sets of points on the quadratic curve. For instance: Y X 0.159529 0 0.5 0.773019 1 1 Is there a function in R to obtain the a, b and c ceofficients? Thanks Barth PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] syntax for a list of components from a list
I'm attempting to generalise a function that reads individual list components, in this case they are matrices, and converts them into 3 dimensional array. I can input each matrix individually, but want to do it for about 1,000 of them ... This works array2 - abind(list1[[1]],list1[[2]],list1[[3]],along=3) This doesn't array2 - abind(list1[[1:3]],along=3) This doesn't either array2 - abind((list1[[1]]:(list1[[3]]),along=3) Any thoughts how I can make this work for larger numbers? Thanks J === Dr. Jim Maas University of East Anglia [[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] Identify duplicate numbers and to increase a value
Hi everybody. I want to identify duplicate numbers and to increase a value of 0.01 for each time that it is duplicated. Example: x=c(1,2,3,5,6,2,8,9,2,2) I want to do this: 1 2 + 0.01 3 5 6 2 + 0.02 8 9 2 + 0.03 2 + 0.04 I am trying to get something like this: 1 2.01 3 5 6 2.02 8 9 2.03 2.04 Actually I just know the way to identify the duplicated numbers rbind(x, duplicated(x) | duplicated(x, fromLast=TRUE)) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] x123562892 2 010001001 1 Some advice? Thanks and regards John Ortiz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Accessing MySQL Database in R
Hello, I used to use RMySQL but as there is no more package for windows, I decided to move to RODBC. I installed ODBC driver for MySQL (downloaded on the MySQL website) and then the RODBC package. I finally discovered that it was not needed to register your database with ODBC before using it. These commands below work for me. library(RODBC) ch-odbcDriverConnect(connection=SERVER=localhost;DRIVER=MySQL ODBC 5.1 Driver;DATABASE=my_database;UID=root;PWD=my_password;case=tolower) resultdb-sqlQuery(ch,SELECT * from my_table) odbcClose(ch) Try to modify them for your case. I hope it will work for you. Good luck, Ptit Bleu. Re: Accessing MySQL Database in R Jan 18, 2011; 12:10am — by djmuseR [User is online] djmuseR Hi: Because R does not have a direct interface to MySQL? You need to load a communication package - the two most common ones are RODBC and RMySQL. The former requires that you register your MySQL database table(s) with ODBC before using the RODBC package on them, whereas the latter works with specific version combinations of MySQL and R. The RODBC package has a very informative vignette; for information re the RMySQL package, see http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL HTH, Dennis On Mon, Jan 17, 2011 at 1:30 PM, schlafly [hidden email] wrote: I have a local installation of MySQL on my computer. I enter the following to access MySQL from the command line: /Applications/MAMP/Library/bin/mysql -h localhost -u root -p I am then prompted for a password, and I use: root This connects me to MySQL in the command line. I now want to access MySQL databases in R. I enter the following: mysql - dbDriver(MySQL) conn - dbConnect(mysql,user='root',host='localhost', password='root') I get the following error message: Error in mysqlNewConnection(drv, ...) : RS-DBI driver: (Failed to connect to database: Error: Access denied for user 'root'@'localhost' (using password: YES) Does anyone know why these aren't equivalent? -- View this message in context: http://r.789695.n4.nabble.com/Accessing-MySQL-Database-in-R-tp3221264p3221264.html Sent from the R help mailing list archive at Nabble.com. -- View this message in context: http://r.789695.n4.nabble.com/Accessing-MySQL-Database-in-R-tp3221264p3225507.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] Using anova() with glmmPQL()
Hi Ben Bolker, Just to say thank you VERY much for the reply below and for taking the time to go through my code. I think you're absolutely right and I have been using the wrong formula completely. I have been trying out several more examples (am still struggling with this) and will submit any further posts to r-sig-mixed-models. Best, Toby From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of Ben Bolker [bbol...@gmail.com] Sent: 18 January 2011 16:15 To: r-h...@stat.math.ethz.ch Subject: Re: [R] Using anova() with glmmPQL() Toby Marthews toby.marthews at ouce.ox.ac.uk writes: Dear R HELP, ABOUT glmmPQL and the anova command. Here is an example of a repeated-measures ANOVA focussing on the way starling masses vary according to (i) roost situation and (ii) time (two time points only). [snip] lmeres=lme(fixed=stmass~mnth*roostsitu, random=~1|subject/mnth,na.action=na.exclude) anova(object=lmeres,test=Chisq) By the way, 'test=Chisq' has no effect -- it's silently ignored -- in an anova run on an lme() object the F test is always used (as your output suggests). numDF denDF F-value p-value (Intercept)136 31143.552 .0001 mnth 13695.458 .0001 roostsitu 33610.614 .0001 mnth:roostsitu 336 0.657 0.5838 By the way, I'm a bit puzzled/suspicious about your setup here. You seem to measure each subject once in each month, so your grouping variable subject/month is confounded with the residual error. I would suggest random=~1|subject (which gives a very nearly identical ANOVA table but makes more sense). In this case, because you have only two months, you could do almost the same analysis by taking differences or averages of subjects across months: a paired t-test on subjects for the effect of month, a one-way ANOVA on subject averages for the effect of roost, and a one-way ANOVA on subject differences for the month x roost interaction. I can conclude from this that variation with both roost situation and month are significant, but with no interaction term. So far so good. However, say I were interested only in whether or not those starlings were heavier or lighter than 78g: seemingly, I could change my response variable and analyse like this - [snip lme with family=binomial] lmeres2=glmmPQL(fixed=stmassheavy~mnth*roostsitu, random=~1|subject/mnth,na.action=na.exclude,family=binomial) anova(object=lmeres2,test=Chisq) The glmmPQL command runs, but I get Error in anova.glmmPQL(object = lmeres, test = Chisq) : 'anova' is not available for PQL fits. [snip] However, I couldn't find any other way to run a repeated-measures ANOVA with famiy=binomial. After a while longer on Google, I found a 'workaround' from Spencer Graves (on http://markmail.org/message/jddj6aq66wdidrog#query:how%20to%20use%20anova%20with%20glmmPQL+page:1+mid:jddj6aq66wdidrog+state:results ): class(lmeres2)=lme anova(object=lmeres2,test=Chisq) numDF denDF F-value p-value (Intercept)136 182.84356 .0001 mnth 136 164.57288 .0001 roostsitu 336 17.79263 .0001 mnth:roostsitu 336 3.26912 0.0322 Which does give me a result and tells me that the interaction term is significant here. HOWEVER, on that link Douglas Bates told Spencer Graves that this wasn't an approprate method. I haven't found any other workarounds for this except some general advice that I should move onto using the lmer command (which I can't do because I need to get p-values for my fits and according to https://stat.ethz.ch/pipermail/r-help/2006-May/094765.html I won't get those from lmer). My questions are: (1) Is lmer the only way to do a binomial repeated-measures ANOVA in R? (which means that there's no way to do such an ANOVA in R without losing the p-values) and (2) if I am supposed to be using glmmPQL for this simple situation, what am I doing wrong? Hmm. This feels harder than it ought to be, and I've already spent longer on it than I should, so I'm going to give you some thoughts and encourage you to send this on to R-sig-mixed-models. I think the *best* way to do this would probably be to do the analogue of the paired/grouped tests I suggested above: for the month effect, test whether more individuals go from light to heavy or heavy to light, and so forth. Treating this as a binomial problem: you can use glmmPQL and use the Wald test (see wald.test in the aod package, as below) to test groups of parameters. In principle you could do this for glmer, too, but beware the Hauck-Donner effect (e.g., the 'Jan x other' parameter in the glmer fit has estimate -13.6, standard error 6840 [!]) you can use (g)lmer and anova() to do Likelihood Ratio Tests on the effects: this is a little bit dicey for small sample sizes. I also question your approach a little bit here: it looks
[R] Writing functions. please help
Hi, my name is Guilherme and I'm trying to solve an optimization problem in R, regarding reliability and survival time of equipments. I Have to write the function in the image attached to this email, please take a look, where the f(t) is weibull's distribution density function, Ca=1000 and Cb=100 are costs of two equipments and i'm using shape=2.5 and scale=20. However, a few problems have appeared: 1- at the beginnig I thought of using the function dweibull, but the input is a vector of quantiles and my objective is to work with different time periods. So I chosed to write weibull's function already with the parameters shape and scale pre-defined, even though I know that's not the best option. So I have the following code which works perfectly: weibull=function(t){ +dist=(2.5/20)*(t/20)^(2.5-1)*exp(-(t/20)^2.5) +return(dist)} and then i used that to write as follows, use shape=2.5, scale=20, and transfering Ca and Cb to the integral's interior: func=function(t){ func1=function(t){ weibull=function(t){ dist=1000*(2.5/20)*(t/20)^(2.5-1)*exp(-(t/20)^2.5) return(dist)} calc=integrate(weibull, 0, t) return(calc)} func2=function(t){ weibull=function(t){ dist=100*(2.5/20)*(t/20)^(2.5-1)*exp(-(t/20)^2.5) return(dist)} calc=integrate(weibull,t, 100) return(calc)} func3=function(t){ weibull=function(t){ dist=t*(2.5/20)*(t/20)^(2.5-1)*exp(-(t/20)^2.5) return(dist)} calc=integrate(weibull,0 ,t) return(calc)} func4=function(t){ weibull=function(t){ dist=t*(2.5/20)*(t/20)^(2.5-1)*exp(-(t/20)^2.5) return(dist)} calc=integrate(weibull,t ,100) return(calc)} lastcalc=(func1+func2)/(func3+func4) return(lastcalc)} appears the following: Error in func1 + func2 : non numeric operator to binary operator 2-How the function is composed by four integrations, two on the numerator and the other tow on the denominator, and how i was not being succesful in writing the function directly, I wrote these four integrals separately,considering already the shape, the scale, Ca, Cb as given. The code is the following: 2.1: for the first part in the numerator intWeibull1=function(t){ + integr=function(t) 1000*(2.5/20)*(t/20)^(2.5-1)*exp(-(t/20)^2.5) + calc=integrate(integr, 0, t) + return(calc)} 2.2: for the second part in the numerator intWeibull2=function(t){ + integr=function(t) 100*(2.5/20)*(t/20)^(2.5-1)*exp(-(t/20)^2.5) + calc=integrate(integr,t,100) + return(calc)} 2.3: for the third part, the first in the denominator intTweibull=function(t){ + integr=function(t) t*(2.5/20)*(t/20)^(2.5-1)*exp(-(t/20)^2.5) + calc=integrate(integr,0,t) + return(calc)} 2.4: for the last part, the secondin the denominator intTweibull2=function(t){ + integr=function(t) t*(2.5/20)*(t/20)^(2.5-1)*exp(-(t/20)^2.5) + calc=integrate(integr,t,100) + return(calc)} 3-All the functions above are working perfectly, but when i try to put everything together trough this code and call the function, appears a error message: FUNC=function(f1,f2,f3,f4,t){ + a=f1(t); b=f2(t); c=f3(t); d=f4(t) + calc=(a+b)/(c+d) + return(calc)} FUNC(intWeibullmil,intWeibullcem,intTweibull,intTweibull2,3) # t=3 is just an example Error in a+b: non numeric argument to binary operator which I don't understand, becouse in previous examples I used the same programming intuition and it worked,for example: f1=function(x){ + calc=2*x + return(calc)} f2=function(x){ + calc=3*x + return(calc)} f4=function(fun1,fun2,x){ + a=fun1(x);b=fun2(x) + calc=a+b + return(calc)} f4(f1,f2,2) [1] 10 4-another doubt is: even if I manage to write this function (FUNC), when I try to optimize it, will it be equivalent to optimize a one variable function? (which is not very complex) or it means I'm gonna have to optimize a five variable function? (which is really hard). Are there any packages able to help me out here, I mean with writing weibull's distribution and optimization issues? Any suggestions of how i can write that differently, or what am I missing here will be more than welcome. Thank you so much for your attention, Guilherme __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Obtaining a quadratic function igven three points on a curve
I think you need poly(X, 2, raw = TRUE) to interpret the coefficients in the manner described below. poly uses orthogonal polynomials by default: poly package:stats R Documentation Compute Orthogonal Polynomials Description: Returns or evaluates orthogonal polynomials of degree 1 to 'degree' over the specified set of points 'x'. These are all orthogonal to the constant polynomial of degree 0. Alternatively, evaluate raw polynomials. David Scott On 21/01/2011 3:50 a.m., Joshua Wiley wrote: Hi Barth, Here is an option fitting a linear model toa second order polynomial and extracting the coefficients. The Intercept corresponds to c in your email, then poly(...)1 to b and poly(...)2 to a. dat- read.table(textConnection( Y X 0.159529 0 0.5 0.773019 1 1), header = TRUE) closeAllConnections() coef(lm(Y ~ poly(X, 2), data = dat)) # For details see: ?poly ?lm ?coef Hope this helps, Josh On Thu, Jan 20, 2011 at 6:42 AM, Barth B. Rileybbri...@chestnut.org wrote: Hello I would like to obtain the coefficients for a quadratic function (ax^2 + bx + c) given three sets of points on the quadratic curve. For instance: Y X 0.1595290 0.5 0.773019 1 1 Is there a function in R to obtain the a, b and c ceofficients? Thanks Barth PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142,NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Obtaining a quadratic function igven three points on a curve
Many thanks for the correction David. Josh On Thu, Jan 20, 2011 at 7:17 AM, David Scott d.sc...@auckland.ac.nz wrote: I think you need poly(X, 2, raw = TRUE) to interpret the coefficients in the manner described below. poly uses orthogonal polynomials by default: poly package:stats R Documentation Compute Orthogonal Polynomials Description: Returns or evaluates orthogonal polynomials of degree 1 to 'degree' over the specified set of points 'x'. These are all orthogonal to the constant polynomial of degree 0. Alternatively, evaluate raw polynomials. David Scott [snip] -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142, NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] syntax for a list of components from a list
Hi, On Thu, Jan 20, 2011 at 6:59 AM, Maas James Dr (MED) j.m...@uea.ac.uk wrote: I'm attempting to generalise a function that reads individual list components, in this case they are matrices, and converts them into 3 dimensional array. I can input each matrix individually, but want to do it for about 1,000 of them ... This works array2 - abind(list1[[1]],list1[[2]],list1[[3]],along=3) This doesn't array2 - abind(list1[[1:3]],along=3) This is close, but using the `[[` operator is not quite what you want here. myl - rep(list(matrix(1:9, 3)), 9) length(myl) # look at the length of the list (9) myl[1:3] # select elements 1:3 of the list ## Contrast this with: myl[[1:2]] # select the 1st element of the list, then the 2nd element of that myl[[c(3, 1)]] # 3rd element of list, 1st element of that ## This does what you want I think require(abind) # load relevant package abind(myl[1:3], along = 3) Cheers, Josh This doesn't either array2 - abind((list1[[1]]:(list1[[3]]),along=3) Any thoughts how I can make this work for larger numbers? Thanks J === Dr. Jim Maas University of East Anglia [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Obtaining a quadratic function given three points on a curve
Thanks Josh and David Barth PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. [[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] Identify duplicate numbers and to increase a value
If you haven't got so much data a loop should do: while(sum(duplicated(x))0) #if this condition is TRUE then there are still duplicates in x { x[duplicated(x)] - x[duplicated(x)]+0.01 #using duplicated(x) to index the x vector } Hope this helps, Regards Moritz Moritz Grenke http://www.360mix.de -Ursprüngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von Ortiz, John Gesendet: Donnerstag, 20. Januar 2011 16:13 An: r-help@r-project.org Betreff: [R] Identify duplicate numbers and to increase a value Hi everybody. I want to identify duplicate numbers and to increase a value of 0.01 for each time that it is duplicated. Example: x=c(1,2,3,5,6,2,8,9,2,2) I want to do this: 1 2 + 0.01 3 5 6 2 + 0.02 8 9 2 + 0.03 2 + 0.04 I am trying to get something like this: 1 2.01 3 5 6 2.02 8 9 2.03 2.04 Actually I just know the way to identify the duplicated numbers rbind(x, duplicated(x) | duplicated(x, fromLast=TRUE)) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] x123562892 2 010001001 1 Some advice? Thanks and regards John Ortiz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] How to reshape wide format data.frame to long format?
Dear list, I need to convert this data.frame names(codesM) [1] keyAMR.pa1.M AMR.pa2.M AMR.pa3.M AMR.pa4.M [6] AMR.pa5.M AMR.pa6.M AMR.pa7.M AMR.pa8.M AMR.pa9.M [11] AMR.pa10.M AMR.ta1.M AMR.ta2.M AMR.ta3.M AMR.ta4.M [16] AMR.ta5.M AMR.ta6.M AMR.ta7.M AMR.ta8.M AMR.ta9.M [21] AMR.ta10.M AMR.ka1.M AMR.ka2.M AMR.ka3.M AMR.ka4.M [26] AMR.ka5.M AMR.ka6.M AMR.ka7.M AMR.ka8.M AMR.ka9.M [31] AMR.ka10.M SMR.pa1.M SMR.pa2.M SMR.pa3.M SMR.pa4.M [36] SMR.pa5.M SMR.pa6.M SMR.pa7.M SMR.pa8.M SMR.pa9.M [41] SMR.pa10.M SMR.ta1.M SMR.ta2.M SMR.ta3.M SMR.ta4.M [46] SMR.ta5.M SMR.ta6.M SMR.ta7.M SMR.ta8.M SMR.ta9.M [51] SMR.ta10.M SMR.ka1.M SMR.ka2.M SMR.ka3.M SMR.ka4.M [56] SMR.ka5.M SMR.ka6.M SMR.ka7.M SMR.ka8.M SMR.ka9.M [61] SMR.ka10.M dim(codesM) [1] 42 61 into a 3 x 2501 data.frame where the key variable is kept, the values in columns 2-61 above is inserted into a values column and the name of the column is inserted in a third column (variable perhaps). Like key variable value POSTOFF_1_1AMR.pa1.M 5 POSTOFF_1_1AMR.pa2.M 3 I think I should be able to do this using the reshape function, but I cannot get it to work. I think I need some help to understand this... (If I could split the variable into three separate columns splitting by ., that would be even better.) I appreciate all the help I could get. /Fredrik -- Life is like a trumpet - if you don't put anything into it, you don't get anything out of it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Identify duplicate numbers and to increase a value
Hi John, If you only have one duplicated number (e.g., just 2), then this will work: x - c(1,2,3,5,6,2,8,9,2,2) xd - duplicated(x) x[xd] - x[xd] + seq(sum(xd))/100 x otherwise, I think a different framework than duplicated() will be necessary, because it will matter not just if the number is duplicated but which one how many times and where. Cheers, Josh On Thu, Jan 20, 2011 at 7:12 AM, Ortiz, John ort...@si.edu wrote: Hi everybody. I want to identify duplicate numbers and to increase a value of 0.01 for each time that it is duplicated. Example: x=c(1,2,3,5,6,2,8,9,2,2) I want to do this: 1 2 + 0.01 3 5 6 2 + 0.02 8 9 2 + 0.03 2 + 0.04 I am trying to get something like this: 1 2.01 3 5 6 2.02 8 9 2.03 2.04 Actually I just know the way to identify the duplicated numbers rbind(x, duplicated(x) | duplicated(x, fromLast=TRUE)) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] x 1 2 3 5 6 2 8 9 2 2 0 1 0 0 0 1 0 0 1 1 Some advice? Thanks and regards John Ortiz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology University of California, Los Angeles http://www.joshuawiley.com/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to reshape wide format data.frame to long format?
I would think that the following code should work: newcodesM = reshape(codesM, id=1) If other variables in the data.frame are factors, reshape thinks all of them are ID variables and tries to use all of them as keys. Specifying the id variable you want to keep (I used id=1 since key is in the 1st column) will probably solve the issue. Abhijit On Jan 20, 2011, at 10:51 AM, Fredrik Karlsson wrote: Dear list, I need to convert this data.frame names(codesM) [1] keyAMR.pa1.M AMR.pa2.M AMR.pa3.M AMR.pa4.M [6] AMR.pa5.M AMR.pa6.M AMR.pa7.M AMR.pa8.M AMR.pa9.M [11] AMR.pa10.M AMR.ta1.M AMR.ta2.M AMR.ta3.M AMR.ta4.M [16] AMR.ta5.M AMR.ta6.M AMR.ta7.M AMR.ta8.M AMR.ta9.M [21] AMR.ta10.M AMR.ka1.M AMR.ka2.M AMR.ka3.M AMR.ka4.M [26] AMR.ka5.M AMR.ka6.M AMR.ka7.M AMR.ka8.M AMR.ka9.M [31] AMR.ka10.M SMR.pa1.M SMR.pa2.M SMR.pa3.M SMR.pa4.M [36] SMR.pa5.M SMR.pa6.M SMR.pa7.M SMR.pa8.M SMR.pa9.M [41] SMR.pa10.M SMR.ta1.M SMR.ta2.M SMR.ta3.M SMR.ta4.M [46] SMR.ta5.M SMR.ta6.M SMR.ta7.M SMR.ta8.M SMR.ta9.M [51] SMR.ta10.M SMR.ka1.M SMR.ka2.M SMR.ka3.M SMR.ka4.M [56] SMR.ka5.M SMR.ka6.M SMR.ka7.M SMR.ka8.M SMR.ka9.M [61] SMR.ka10.M dim(codesM) [1] 42 61 into a 3 x 2501 data.frame where the key variable is kept, the values in columns 2-61 above is inserted into a values column and the name of the column is inserted in a third column (variable perhaps). Like key variable value POSTOFF_1_1AMR.pa1.M 5 POSTOFF_1_1AMR.pa2.M 3 I think I should be able to do this using the reshape function, but I cannot get it to work. I think I need some help to understand this... (If I could split the variable into three separate columns splitting by ., that would be even better.) I appreciate all the help I could get. /Fredrik -- Life is like a trumpet - if you don't put anything into it, you don't get anything out of it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to reshape wide format data.frame to long format?
As for your second question, you could certainly do newcodesM = transform(newcodesM, variable1 = unlist(strsplit(variable,'\\.'))[1], variable2 = unlist(strsplit(variable, '\\.'))[2], variable3 = unlist(strsplit(variable,'\\.'))[3]) though I'm sure there is a more efficient use of strsplit in this context. Abhijit On Jan 20, 2011, at 10:51 AM, Fredrik Karlsson wrote: Dear list, I need to convert this data.frame names(codesM) [1] keyAMR.pa1.M AMR.pa2.M AMR.pa3.M AMR.pa4.M [6] AMR.pa5.M AMR.pa6.M AMR.pa7.M AMR.pa8.M AMR.pa9.M [11] AMR.pa10.M AMR.ta1.M AMR.ta2.M AMR.ta3.M AMR.ta4.M [16] AMR.ta5.M AMR.ta6.M AMR.ta7.M AMR.ta8.M AMR.ta9.M [21] AMR.ta10.M AMR.ka1.M AMR.ka2.M AMR.ka3.M AMR.ka4.M [26] AMR.ka5.M AMR.ka6.M AMR.ka7.M AMR.ka8.M AMR.ka9.M [31] AMR.ka10.M SMR.pa1.M SMR.pa2.M SMR.pa3.M SMR.pa4.M [36] SMR.pa5.M SMR.pa6.M SMR.pa7.M SMR.pa8.M SMR.pa9.M [41] SMR.pa10.M SMR.ta1.M SMR.ta2.M SMR.ta3.M SMR.ta4.M [46] SMR.ta5.M SMR.ta6.M SMR.ta7.M SMR.ta8.M SMR.ta9.M [51] SMR.ta10.M SMR.ka1.M SMR.ka2.M SMR.ka3.M SMR.ka4.M [56] SMR.ka5.M SMR.ka6.M SMR.ka7.M SMR.ka8.M SMR.ka9.M [61] SMR.ka10.M dim(codesM) [1] 42 61 into a 3 x 2501 data.frame where the key variable is kept, the values in columns 2-61 above is inserted into a values column and the name of the column is inserted in a third column (variable perhaps). Like key variable value POSTOFF_1_1AMR.pa1.M 5 POSTOFF_1_1AMR.pa2.M 3 I think I should be able to do this using the reshape function, but I cannot get it to work. I think I need some help to understand this... (If I could split the variable into three separate columns splitting by ., that would be even better.) I appreciate all the help I could get. /Fredrik -- Life is like a trumpet - if you don't put anything into it, you don't get anything out of it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] circular reference lines in splom
On 2011-01-19 20:15, Max Kuhn wrote: Hello everyone, I'm stumped. I'd like to create a scatterplot matrix with circular reference lines. Here is an example in 2d: library(ellipse) set.seed(1) dat- matrix(rnorm(300), ncol = 3) colnames(dat)- c(X1, X2, X3) dat- as.data.frame(dat) grps- factor(rep(letters[1:4], 25)) panel.circ- function(x, y, ...) { circ1- ellipse(diag(rep(1, 2)), t = 1) panel.xyplot(circ1[,1], circ1[,2], type = l, lty = 2) circ2- ellipse(diag(rep(1, 2)), t = 2) panel.xyplot(circ2[,1], circ2[,2], type = l, lty = 2) panel.xyplot(x, y) } xyplot(X2 ~ X1, data = dat, panel = panel.circ, aspect = 1) I'd like to to the sample with splom, but with groups. My latest attempt: panel.circ2- function(x, y, groups, ...) { circ1- ellipse(diag(rep(1, 2)), t = 1) panel.xyplot(circ1[,1], circ1[,2], type = l, lty = 2) circ2- ellipse(diag(rep(1, 2)), t = 2) panel.xyplot(circ2[,1], circ2[,2], type = l, lty = 2) panel.xyplot(x, y, type = p, groups) } splom(~dat, panel = panel.superpose, panel.groups = panel.circ2) produces nothing but warnings: warnings() Warning messages: 1: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL' It does not appear to me that panel.circ2 is even being called. Thanks, Max I don't see a function panel.groups() in lattice. Does this do what you want or am I missing the point: splom(~dat|grps, panel = panel.circ2) Peter Ehlers __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to reshape wide format data.frame to long format?
On Jan 20, 2011, at 10:51 AM, Fredrik Karlsson wrote: Dear list, I need to convert this data.frame names(codesM) [1] keyAMR.pa1.M AMR.pa2.M AMR.pa3.M AMR.pa4.M [6] AMR.pa5.M AMR.pa6.M AMR.pa7.M AMR.pa8.M AMR.pa9.M [11] AMR.pa10.M AMR.ta1.M AMR.ta2.M AMR.ta3.M AMR.ta4.M [16] AMR.ta5.M AMR.ta6.M AMR.ta7.M AMR.ta8.M AMR.ta9.M [21] AMR.ta10.M AMR.ka1.M AMR.ka2.M AMR.ka3.M AMR.ka4.M [26] AMR.ka5.M AMR.ka6.M AMR.ka7.M AMR.ka8.M AMR.ka9.M [31] AMR.ka10.M SMR.pa1.M SMR.pa2.M SMR.pa3.M SMR.pa4.M [36] SMR.pa5.M SMR.pa6.M SMR.pa7.M SMR.pa8.M SMR.pa9.M [41] SMR.pa10.M SMR.ta1.M SMR.ta2.M SMR.ta3.M SMR.ta4.M [46] SMR.ta5.M SMR.ta6.M SMR.ta7.M SMR.ta8.M SMR.ta9.M [51] SMR.ta10.M SMR.ka1.M SMR.ka2.M SMR.ka3.M SMR.ka4.M [56] SMR.ka5.M SMR.ka6.M SMR.ka7.M SMR.ka8.M SMR.ka9.M [61] SMR.ka10.M dim(codesM) [1] 42 61 into a 3 x 2501 data.frame where the key variable is kept, the values in columns 2-61 above is inserted into a values column and the name of the column is inserted in a third column (variable perhaps). Like key variable value POSTOFF_1_1AMR.pa1.M 5 POSTOFF_1_1AMR.pa2.M 3 I don't see anything special about this. If there is an unusual aspect to it, then you should post a simpler full example. What happens when you try: library(reshape2) longCodes - melt(codesM) (Then you can fiddle with the names() of the new dataframe.) I think I should be able to do this using the reshape function, but I cannot get it to work. I think I need some help to understand this... (If I could split the variable into three separate columns splitting by ., that would be even better.) Use strsplit and [ If that's not clear, then post results of dput( codesM[1:5, 1:10] ) to provide a reproducible example. I appreciate all the help I could get. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Identify duplicate numbers and to increase a value
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ortiz, John Sent: Thursday, January 20, 2011 7:13 AM To: r-help@r-project.org Subject: [R] Identify duplicate numbers and to increase a value Hi everybody. I want to identify duplicate numbers and to increase a value of 0.01 for each time that it is duplicated. Example: x=c(1,2,3,5,6,2,8,9,2,2) I want to do this: 1 2 + 0.01 3 5 6 2 + 0.02 8 9 2 + 0.03 2 + 0.04 Your words made it sound like you wanted the following x + (ave(x, x, FUN=seq_along)-1)/100 [1] 1.00 2.00 3.00 5.00 6.00 2.01 8.00 9.00 2.02 2.03 but your example indicates that you want to alter any value that has a duplicate (including the first) so it gets a bit more complicated. E.g., x + ave(x, x, FUN=function(xi)if(length(xi)==1) 0.0 else seq_along(xi))/100 [1] 1.00 2.01 3.00 5.00 6.00 2.02 8.00 9.00 2.03 2.04 You could also use subscripting to use ave() only on those elements of x which had duplicates. There are trickier but faster ways (based on runs) of doing this if you have very long vectors with lots of unique values. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com I am trying to get something like this: 1 2.01 3 5 6 2.02 8 9 2.03 2.04 Actually I just know the way to identify the duplicated numbers rbind(x, duplicated(x) | duplicated(x, fromLast=TRUE)) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] x123562892 2 010001001 1 Some advice? Thanks and regards John Ortiz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Identify duplicate numbers and to increase a value
Try this: replace(x + ave(x, x, FUN = seq) * .01, !(duplicated(x) | duplicated(x, fromLast = TRUE)), x) On Thu, Jan 20, 2011 at 1:12 PM, Ortiz, John ort...@si.edu wrote: Hi everybody. I want to identify duplicate numbers and to increase a value of 0.01 for each time that it is duplicated. Example: x=c(1,2,3,5,6,2,8,9,2,2) I want to do this: 1 2 + 0.01 3 5 6 2 + 0.02 8 9 2 + 0.03 2 + 0.04 I am trying to get something like this: 1 2.01 3 5 6 2.02 8 9 2.03 2.04 Actually I just know the way to identify the duplicated numbers rbind(x, duplicated(x) | duplicated(x, fromLast=TRUE)) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] x123562892 2 010001001 1 Some advice? Thanks and regards John Ortiz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Accessing MySQL Database in R
The following worked for me recently: library(RMySQL) MySQL. - MySQL() MySQLcon - dbConnect(MySQL., user='thisuser', password='thispassword', dbname='desiredDB') I have the following suggestions and questions for you: 1. Have you tried supplying dbname rather than host? 2. Please provide sessionInfo(). Many packages have a function named dbConnect, and I don't know which one you are using. 3. I don't know if MySQL() is equivalent to dbDriver(MySQL), which you used. It might be; I don't know. 4. The standard install.packages('RMySQL') may not work, because this package needs to be built to configure itself properly to your local operating system and versions of MySQL and R installed. Installation instructions are available at http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL;. If you have not already followed those instructions, please do so. There is a good chance that will fix your problem, I think. 5. If this is not adequate, I suggest you post this question to r-sig...@stat.math.ethz.ch. [I suggest you subscribe first. This list has low volume and you can unsubscribe later if you prefer. And please also provide sessionInfo().] 6. Or use RODBC as suggested by Ptit Bleu. It comes highly recommended (including by Brian Ripley). However, I had difficulties getting positive results from both RMySQL and RODBC. I tried both, with each receiving similar quantities of expletives. Finally, I got RMySQL to do what I wanted and suspended my schoolboy exercises with RODBC. Hope this helps. Spencer On 1/20/2011 5:55 AM, PtitBleu wrote: Hello, I used to use RMySQL but as there is no more package for windows, I decided to move to RODBC. I installed ODBC driver for MySQL (downloaded on the MySQL website) and then the RODBC package. I finally discovered that it was not needed to register your database with ODBC before using it. These commands below work for me. library(RODBC) ch-odbcDriverConnect(connection=SERVER=localhost;DRIVER=MySQL ODBC 5.1 Driver;DATABASE=my_database;UID=root;PWD=my_password;case=tolower) resultdb-sqlQuery(ch,SELECT * from my_table) odbcClose(ch) Try to modify them for your case. I hope it will work for you. Good luck, Ptit Bleu. Re: Accessing MySQL Database in R Jan 18, 2011; 12:10am — by djmuseR [User is online] djmuseR Hi: Because R does not have a direct interface to MySQL? You need to load a communication package - the two most common ones are RODBC and RMySQL. The former requires that you register your MySQL database table(s) with ODBC before using the RODBC package on them, whereas the latter works with specific version combinations of MySQL and R. The RODBC package has a very informative vignette; for information re the RMySQL package, see http://biostat.mc.vanderbilt.edu/wiki/Main/RMySQL HTH, Dennis On Mon, Jan 17, 2011 at 1:30 PM, schlafly[hidden email] wrote: I have a local installation of MySQL on my computer. I enter the following to access MySQL from the command line: /Applications/MAMP/Library/bin/mysql -h localhost -u root -p I am then prompted for a password, and I use: root This connects me to MySQL in the command line. I now want to access MySQL databases in R. I enter the following: mysql- dbDriver(MySQL) conn- dbConnect(mysql,user='root',host='localhost', password='root') I get the following error message: Error in mysqlNewConnection(drv, ...) : RS-DBI driver: (Failed to connect to database: Error: Access denied for user 'root'@'localhost' (using password: YES) Does anyone know why these aren't equivalent? -- View this message in context: http://r.789695.n4.nabble.com/Accessing-MySQL-Database-in-R-tp3221264p3221264.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] Scale of 2nd y-axis
Dear list, My query follows on from a question I posted a few days ago. I have the following 2 sets of data: wetMeans[1] 9.904762[2] 6.344828[3] 6.346154[4] 6.855769[5] 9.074324[6] 9.953988[7] 13.482966[8] 14.546053[9] 10.841584[10] 9.752033[11] 6.739336[12] 8.955056burnMeans[1] 0.06214286[2] 0.05396552[3] 0.04096154[4] 0.05302885[5] 0.05831081[6] 0.07392638[7] 0.29969940[8] 0.25596217[9] 0.09316832[10] 0.14441057[11] 0.13180095[12] 0.05348315 which I am trying to plot on the same graph. I wish to plot the variable wetMeans as bars and overlay burnMeans as a line, using the same x-axis (there are 12 observations in each set, corresponding to the months of the year) but different y-axes. I have produced the following code which addresses my previous issue (aligning the centre of each bar and the points of the line plot); my problem now relates to the 2nd y-axis (which is being used for the burnMeans data): library(plotrix) par(oma=c(1,1,1,1))par(las=1) xvals - barp(wetMeans, xlab=, ylab=, main=TEST, col=grey, names.arg=c(Jan,Feb,Mar,Apr,May, Jun,Jul,Aug,Sep,Oct,Nov,Dec), staxx=T, cylindrical=T, srt=45) par(new=T) plot(xvals$x,burnMeans, xaxt=n, yaxt=n, xlab=, ylab=, type=b, cex=1, pch=16, lty=44, col=black, lwd=1.5) axis(4, pretty(c(0,max(burnMeans)),n=4)) As you can see when you plot the data, the 2nd y-axis does not have an origin at 0. From a quick inspection of the graph it appears that the scale of the 2nd y-axis is such that the 0 marker would not fit on the grid. My question is therefore if there is a method by which I can shift the line plot (burnMeans) upwards, so that both plotted data sets have their respective y-axes beginning at 0. Many thanks in advance,Andy [[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] Select unique point occurences per pixel - raster package (?) question
Dear all, This may be a simple question, but I cannot find the solution. I have a point shapefile containing several hundreds of points, and a grid file with a certain pixels size. Certain grid cells have several points falling into them. I am looking for a way to randomly select one point per grid cell, resulting in a new point shapefile whereby there maximum one point per pixel remains. In other words, for the grid layer under consideration, I want to select 'unique point occurrences'. Any suggestions? Many thanks, Diederik -- Dr.Diederik Strubbe Evolutionary Ecology Group Department of Biology University of Antwerp Middelheimcampus GV310 Groenenborgerlaan 171 2020 Antwerpen, Belgium office: +32 3 265 3282 mobile phone: +32 477445568 skype user name: lakrinn [[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] Identify duplicate numbers and to increase a value
Hello John, If many numbers are duplicated, then one way is to coerce to a factor and use the levels() function. For instance: x - c(1,1,2,2,2,3,3,4,1,1,2,4) X - factor(x) for (i in levels(X)) { loc - (X==i); len = length(loc) x[loc] - x[loc] + 0.01 * (1:len) } x [1] 1.01 1.02 2.01 2.02 2.03 3.01 3.02 4.01 1.03 1.04 2.04 4.02 Hope that helps James Lawrence On Thu, 2011-01-20 at 08:00 -0800, Joshua Wiley wrote: Hi John, If you only have one duplicated number (e.g., just 2), then this will work: x - c(1,2,3,5,6,2,8,9,2,2) xd - duplicated(x) x[xd] - x[xd] + seq(sum(xd))/100 x otherwise, I think a different framework than duplicated() will be necessary, because it will matter not just if the number is duplicated but which one how many times and where. Cheers, Josh On Thu, Jan 20, 2011 at 7:12 AM, Ortiz, John ort...@si.edu wrote: Hi everybody. I want to identify duplicate numbers and to increase a value of 0.01 for each time that it is duplicated. Example: x=c(1,2,3,5,6,2,8,9,2,2) I want to do this: 1 2 + 0.01 3 5 6 2 + 0.02 8 9 2 + 0.03 2 + 0.04 I am trying to get something like this: 1 2.01 3 5 6 2.02 8 9 2.03 2.04 Actually I just know the way to identify the duplicated numbers rbind(x, duplicated(x) | duplicated(x, fromLast=TRUE)) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] x123562892 2 010001001 1 Some advice? Thanks and regards John Ortiz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] MCMC object indexing
Stoker, Ben wrote: A reproducible example would be very useful. In general I find that I can just index an mcmc object as though it were a matrix, e.g.: z - cbind(a=runif(20),b=runif(20),c=runif(20)) library(coda) m - mcmc(data=z) t(apply(m,2,quantile,c(0.025,0.975))) If that sort of thing doesn't work for you, please post an example of what doesn't work ... Ben Bolker Ben, thanks for the suggestion and it got me going the right direction. FWIW-I did get an error from your suggestion, but it led me to find that I had an mcmc.list object and not an mcmc object. Once I got past that, your suggestion worked perfectly. Thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Constrained Regression
Hi everyone, I'm trying to perform a linear regression y = b1x1 + b2x2 + b3x3 + b4x4 + b5x5 while constraining the coefficients such that -3 = bi = 3, and the sum of bi =1. I've searched R-help and have found solutions for constrained regression using quadratic programming (solve.QP) where the coefficients are between 0 and 1 and sum to 1, but unfortunately do not understand it well enough to adapt to my problem. Is there a way to do this using the lm function or do I absolutely need to use solve.QP? And if I need to use solve.QP, how would I modify the Boston data example to my problem? Thanks so much. Jackie --- This communication may contain confidential and/or privileged information. If you are not the intended recipient (or have received this communication in error) please notify the sender immediately and destroy this communication. Any unauthorized copying, disclosure or distribution of the material in this communication is strictly forbidden. Deutsche Bank does not render legal or tax advice, and the information contained in this communication should not be regarded as such. [[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] spacing of color key in filled.contour
I've gotten good results using the sine function to map colors. For example, when plotting x, map the range(x) to (-pi/2,pi/2) which the sine will transform to (-1,1), then add 1 and multiply by half the desired number of colors. Now the integer values will pick the colors and give a pleasing display. If the squeeze is taking place only over one of the tails (which sounds like your case) map the range from (0,pi/2) or (-pi/2,0) and make the necessary scaling adjustments to cover the number of colors desired. Essentially, you are transforming the color mapping instead of transforming your data. Clint -- Clint BowmanINTERNET: cl...@ecy.wa.gov Air Quality Modeler INTERNET: cl...@math.utah.edu Department of Ecology VOICE: (360) 407-6815 PO Box 47600FAX:(360) 407-7534 Olympia, WA 98504-7600 USPS: PO Box 47600, Olympia, WA 98504-7600 Parcels:300 Desmond Drive, Lacey, WA 98503-1274 On Thu, 20 Jan 2011, Jim Lemon wrote: On 01/20/2011 09:19 AM, claudia tebaldi wrote: Hi all I'm plotting colored contour maps using filled.contour. My levels are very unevenly spaced, with, say, high resolution in the small numbers but ranges that can be an order of magnitude or two larger in absolute value compared to where the action takes place. Aside from transforming the data, is there a way to control the color spacing in the key to the right of the map? Right now I get most of the key length taken up by a couple of colors and the rest all squeezed into thin slices, which also creates a problem with the fourth axis labels getting drawn on top of one another. Hi Claudia, You can roll your own color key with the color.legend function in plotrix. Just specify the colors you want in rect.col and the labels in legend. Jim __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Scale of 2nd y-axis
Hi Andy, this is my way of doing it: #first data: wetMeans-c(9.904762,6.344828,6.346154,6.855769,9.074324,9.953988,13.482966, 14.546053,10.841584,9.752033,6.739336,8.955056) burnMeans-c(0.06214286,0.05396552,0.04096154,0.05302885,0.05831081,0.073926 38,0.29969940,0.25596217,0.09316832,0.14441057,0.13180095,0)#0.05348315) #your code library(plotrix) par(oma=c(1,1,1,1)) par(las=1) xvals - barp(wetMeans, xlab=, ylab=, main=TEST, col=grey, names.arg=c(Jan,Feb,Mar,Apr,May, Jun,Jul,Aug,Sep,Oct,Nov,Dec), staxx=T, cylindrical=T, srt=45) #par(new=T) #plot(xvals$x,burnMeans, xaxt=n, yaxt=n, xlab=, ylab=, type=b, cex=1, pch=16, lty=44, col=black, lwd=1.5, ylim=c(0, max(burnMeans))) #axis(4, pretty(c(0,max(burnMeans)),n=4)) #my replacement of your last three lines # I only want to have one plot scaleFactor=max(wetMeans)/max(burnMeans) lines(x=seq(along=burnMeans), y=burnMeans*scaleFactor, lwd=1.5, lty=44, type=b) axis(4, at=pretty(c(0,max(burnMeans)),n=4)*scaleFactor, labels=pretty(c(0,max(burnMeans)),n=4)) Explanation: I'm using only one plot. The BurnMeans are scaled by scaleFactor and plotted into the first plot with lines(). For the axis I'm using the scaled at values with not scaled labels. Hope this helps, Moritz _ Moritz Grenke http://www.360mix.de -Ursprüngliche Nachricht- Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im Auftrag von Andy Aldersley Gesendet: Donnerstag, 20. Januar 2011 17:35 An: r-help@r-project.org Betreff: [R] Scale of 2nd y-axis Dear list, My query follows on from a question I posted a few days ago. I have the following 2 sets of data: wetMeans[1] 9.904762[2] 6.344828[3] 6.346154[4] 6.855769[5] 9.074324[6] 9.953988[7] 13.482966[8] 14.546053[9] 10.841584[10] 9.752033[11] 6.739336[12] 8.955056burnMeans[1] 0.06214286[2] 0.05396552[3] 0.04096154[4] 0.05302885[5] 0.05831081[6] 0.07392638[7] 0.29969940[8] 0.25596217[9] 0.09316832[10] 0.14441057[11] 0.13180095[12] 0.05348315 which I am trying to plot on the same graph. I wish to plot the variable wetMeans as bars and overlay burnMeans as a line, using the same x-axis (there are 12 observations in each set, corresponding to the months of the year) but different y-axes. I have produced the following code which addresses my previous issue (aligning the centre of each bar and the points of the line plot); my problem now relates to the 2nd y-axis (which is being used for the burnMeans data): library(plotrix) par(oma=c(1,1,1,1))par(las=1) xvals - barp(wetMeans, xlab=, ylab=, main=TEST, col=grey, names.arg=c(Jan,Feb,Mar,Apr,May, Jun,Jul,Aug,Sep,Oct,Nov,Dec), staxx=T, cylindrical=T, srt=45) par(new=T) plot(xvals$x,burnMeans, xaxt=n, yaxt=n, xlab=, ylab=, type=b, cex=1, pch=16, lty=44, col=black, lwd=1.5) axis(4, pretty(c(0,max(burnMeans)),n=4)) As you can see when you plot the data, the 2nd y-axis does not have an origin at 0. From a quick inspection of the graph it appears that the scale of the 2nd y-axis is such that the 0 marker would not fit on the grid. My question is therefore if there is a method by which I can shift the line plot (burnMeans) upwards, so that both plotted data sets have their respective y-axes beginning at 0. Many thanks in advance,Andy [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Identify duplicate numbers and to increase a value
On Thu, Jan 20, 2011 at 10:12 AM, Ortiz, John ort...@si.edu wrote: Hi everybody. I want to identify duplicate numbers and to increase a value of 0.01 for each time that it is duplicated. Example: x=c(1,2,3,5,6,2,8,9,2,2) I want to do this: 1 2 + 0.01 3 5 6 2 + 0.02 8 9 2 + 0.03 2 + 0.04 I am trying to get something like this: 1 2.01 3 5 6 2.02 8 9 2.03 2.04 Actually I just know the way to identify the duplicated numbers rbind(x, duplicated(x) | duplicated(x, fromLast=TRUE)) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] x 1 2 3 5 6 2 8 9 2 2 0 1 0 0 0 1 0 0 1 1 There is a function in the unreleased zooExtra package that will uniquify numbers via linear interpolation: library(zoo) source(http://r-forge.r-project.org/scm/viewvc.php/*checkout*/pkg/zooExtra/R/make.unique.R?root=zoo;) x - c(1, 2, 3, 5, 6, 2, 8, 9, 2, 2) make.unique.approx(x) [1] 1.00 2.00 3.00 5.00 6.00 2.25 8.00 9.00 2.50 2.75 # If you wish to make the increments smaller: ifelse(x == y, x, x + (y-x)/100) [1] 1. 2. 3. 5. 6. 2.0025 8. 9. 2.0050 2.0075 -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Procuct of a sequence or vector
Dear list, is there a function in R that returns the product of a vector? E.g. if the vector is c(1,2,3,4) it should return 1*2*3*4=24 Cheers Jannis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] function of probability for normal distribution
Jeremy, I don't seem to remember signing up to have R-help be my personal e-mail :-) It is common to use phi to represent the standard normal distribution (with mean 0, and variance 1), the script/small/lower case version is for the distribution (height of the bell curve) and the block/capitol/upper case is for the cumulative distribution. So for arbitrary mean and variance you get 1/sigma * phi( (x-mu)/sigma ). The general idea for any truncated distribution is that it will have the same shape as the non-truncated version, it just needs to be scaled so that the area is 1, the proper scaling is just the area under the original. So the formulas you see on that page start with the regular normal (phi) divided by the area under the curve between A and B which is just the difference in the cumulative distribution at those 2 points. In R dnorm will correspond to phi and pnorm to PHI. You could use the exact formulas on that page, but it would be simpler to use the arguments to dnorm and pnorm. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of JClark Sent: Wednesday, January 19, 2011 4:04 PM To: r-help@r-project.org Subject: Re: [R] function of probability for normal distribution Dear Greg Snow, I'm a biologist trying to write a mathematical formula for a doubly truncated normal distribution to be used in the language R. I realise this is simple stuff for a mathematician but I'm stumped. Wikipedia gives what seems a fairly simple formula - with function = maths with mean and standard deviation - but also phi - WHAT IS PHI !!?? - especially how do I write this in R and why is the top phi in italics ?? Hoping you can help. Yours sincerely, Jeremy Clark -- View this message in context: http://r.789695.n4.nabble.com/Re-R- function-for-Probabilities-for-the-standard-normal-distribution- tp903639p3225457.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] Procuct of a sequence or vector
Is this what you want: prod(c(1,2,3,4)) [1] 24 On Thu, Jan 20, 2011 at 12:18 PM, Jannis bt_jan...@yahoo.de wrote: Dear list, is there a function in R that returns the product of a vector? E.g. if the vector is c(1,2,3,4) it should return 1*2*3*4=24 Cheers Jannis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Procuct of a sequence or vector
Take a look in prod function: prod(1:4) On Thu, Jan 20, 2011 at 3:18 PM, Jannis bt_jan...@yahoo.de wrote: Dear list, is there a function in R that returns the product of a vector? E.g. if the vector is c(1,2,3,4) it should return 1*2*3*4=24 Cheers Jannis __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] randomForest: too many elements specified?
I getting Error in matrix(0, n, n) : too many elements specified while building randomForest model, which looks like memory allocation error. Software versions are: randomForest 4.5-25, R version 2.7.1 Dataset is big (~90K rows, ~200 columns), but this is on a big machine ( ~120G RAM) and I call randomForest like this: randomForest(x,y) i.e. in supervised mode and not requesting proximity matrix, therefore answer from Andy Liaw to an email reporting the same problems in 2005 (see below) is probably not directly applicable, still it looks like it is too big data set for this dataset/machine combination. How does memory usage in randomForest scale with dataset size? Is there a way to build global rf model with dataset of this size? Best regards, Ryszard Ryszard Czerminski AstraZeneca Pharmaceuticals LP 35 Gatehouse Drive Waltham, MA 02451 USA 781-839-4304 ryszard.czermin...@astrazeneca.com RE: [R] randomForest: too many element specified? Liaw, Andy Mon, 17 Jan 2005 05:56:28 -0800 From: luk When I run randonForest with a 169453x5 matrix, I got the following message. Error in matrix(0, n, n) : matrix: too many elements specified Can you please advise me how to solve this problem? Thanks, Lu 1. When asking new questions, please don't reply to other posts. 2. When asking questions like these, please do show the commands you used. My guess is that you asked for the proximity matrix, or is running unsupervised randomForest (by not providing a response vector). This will requires a couple of n by n matrices to be created (on top of other things), n being 169453 in this case. To store a 169453 x 169453 matrix in double precision, you need 169453^2 * 8 bytes, or or nearly 214 GB of memory. Even if you have that kind of hardware, I doubt you'll be able to make much sense out of the result. Andy -- Confidentiality Notice: This message is private and may ...{{dropped:11}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Constrained Regression
Hello, Your problem is y=bX+epsilon It can be transformed into: epsilon^2=(y-bX)^2 Standard (unconstrained) regressions are about minimizing the variance of epsilon, ie (y-bX)^2. In your case, you need to minimize again the quantity (y-bX)^2 with your constraints on b=(b1,...,b5). Solve.QP should just do that for you. HTH, Samuel -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jackie Chen Sent: 20 January 2011 16:31 To: R-help@r-project.org Subject: [R] Constrained Regression Hi everyone, I'm trying to perform a linear regression y = b1x1 + b2x2 + b3x3 + b4x4 + b5x5 while constraining the coefficients such that -3 = bi = 3, and the sum of bi =1. I've searched R-help and have found solutions for constrained regression using quadratic programming (solve.QP) where the coefficients are between 0 and 1 and sum to 1, but unfortunately do not understand it well enough to adapt to my problem. Is there a way to do this using the lm function or do I absolutely need to use solve.QP? And if I need to use solve.QP, how would I modify the Boston data example to my problem? Thanks so much. Jackie --- This communication may contain confidential and/or privileged information. If you are not the intended recipient (or have received this communication in error) please notify the sender immediately and destroy this communication. Any unauthorized copying, disclosure or distribution of the material in this communication is strictly forbidden. Deutsche Bank does not render legal or tax advice, and the information contained in this communication should not be regarded as such. [[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. __ Information from ESET NOD32 Antivirus, version of virus signature database 5803 (20110120) __ The message was checked by ESET NOD32 Antivirus. http://www.eset.com __ Information from ESET NOD32 Antivirus, version of virus signature database 5803 (20110120) __ The message was checked by ESET NOD32 Antivirus. http://www.eset.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] circular reference lines in splom
This did the trick: panel.circ3 - function(...) { args - list(...) circ1 - ellipse(diag(rep(1, 2)), t = 1) panel.xyplot(circ1[,1], circ1[,2], type = l, lty = trellis.par.get(reference.line)$lty, col = trellis.par.get(reference.line)$col, lwd = trellis.par.get(reference.line)$lwd) circ2 - ellipse(diag(rep(1, 2)), t = 2) panel.xyplot(circ2[,1], circ2[,2], type = l, lty = trellis.par.get(reference.line)$lty, col = trellis.par.get(reference.line)$col, lwd = trellis.par.get(reference.line)$lwd) panel.xyplot(args$x, args$y, groups = args$groups, subscripts = args$subscripts) } splom(~dat, groups = grps, lower.panel = panel.circ3, upper.panel = panel.circ3) Thanks, Max On Thu, Jan 20, 2011 at 11:13 AM, Peter Ehlers ehl...@ucalgary.ca wrote: On 2011-01-19 20:15, Max Kuhn wrote: Hello everyone, I'm stumped. I'd like to create a scatterplot matrix with circular reference lines. Here is an example in 2d: library(ellipse) set.seed(1) dat- matrix(rnorm(300), ncol = 3) colnames(dat)- c(X1, X2, X3) dat- as.data.frame(dat) grps- factor(rep(letters[1:4], 25)) panel.circ- function(x, y, ...) { circ1- ellipse(diag(rep(1, 2)), t = 1) panel.xyplot(circ1[,1], circ1[,2], type = l, lty = 2) circ2- ellipse(diag(rep(1, 2)), t = 2) panel.xyplot(circ2[,1], circ2[,2], type = l, lty = 2) panel.xyplot(x, y) } xyplot(X2 ~ X1, data = dat, panel = panel.circ, aspect = 1) I'd like to to the sample with splom, but with groups. My latest attempt: panel.circ2- function(x, y, groups, ...) { circ1- ellipse(diag(rep(1, 2)), t = 1) panel.xyplot(circ1[,1], circ1[,2], type = l, lty = 2) circ2- ellipse(diag(rep(1, 2)), t = 2) panel.xyplot(circ2[,1], circ2[,2], type = l, lty = 2) panel.xyplot(x, y, type = p, groups) } splom(~dat, panel = panel.superpose, panel.groups = panel.circ2) produces nothing but warnings: warnings() Warning messages: 1: In is.na(x) : is.na() applied to non-(list or vector) of type 'NULL' It does not appear to me that panel.circ2 is even being called. Thanks, Max I don't see a function panel.groups() in lattice. Does this do what you want or am I missing the point: splom(~dat|grps, panel = panel.circ2) Peter Ehlers -- Max __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Inverse Prediction with splines
Hello, I have fit a simple spline model to the following data. Data x y 0 1.298 2 0.605 3 0.507 4 0.399 5 0.281 6 0.203 7 0.150 8 0.101 Model Sp.1=lm(y~bs(x,df=4)) Now I wish to inverse predict the x for y=.75, say. Optimize works fine for a polynomial but I can figure out how to get the spline model into the function argument. Can anyone help me out. Thanks!! Jeff Jeff Morris Sanofi Pasteur This communication, including any attachments, is intended solely for the use of the addressee and may contain information which is privileged, confidential, exempt from disclosure under applicable law or subject to copyright. If you are not an intended recipient, any use, disclosure, distribution, reproduction, review or copying is unauthorized and may be unlawful. If you have received this transmission in error, please notify the sender immediately. Thank you. Cette communication,y compris les pieces jointes, est reservee a l'usage exclusif du destinataire et peut contenir des informations privilegiees, confidentielles, exemptees de divulgation selon la loi ou protegees par les droits de publication. Si vous n'etes pas un destinataire, toute utilisation, divulgation, distribution, reproduction, examen ou copie est non-autorisee et peut etre illegale. Si vous avez recu cette communication par erreur, veuillez aviser l'expediteur immediatement. Merci. [[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] densities greater than 1 for values within an (0, 1) intervall
How does one then interpret kernel density distributions with values greater than one? My output from the density function. --- density(delt.m[[1]][,6], na.rm=TRUE) Call: density.default(x = delt.m[[1]][, 6], na.rm = TRUE) Data: delt.m[[1]][, 6] (171 obs.); Bandwidth 'bw' = 0.004501 x y Min. :-0.05211 Min. : 0.00586 1st Qu.:-0.02177 1st Qu.: 0.43632 Median : 0.00856 Median : 3.08833 Mean : 0.00856 Mean : 8.23366 3rd Qu.: 0.03889 3rd Qu.:14.97542 Max. : 0.06923 Max. :30.04107 -- View this message in context: http://r.789695.n4.nabble.com/densities-greater-than-1-for-values-within-an-0-1-intervall-tp2286439p3228268.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] Regression Testing
I'm new to R and some what new to the world of stats. I got frustrated with excel and found R. Enough of that already. I'm trying to test and correct for Heteroskedasticity I have data in a csv file that I load and store in a dataframe. ds - read.csv(book2.csv) df - data.frame(ds) I then preform a OLS regression: lmfit - lm(df$y~df$x) To test for Heteroskedasticity, I run the BPtest: bptest(lmfit) studentized Breusch-Pagan test data: lmfit BP = 11.6768, df = 1, p-value = 0.0006329 From the above, if I'm interpreting this correctly, there is Heteroskedasticity present. To correct for this, I need to calculate robust error terms. From my reading on this list, it seems like I need to vcovHC. vcovHC(lmfit) (Intercept) df$x (Intercept) 1.057460e-03 -4.961118e-05 df$x -4.961118e-05 2.378465e-06 I'm having a little bit of a hard time following the help pages. So is the first column the intercepts and the second column new standard errors? Thanks, mojo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] ANOVA plotting
Dear List, I recently started using R and I have a simple question. I am running R (v. 2.12.1) and Rcmdr (v.1-6.3) on Mac (Snow Leopard). I am using a data set I used before for practicing ANOVA with R, so I know what the results should look like. I can get ANOVA table using both Rcmdr and GUI. However, I cannot make R prepare the ANOVA diagram (with boxplots, showing the data points, including the outliers) for the dataset. If I use Rcmdr (ModelsGraphs) then I get some graphical representation for the ANOVA model I prepared in R (showing diagnostic plots, Q-Q plots, etc.). However, the real ANOVA diagram is not coming up. I tried using plot command in GUI but did not get what I wanted. I could not find an answer to this on-line or in my book. I apologize if this was covered recently in the mailing list, I just became a member. Thanks for all the help! -- BÜLENT [[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] CCF and missing values.
combine them and then use acf: x - ts(rnorm(10)) y - ts(x+ rnorm(10)) u - ts.union(x, y) (acf(u, na.action=na.pass)) I don't know if it's correct, but it gives an answer... I'm too afraid to check if it's correct. -- View this message in context: http://r.789695.n4.nabble.com/CCF-and-missing-values-tp3225942p3228341.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] densities greater than 1 for values within an (0, 1) intervall
The same way you interpret densities less than one? On Jan 20, 2011, at 2:28 PM, Paul Ramer wrote: How does one then interpret kernel density distributions with values greater than one? The same way you interpret densities less than one? density != probability My output from the density function. --- density(delt.m[[1]][,6], na.rm=TRUE) Call: density.default(x = delt.m[[1]][, 6], na.rm = TRUE) Data: delt.m[[1]][, 6] (171 obs.); Bandwidth 'bw' = 0.004501 x y Min. :-0.05211 Min. : 0.00586 1st Qu.:-0.02177 1st Qu.: 0.43632 Median : 0.00856 Median : 3.08833 Mean : 0.00856 Mean : 8.23366 3rd Qu.: 0.03889 3rd Qu.:14.97542 Max. : 0.06923 Max. :30.04107 -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] spacing of color key in filled.contour
Hi again thank you to those who replied. I actually figured out a simple way (which does entail transforming the data, oh well...) and I thought I throw it out there just in case someone needs to solve a similar problem. Apologies if it is in fact obvious. Once the right levels for the contouring have been identified (for example using the quantile function), just use cut() on your data with those as the breaks, and the argument labels=F. This will return your data in the form of integers, with a unique integer associated to all the values that fall in a given interval identified by your levels. Use filled.contour on your new data, and work on the key.axes={axes(4,at=...,labels=...)} argument to print the right values besides the color key. For what is worth. And thanks again Jim and Clint Claudia __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Regression Testing
On Jan 20, 2011, at 2:08 PM, Mojo wrote: I'm new to R and some what new to the world of stats. I got frustrated with excel and found R. Enough of that already. I'm trying to test and correct for Heteroskedasticity I have data in a csv file that I load and store in a dataframe. ds - read.csv(book2.csv) df - data.frame(ds) I then preform a OLS regression: lmfit - lm(df$y~df$x) To test for Heteroskedasticity, I run the BPtest: bptest(lmfit) studentized Breusch-Pagan test data: lmfit BP = 11.6768, df = 1, p-value = 0.0006329 From the above, if I'm interpreting this correctly, there is Heteroskedasticity present. To correct for this, I need to calculate robust error terms. From my reading on this list, it seems like I need to vcovHC. vcovHC(lmfit) (Intercept) df$x (Intercept) 1.057460e-03 -4.961118e-05 df$x -4.961118e-05 2.378465e-06 I'm having a little bit of a hard time following the help pages. So is the first column the intercepts and the second column new standard errors? No, It's a variance-covariance matrix, so all of the elements are variance estimates. To get what you are expecting ... the SE's of the coefficients (which are the diagonal elements of a var-covar matrix, you would wrap sqrt(diag(.)) around that object. Thanks, mojo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Regression Testing
On 1/20/2011 3:37 PM, David Winsemius wrote: On Jan 20, 2011, at 2:08 PM, Mojo wrote: I'm new to R and some what new to the world of stats. I got frustrated with excel and found R. Enough of that already. I'm trying to test and correct for Heteroskedasticity I have data in a csv file that I load and store in a dataframe. ds - read.csv(book2.csv) df - data.frame(ds) I then preform a OLS regression: lmfit - lm(df$y~df$x) To test for Heteroskedasticity, I run the BPtest: bptest(lmfit) studentized Breusch-Pagan test data: lmfit BP = 11.6768, df = 1, p-value = 0.0006329 From the above, if I'm interpreting this correctly, there is Heteroskedasticity present. To correct for this, I need to calculate robust error terms. From my reading on this list, it seems like I need to vcovHC. vcovHC(lmfit) (Intercept) df$x (Intercept) 1.057460e-03 -4.961118e-05 df$x -4.961118e-05 2.378465e-06 I'm having a little bit of a hard time following the help pages. So is the first column the intercepts and the second column new standard errors? No, It's a variance-covariance matrix, so all of the elements are variance estimates. To get what you are expecting ... the SE's of the coefficients (which are the diagonal elements of a var-covar matrix, you would wrap sqrt(diag(.)) around that object. Perfect. Thank you very much! Mojo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Inverse Prediction with splines
On Jan 20, 2011, at 2:37 PM, jeffrey.mor...@sanofipasteur.com jeffrey.mor...@sanofipasteur.com wrote: Hello, I have fit a simple spline model to the following data. Data x y 0 1.298 2 0.605 3 0.507 4 0.399 5 0.281 6 0.203 7 0.150 8 0.101 Model Sp.1=lm(y~bs(x,df=4)) Now I wish to inverse predict the x for y=.75, say. Optimize works fine for a polynomial but I can figure out how to get the spline model into the function argument. Why not pass the reversed x and y vectors from the spline fit to approxfun()? pred.Spl - predict(Sp.1, data.frame(x=seq(0,8, by=0.01) ) ) approxfun(x=pred.Spl, y=seq(0,8, by=0.01) )(0.75) [1] 1.447311 Looks plausible, anyway. -- David. Can anyone help me out. Thanks!! Jeff Jeff Morris Sanofi Pasteur This communication, including any attachments, is intended solely for the use of the addressee and may contain information which is privileged, confidential, exempt from disclosure under applicable law or subject to copyright. If you are not an intended recipient, any use, disclosure, distribution, reproduction, review or copying is unauthorized and may be unlawful. If you have received this transmission in error, please notify the sender immediately. Thank you. Cette communication,y compris les pieces jointes, est reservee a l'usage exclusif du destinataire et peut contenir des informations privilegiees, confidentielles, exemptees de divulgation selon la loi ou protegees par les droits de publication. Si vous n'etes pas un destinataire, toute utilisation, divulgation, distribution, reproduction, examen ou copie est non-autorisee et peut etre illegale. Si vous avez recu cette communication par erreur, veuillez aviser l'expediteur immediatement. Merci. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to reshape wide format data.frame to long format?
I think I should be able to do this using the reshape function, but I cannot get it to work. I think I need some help to understand this... (If I could split the variable into three separate columns splitting by ., that would be even better.) Use strsplit and [ Or colsplit, from reshape, that does this for you. Hadley -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Generating time progressing line for Google Earth
Dear, I am trying to visualise a time-progressing line (it's supposed to represent spread patterns) using brew package and Google Earth. The idea is to have a function which takes start and end point geographic coordinates, as well as number of intervals to chop the path up, and returns the collection of points segmenting this line. Unfortunately my calculations fail for large distances, as the generated lines are nowhere near being straigth (run the code to see the example). My R code so far: #---LIBS---# library(brew) ### #---GREAT CIRCULAR DISTANCE---# ### #degrees to radians Radians - function (degree) { radian = degree * (pi/180.0) return(radian) } #radians to degrees Degrees - function (radian) { degree = radian * (180.0/pi) return(degree) } # Calculates the distance between two points using the # Spherical Law of Cosines gcd.slc - function(lon1, lat1, lon2, lat2) { R = 6371.0 # Earth mean radius [km] lon1 = Radians(lon1) lat1 = Radians(lat1) lon2 = Radians(lon2) lat2 = Radians(lat2) d = acos(sin(lat1)*sin(lat2) + cos(lat1)*cos(lat2) * cos(lon2-lon1)) * R return(d) # Distance in km } #---PROGRESSING LINE---# GenerateLineSegments - function(start_point.Long, start_point.Lat, end_point.Long, end_point.Lat, numberOfIntervals) { coords - matrix(NA, numberOfIntervals, 2) full_distance = gcd.slc(lat1 = start_point.Lat, lon1 = start_point.Long, lat2 = end_point.Lat, lon2 = end_point.Long) distance_slice = full_distance / numberOfIntervals for(i in 1 : numberOfIntervals) { distance = i * distance_slice ang_dist = distance / 6371.0 lon_1 = Radians(start_point.Long); lat_1 = Radians(start_point.Lat); lat_2 = Radians(end_point.Lat); lon_diff = Radians(end_point.Long - start_point.Long); # First calculate the bearing bearing = atan2( sin(lon_diff) * cos(lat_2), (cos(lat_1) * sin(lat_2)) - (sin(lat_1) * cos(lat_2) * cos(lon_diff)) ); # Then use the bearing and the start point to find the destination new_lat_rad = asin(sin(lat_1) * cos(ang_dist) + cos(lat_1) * sin(ang_dist) * cos(bearing)); new_lon_rad = lon_1 + atan2( sin(bearing) * sin(ang_dist) * cos(lat_1), cos(ang_dist) - sin(lat_1) * sin(lat_2) ); # Convert from radians to degrees new_lat = Degrees(new_lat_rad); new_lon = Degrees(new_lon_rad); coords[i, 2] = new_lat coords[i, 1] = new_lon } return(coords) } ### #---BREWING KML---# ### #A 39.5-4.5 #E 44.75 -107.5 startLong = -4.5 startLat = 39.5 endLong = -107.5 endLat = 44.75 numberOfIntervals = 100 coords - GenerateLineSegments(startLong, startLat, endLong, endLat, numberOfIntervals) coords - as.data.frame(coords) names(coords) - c(Long, Lat) seg - data.frame(matrix(NA, nrow(coords) - 1, 5)) names(seg) - c(x, y, xend, yend, segment) for (i in 1 : (nrow(coords) - 1 ) ) { seg[i, ]$x = coords[i, ]$Long seg[i, ]$y = coords[i, ]$Lat seg[i, ]$xend = coords[i + 1, ]$Long seg[i, ]$yend = coords[i + 1, ]$Lat seg[i, ]$segment = paste(i) } #seg brew(file = LinesTemplate.xml, output = RKMLoutput.kml ) ...and the kml template file to be used with brewer: ?xml version=1.0 encoding=utf-8 ? kml xmlns=http://www.opengis.net/kml/2.2; Document Foldernamelines/name % for(i in 1:nrow(seg)){ % Placemark TimeSpan begin%= paste(1980+i, 01, 01, sep=-)%/begin /TimeSpan name%=paste(seg$x[i], ,, seg$y[i], : , seg$xend[i], ,, seg$yend[i], sep=)%/name StyleLineStylecolor7f9b/colorwidth3.5/width/LineStyle/Style LineString tessellate1/tessellate coordinates%=seg[i,]$x%, %=seg[i,]$y%, 0.0 %=seg[i,]$xend%, %=seg[i,]$yend%, 0.0 /coordinates/LineString /Placemark % } % /Folder /Document/kml What is going wrong here? -- while(!succeed) { try(); } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] splitting a square symmetric matrix
So many matrices are square symmetrical (i.e. variance-covariance matrices), is there any way to get R to split the matrix on its diagonal and just return one diagonal? So if I have mat-matrix(c(1,4,3,4,1,2,3,2,1), nrow = 3, ncol=3, byrow=TRUE) is there anyway to get the lower right diagonal instead of the entire symmetric matrix? --- Joe King, M.A. Ph.D. Student University of Washington - Seattle 206-913-2912 mailto:j...@joepking.com j...@joepking.com --- Ad astra per aspera - Through hardships to the stars [[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] adding text to y-axis per row of panels (lattice)
On Thu, 20-Jan-2011 at 10:34AM +0200, E Hofstadler wrote: | Dear all, | | Being a newbie to R, I've trawled through many old posts on this list | looking for a solution to my problem, but unfortunately couldn't quite | figure it out myself. I'd be very grateful if someone here on this | list could perhaps help me out. | | I have a lattice plot with several panels and would like to add some | text next to the y-axis on the right hand side of each row of panels. | This text should help the reader to interpret the value ranges of the | y-axis: so the range between -1 and 1 (in between the two reference | lines) should e.g. labelled balanced, the rest of the positive scale | as too high, and the rest of the negative scale as too low. The | text should be printed in parallel to the y-axis. | | If this was a base graphic plot, I'd use mtext, but I'm not sure how | to get to the same results when using lattice. | | Here is some example data: | | library(lattice) | varx - c(1:4,1:4,1:4,1:4) | vary - c(2,2,1.5,0.3,1,2,3,4,-1,-0.5,3,-1,-1,-0.5,1,-3) | condvar - c(1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4) | exampledata -data.frame(cbind(varx,vary,condvar)) | exampledata | xyplot(vary~varx|condvar, type=o,data=exampledata, | scales=list(alternating=F,x=list(at=c(1,2,3,4)), | y=list(at=c(-3,-1,0,1,3))), | panel=function(x,y,...){ panel.abline(h=-1) | panel.abline(h=1) | panel.xyplot(x,y,...) | }) What you want to do would probably require some tricky coding with grid functions. I think it would be easier, and more effective to shade the area you want to highlight like this (after you install latticeExtra:) install.packages(latticeExtra) require(latticeExtra) xyplot(vary ~ varx|condvar, type=o, data = exampledata, scales = list(alternating = FALSE, x = list(at=c(1,2,3,4)), y = list(at=c(-3,-1,0,1,3))), panel = function(x, y, ...){ panel.xyarea(x = c(0,4.5,4.5,0), y = c(-1, -1, 1, 1), col = grey, border = grey) panel.xyplot(x,y,...) } ) If you prefer, you could shade the too high and too low areas. (You could even use different colours. You'll notice that I've extended the polygon to be outside the plotting range. It has the advantage of avoiding a bug that leaves a vertical line at the beginning. I've not tried it before, and you might find a more elegant way of avoiding it. | | | | Any help is greatly appreciated! HTH -- Patrick Connolly Plant Food Research Mt Albert Auckland New Zealand Ph: +64-9 925 7079 ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~ I have the world`s largest collection of seashells. I keep it on all the beaches of the world ... Perhaps you`ve seen it. ---Steven Wright ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot2, geom_hline and facet_grid
Ok, that's a known bug: https://github.com/hadley/ggplot2/issues/labels/facet#issue/96 Thanks for the reproducible example though! Hadley On Thu, Jan 20, 2011 at 3:46 AM, Sandy Small sandy.sm...@nhs.net wrote: Thank you. That seems to work - also on my much larger data set. I'm not sure I understand why it has to be defined as a factor, but if it works... Sandy Dennis Murphy wrote: Hi Sandy: I can reproduce your problem given the data provided. When I change ecd_rhythm from character to factor, it works as you intended. str(lvefeg) List of 4 ### Interesting... $ cvd_basestudy: chr [1:10] CBP05J02 CBP05J02 CBP05J02 CBP05J02 ... $ ecd_rhythm : chr [1:10] AF AF AF AF ... $ fixed_time : num [1:10] 30.9 33.2 32.6 32.1 30.9 ... $ variable_time: num [1:10] 29.4 32 30.3 33.7 28.3 ... - attr(*, row.names)= int [1:10] 1 2 3 4 5 6 7 9 10 11 class(lvefeg) [1] cast_df data.frame lvefeg$ecd_rhythm - factor(lvefeg$ecd_rhythm) p - qplot((variable_time + fixed_time) /2 , variable_time - fixed_time, data = lvefeg, geom='point') p p + facet_grid(ecd_rhythm ~ .) + geom_hline(yintercept=0) Does that work on your end? (And thank you for the reproducible example. Using dput() allows us to see what you see, which is very helpful.) HTH, Dennis On Wed, Jan 19, 2011 at 1:30 PM, Small Sandy (NHS Greater Glasgow Clyde) [1]sandy.sm...@nhs.net wrote: Hi Still having problems in that when I use geom_hline and facet_grid together I get two extra empty panels A reproducible example can be found at: [2]https://gist.github.com/786894 Sandy Small From: [3]h.wick...@gmail.com [[4]h.wick...@gmail.com] On Behalf Of Hadley Wickham [[5]had...@rice.edu] Sent: 19 January 2011 15:11 To: Small Sandy (NHS Greater Glasgow Clyde) Cc: [6]r-help@r-project.org Subject: Re: [R] ggplot2, geom_hline and facet_grid Hi Sandy, It's difficult to know what's going wrong without a small reproducible example ([7]https://github.com/hadley/devtools/wiki/Reproducibility) - could you please provide one? You might also have better luck with an email directly to the ggplot2 mailing list. Hadley On Wed, Jan 19, 2011 at 2:57 AM, Sandy Small [8]sandy.sm...@nhs.net wrote: Having upgraded to R version 2.12.1 I still have the same problem: The combination of facet_grid and geom_hline produce (for me) 4 panels of which two are empty of any data or lines (labelled 1 and 2). Removing either the facet_grid or the geom_hline gives me the result I would then expect. I have tried forcing the rhythm to be a factor Anyone have any ideas? Sandy Dennis Murphy wrote: Hi: The attached plot comes from the following code: g - ggplot(data =f, aes(x = (variable_time + fixed_time)/2, y variable_time - fixed_time)) g + geom_point() + geom_hline(yintercept =) + facet_grid(ecd_rhythm ~ .) Is this what you were expecting? sessionInfo() R version 2.12.1 Patched (2010-12-18 r53869) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=glish_United States.1252 [2] LC_CTYPE=glish_United States.1252 [3] LC_MONETARY=glish_United States.1252 [4] LC_NUMERIC=nbsp; [5] LC_TIME=glish_United States.1252 attached base packages: [1] splines stats graphics grDevices utils datasets grid [8] methods base other attached packages: [1] data.table_1.5.1 doBy_4.2.2 R2HTML_2.2 contrast_0.13 [5] Design_2.3-0 Hmisc_3.8-3 survival_2.36-2 sos_1.3-0 [9] brew_1.0-4 lattice_0.19-17 ggplot2_0.8.9 proto_0.3-8 [13] reshape_0.8.3 plyr_1.4 loaded via a namespace (and not attached): [1] cluster_1.13.2 digest_0.4.2 Matrix_0.999375-46 reshape2_1.1 [5] stringr_0.4 tools_2.12.1 HTH, Dennis On Tue, Jan 18, 2011 at 1:46 AM, Small Sandy (NHS Greater Glasgow Clyde) [9]sandy.sm...@nhs.net [10]ailto:sandy.sm...@nhs.net%22 wrote: Hi I have a long data set on which I want to do Bland-Altman style plots for each rhythm type Using ggplot2, when I use geom_hline with facet_grid I get an extra set of empty panels. I can't get it to do it with the Diamonds data supplied with the package so here is a (much abbreviated) example: lvexs cvd_basestudy ecd_rhythm fixed_time variable_time 1 CBP05J02 AF 30.9000 29.4225 2 CBP05J02 AF 33.1700 32.0350 3 CBP05J02 AF 32.5700 30.2775 4 CBP05J02
Re: [R] splitting a square symmetric matrix
Joe P King wrote: So many matrices are square symmetrical (i.e. variance-covariance matrices), is there any way to get R to split the matrix on its diagonal and just return one diagonal? mat-matrix(c(1,4,3,4,1,2,3,2,1), nrow = 3, ncol=3, byrow=TRUE) is there anyway to get the lower right diagonal instead of the entire symmetric matrix? Is ?lower.tri what you're looking for? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ANOVA plotting
I'm not sure what a real ANOVA diagram is supposed to look like, nor do I know what your data look like. But this might get you started: fakedata - runif(100) fakegroups - sample(rep(letters[1:5], each=20)) boxplot(fakedata ~ fakegroups) If that isn't what you're after, a clearer explanation with a reproducible example would help us help you. Sarah On Thu, Jan 20, 2011 at 2:15 PM, Bulent Arikan bulent.ari...@gmail.com wrote: Dear List, I recently started using R and I have a simple question. I am running R (v. 2.12.1) and Rcmdr (v.1-6.3) on Mac (Snow Leopard). I am using a data set I used before for practicing ANOVA with R, so I know what the results should look like. I can get ANOVA table using both Rcmdr and GUI. However, I cannot make R prepare the ANOVA diagram (with boxplots, showing the data points, including the outliers) for the dataset. If I use Rcmdr (ModelsGraphs) then I get some graphical representation for the ANOVA model I prepared in R (showing diagnostic plots, Q-Q plots, etc.). However, the real ANOVA diagram is not coming up. I tried using plot command in GUI but did not get what I wanted. I could not find an answer to this on-line or in my book. I apologize if this was covered recently in the mailing list, I just became a member. Thanks for all the help! -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Regression Testing
On Thu, 20 Jan 2011, Mojo wrote: I'm new to R and some what new to the world of stats. I got frustrated with excel and found R. Enough of that already. I'm trying to test and correct for Heteroskedasticity I have data in a csv file that I load and store in a dataframe. ds - read.csv(book2.csv) df - data.frame(ds) I then preform a OLS regression: lmfit - lm(df$y~df$x) Just btw: lm(y ~ x, data = df) is somewhat easier to read and also easier to write when the formula involves more regressors. To test for Heteroskedasticity, I run the BPtest: bptest(lmfit) studentized Breusch-Pagan test data: lmfit BP = 11.6768, df = 1, p-value = 0.0006329 From the above, if I'm interpreting this correctly, there is Heteroskedasticity present. To correct for this, I need to calculate robust error terms. That is one option. Another one would be using WLS instead of OLS - or maybe FGLS. As the model just has one regressor, this might be possible and result in a more efficient estimate than OLS. From my reading on this list, it seems like I need to vcovHC. That's another option, yes. vcovHC(lmfit) (Intercept) df$x (Intercept) 1.057460e-03 -4.961118e-05 df$x -4.961118e-05 2.378465e-06 I'm having a little bit of a hard time following the help pages. Yes, the manual page is somewhat technical but the first thing the Details section does is: It points you to some references that should be easier to read. I recommend starting with Zeileis A (2004), Econometric Computing with HC and HAC Covariance Matrix Estimators. _Journal of Statistical Software_, *11*(10), 1-17. URL URL: http://www.jstatsoft.org/v11/i10/. That has also some worked examples. So is the first column the intercepts and the second column new standard errors? As David pointed out, it's the full covariance matrix estimate. hth, Z Thanks, mojo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Installing package in windows 7
Haseeb - thank you for republishing your solution. Prof Brian Ripley - thanks for pointing to my error. Best, Tal Contact Details:--- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) -- On Thu, Jan 20, 2011 at 3:38 PM, Haseeb Mahmud haseeb.mah...@gmail.comwrote: Haseeb [[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] splitting a square symmetric matrix
It looks like you might be asking for this. This gets the lower right diagonal. mat - matrix(c(1,4,3,4,1,2,3,2,1), nrow = 3, ncol=3, byrow=TRUE) mat [,1] [,2] [,3] [1,]143 [2,]412 [3,]321 diag(mat[rev(2:nrow(mat)),-1]) [1] 2 2 This gets the upper off-diagonal diag(mat[,-1]) [1] 4 2 Rich You can accomplish much with subscripting. Rich On Thu, Jan 20, 2011 at 4:20 PM, Joe P King j...@joepking.com wrote: So many matrices are square symmetrical (i.e. variance-covariance matrices), is there any way to get R to split the matrix on its diagonal and just return one diagonal? So if I have mat-matrix(c(1,4,3,4,1,2,3,2,1), nrow = 3, ncol=3, byrow=TRUE) is there anyway to get the lower right diagonal instead of the entire symmetric matrix? --- Joe King, M.A. Ph.D. Student University of Washington - Seattle 206-913-2912 mailto:j...@joepking.com j...@joepking.com --- Ad astra per aspera - Through hardships to the stars [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ANOVA plotting
I recently started using R and I have a simple question. I am running R (v. 2.12.1) and Rcmdr (v.1-6.3) on Mac (Snow Leopard). I am using a data set I used before for practicing ANOVA with R, so I know what the results should look like. I can get ANOVA table using both Rcmdr and GUI. However, I cannot make R prepare the ANOVA diagram (with boxplots, showing the data points, including the outliers) for the dataset. If I use Rcmdr (ModelsGraphs) then I get some graphical representation for the ANOVA model I prepared in R (showing diagnostic plots, Q-Q plots, etc.). However, the real ANOVA diagram is not coming up. I tried using plot command in GUI but did not get what I wanted. I could not find an answer to this on-line or in my book. I apologize if this was covered recently in the mailing list, I just became a member. Note that it is possible to do any Rcmdr menu operation from the command line simply by typing the command line output that results from doing the menu operation in Rcmdr. Observe the red text in the output window. The Rcmdr package supplies not only the Menu driven window, but some functions to accomplish the operations of the Window. Observe the red text in the output window. Assuming you want an interaction plot for 2-factor ANOVA and following on from Sarah's example paste the following code at the command line. Note that it makes use of the Rcmdr convenience function plotMeans() so you need the Rcmdr package loaded: library(Rcmdr) fakedata - runif(100) fakegroups - sample(rep(letters[1:5], each=20)) factor2 = sample(rep(letters[1:2], each=50)) plotMeans(df$data, df$groups, df$factor2, error.bars=se) For more information on how to use this function from the command line see its help file by typing ?plotMeans Hope you can generalize this if you were actually asking a different question. See posting guide for best practices on providing a reproducible example of what you want to accomplish. Rob __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.