[R] Interactions in 'MatchBalance' of the package 'Matching'
Hello together, In the package 'Matching' there ist a possibility to determine balance statistics after Matching with the function 'MatchBalance'. In this function there has a formula 'formul' to be given. I'm wondering how I can implement all two-way interactions, without specifying them explicitly. For example in logistic regression you can write y ~ (x1 + x2 + x3 + x4 + x5 + ...)^2 and R includes all two-way interactions. Is there such a possibility in 'MatchBalance', too? (Unfortunately, with the notation of logistic regression it doesn't work and I can't find an alternative in the help). Thank you very much in advance! Anna -- View this message in context: http://old.nabble.com/Interactions-in-%27MatchBalance%27-of-the-package-%27Matching%27-tp26473798p26473798.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] Removing + and ? signs
Jorge Ivan Velez wrote: And if you want to replace both + and ?, here is a suggestion: x - asdf+,jkl? gsub([?]|[+], , x) # [1] asdf,jkl Once you're into character classes ([]), you might as well go all the way: gsub([?+], , x) [1] asdf,jkl -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] dynlm predict with newdata?
On Sun, 22 Nov 2009, zubin wrote: Hello, can one use predict, as you can with other model objects like lm, with dynlm to predict a new data set that is identical in field names, just a different time period. Be nice if you could, I don't really want to create a new data set with all the lags, hoping it would generate dynamically. Does not seem to work, get a # of column error. Any suggestions? Currently, this is not possible, yet. It would indeed be nice if dynlm() could figure out which of the variables are determined by the response and predict these recursively, while the remaining variables would need to be provided (or even updated by auxiliary AR models). But currently, it's not clear to me how all these cases should be resolved exactly and how the additional formula parsing should be done, so it's not implemented yet. Sorry... Z R str(dfz) An 'xts' object from 2009-09-25 09:45:06 to 2009-10-19 15:00:57 containing: Data: num [1:28232, 1:8] 0.54771 -0.00825 1.27406 0.69705 1.08107 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:8] PC1 PC2 PC3 PC4 ... Indexed by objects of class: [POSIXt,POSIXct] TZ: GMT xts Attributes: NULL R str(z) An 'xts' object from 2009-10-21 09:45:04 to 2009-10-21 15:00:56 containing: Data: num [1:2304, 1:8] -0.5044 1.237 -0.7764 0.3931 0.0629 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:8] PC1 PC2 PC3 PC4 ... Indexed by objects of class: [POSIXt,POSIXct] TZ: GMT xts Attributes: NULL dols = dynlm(FAS0 ~ L(FAS0,1:10) + L(PC1,0:10) + L(PC2,0:10) + L(PC3,0:10) + L(PC4,0:10) + L(PC5,0:10) + L(PC6,0:10) + L(PC7,0:10), data=dfz) R predict(dols,newdata=z) /*Error in fix.by(by.x, x) : 'by' must match numbers of columns*/ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] FUN argument to return a vector in aggregate function
Hi All, I am currently doing the following to compute summary statistics of aggregated data: a = aggregate(warpbreaks$breaks, warpbreaks[,-1], mean) b = aggregate(warpbreaks$breaks, warpbreaks[,-1], sum) c = aggregate(warpbreaks$breaks, warpbreaks[,-1], length) ans = cbind(a, b[,3], c[,3]) This seems unnecessarily complex to me so I tried aggregate(warpbreaks$breaks, warpbreaks[,-1], function(z) c(mean(z),sum(z),length(z))) but aggregate doesn't allow FUN argument to return a vector. I tried by, tapply and several other functions as well but the output needed further modifications to get the same format as ans above. Is there any other function same as aggregate which allow FUN argument to return vector. Regards Utkarsh __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Downloading clim.pact package
Hi all, I am relatively a new user of R. I need assistance on how to download and install the clim.pact_2.2-39.zip. I am running R on Windows. -- ZABLONE OWITI GRADUATE STUDENT Nanjing University of Information, Science and Technology College of International Education __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] non-intuitive behaviour after type conversion
Deal list, I have a data frame (birth) with mixed variables (numeric and alphanumeric). One variable t1stvisit was originally coded as numeric with values 1,2, and 3. After attaching the data frame, this is what I see when I use str(t1stvisit) $ t1stvisit: int 1 1 1 1 1 1 1 1 2 2 ... This is as expected. I then convert t1stvisit to a factor and to avoid creating a second copy of this variable independent of the data frame I use: birth$t1stvisit = as.factor(birth$t1stvisit) if I check that the conversion has worked: is.factor(t1stvisit) [1] FALSE Now the only object present in the workspace in the data frame birth and, as noted, I have not created any new variables. So why does R still treat t1stvisit as numeric? is.factor(t1stvisit) [1] FALSE Yet when I try the following: is.factor(birth$t1stvisit) [1] TRUE So, there appears to be two versions of t1stvisit - the original numeric version and the correct factor version although ls() only shows birth as present in the workspace. If I type: summary(t1stvisit) Min. 1st Qu. MedianMean 3rd Qu.Max.NA's 1.000 1.000 2.000 1.574 2.000 3.000 29.000 I get the numeric version, but if I try summary(birth$t1stvisit) 123 NA's 180 169 22 29 I get the factor version. Frankly I feel that this behaviour is non-intuitive and potentially problematic. Nor have I seen warnings about this in the various text books on R. Can anyone comment on why this should occur? Many thanks, Alan Kelly Dr. Alan Kelly Department of Public Health Primary Care Trinity College Dublin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] FUN argument to return a vector in aggregate function
On 11/23/2009 07:15 PM, utkarshsinghal wrote: Hi All, I am currently doing the following to compute summary statistics of aggregated data: a = aggregate(warpbreaks$breaks, warpbreaks[,-1], mean) b = aggregate(warpbreaks$breaks, warpbreaks[,-1], sum) c = aggregate(warpbreaks$breaks, warpbreaks[,-1], length) ans = cbind(a, b[,3], c[,3]) This seems unnecessarily complex to me so I tried aggregate(warpbreaks$breaks, warpbreaks[,-1], function(z) c(mean(z),sum(z),length(z))) but aggregate doesn't allow FUN argument to return a vector. I tried by, tapply and several other functions as well but the output needed further modifications to get the same format as ans above. Is there any other function same as aggregate which allow FUN argument to return vector. Hi Utkarsh, Does this do what you want? data(warpbreaks) library(prettyR) # can't use length as it doesn't have na.rm argument brkdn(breaks~wool+tension,warpbreaks, num.desc=c(mean,sum,valid.n)) 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] MASS loading error
Erin Hodgess wrote: Hello again. I did the update and it worked well, except for one thing: the Rcmdr doesn't work anymore. Has that come up before please? Not that I know. But what does doesn't work anymore mean precisely? Uwe Thank you for all of your help. Sincerely, Erin Ligges lig...@statistik.tu-dortmund.de: Erin Hodgess wrote: Dear R People: I just installed R-2.10.0 on Karmic Koala Ubuntu, via the sudo apt-get install r-base, etc. However, when I try to install an Rcmdr Plugin package, I get the following: install.packages(RcmdrPlugin.qual,depen=TRUE) Warning in install.packages(RcmdrPlugin.qual, depen = TRUE) : argument 'lib' is missing: using '/usr/local/lib/R/site-library' Warning in install.packages(RcmdrPlugin.qual, depen = TRUE) : 'lib = /usr/local/lib/R/site-library' is not writable Would you like to create a personal library '~/R/i486-pc-linux-gnu-library/2.10' to install packages into? (y/n) y --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done also installing the dependency ‘qcc’ trying URL 'http://cran.opensourceresources.org/src/contrib/qcc_2.0.tar.gz' Content type 'application/x-gzip' length 163556 bytes (159 Kb) opened URL == downloaded 159 Kb trying URL 'http://cran.opensourceresources.org/src/contrib/RcmdrPlugin.qual_0.4.0.tar.gz' Content type 'application/x-gzip' length 3545 bytes opened URL == downloaded 3545 bytes * installing *source* package ‘qcc’ ... ** R ** data ** demo ** inst ** preparing package for lazy loading ** help *** installing help indices ** building package indices ... * DONE (qcc) * installing *source* package ‘RcmdrPlugin.qual’ ... ** R ** inst ** preparing package for lazy loading Warning: package 'Rcmdr' was built under R version 2.8.1 and help may not work correctly Loading required package: tcltk Loading Tcl/Tk interface ... done The Commander GUI is launched only in interactive sessions Attaching package: 'Rcmdr' The following object(s) are masked from package:tcltk : tclvalue Warning: package 'rgl' was built under R version 2.8.1 and help may not work correctly Warning: package 'abind' was built under R version 2.8.1 and help may not work correctly Error : This is R 2.10.0, package 'MASS' needs = 2.9.2 ERROR: lazy loading failed for package ‘RcmdrPlugin.qual’ * removing ‘/home/erin/R/i486-pc-linux-gnu-library/2.10/RcmdrPlugin.qual’ The downloaded packages are in ‘/tmp/RtmpioC2DR/downloaded_packages’ Warning message: In install.packages(RcmdrPlugin.qual, depen = TRUE) : installation of package 'RcmdrPlugin.qual' had non-zero exit status The line that looks particularly strange is the 'MASS needs = 2.9.2. Erin, the MASS you have installed in one of your current libraries needs R = 2.9.2 (perhaps in /usr/local/lib/R/site-library ?) Please run update.packages(checkBuilt=TRUE) and packages in your library will be updated. If the one in /usr/local/lib/R/site-library can't be updated, because you do not have write permissions there, please remove it from the library path. Best, Uwe Ligges Could that be the problem, please? Thank you in advance for any help. Sincerely, Erin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Odp: FUN argument to return a vector in aggregate function
Hi r-help-boun...@r-project.org napsal dne 23.11.2009 09:15:02: Hi All, I am currently doing the following to compute summary statistics of aggregated data: a = aggregate(warpbreaks$breaks, warpbreaks[,-1], mean) b = aggregate(warpbreaks$breaks, warpbreaks[,-1], sum) c = aggregate(warpbreaks$breaks, warpbreaks[,-1], length) ans = cbind(a, b[,3], c[,3]) This seems unnecessarily complex to me so I tried aggregate(warpbreaks$breaks, warpbreaks[,-1], function(z) c(mean(z),sum(z),length(z))) but aggregate doesn't allow FUN argument to return a vector. I tried by, tapply and several other functions as well but the output needed further modifications to get the same format as ans above. It is work for sapply/split. sapply(split(warpbreaks$breaks, warpbreaks[,-1]), function(x) c(mean(x), sum(x), length(x))) A.L B.L A.M B.M A.H B.H [1,] 44.6 28.2 24 28.8 24.6 18.8 [2,] 401.0 254.0 216 259.0 221.0 169.0 [3,] 9.0 9.0 9 9.0 9.0 9.0 Regards Petr Is there any other function same as aggregate which allow FUN argument to return vector. Regards Utkarsh __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 tell if its better to standardize your data matrix first when you do principal
masterinex wrote: Hi Hadley , I really apreciate the suggestions you gave, It was helpful , but I still didnt quite get it all. and I really want to do a good job , so any comments would sure come helpful, please understand me . Well, we try to understand you, but we do not either. I think you really nedc to consult some statistics textbook on PCA if my answer was not sufficient. Given your questions, I doubt you understand what PCA does and how it works. It does not predict anything. Uwe Ligges hadley wrote: You've asked the same question on stackoverflow.com and received the same answer. This is rude because it duplicates effort. If you urgently need a response to a question, perhaps you should consider paying for it. Hadley On Sun, Nov 22, 2009 at 12:04 PM, masterinex xevilgan...@hotmail.com wrote: so under which cases is it better to standardize the data matrix first ? also is PCA generally used to predict the response variable , should I keep that variable in my data matrix ? Uwe Ligges-3 wrote: masterinex wrote: Hi guys , Im trying to do principal component analysis in R . There is 2 ways of doing it , I believe. One is doing principal component analysis right away the other way is standardizing the matrix first using s = scale(m)and then apply principal component analysis. How do I tell what result is better ? What values in particular should i look at . I already managed to find the eigenvalues and eigenvectors , the proportion of variance for each eigenvector using both methods. Generally, it is better to standardize. But in some cases, e.g. for the same units in your variables indicating also the importance, it might make sense not to do so. You should think about the analysis, you cannot know which result is `better' unless you know an interpretation. I noticed that the proportion of the variance for the first pca without standardizing had a larger value . Is there a meaning to it ? Isnt this always the case? At last , if I am supposed to predict a variable ie weight should I drop the variable ie weight from my data matrix when I do principal component analysis ? This sounds a bit like homework. If that is the case, please ask your teacher rather than this list. Anyway, it does not make sense to predict weight using a linear combination (principle component) that contains weight, does it? 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. -- View this message in context: http://old.nabble.com/how-to-tell-if-its-better-to-standardize-your-data-matrix-first-when-you-do-principal-tp26462070p26466400.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. -- 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-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Computing multivariate normal probabilities. Was: Re: Problem with Numerical derivatives (numDeriv) and mvtnorm
On Sun, 22 Nov 2009, Ravi Varadhan wrote: Hi Torsten, Hi Ravi, It would be useful to warn the users that the multivariate normal probability calculated by pmvnorm using the GenzBretz algorithm is random, i.e. the result can vary between repeated executions of the function. only if a different seed is used. This would prevent inappropriate use of pmvnorm such as computing derivatives of it (see this email thread). ?pmvt has Randomized quasi-Monte Carlo methods are used for the computations. and appropriate references. In addition, the new book by Alan Genz and Frank Bretz covers all technical details in depth, so the procedures are well documented. Anyway, I'll add a statement to ?pmvnorm. Best wishes, Torsten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 tell if its better to standardize your data matrix first when you do principal
masterinex wrote: this is how my data matrix looks like . This is just for the first 10 observations , but the pattern is similar for the other observations. 112.3 154.25 67.75 36.2 93.1 85.2 94.5 59.0 37.3 21.9 32.0 27.4 17.1 2 6.1 173.25 72.25 38.5 93.6 83.0 98.7 58.7 37.3 23.4 30.5 28.9 18.2 325.3 154.00 66.25 34.0 95.8 87.9 99.2 59.6 38.9 24.0 28.8 25.2 16.6 410.4 184.75 72.25 37.4 101.8 86.4 101.2 60.1 37.3 22.8 32.4 29.4 18.2 528.7 184.25 71.25 34.4 97.3 100.0 101.9 63.2 42.2 24.0 32.2 27.7 17.7 620.9 210.25 74.75 39.0 104.5 94.4 107.8 66.0 42.0 25.6 35.7 30.6 18.8 719.2 181.00 69.75 36.4 105.1 90.7 100.3 58.4 38.3 22.9 31.9 27.8 17.7 812.4 176.00 72.50 37.8 99.6 88.5 97.1 60.0 39.4 23.2 30.5 29.0 18.8 9 4.1 191.00 74.00 38.1 100.9 82.5 99.9 62.9 38.3 23.8 35.9 31.1 18.2 10 11.7 198.25 73.50 42.1 99.6 88.6 104.1 63.1 41.7 25.0 35.6 30.0 19.2 and after standardizing it . 1 -0.831228836 -0.898881671 -0.98330178 -0.77420686 -0.952294055 -0.712961621 -0.814552365 -0.0625400993 -0.53901713 -0.825399059 -0.08244945 2 -1.588060506 -0.185928394 0.75868364 0.23560461 -0.889886435 -0.931523054 -0.155497233 -0.1252522485 -0.53901713 0.295114747 -0.59529632 30.755676279 -0.908262635 -1.56396359 -1.74011349 -0.615292906 -0.444727135 -0.077038289 0.0628841989 0.15515266 0.743320270 -1.17652277 4 -1.063161122 0.245595958 0.75868364 -0.24734870 0.133598535 -0.593746294 0.236797489 0.1674044475 -0.53901713 -0.153090775 0.05430971 51.170713001 0.226834030 0.37157577 -1.56449410 -0.428070046 0.757360745 0.346640011 0.8154299886 1.58687786 0.743320270 -0.01406987 60.218569932 1.202454304 1.72645331 0.45512884 0.470599683 0.201022552 1.27244 1.4007433805 1.50010664 1.938534997 1.18257281 70.011051571 0.104881496 -0.20908604 -0.68639717 0.545488828 -0.166558039 0.095571389 -0.1879643976 -0.10516101 -0.078389855 -0.11663925 8 -0.819021874 -0.082737788 0.85546060 -0.07172932 -0.140994994 -0.385119472 -0.406565855 0.1465003978 0.37208072 0.145712907 -0.59529632 9 -1.832199755 0.480120063 1.43612241 0.05998522 0.021264819 -0.981196107 0.032804234 0.7527178395 -0.10516101 0.593918429 1.25095239 10 -0.904470611 0.752168024 1.24256848 1.81617909 -0.140994994 -0.375184861 0.691859366 0.7945259389 1.36994980 1.490329474 1.14838302 this is the result of applying PCA to the data matrix Standard deviations: [1] 30.6645414 7.5513852 3.6927427 2.8703435 2.5363007 1.9136933 1.5624131 1.3689630 1.2976189 [10] 1.1633458 1.1118231 0.7847148 0.4802303 Rotation: PC1 PC2 PC3 PC4 PC5 PC6 PC7 PC8 var1 0.18110712 -0.74864138 -0.46070566 -0.365658769 0.192810075 -0.132529979 0.023764851 0.03674873 var2 0.86458284 0.34243386 -0.05766909 -0.235504989 -0.046075934 0.001493006 -0.024535011 0.13439659 var3 0.03765598 0.20097537 -0.15709612 -0.343218776 -0.295201121 -0.073295697 -0.086930370 -0.54389141 var40.05965733 0.01737951 0.09854179 -0.030801791 0.125735684 0.341795876 -0.001735808 0.37152696 var5 0.23845698 -0.20616399 0.68948870 0.025904812 0.391188182 -0.428933369 -0.101780281 -0.16965893 var6 0.29928369 -0.47394636 0.24791449 0.341235161 -0.511378719 0.447071255 -0.077534385 -0.13198544 var7 0.19503685 0.01385823 -0.24126047 0.531403827 -0.127426510 -0.410568454 0.608163973 -0.01265457 var8 0.13261863 0.06839078 -0.37740589 0.535332339 0.366103479 0.032376851 -0.574484605 -0.05645694 var90.06246705 0.04407384 -0.09545362 0.037993146 -0.036651080 0.012347288 -0.192976142 -0.13027876 var10 0.03027791 0.05533988 -0.03749859 -0.009257423 0.011026593 -0.010770032 -0.104041067 0.12125263 var11 0.07435322 0.04334969 -0.02666944 0.032036374 0.464035624 0.454970952 0.347507539 -0.60527541 var12 0.04328710 0.04731771 0.00360668 -0.054200633 0.275901346 0.297800123 0.324323749 0.30487145 var13 0.02095652 0.02146485 0.03598618 -0.022510780 0.005192075 0.103988977 0.031541374 0.07877455 PC9 PC10 PC11PC12 PC13 var1 -0.005328345 0.030549780 -0.049283616 -0.02211988 0.015660892 var2 0.170766596 -0.144031738 0.028862963 0.06984674 0.006293703 var3 -0.282549313 0.548650592 0.131284937 -0.14740722 -0.002384605 var4 0.024070488 0.614154008 -0.551480394 -0.03446124 -0.178123011 var5 -0.157551008 0.147685248 0.008044148 -0.04068258 0.007778992 var6 -0.058675551 0.006344813 0.130814072 -0.04088919 -0.028655330 var7 -0.099243751 0.171852216 -0.149231752 -0.06690208 -0.014693444 var80.006629025 0.199158097 0.187226774 -0.02511968 0.070896819 var9-0.658214712 -0.320120384 -0.53990 0.37630539 -0.023642902 var10 -0.259704149 -0.273030750 -0.074006053 -0.83676032
Re: [R] Downloading clim.pact package
ZABLONE OWITI wrote: Hi all, I am relatively a new user of R. I need assistance on how to download and install the clim.pact_2.2-39.zip. I am running R on Windows. See the manual R Installation and Administration and afterwards read ?install.packages 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] Question about S4
Dear R-ers, I don't understand the following, maybe someone will help me explain: setClasss('A') [1] A new('a') Error in new(a) : trying to generate an object from a virtual class (a) setClass('b', contains='a') [1] b new('b') An object of class “b” S4 Type Object In what way is B more concrete than A so that it's possible do instantiate B but not A? I don't quite get it. B adds nothing to nothing, and yet it's instantiable, while it's base is not. Makes no sense to me. -- Hun __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] HTML help missing?
Thanks a lot for the hint! Antje Duncan Murdoch wrote: On 20/11/2009 7:11 AM, Antje wrote: Hey there, I'm running R 2.10 on Windows XP (Professional) and I was wondering where the HTML help window disappeared? With earlier versions everything was fine. Now I get only this old-fashioned text windows without any links when I type ?some_function Can anybody help me? Edit the R_HOME/etc/Rprofile.site file to uncomment the line options(help_type=html) (or just install the patched version, this installer bug was discovered after release). Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Question about S4
PS. All class names were upper-case, I messed up while copying the code, but it has no effect on the result. Thanks for help. --Hun On Mon, 23 Nov 2009 10:28:37 +0100 Hun S. Tesatte hunsynte...@hush.com wrote: Dear R-ers, I don't understand the following, maybe someone will help me explain: setClasss('A') [1] A new('a') Error in new(a) : trying to generate an object from a virtual class (a) setClass('b', contains='a') [1] b new('b') An object of class “b” S4 Type Object In what way is B more concrete than A so that it's possible do instantiate B but not A? I don't quite get it. B adds nothing to nothing, and yet it's instantiable, while it's base is not. Makes no sense to me. -- Hun __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] MASS loading error
The Rcmdr menu does not appear. However, I tried an experiment: I downloaded the R-2.10.0.tar.gz file and installed via ./configure, make, and all was well for Rcmdr. Thanks, Erin 2009/11/23 Uwe Ligges lig...@statistik.tu-dortmund.de: Erin Hodgess wrote: Hello again. I did the update and it worked well, except for one thing: the Rcmdr doesn't work anymore. Has that come up before please? Not that I know. But what does doesn't work anymore mean precisely? Uwe Thank you for all of your help. Sincerely, Erin Ligges lig...@statistik.tu-dortmund.de: Erin Hodgess wrote: Dear R People: I just installed R-2.10.0 on Karmic Koala Ubuntu, via the sudo apt-get install r-base, etc. However, when I try to install an Rcmdr Plugin package, I get the following: install.packages(RcmdrPlugin.qual,depen=TRUE) Warning in install.packages(RcmdrPlugin.qual, depen = TRUE) : argument 'lib' is missing: using '/usr/local/lib/R/site-library' Warning in install.packages(RcmdrPlugin.qual, depen = TRUE) : 'lib = /usr/local/lib/R/site-library' is not writable Would you like to create a personal library '~/R/i486-pc-linux-gnu-library/2.10' to install packages into? (y/n) y --- Please select a CRAN mirror for use in this session --- Loading Tcl/Tk interface ... done also installing the dependency ‘qcc’ trying URL 'http://cran.opensourceresources.org/src/contrib/qcc_2.0.tar.gz' Content type 'application/x-gzip' length 163556 bytes (159 Kb) opened URL == downloaded 159 Kb trying URL 'http://cran.opensourceresources.org/src/contrib/RcmdrPlugin.qual_0.4.0.tar.gz' Content type 'application/x-gzip' length 3545 bytes opened URL == downloaded 3545 bytes * installing *source* package ‘qcc’ ... ** R ** data ** demo ** inst ** preparing package for lazy loading ** help *** installing help indices ** building package indices ... * DONE (qcc) * installing *source* package ‘RcmdrPlugin.qual’ ... ** R ** inst ** preparing package for lazy loading Warning: package 'Rcmdr' was built under R version 2.8.1 and help may not work correctly Loading required package: tcltk Loading Tcl/Tk interface ... done The Commander GUI is launched only in interactive sessions Attaching package: 'Rcmdr' The following object(s) are masked from package:tcltk : tclvalue Warning: package 'rgl' was built under R version 2.8.1 and help may not work correctly Warning: package 'abind' was built under R version 2.8.1 and help may not work correctly Error : This is R 2.10.0, package 'MASS' needs = 2.9.2 ERROR: lazy loading failed for package ‘RcmdrPlugin.qual’ * removing ‘/home/erin/R/i486-pc-linux-gnu-library/2.10/RcmdrPlugin.qual’ The downloaded packages are in ‘/tmp/RtmpioC2DR/downloaded_packages’ Warning message: In install.packages(RcmdrPlugin.qual, depen = TRUE) : installation of package 'RcmdrPlugin.qual' had non-zero exit status The line that looks particularly strange is the 'MASS needs = 2.9.2. Erin, the MASS you have installed in one of your current libraries needs R = 2.9.2 (perhaps in /usr/local/lib/R/site-library ?) Please run update.packages(checkBuilt=TRUE) and packages in your library will be updated. If the one in /usr/local/lib/R/site-library can't be updated, because you do not have write permissions there, please remove it from the library path. Best, Uwe Ligges Could that be the problem, please? Thank you in advance for any help. Sincerely, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] boxplot question
Peter Ehlers wrote: If there's been an answer to this, I've missed it. Here's my take. Antje wrote: Hi there, I was wondering if anybody can explain to me why the boxplot ends up with different results in the following case: I have some integer data as a vector and I compare the stats of boxplot with the same data divided by a factor. I've attached a csv file with both data present (d1, d2). The factor is 34.16667. If I run the boxplot function on d1 I get the following stats: 0.848... 0.907... 0.936... 0.965... 1.024... For d2 I get these stats: 29 31 32 33 36 If I convert the stats of d1 with the factor, I get 29 31 32 33 35 Obviously different for the upper whisker. But why??? Antje Antje: Three comments: 1. I think your 'factor' is actually 205/6, not 34.16667. 2. This looks like another case of FAQ 7.31: # Let's take your d2 and create d1; I'll call them x and y: x - rep(c(29:38, 40), c(7, 24, 50, 71, 24, 12, 14, 7, 13, 5, 1)) y - x * 6 / 205 # x is your d2, sorted # y is your d1, sorted # The critical values are x[202:203] and y[202:203]; x[201:204] #[1] 35 35 36 36 # The boxplot stats are: sx - boxplot.stats(x)$stats sy - boxplot.stats(y)$stats # Calculate potential extent of upper whisker: ux - sx[4] + (sx[4] - sx[2]) * 1.5 #36 uy - sy[4] + (sy[4] - sy[2]) * 1.5 #1.053658536585366 # Is y[203] = uy? y[203] = uy #[1] FALSE #!!! y[202] = uy #[1] TRUE # For x: x[203] = ux #[1] TRUE And there's your answer: for y the whisker goes to y[202], not y[203], due to the inevitable imprecision in machine calculation. 3. last comment: I would not use boxplots for data like this. -Peter Ehlers Hi Peter, thanks a lot for your explanation! Now I understand the difference. I was using the boxplot statistic to filter outliers from my data. Do you have any suggestion for me what to use instead? (I tried to improve the estimation of mean and sd, when iteratively removing outliers by boxplot stats...) Antje __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] unable to use coplot function with zoo package
Readers, I have tried to use the zoo package to merge datasets and then use the coplot function, but the graph is not fully created. Only the panel data is shown. Command terminal output below, with csv files. What is the meaning of the warning message? Can anyone help please? rhelpatconference.jabber.org r 251 mandriva 2008 library(chron) library(zoo) z1-read.zoo(test1.csv,header=FALSE,sep=,,FUN=times) z2-read.zoo(test2.csv,header=FALSE,sep=,,FUN=times) z3-read.zoo(test3.csv,header=FALSE,sep=,,FUN=times) z4-(na.approx(merge(z1,z2,z3),time(z1))) coplot(z4$z2~z4$z1|z4$z3) Warning messages: 1: Index vectors are of different classes: integer times in: merge.zoo(e1, e2, all = FALSE, retclass = NULL) 2: Index vectors are of different classes: integer times in: merge.zoo(e1, e2, all = FALSE, retclass = NULL) 3: Index vectors are of different classes: integer times in: merge.zoo(e1, e2, all = FALSE, retclass = NULL) 4: Index vectors are of different classes: integer times in: merge.zoo(e1, e2, all = FALSE, retclass = NULL) 5: Index vectors are of different classes: integer times in: merge.zoo(e1, e2, all = FALSE, retclass = NULL) 6: Index vectors are of different classes: integer times in: merge.zoo(e1, e2, all = FALSE, retclass = NULL) z4$z1 09:50:01 09:50:30 09:50:44 09:51:00 09:51:27 09:51:30 09:52:00 09:52:10 320.61 325.43 320.48 315.53 314.63 313.73 316.11 323.88 09:52:30 09:52:54 331.65 328.48 z4$z2 09:50:01 09:50:30 09:50:44 09:51:00 09:51:27 09:51:30 09:52:00 09:52:10 404.7500 402.7450 400.7400 300.2450 199.7500 266.7867 333.8233 400.8600 09:52:30 09:52:54 402.8350 404.8100 z4$z3 09:50:01 09:50:30 09:50:44 09:51:00 09:51:27 09:51:30 09:52:00 09:52:10 166.120 175.770 185.420 198.395 211.370 214.820 218.270 221.720 09:52:30 09:52:54 228.370 235.020 test1.csv: 09:50:00,315.79 09:50:30,325.43 09:51:00,315.53 09:51:30,313.73 09:52:00,316.11 09:52:30,331.65 09:53:00,325.31 09:53:30,334.33 09:54:00,334.54 09:54:30,336.55 09:55:00,339.34 09:55:30,341.93 test2.csv: 09:50:01,404.75 09:50:44,400.74 09:51:27,199.75 09:52:10,400.86 09:52:54,404.81 09:53:41,404.36 09:54:20,406.11 09:55:03,408.85 test3.csv: 09:50:01,166.12 09:50:44,185.42 09:51:27,211.37 09:52:10,221.72 09:52:54,235.02 09:53:41,262.85 09:54:20,306.64 09:55:03,346.3 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Computing multivariate normal probabilities. Was: Re: Problem with Numerical derivatives (numDeriv) and mvtnorm
Hi Torsten, Thanks for you comment. If you have some free time to spare, partial derivatives with respect to bounds and correlation coefficients would be great for pmvnorm! In complex problems, optim is not very good at estimating the hessian numerically and first order derivatives help to build an OPG estimator, which is not very good as compared to an analytical hessian but still much better than the numerical hessian provided by optim i have found the problems I study. Best, Stephane 2009/11/23 Torsten Hothorn torsten.hoth...@stat.uni-muenchen.de: On Sun, 22 Nov 2009, Ravi Varadhan wrote: Hi Torsten, Hi Ravi, It would be useful to warn the users that the multivariate normal probability calculated by pmvnorm using the GenzBretz algorithm is random, i.e. the result can vary between repeated executions of the function. only if a different seed is used. This would prevent inappropriate use of pmvnorm such as computing derivatives of it (see this email thread). ?pmvt has Randomized quasi-Monte Carlo methods are used for the computations. and appropriate references. In addition, the new book by Alan Genz and Frank Bretz covers all technical details in depth, so the procedures are well documented. Anyway, I'll add a statement to ?pmvnorm. Best wishes, Torsten __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] interaction effects in a Linear model
On 11/23/2009 1:06 AM, ashok varma wrote: hello, i am fitting a Linear model using R. I have to fit the model considering all the interaction effects of order 1 of the independent variables. But I have 9 variables. So, it will be difficult for me to write all the 36 combinations in the model. Can anyone please help how to get this done in much smarter way?? This will include all main effects and two-way interactions: lm(Y ~ (A + B + C + D + E + F + G + H + I)^2, data=mydata) thanks a lot, Ashok Varma. [[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. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Speed up R code
Hi, Im new to R and having some trouble with my code - it works, its just very slow! Ive tried lots of things, but nothing quite seems to work, so any help and suggestions would be really appreciated! I want to calculate the marginal likelihood for every element of a row of a matrix and the corresponding element in every other row. Then sum these for each row, so I get an upper triangular matrix which consists of the sum of the marginal likelihoods for row i and row j. X-read.table() X1-as.matrix(X) mlr-function(X1,p,q,Vinv=1){ X2-X1^2 P-length(p) Q-length(q) Res-matrix(ncol=P,nrow=P) for(i in 1:(P-1)){ lpi-p[i] Y1-matrix(nrow=(P-i),ncol=Q) Y2-matrix(nrow=(P-i),ncol=Q) tB-matrix(nrow=(P-i),ncol=Q) for(j in (i+1):P){ lpj-p[j] for(k in 1:Q){ Y1[j-i,k]-sum(X1[c(i,j),k]) Y2[j-i,k]-sum(X2[c(i,j),k]) } tB[j-i,]-(lpi+lpj)*q } V1- (Vinv + tB)^(-1) c-tB/2 a1-1 + c b1-1 + (Y2 - V1*(Y1^2))/2 z-log(V1)/2 + lgamma(a1) - c*log.pi - a1*log(b1) Res[i,]-c(rep(NA,i),apply(z,1,sum)) } return(Res) } Its fine for a matrix of 100x100, but the data Im working with is 3538x116, and so this can take hours! Any help would be really appreciated! Thanks, Anna -- View this message in context: http://old.nabble.com/Speed-up-R-code-tp26474898p26474898.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] Speed up R code
Loops tend to dramatically increase computation time. You may re-write a vectorized version of your code if possible, i.e. use matrix algebra. Calculus is a lot faster if one can avoid loops (at least some of them) . Best, Stephane 2009/11/23 AnnaFowler a.fowle...@imperial.ac.uk: Hi, Im new to R and having some trouble with my code - it works, its just very slow! Ive tried lots of things, but nothing quite seems to work, so any help and suggestions would be really appreciated! I want to calculate the marginal likelihood for every element of a row of a matrix and the corresponding element in every other row. Then sum these for each row, so I get an upper triangular matrix which consists of the sum of the marginal likelihoods for row i and row j. X-read.table() X1-as.matrix(X) mlr-function(X1,p,q,Vinv=1){ X2-X1^2 P-length(p) Q-length(q) Res-matrix(ncol=P,nrow=P) for(i in 1:(P-1)){ lpi-p[i] Y1-matrix(nrow=(P-i),ncol=Q) Y2-matrix(nrow=(P-i),ncol=Q) tB-matrix(nrow=(P-i),ncol=Q) for(j in (i+1):P){ lpj-p[j] for(k in 1:Q){ Y1[j-i,k]-sum(X1[c(i,j),k]) Y2[j-i,k]-sum(X2[c(i,j),k]) } tB[j-i,]-(lpi+lpj)*q } V1- (Vinv + tB)^(-1) c-tB/2 a1-1 + c b1-1 + (Y2 - V1*(Y1^2))/2 z-log(V1)/2 + lgamma(a1) - c*log.pi - a1*log(b1) Res[i,]-c(rep(NA,i),apply(z,1,sum)) } return(Res) } Its fine for a matrix of 100x100, but the data Im working with is 3538x116, and so this can take hours! Any help would be really appreciated! Thanks, Anna -- View this message in context: http://old.nabble.com/Speed-up-R-code-tp26474898p26474898.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Calibration score for survival probability
Good afternoon! I need to evaluate the goodness-of-fit (aka calibration) for survival probability estimates from a Cox model. I tried to use 'calibrate' in the Design package but I'm not sure if it should/would produce what I need (ie a chi-sq type statistic with a table of expected vs observed probabilities). Any other functions I should be aware of? Also, has anybody come across an implementation of the statistic described in: A global goodness of fit statistic for Cox regression models by Parzen Lpisitz, Biometrics 55, 1999 Many thanks in advance Eleni Rapsomaniki Research Associate Strangeways Research Laboratory Department of Public Health and Primary Care University of Cambridge __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 bug in predict.randomForest()
The NEWS of the randomForest R library mention that version 4.5-13 fixed a bug in predict.randomForest() when newdata is a matrix with no rownames. Can anyone explain what were the consequences of this bug in the predictions? I think the bug was fixed with the new line if (is.null(rn)) rn - keep in file predict.randomForest.R I got predictions with the new version using a RF trained before version 4.5-13 and I can't see differences... Thanks, jaslqa __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] non-intuitive behaviour after type conversion
Alan Kelly wrote: Deal list, I have a data frame (birth) with mixed variables (numeric and alphanumeric). One variable t1stvisit was originally coded as numeric with values 1,2, and 3. After attaching the data frame, this is what I see when I use str(t1stvisit) actually, str(birth), I suspect, but not important. $ t1stvisit: int 1 1 1 1 1 1 1 1 2 2 ... This is as expected. I then convert t1stvisit to a factor and to avoid creating a second copy of this variable independent of the data frame I use: birth$t1stvisit = as.factor(birth$t1stvisit) if I check that the conversion has worked: is.factor(t1stvisit) [1] FALSE Now the only object present in the workspace in the data frame birth and, as noted, I have not created any new variables. So why does R still treat t1stvisit as numeric? is.factor(t1stvisit) [1] FALSE Yet when I try the following: is.factor(birth$t1stvisit) [1] TRUE So, there appears to be two versions of t1stvisit - the original numeric version and the correct factor version although ls() only shows birth as present in the workspace. If I type: summary(t1stvisit) Min. 1st Qu. MedianMean 3rd Qu.Max.NA's 1.000 1.000 2.000 1.574 2.000 3.000 29.000 I get the numeric version, but if I try summary(birth$t1stvisit) 123 NA's 180 169 22 29 I get the factor version. Frankly I feel that this behaviour is non-intuitive and potentially problematic. Nor have I seen warnings about this in the various text books on R. Can anyone comment on why this should occur? I haven't looked at discussions of 'attach()' for a while, since I rarely use it nowadays (I find with() more convenient most of the time), but Chapter 6 in 'An Introduction to R' does discuss it. There are indeed two versions of 'birth'. Your basic problem is which version of 'birth' is being modified. Hint: it's NOT the attached version. Small example: dat - data.frame(x=1:3) attach(dat) dat$y - 4:6 y #Error: object 'y' not found dat$y #[1] 4 5 6 BTW, you don't need as.factor(); use factor(). -Peter Ehlers Many thanks, Alan Kelly Dr. Alan Kelly Department of Public Health Primary Care Trinity College Dublin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 do i persuade IT to install R on PCs ?? ...and should I ??
On Sun, Nov 22, 2009 at 11:15 PM, David Winsemius dwinsem...@comcast.netwrote: On Nov 22, 2009, at 4:45 PM, stephen's mailinglist account wrote: On Sun, Nov 22, 2009 at 11:14 AM, frenchcr frenc...@btinternet.com wrote: Please help me persuade IT to install R on my computer! All suggestions welcome. Our IT department run scared when you mention software that they have no working experience of. I need to know the pros and cons of having R on corporate desktops. Please no funny stuff, this is quite a serious issue for us. Pros and cons would be good. Thanks. -- View this message in context: http://old.nabble.com/how-do-i-persuade-IT-to-install-R-on-PCs...and-should-Itp26464163p26464163.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. I requested to have R installed at work. For me it helped that I have a lot of non-standard technical packages anyway that are off radar for support from the IT department anyway - they only support for original install rights anyway. They wanted to know what the licence was - GPL is recognised and they don't run a mile. I did my homework and found some other people on a company research site were already using R so I could use that as justification. I had some code ready to run that could produce graphs easily that are very hard to do in Excel and require a lot of custom code (and even then aren't good). We do use some other stats packages anyway and are being encouraged to use proper packages rather than kludging through in Excel References like this (below) have been circulated at work which adds weight to arguments that we should not just accept the 'standard' Office install. Although I did not use this in my justification. @ARTICLE{, author = {B.D. McCullough and David A. Heiser}, I'm not surprised to see McCollough and Heiser's names on such an article. They have both a long track record of pointing out Excel's statistical deficiencies. (I don't they did so together in the past.) MS has turned a deaf ear to their efforts to point the way to correct methods. It is truly amazing that MS continues to ignore constrictive criticism and that such arrogance is compounded by corporate policies encouraging reliance on demonstrably faulty tools. The full list of articles documenting MS's resistance to statistical corrections would be much longer that just this one article and extends back more than a decade. title = {On the accuracy of statistical procedures in Microsoft Excel 2007}, journal = {Computational Statistics \ Data Analysis}, year = {2008}, volume = {52}, pages = {4570--4578}, number = {10} } ( http://dx.doi.org/10.1016/j.csda.2008.03.004) I use R via TINN-R (http://www.sciviews.org/Tinn-R/) on a Windows desktop. Stephen -- David Winsemius, MD Heritage Laboratories West Hartford, CT Further similar articles can be found at http://www.practicalstats.com/xlsstats/excelstats.html and in the same issue of Computional Statistics and data analysis regards Stephen [[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] boxplot question
Antje wrote: Peter Ehlers wrote: If there's been an answer to this, I've missed it. Here's my take. Antje wrote: Hi there, I was wondering if anybody can explain to me why the boxplot ends up with different results in the following case: I have some integer data as a vector and I compare the stats of boxplot with the same data divided by a factor. I've attached a csv file with both data present (d1, d2). The factor is 34.16667. If I run the boxplot function on d1 I get the following stats: 0.848... 0.907... 0.936... 0.965... 1.024... For d2 I get these stats: 29 31 32 33 36 If I convert the stats of d1 with the factor, I get 29 31 32 33 35 Obviously different for the upper whisker. But why??? Antje Antje: Three comments: 1. I think your 'factor' is actually 205/6, not 34.16667. 2. This looks like another case of FAQ 7.31: # Let's take your d2 and create d1; I'll call them x and y: x - rep(c(29:38, 40), c(7, 24, 50, 71, 24, 12, 14, 7, 13, 5, 1)) y - x * 6 / 205 # x is your d2, sorted # y is your d1, sorted # The critical values are x[202:203] and y[202:203]; x[201:204] #[1] 35 35 36 36 # The boxplot stats are: sx - boxplot.stats(x)$stats sy - boxplot.stats(y)$stats # Calculate potential extent of upper whisker: ux - sx[4] + (sx[4] - sx[2]) * 1.5 #36 uy - sy[4] + (sy[4] - sy[2]) * 1.5 #1.053658536585366 # Is y[203] = uy? y[203] = uy #[1] FALSE #!!! y[202] = uy #[1] TRUE # For x: x[203] = ux #[1] TRUE And there's your answer: for y the whisker goes to y[202], not y[203], due to the inevitable imprecision in machine calculation. 3. last comment: I would not use boxplots for data like this. -Peter Ehlers Hi Peter, thanks a lot for your explanation! Now I understand the difference. I was using the boxplot statistic to filter outliers from my data. Do you have any suggestion for me what to use instead? (I tried to improve the estimation of mean and sd, when iteratively removing outliers by boxplot stats...) Antje Removing outliers to 'improve ...' is always problematic. Perhaps you should not use mean or sd? Consider robust alternatives, e.g. median/IQR. This very much depends on the purpose of the analysis. See the taskview on Robust Statistical Methods. For outliers, there's pkg:outliers. I haven't used it. There seems to be quite a bit more: I got 277 hits from: library(sos) ???outlier -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] non-intuitive behaviour after type conversion
On Nov 23, 2009, at 7:34 AM, Peter Ehlers wrote: Alan Kelly wrote: Deal list, I have a data frame (birth) with mixed variables (numeric and alphanumeric). One variable t1stvisit was originally coded as numeric with values 1,2, and 3. After attaching the data frame, this is what I see when I use str(t1stvisit) actually, str(birth), I suspect, but not important. $ t1stvisit: int 1 1 1 1 1 1 1 1 2 2 ... This is as expected. I then convert t1stvisit to a factor and to avoid creating a second copy of this variable independent of the data frame I use: birth$t1stvisit = as.factor(birth$t1stvisit) if I check that the conversion has worked: is.factor(t1stvisit) [1] FALSE Now the only object present in the workspace in the data frame birth and, as noted, I have not created any new variables. So why does R still treat t1stvisit as numeric? is.factor(t1stvisit) [1] FALSE Yet when I try the following: is.factor(birth$t1stvisit) [1] TRUE So, there appears to be two versions of t1stvisit - the original numeric version and the correct factor version although ls() only shows birth as present in the workspace. If I type: summary(t1stvisit) Min. 1st Qu. MedianMean 3rd Qu.Max.NA's 1.000 1.000 2.000 1.574 2.000 3.000 29.000 I get the numeric version, but if I try summary(birth$t1stvisit) 123 NA's 180 169 22 29 I get the factor version. Frankly I feel that this behaviour is non-intuitive and potentially problematic. Nor have I seen warnings about this in the various text books on R. Can anyone comment on why this should occur? I haven't looked at discussions of 'attach()' for a while, since I rarely use it nowadays (I find with() more convenient most of the time), but Chapter 6 in 'An Introduction to R' does discuss it. There are indeed two versions of 'birth'. Your basic problem is which version of 'birth' is being modified. Hint: it's NOT the attached version. Small example: dat - data.frame(x=1:3) attach(dat) dat$y - 4:6 y #Error: object 'y' not found dat$y #[1] 4 5 6 BTW, you don't need as.factor(); use factor(). -Peter Ehlers Alan; Let me second Peter's advice. Attach creates more problems than it solves. When I ran his code above, I got output from y but it was not the 4:6 vector but something else that was in my workspace from a prior project. You should also be wary, however, of unexpected (to some of us newbies anyway) behavior with with: with(dat, z- x + y) dat x y 1 1 4 2 2 5 3 3 6 Since with is a function the assignment to z was local within that environment. More effective this way. dat$z - with(dat, x+y) dat x y z 1 1 4 5 2 2 5 7 3 3 6 9 -- David Many thanks, Alan Kelly Dr. Alan Kelly Department of Public Health Primary Care Trinity College Dublin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] dynlm predict with newdata?
The dyn package has a predict method that can typically be used to predict one step ahead (and you can use a loop to get multiple steps). To use just preface lm (or glm or any model fitting function in R that uses model.frame in the same way as lm). It works with zoo, zooreg, ts, its and irts class series. library(dyn) # this also pulls in zoo # generate test data set.seed(123) x - zooreg(rep(1, 10)) for(i in 2:10) x[i] - x[i-1] + rnorm(1) # fit model Lag - function(x, k = 1) lag(x, -k) mod - dyn$lm(x ~ Lag(x)) # perform prediction and plot x. - predict(mod, list(x = x)) plot(cbind(x, x.), col = 1:2, screen = 1) # get more info package?dyn ?dyn On Sun, Nov 22, 2009 at 9:43 PM, zubin binab...@bellsouth.net wrote: Hello, can one use predict, as you can with other model objects like lm, with dynlm to predict a new data set that is identical in field names, just a different time period. Be nice if you could, I don't really want to create a new data set with all the lags, hoping it would generate dynamically. Does not seem to work, get a # of column error. Any suggestions? R str(dfz) An 'xts' object from 2009-09-25 09:45:06 to 2009-10-19 15:00:57 containing: Data: num [1:28232, 1:8] 0.54771 -0.00825 1.27406 0.69705 1.08107 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:8] PC1 PC2 PC3 PC4 ... Indexed by objects of class: [POSIXt,POSIXct] TZ: GMT xts Attributes: NULL R str(z) An 'xts' object from 2009-10-21 09:45:04 to 2009-10-21 15:00:56 containing: Data: num [1:2304, 1:8] -0.5044 1.237 -0.7764 0.3931 0.0629 ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:8] PC1 PC2 PC3 PC4 ... Indexed by objects of class: [POSIXt,POSIXct] TZ: GMT xts Attributes: NULL dols = dynlm(FAS0 ~ L(FAS0,1:10) + L(PC1,0:10) + L(PC2,0:10) + L(PC3,0:10) + L(PC4,0:10) + L(PC5,0:10) + L(PC6,0:10) + L(PC7,0:10), data=dfz) R predict(dols,newdata=z) /*Error in fix.by(by.x, x) : 'by' must match numbers of columns*/ [[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] Calibration score for survival probability
Eleni Rapsomaniki wrote: Good afternoon! I need to evaluate the goodness-of-fit (aka calibration) for survival probability estimates from a Cox model. I tried to use 'calibrate' in the Design package but I'm not sure if it should/would produce what I need (ie a chi-sq type statistic with a table of expected vs observed probabilities). Any other functions I should be aware of? Also, has anybody come across an implementation of the statistic described in: A global goodness of fit statistic for Cox regression models by Parzen Lpisitz, Biometrics 55, 1999 Many thanks in advance Eleni Rapsomaniki Eleni, The Design package, and its replacement, the rms package, produces calibration curves but no chi-square test because we do not have a corresponding method for that. Formal tests are overused in this context anyway. An index such as the maximum or 90th percentile of absolute calibration error are often more useful. I have learned however that any statistical method that categorizes continuous variables (in this case, the predictions or the covariate space) is arbitrary and has many other problems. The calibrate functions in the rms package have a new option to obtain smooth calibration curves without grouping, by fitting spline hazard models during validation. Note that if you have done any model/variable selection you have to re-run such model building from scratch for each resample of the data, or the calibration plot will be over optimistic. calibrate() makes this automatic if doing backward stepdown variable selection. Many statisticians make the mistake of only validating the final selected model, which can only be done by one-time data splitting (which requires tens of thousands of observations to perform adequately). Frank Research Associate Strangeways Research Laboratory Department of Public Health and Primary Care University of Cambridge __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how do i persuade IT to install R on PCs ?? ...and should I ??
On Nov 23, 2009, at 7:47 AM, stephen's mailinglist account wrote: On Sun, Nov 22, 2009 at 11:15 PM, David Winsemius dwinsem...@comcast.net wrote: On Nov 22, 2009, at 4:45 PM, stephen's mailinglist account wrote: On Sun, Nov 22, 2009 at 11:14 AM, frenchcr frenc...@btinternet.com wrote: Please help me persuade IT to install R on my computer! All suggestions welcome. Our IT department run scared when you mention software that they have no working experience of. I need to know the pros and cons of having R on corporate desktops. Please no funny stuff, this is quite a serious issue for us. Pros and cons would be good. Thanks. -- I requested to have R installed at work. For me it helped that I have a lot of non-standard technical packages anyway that are off radar for support from the IT department anyway - they only support for original install rights anyway. They wanted to know what the licence was - GPL is recognised and they don't run a mile. I did my homework and found some other people on a company research site were already using R so I could use that as justification. I had some code ready to run that could produce graphs easily that are very hard to do in Excel and require a lot of custom code (and even then aren't good). We do use some other stats packages anyway and are being encouraged to use proper packages rather than kludging through in Excel References like this (below) have been circulated at work which adds weight to arguments that we should not just accept the 'standard' Office install. Although I did not use this in my justification. @ARTICLE{, author = {B.D. McCullough and David A. Heiser}, I'm not surprised to see McCollough and Heiser's names on such an article. They have both a long track record of pointing out Excel's statistical deficiencies. (I don't they did so together in the past.) MS has turned a deaf ear to their efforts to point the way to correct methods. It is truly amazing that MS continues to ignore constrictive criticism and that such arrogance is compounded by corporate policies encouraging reliance on demonstrably faulty tools. The full list of articles documenting MS's resistance to statistical corrections would be much longer that just this one article and extends back more than a decade. title = {On the accuracy of statistical procedures in Microsoft Excel 2007}, journal = {Computational Statistics \ Data Analysis}, year = {2008}, volume = {52}, pages = {4570--4578}, number = {10} } -- David Winsemius, MD Further similar articles can be found at http://www.practicalstats.com/xlsstats/excelstats.html and in the same issue of Computional Statistics and data analysis It was a good read. We had a recent example submitted to r-help where I had occasion to test their solution 2 (use OO.org' Calc) and found it to be just as bad at curve fitting for a polynomial as had been Excel. Take a look at the pdf attached to this r-help item: https://stat.ethz.ch/pipermail/r-help/2009-November/218005.html regards Stephen David Winsemius, MD Heritage Laboratories West Hartford, CT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R: Re: chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails
simona.racio...@libero.it wrote: It works! But Once I have the square root of this matrix, how do I convert it to a real (not imaginary) matrix which has the same property? Is that possible? No. That is theoretically impossible. If A = B'B, then x'Ax = ||Bx||^2 = 0 for any x, which implies in particular that all eigenvalues of A should be nonnegative. Best, Simon Messaggio originale Da: p.dalga...@biostat.ku.dk Data: 21-nov-2009 18.56 A: Charles C. Berrycbe...@tajo.ucsd.edu Cc: simona.racio...@libero.itsimona.racio...@libero.it, r-h...@r- project.org Ogg: Re: [R] chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails Charles C. Berry wrote: On Sat, 21 Nov 2009, simona.racio...@libero.it wrote: Hi Everyone, I need to take the square root of the following matrix: [,1] [,2][,3] [1,] 0.5401984 -0.3998675 -1.3785897 [2,] -0.3998675 1.0561872 0.8158639 [3,] -1.3785897 0.8158639 1.6073119 I tried Choleski which fails. I then tried Choleski with pivoting, but unfortunately the square root I get is not valid. I also tried eigen decomposition but i did no get far. Any clue on how to do it?! If you want to take the square root of a negative definite matrix, you could use sqrtm( neg.def.mat ) from the expm package on rforge: http://r-forge.r-project.org/projects/expm/ But that matrix is not negative definite! It has 2 positive and one negative eigenvalue. It is non-positive definite. It is fairly easy in any case to get a matrix square root from the eigen decomposition: v%*%diag(sqrt(d+0i))%*%t(v) [,1] [,2] [,3] [1,] 0.5164499+0.4152591i -0.1247682-0.0562317i -0.7257079+0.3051868i [2,] -0.1247682-0.0562317i 0.9618445+0.0076145i 0.3469916-0.0413264i [3,] -0.7257079+0.3051868i 0.3469916-0.0413264i 1.0513849+0.2242912i ch - v%*%diag(sqrt(d+0i))%*%t(v) t(ch)%*% ch [,1] [,2] [,3] [1,] 0.5401984+0i -0.3998675-0i -1.3785897-0i [2,] -0.3998675-0i 1.0561872+0i 0.8158639-0i [3,] -1.3785897-0i 0.8158639-0i 1.6073119-0i A triangular square root is, er, more difficult, but hardly impossible. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] unable to use coplot function with zoo package
You have no complete rows so how could it plot anything? If you had some complete rows then this should work: coplot(z1 ~ z2 | z3, as.data.frame(z4)) Lines1 - 09:50:00,315.79 09:50:30,325.43 09:51:00,315.53 09:51:30,313.73 09:52:00,316.11 09:52:30,331.65 09:53:00,325.31 09:53:30,334.33 09:54:00,334.54 09:54:30,336.55 09:55:00,339.34 09:55:30,341.93 Lines2 - 09:50:01,404.75 09:50:44,400.74 09:51:27,199.75 09:52:10,400.86 09:52:54,404.81 09:53:41,404.36 09:54:20,406.11 09:55:03,408.85 Lines3 - 09:50:01,166.12 09:50:44,185.42 09:51:27,211.37 09:52:10,221.72 09:52:54,235.02 09:53:41,262.85 09:54:20,306.64 09:55:03,346.3 library(zoo) library(chron) z1 - read.zoo(textConnection(Lines1), sep = ,, FUN = times) z2 - read.zoo(textConnection(Lines2), sep = ,, FUN = times) z3 - read.zoo(textConnection(Lines3), sep = ,, FUN = times) z4 - merge(z1, z2, z3) z4 z1 z2 z3 09:50:00 315.79 NA NA 09:50:01 NA 404.75 166.12 09:50:30 325.43 NA NA 09:50:44 NA 400.74 185.42 09:51:00 315.53 NA NA 09:51:27 NA 199.75 211.37 09:51:30 313.73 NA NA 09:52:00 316.11 NA NA 09:52:10 NA 400.86 221.72 09:52:30 331.65 NA NA 09:52:54 NA 404.81 235.02 09:53:00 325.31 NA NA 09:53:30 334.33 NA NA 09:53:41 NA 404.36 262.85 09:54:00 334.54 NA NA 09:54:20 NA 406.11 306.64 09:54:30 336.55 NA NA 09:55:00 339.34 NA NA 09:55:03 NA 408.85 346.30 09:55:30 341.93 NA NA packageDescription(zoo)$Version [1] 1.6-1 R.version.string # Windows Vista [1] R version 2.10.0 Patched (2009-11-21 r50532) On Mon, Nov 23, 2009 at 5:25 AM, e-letter inp...@gmail.com wrote: Readers, I have tried to use the zoo package to merge datasets and then use the coplot function, but the graph is not fully created. Only the panel data is shown. Command terminal output below, with csv files. What is the meaning of the warning message? Can anyone help please? rhelpatconference.jabber.org r 251 mandriva 2008 library(chron) library(zoo) z1-read.zoo(test1.csv,header=FALSE,sep=,,FUN=times) z2-read.zoo(test2.csv,header=FALSE,sep=,,FUN=times) z3-read.zoo(test3.csv,header=FALSE,sep=,,FUN=times) z4-(na.approx(merge(z1,z2,z3),time(z1))) coplot(z4$z2~z4$z1|z4$z3) Warning messages: 1: Index vectors are of different classes: integer times in: merge.zoo(e1, e2, all = FALSE, retclass = NULL) 2: Index vectors are of different classes: integer times in: merge.zoo(e1, e2, all = FALSE, retclass = NULL) 3: Index vectors are of different classes: integer times in: merge.zoo(e1, e2, all = FALSE, retclass = NULL) 4: Index vectors are of different classes: integer times in: merge.zoo(e1, e2, all = FALSE, retclass = NULL) 5: Index vectors are of different classes: integer times in: merge.zoo(e1, e2, all = FALSE, retclass = NULL) 6: Index vectors are of different classes: integer times in: merge.zoo(e1, e2, all = FALSE, retclass = NULL) z4$z1 09:50:01 09:50:30 09:50:44 09:51:00 09:51:27 09:51:30 09:52:00 09:52:10 320.61 325.43 320.48 315.53 314.63 313.73 316.11 323.88 09:52:30 09:52:54 331.65 328.48 z4$z2 09:50:01 09:50:30 09:50:44 09:51:00 09:51:27 09:51:30 09:52:00 09:52:10 404.7500 402.7450 400.7400 300.2450 199.7500 266.7867 333.8233 400.8600 09:52:30 09:52:54 402.8350 404.8100 z4$z3 09:50:01 09:50:30 09:50:44 09:51:00 09:51:27 09:51:30 09:52:00 09:52:10 166.120 175.770 185.420 198.395 211.370 214.820 218.270 221.720 09:52:30 09:52:54 228.370 235.020 test1.csv: 09:50:00,315.79 09:50:30,325.43 09:51:00,315.53 09:51:30,313.73 09:52:00,316.11 09:52:30,331.65 09:53:00,325.31 09:53:30,334.33 09:54:00,334.54 09:54:30,336.55 09:55:00,339.34 09:55:30,341.93 test2.csv: 09:50:01,404.75 09:50:44,400.74 09:51:27,199.75 09:52:10,400.86 09:52:54,404.81 09:53:41,404.36 09:54:20,406.11 09:55:03,408.85 test3.csv: 09:50:01,166.12 09:50:44,185.42 09:51:27,211.37 09:52:10,221.72 09:52:54,235.02 09:53:41,262.85 09:54:20,306.64 09:55:03,346.3 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] categorisation of continuous variables in R
Dear all, I'm looking for a function comparable to switch, to categorize a continuous variable in a few levels. Off course that can be done with a series of ifelse statements, but that looks rather clumsy. I looked at switch, but couldn't figure out how to use it for this. I guess that's not possible, as it only works with characters or integers, not with intervals. Basically, I'm looking for a clean way to do : test - runif(10,1,100) testFunc -function(x){ x - ifelse(test10,lowest, ifelse(10=test test 50,low, ifelse(50=test test 90,high, ifelse(90=test test100,highest,NA) ) ) ) return(as.factor(x)) } testFunc(test) Thank you in advance __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] FUN argument to return a vector in aggregate function
Try this: library(doBy) summaryBy(breaks ~ ., warpbreaks, FUN = c(mean, sum, length)) wool tension breaks.mean breaks.sum breaks.length 1A L44.6401 9 2A M24.0216 9 3A H24.6221 9 4B L28.2254 9 5B M28.8259 9 6B H18.8169 9 On Mon, Nov 23, 2009 at 3:15 AM, utkarshsinghal utkarsh.sing...@global-analytics.com wrote: Hi All, I am currently doing the following to compute summary statistics of aggregated data: a = aggregate(warpbreaks$breaks, warpbreaks[,-1], mean) b = aggregate(warpbreaks$breaks, warpbreaks[,-1], sum) c = aggregate(warpbreaks$breaks, warpbreaks[,-1], length) ans = cbind(a, b[,3], c[,3]) This seems unnecessarily complex to me so I tried aggregate(warpbreaks$breaks, warpbreaks[,-1], function(z) c(mean(z),sum(z),length(z))) but aggregate doesn't allow FUN argument to return a vector. I tried by, tapply and several other functions as well but the output needed further modifications to get the same format as ans above. Is there any other function same as aggregate which allow FUN argument to return vector. Regards Utkarsh __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] categorisation of continuous variables in R
Never mind, found the function : cut(test,breaks=c(0,10,50,90,100),labels=c(lowest,low,high,highest),include.lowest=T,right=F) Cheers Joris On Mon, Nov 23, 2009 at 2:14 PM, joris meys jorism...@gmail.com wrote: Dear all, I'm looking for a function comparable to switch, to categorize a continuous variable in a few levels. Off course that can be done with a series of ifelse statements, but that looks rather clumsy. I looked at switch, but couldn't figure out how to use it for this. I guess that's not possible, as it only works with characters or integers, not with intervals. Basically, I'm looking for a clean way to do : test - runif(10,1,100) testFunc -function(x){ x - ifelse(test10,lowest, ifelse(10=test test 50,low, ifelse(50=test test 90,high, ifelse(90=test test100,highest,NA) ) ) ) return(as.factor(x)) } testFunc(test) Thank you in advance __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] categorisation of continuous variables in R
On Nov 23, 2009, at 8:14 AM, joris meys wrote: Dear all, I'm looking for a function comparable to switch, to categorize a continuous variable in a few levels. ?cut Off course that can be done with a series of ifelse statements, but that looks rather clumsy. I looked at switch, but couldn't figure out how to use it for this. I guess that's not possible, as it only works with characters or integers, not with intervals. Basically, I'm looking for a clean way to do : test - runif(10,1,100) test - runif(10,1,100) testcut - cut(test, breaks=c(-Inf, 10, 50, 90, 100)) table(testcut) testcut (-Inf,10] (10,50] (50,90] (90,100] 1 4 5 0 testFunc -function(x){ x - ifelse(test10,lowest, ifelse(10=test test 50,low, ifelse(50=test test 90,high, ifelse(90=test test100,highest,NA) ) ) ) return(as.factor(x)) } testFunc(test) Thank you in advance -- David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how do i persuade IT to install R on PCs ?? ...and should I ??
On Mon, Nov 23, 2009 at 1:01 PM, David Winsemius dwinsem...@comcast.net wrote: It was a good read. We had a recent example submitted to r-help where I had occasion to test their solution 2 (use OO.org' Calc) and found it to be just as bad at curve fitting for a polynomial as had been Excel. Take a look at the pdf attached to this r-help item: https://stat.ethz.ch/pipermail/r-help/2009-November/218005.html Well, the OO.org guys are trying to make something compatible with a piece of MS software, but maybe this is taking it too far. I love the story that sections of Microsoft XML spec for Office says things like Do whatever Excel does, thus setting into stone the bugs inherent in that package as an ISO standard... Barry __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Check if string has all alphabets or numbers
Hi R users, I'd like to know if anyone has come across problems wherein it was necessary to check if strings contained all alphabets, some numbers or all numbers? In my attempt to test if a string is numeric, alpha-numeric (also includes if string is only alphabets) : # Reproducible R code below mywords- c(harry,met,sally,subway10,1800Movies,12345) mywords.alphanum -lapply(sapply(mywords,function(x)strsplit(x,NULL)),function(y) ifelse(sum(is.na(sapply(y,as.numeric))) == 0 length(y) 0,numeric,alpha-numeric)) names(mywords.alphanum)[(which(mywords.alphanum == numeric))] I understand that such one-liners (the second line of code above) that make multiple calls are discouraged, but I seem to find then fascinating. Looking forward to alternate solutions/packages for the above problem. Thanks Harsh Singhal [[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] Calibration score for survival probability
Dear Prof. Harrell, Thank you very much for your prompt and very helpful response. I guess that since a global statistic such as a chi-sq test is not applicable in this case, the calibration curve itself from the calibration() is the most informative alternative (most graphical methods reveal more information than a single statistic anyway!). I will try the updated version in the rms package to compare. Best Wishes Eleni Rapsomaniki Research Associate Strangeways Research Laboratory Department of Public Health and Primary Care University of Cambridge -Original Message- From: Frank E Harrell Jr [mailto:f.harr...@vanderbilt.edu] Sent: 23 November 2009 13:01 To: Eleni Rapsomaniki Cc: r-help@r-project.org Subject: Re: [R] Calibration score for survival probability Eleni Rapsomaniki wrote: Good afternoon! I need to evaluate the goodness-of-fit (aka calibration) for survival probability estimates from a Cox model. I tried to use 'calibrate' in the Design package but I'm not sure if it should/would produce what I need (ie a chi-sq type statistic with a table of expected vs observed probabilities). Any other functions I should be aware of? Also, has anybody come across an implementation of the statistic described in: A global goodness of fit statistic for Cox regression models by Parzen Lpisitz, Biometrics 55, 1999 Many thanks in advance Eleni Rapsomaniki Eleni, The Design package, and its replacement, the rms package, produces calibration curves but no chi-square test because we do not have a corresponding method for that. Formal tests are overused in this context anyway. An index such as the maximum or 90th percentile of absolute calibration error are often more useful. I have learned however that any statistical method that categorizes continuous variables (in this case, the predictions or the covariate space) is arbitrary and has many other problems. The calibrate functions in the rms package have a new option to obtain smooth calibration curves without grouping, by fitting spline hazard models during validation. Note that if you have done any model/variable selection you have to re-run such model building from scratch for each resample of the data, or the calibration plot will be over optimistic. calibrate() makes this automatic if doing backward stepdown variable selection. Many statisticians make the mistake of only validating the final selected model, which can only be done by one-time data splitting (which requires tens of thousands of observations to perform adequately). Frank Research Associate Strangeways Research Laboratory Department of Public Health and Primary Care University of Cambridge __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Check if string has all alphabets or numbers
try this: mywords- c(harry,met,sally,subway10,1800Movies,12345) grep(^[[:alpha:]]*$, mywords) # letters [1] 1 2 3 grep(^[[:digit:]]*$, mywords) # numbers [1] 6 On Mon, Nov 23, 2009 at 8:28 AM, Harsh singhal...@gmail.com wrote: Hi R users, I'd like to know if anyone has come across problems wherein it was necessary to check if strings contained all alphabets, some numbers or all numbers? In my attempt to test if a string is numeric, alpha-numeric (also includes if string is only alphabets) : # Reproducible R code below mywords- c(harry,met,sally,subway10,1800Movies,12345) mywords.alphanum -lapply(sapply(mywords,function(x)strsplit(x,NULL)),function(y) ifelse(sum(is.na(sapply(y,as.numeric))) == 0 length(y) 0,numeric,alpha-numeric)) names(mywords.alphanum)[(which(mywords.alphanum == numeric))] I understand that such one-liners (the second line of code above) that make multiple calls are discouraged, but I seem to find then fascinating. Looking forward to alternate solutions/packages for the above problem. Thanks Harsh Singhal [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Check if string has all alphabets or numbers
Added a little more: mywords- c(harry,met,sally,subway10,1800Movies,12345, not correct 123) all.letters - grep(^[[:alpha:]]*$, mywords) all.numbers - grep(^[[:digit:]]*$, mywords) # numbers mixed - grep(^[[:digit:][:alpha:]]*$, mywords) all.letters [1] 1 2 3 all.numbers [1] 6 # mixed setdiff(mixed, c(all.numbers, all.letters)) [1] 4 5 # not any of the above setdiff(seq(length(mywords)), c(mixed, all.numbers, all.letters)) [1] 7 On Mon, Nov 23, 2009 at 8:28 AM, Harsh singhal...@gmail.com wrote: Hi R users, I'd like to know if anyone has come across problems wherein it was necessary to check if strings contained all alphabets, some numbers or all numbers? In my attempt to test if a string is numeric, alpha-numeric (also includes if string is only alphabets) : # Reproducible R code below mywords- c(harry,met,sally,subway10,1800Movies,12345) mywords.alphanum -lapply(sapply(mywords,function(x)strsplit(x,NULL)),function(y) ifelse(sum(is.na(sapply(y,as.numeric))) == 0 length(y) 0,numeric,alpha-numeric)) names(mywords.alphanum)[(which(mywords.alphanum == numeric))] I understand that such one-liners (the second line of code above) that make multiple calls are discouraged, but I seem to find then fascinating. Looking forward to alternate solutions/packages for the above problem. Thanks Harsh Singhal [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how do i persuade IT to install R on PCs ?? ...and should I ??
On Nov 23, 2009, at 7:24 AM, Barry Rowlingson wrote: On Mon, Nov 23, 2009 at 1:01 PM, David Winsemius dwinsem...@comcast.net wrote: It was a good read. We had a recent example submitted to r-help where I had occasion to test their solution 2 (use OO.org' Calc) and found it to be just as bad at curve fitting for a polynomial as had been Excel. Take a look at the pdf attached to this r-help item: https://stat.ethz.ch/pipermail/r-help/2009-November/218005.html Well, the OO.org guys are trying to make something compatible with a piece of MS software, but maybe this is taking it too far. I love the story that sections of Microsoft XML spec for Office says things like Do whatever Excel does, thus setting into stone the bugs inherent in that package as an ISO standard... Barry Just to reinforce Baz' statement about OO.org, for those who have been around here for a while, you may recall this discussion back in 2003: https://stat.ethz.ch/pipermail/r-help/2003-June/034565.html https://stat.ethz.ch/pipermail/r-help/2003-June/034860.html Nothing has changed since then in OO.org's Calc version 3.1.1, which is the current release. On OSX, I can add Numbers from Apple's iWork '09 the mix: Formula: =4.145 * 100 + 0.5 Result: 415.00 Formula: =0.5 - 0.4 - 0.1 Result: -0.27755575615629 Formula: =(0.5 - 0.4 - 0.1) Result: -0.27755575615629 So FWIW, Apple has not made the same errors as MS and OO.org, at least in this narrow example. Also, here are two additional Excel resources: David Heiser's page: http://www.daheiser.info/excel/frontpage.html Patrick Burns' Spreadsheet Addition: http://www.burns-stat.com/pages/Tutor/spreadsheet_addiction.html HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Over-coloring facets on persp() plot
Thanks Duncan (and David). I couldn't get back to my computer until today. I understand it pretty well now and I'm able to get what I need. On a side note, I have had a hard time getting rgl to work. For the moment, I have to compile without libpng and ftfonts, and when I load the package I get an error related to OpenGL (from memory, something like no GLX extension found). I'll write more as soon as I'm able. Regards, Marc Chiarini Duncan Murdoch wrote: On 22/11/2009 1:07 AM, Marc Chiarini (Tufts) wrote: Dear R Community: Recently, I have managed to plot some really useful graphs of my research data using persp(). I have even figured out how to overplot rectangular regions (corresponding to submatrices) with a different color. This is accomplished by using par(new=T). I am now searching for a way to highlight a set of (possibly non-contiguous) facets with a specific color, e.g., the facet between each set of four points whose values are all above a certain threshold. An example would be coloring the raised corners of the classic sombrero (found in example(persp)) differently from the rest of the sombrero. I feel like the last example in persp() is pointing me in the right direction, but I'm not quite getting it. Any help is much appreciated. Think of the facets as an nx-1 by ny-1 matrix. Pass the col arg by creating a matrix of this shape. (A vector version of the data in the matrix would also be good enough.) If you pass something shorter, it will be recycled to that length. You could also use persp3d from the rgl package, but an important difference is that it colours all nx by ny vertices, and interpolates colours on the facets. So you can't use the same colour matrix as in persp. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 add a top level title to multiple plots
In the example below, is there any way to get the top title, i.e. Distribution Comparisons, in a bit from the top margin? Thanks agian - Original Message From: Jason Rupert jasonkrup...@yahoo.com To: Peter Ehlers ehl...@ucalgary.ca Cc: R Project Help R-help@r-project.org; Me jasonkrup...@yahoo.com Sent: Sat, November 21, 2009 12:31:04 AM Subject: Re: [R] How to add a top level title to multiple plots Cool. I ended up with the following: par(mfrow = c(2, 2)) # Plot 1 plot(rnorm(10),type=l,col=red) title(main = list(paste(Normal), col=black, cex = 1.0)) # Plot 2 plot(rpois(10, 4),type=l,col=blue) title(main = list(paste(Poison), col=black, cex = 1.0)) # Plot 3 plot(rnbinom(10, mu = 4, size = 100),type=l,col=green) title(main = list(paste(Binomial), col=black, cex = 1.0)) # Plot 4 plot(runif(10),type=l,col=black) title(main = list(paste(Uniform), col=black, cex = 1.0)) title(Distribution Comparisons, outer = TRUE) # c(bottom, left, top, right) par(oma=c(2,2,3,2)) Thanks again. - Original Message From: Peter Ehlers ehl...@ucalgary.ca To: Jason Rupert jasonkrup...@yahoo.com Cc: R-help@r-project.org Sent: Fri, November 20, 2009 5:23:33 PM Subject: Re: [R] How to add a top level title to multiple plots Jason Rupert wrote: How can I add an overall plot title to these four plots? I would like to have something that says, Distribution Comparisons: title(Distribution Comparisons, outer = TRUE) But you may have to make room for it with par(oma=...). -Peter Ehlers par(mfrow = c(2, 2)) # Plot 1 plot(rnorm(10),type=l,col=red) title(main = list(paste(Normal), col=black, cex = 1.0)) # Plot 2 plot(rpois(10, 4),type=l,col=blue) title(main = list(paste(Poison), col=black, cex = 1.0)) # Plot 3 plot(rnbinom(10, mu = 4, size = 100),type=l,col=green) title(main = list(paste(Binomial), col=black, cex = 1.0)) # Plot 4 plot(runif(10),type=l,col=black) title(main = list(paste(Uniform), col=black, cex = 1.0)) Thanks again for any feedback and insights. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Over-coloring facets on persp() plot
On 23/11/2009 8:55 AM, Marc Chiarini (Tufts) wrote: Thanks Duncan (and David). I couldn't get back to my computer until today. I understand it pretty well now and I'm able to get what I need. On a side note, I have had a hard time getting rgl to work. For the moment, I have to compile without libpng and ftfonts, and when I load the package I get an error related to OpenGL (from memory, something like no GLX extension found). I'll write more as soon as I'm able. You likely need to install OpenGL support on your system. (It might be in MesaGL.) Duncan Murdoch Regards, Marc Chiarini Duncan Murdoch wrote: On 22/11/2009 1:07 AM, Marc Chiarini (Tufts) wrote: Dear R Community: Recently, I have managed to plot some really useful graphs of my research data using persp(). I have even figured out how to overplot rectangular regions (corresponding to submatrices) with a different color. This is accomplished by using par(new=T). I am now searching for a way to highlight a set of (possibly non-contiguous) facets with a specific color, e.g., the facet between each set of four points whose values are all above a certain threshold. An example would be coloring the raised corners of the classic sombrero (found in example(persp)) differently from the rest of the sombrero. I feel like the last example in persp() is pointing me in the right direction, but I'm not quite getting it. Any help is much appreciated. Think of the facets as an nx-1 by ny-1 matrix. Pass the col arg by creating a matrix of this shape. (A vector version of the data in the matrix would also be good enough.) If you pass something shorter, it will be recycled to that length. You could also use persp3d from the rgl package, but an important difference is that it colours all nx by ny vertices, and interpolates colours on the facets. So you can't use the same colour matrix as in persp. Duncan Murdoch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Check if string has all alphabets or numbers
mywords- c(harry,met,sally,subway10,1800Movies,12345, not correct 123) all.letters - grep(^[[:alpha:]]*$, mywords) all.numbers - grep(^[[:digit:]]*$, mywords) # numbers mixed - grep(^[[:digit:][:alpha:]]*$, mywords) mywords- c(harry,met,sally,subway10,1800Movies,12345, not correct 123, ) mywords[grepl(^[[:digit:][:alpha:]]*$, mywords)] So maybe you should use mywords[grepl(^[[:digit:][:alpha:]]+$, mywords)] And grepl is highly recommended over grep. Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] other decriptive stats packages
are there any more packages that help decribe and explore data sets package tdisplay at http://forums.cirad.fr/logiciel-R/viewtopic.php?t=2409 Details: display-packageTool Box for Data Importation and Display import Import Data From External Data Bases (Access, Excel or Dbf formats) using package RODBC displayContents of Variables of a Data frame aggstatComplement to Aggregate univar Descriptive Statistics for a Continuous variable quant Quantiles for a Continuous variable ctab Cross Tabulation (table outputs) ctab2 Cross Tabulation (data frame outputs) splitbin Splits Binomial Data into Bernoulli Data (used in functions ctab and ctab2) [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to add a top level title to multiple plots
On Nov 23, 2009, at 8:58 AM, Jason Rupert wrote: In the example below, is there any way to get the top title, i.e. Distribution Comparisons, in a bit from the top margin? You could use instead: title(\nDistribution Comparisons, outer = TRUE) And please correct the spelling of Poisson. -- David Thanks agian - Original Message From: Jason Rupert jasonkrup...@yahoo.com To: Peter Ehlers ehl...@ucalgary.ca Cc: R Project Help R-help@r-project.org; Me jasonkrup...@yahoo.com Sent: Sat, November 21, 2009 12:31:04 AM Subject: Re: [R] How to add a top level title to multiple plots Cool. I ended up with the following: par(mfrow = c(2, 2)) # Plot 1 plot(rnorm(10),type=l,col=red) title(main = list(paste(Normal), col=black, cex = 1.0)) # Plot 2 plot(rpois(10, 4),type=l,col=blue) title(main = list(paste(Poison), col=black, cex = 1.0)) # Plot 3 plot(rnbinom(10, mu = 4, size = 100),type=l,col=green) title(main = list(paste(Binomial), col=black, cex = 1.0)) # Plot 4 plot(runif(10),type=l,col=black) title(main = list(paste(Uniform), col=black, cex = 1.0)) title(Distribution Comparisons, outer = TRUE) # c(bottom, left, top, right) par(oma=c(2,2,3,2)) Thanks again. - Original Message From: Peter Ehlers ehl...@ucalgary.ca To: Jason Rupert jasonkrup...@yahoo.com Cc: R-help@r-project.org Sent: Fri, November 20, 2009 5:23:33 PM Subject: Re: [R] How to add a top level title to multiple plots Jason Rupert wrote: How can I add an overall plot title to these four plots? I would like to have something that says, Distribution Comparisons: title(Distribution Comparisons, outer = TRUE) But you may have to make room for it with par(oma=...). -Peter Ehlers par(mfrow = c(2, 2)) # Plot 1 plot(rnorm(10),type=l,col=red) title(main = list(paste(Normal), col=black, cex = 1.0)) # Plot 2 plot(rpois(10, 4),type=l,col=blue) title(main = list(paste(Poison), col=black, cex = 1.0)) # Plot 3 plot(rnbinom(10, mu = 4, size = 100),type=l,col=green) title(main = list(paste(Binomial), col=black, cex = 1.0)) # Plot 4 plot(runif(10),type=l,col=black) title(main = list(paste(Uniform), col=black, cex = 1.0)) Thanks again for any feedback and insights. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Speed up R code
Thanks Stephane, Thats a great help! SL-16 wrote: Loops tend to dramatically increase computation time. You may re-write a vectorized version of your code if possible, i.e. use matrix algebra. Calculus is a lot faster if one can avoid loops (at least some of them) . Best, Stephane 2009/11/23 AnnaFowler a.fowle...@imperial.ac.uk: Hi, Im new to R and having some trouble with my code - it works, its just very slow! Ive tried lots of things, but nothing quite seems to work, so any help and suggestions would be really appreciated! I want to calculate the marginal likelihood for every element of a row of a matrix and the corresponding element in every other row. Then sum these for each row, so I get an upper triangular matrix which consists of the sum of the marginal likelihoods for row i and row j. X-read.table() X1-as.matrix(X) mlr-function(X1,p,q,Vinv=1){ X2-X1^2 P-length(p) Q-length(q) Res-matrix(ncol=P,nrow=P) for(i in 1:(P-1)){ lpi-p[i] Y1-matrix(nrow=(P-i),ncol=Q) Y2-matrix(nrow=(P-i),ncol=Q) tB-matrix(nrow=(P-i),ncol=Q) for(j in (i+1):P){ lpj-p[j] for(k in 1:Q){ Y1[j-i,k]-sum(X1[c(i,j),k]) Y2[j-i,k]-sum(X2[c(i,j),k]) } tB[j-i,]-(lpi+lpj)*q } V1- (Vinv + tB)^(-1) c-tB/2 a1-1 + c b1-1 + (Y2 - V1*(Y1^2))/2 z-log(V1)/2 + lgamma(a1) - c*log.pi - a1*log(b1) Res[i,]-c(rep(NA,i),apply(z,1,sum)) } return(Res) } Its fine for a matrix of 100x100, but the data Im working with is 3538x116, and so this can take hours! Any help would be really appreciated! Thanks, Anna -- View this message in context: http://old.nabble.com/Speed-up-R-code-tp26474898p26474898.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. -- View this message in context: http://old.nabble.com/Speed-up-R-code-tp26474898p26477645.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] Re adline()
Hello, I would like to ask you a question.I have a program in R and I use the readline method to ask the user some things,but i don´t use the R console but I use Win console then not appear what I put.I put the code as you look for: cat(1- 24horas\n) cat(2- 12horas\n) cat(3- 8horas\n) selection-readline(prompt=\nSelecciona numero de horas:) if(selection==1){ prediccion=exp(x.reconstruida[1441:1450]) } if(selection==2){ prediccion=exp(x.reconstruida[720:729]) } if(selection==3){ prediccion=exp(x.reconstruida[481:491]) } write.table(prediccion,C:\\Temp\\prePrueba.txt,quote=F,row.names=F,append=T,col.names=F) //end of code. Excuse me but my English is bad, i hope explained me well, A greeting, Ignacio. -- View this message in context: http://old.nabble.com/Readline%28%29-tp26476979p26476979.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] R: chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails
Thanks Chuck! It works! But Once I have the square root of this matrix, how do I convert it to a real (not imaginary) matrix which has the same property? Is that possible? Best, Simon Messaggio originale Da: cbe...@tajo.ucsd.edu Data: 21-nov-2009 18.11 A: simona.racio...@libero.itsimona.racio...@libero.it Cc: r-help@r-project.org Ogg: chol( neg.def.matrix ) WAS: Re: [R] Choleski and Choleski with pivoting of matrix fails On Sat, 21 Nov 2009, simona.racio...@libero.it wrote: Hi Everyone, I need to take the square root of the following matrix: [,1] [,2][,3] [1,] 0.5401984 -0.3998675 -1.3785897 [2,] -0.3998675 1.0561872 0.8158639 [3,] -1.3785897 0.8158639 1.6073119 I tried Choleski which fails. I then tried Choleski with pivoting, but unfortunately the square root I get is not valid. I also tried eigen decomposition but i did no get far. Any clue on how to do it?! If you want to take the square root of a negative definite matrix, you could use sqrtm( neg.def.mat ) from the expm package on rforge: http://r-forge.r-project.org/projects/expm/ HTH, Chuck Thanks, Simon __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide. html and provide commented, minimal, self-contained, reproducible code. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] R: Re: chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails
It works! But Once I have the square root of this matrix, how do I convert it to a real (not imaginary) matrix which has the same property? Is that possible? Best, Simon Messaggio originale Da: p.dalga...@biostat.ku.dk Data: 21-nov-2009 18.56 A: Charles C. Berrycbe...@tajo.ucsd.edu Cc: simona.racio...@libero.itsimona.racio...@libero.it, r-h...@r- project.org Ogg: Re: [R] chol( neg.def.matrix ) WAS: Re: Choleski and Choleski with pivoting of matrix fails Charles C. Berry wrote: On Sat, 21 Nov 2009, simona.racio...@libero.it wrote: Hi Everyone, I need to take the square root of the following matrix: [,1] [,2][,3] [1,] 0.5401984 -0.3998675 -1.3785897 [2,] -0.3998675 1.0561872 0.8158639 [3,] -1.3785897 0.8158639 1.6073119 I tried Choleski which fails. I then tried Choleski with pivoting, but unfortunately the square root I get is not valid. I also tried eigen decomposition but i did no get far. Any clue on how to do it?! If you want to take the square root of a negative definite matrix, you could use sqrtm( neg.def.mat ) from the expm package on rforge: http://r-forge.r-project.org/projects/expm/ But that matrix is not negative definite! It has 2 positive and one negative eigenvalue. It is non-positive definite. It is fairly easy in any case to get a matrix square root from the eigen decomposition: v%*%diag(sqrt(d+0i))%*%t(v) [,1] [,2] [,3] [1,] 0.5164499+0.4152591i -0.1247682-0.0562317i -0.7257079+0.3051868i [2,] -0.1247682-0.0562317i 0.9618445+0.0076145i 0.3469916-0.0413264i [3,] -0.7257079+0.3051868i 0.3469916-0.0413264i 1.0513849+0.2242912i ch - v%*%diag(sqrt(d+0i))%*%t(v) t(ch)%*% ch [,1] [,2] [,3] [1,] 0.5401984+0i -0.3998675-0i -1.3785897-0i [2,] -0.3998675-0i 1.0561872+0i 0.8158639-0i [3,] -1.3785897-0i 0.8158639-0i 1.6073119-0i A triangular square root is, er, more difficult, but hardly impossible. -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Excel-Export
Dear all, i use the following package/syntax to export data to excel: library(xlsReadWrite) write.xls( exportdata,pfad,colNames = TRUE,sheet = 1,from = 1,rowNames = FALSE ) Everything is fine, but the format of the export is not the best. For example, I every time have to adjust the column width. Furthermore there is no possibility to highlight some cell or make them colourful. I create a lot of such outputs and I want to have the sheets in a nicer format to make them better readable, especially for the people, who works with my files. Have you any suggestions to reach this target? Ideally I can do this within R and not in a second step via a VBA-Makro or something like this. Is there a possibility in R, e. g. with a package? I have the same problem with the package xtable for export to Latex. I am very happy about the packages, but it would be perfect, if I can adjust some things in this direction. Probably there are somes ways for a solution. I am very glad about references. Thank you very much in advance, Jens. -- View this message in context: http://old.nabble.com/Excel-Export-tp26477654p26477654.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] R-help Digest, Vol 81, Issue 23
Hi, keine ahnung. Das liegt jetzt bei Hr. Feld. Frag mal bei ihm nach. Grüße Thushyanthan r-help-requ...@r-project.org wrote: Send R-help mailing list submissions to r-help@r-project.org To subscribe or unsubscribe via the World Wide Web, visit https://stat.ethz.ch/mailman/listinfo/r-help or, via email, send a message with subject or body 'help' to r-help-requ...@r-project.org You can reach the person managing the list at r-help-ow...@r-project.org When replying, please edit your Subject line so it is more specific than Re: Contents of R-help digest... Today's Topics: 1. Define return values of a function (soeren.vo...@eawag.ch) 2. Re: Define return values of a function (baptiste auguie) 3. Re: python (Stefan Evert) 4. Re: other decriptive stats packages (Jakson A. Aquino) 5. Re: python (Jean Legeande) 6. Re: Over-coloring facets on persp() plot (Duncan Murdoch) 7. Re: other decriptive stats packages (Tal Galili) 8. Re: other decriptive stats packages (Tal Galili) 9. Re: Define return values of a function (David Winsemius) 10. Re: other decriptive stats packages (Liviu Andronic) 11. Re: Over-coloring facets on persp() plot (David Winsemius) 12. Re: Over-coloring facets on persp() plot (David Winsemius) 13. How to make a matrix of a number of factors? (Peng Yu) 14. Repeated measures unbalanced in a split-split design (Marcelo Laia) 15. Re: MASS loading error (Uwe Ligges) 16. How to make the assignment in a for-loop not affect variables outside the loop? (Peng Yu) 17. Re: How to make a matrix of a number of factors? (baptiste auguie) 18. Re: Metaplot Axis Annotation (Uwe Ligges) 19. Re: How to make the assignment in a for-loop not affect variables outside the loop? (Uwe Ligges) 20. Why F value and Pr are not show in summary() of an aov() result? (Peng Yu) 21. Re: how to tell if its better to standardize your data matrix first when you do principal (Uwe Ligges) 22. how do i persuade IT to install R on PCs ?? ...and should I ?? (frenchcr) 23. Computing multivariate normal probabilities. Was: Re: Problem with Numerical derivatives (numDeriv) and mvtnorm (Ravi Varadhan) 24. Re: consecutive numbering of elements in a matrix (Jim Bouldin) 25. Re: Why F value and Pr are not show in summary() of an aov() result? (Sundar Dorai-Raj) 26. scatter plot equation (Rofizah Mohammad) 27. Re: python (Peter Ehlers) 28. Re: scatter plot equation (Duncan Murdoch) 29. Re: consecutive numbering of elements in a matrix (David Winsemius) 30. Re: scatter plot equation (David Winsemius) 31. Do you keep an archive of useful R code? and if so - how? (Tal Galili) 32. Re: python (Jean Legeande) 33. Re: how do i persuade IT to install R on PCs ?? ...and should I ?? (Marc Schwartz) 34. contour(): lines labels in different colours? ( (Ted Harding)) 35. Re: Do you keep an archive of useful R code? and if so - how? (Marc Schwartz) 36. Re: how do i persuade IT to install R on PCs ?? ...and should I ?? (Ben Bolker) 37. Re: scatter plot equation (Rofizah Mohammad) 38. Re: AKIMA: z values at a set coordinate (Rhelp wanted) 39. Re: Do you keep an archive of useful R code? and if so - how? (Tal Galili) 40. Re: Do you keep an archive of useful R code? and if so - how? (Barry Rowlingson) 41. Re: Do you keep an archive of useful R code? and if so - how? (Marc Schwartz) 42. Re: Do you keep an archive of useful R code? and if so - how? (Tal Galili) 43. Re: consecutive numbering of elements in a matrix (Jim Bouldin) 44. serialized plot object (2 years later) (Jack Tanner) 45. Re: consecutive numbering of elements in a matrix (Dimitris Rizopoulos) 46. Re: Do you keep an archive of useful R code? and if so - how? (Hans-Peter Suter) 47. Re: Computing multivariate normal probabilities. Was: Re: Problem with Numerical derivatives (numDeriv) and mvtnorm (stephane Luchini) 48. mac os X: mprobit fails to install (stephane Luchini) 49. Re: Do you keep an archive of useful R code? and if so - how? (Joe King) 50. Re: Do you keep an archive of useful R code? and if so - how? (Carlos J. Gil Bellosta) 51. Re: mac os X: mprobit fails to install (Phil Spector) 52. Re: how to tell if its better to standardize your data matrix first when you do principal (masterinex) 53. Re: consecutive numbering of elements in a matrix (Jim Bouldin) 54. Re: mac os X: mprobit fails to install (SL) 55. How to get the factor level means with interaction term? (Peng Yu) 56. Re: Do you keep an archive of useful R code? and if so - how? (Nikhil Kaza) 57. where is lme() that is referred by aov() help page? (Peng Yu) 58. Re: where is lme() that is referred by aov() help page? (Duncan Murdoch) 59. Re: mac os X: mprobit fails to install (David Winsemius) 60. Re: where
[R] testing of randomness of residuals in the lm function in R
Hello, I am fitting a Linear model using R. Now, i want to know how to test whether my model is following the homoscadasticity and residuals being random assumptions or not while fitting the model. thanks a lot in advance, Ashok Varma [[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] heatmap.2 adapting the colour scale and text overlay
Hello, I am using heatmap.2 from the gplots library to plot a small symmetrical matrix. This is the command: heatmap.2(tempHeat,symm=T,trace=none,cexRow=0.7,cexCol=0.7,col=redgreen,density.info=none) I have a couple of questions: 1) The range is from -0.2 to 0.4 and the colour scheme I am using is redgreen. What I would like is that a zero value to be black, 0.4 strong green and -0.2 red. Is this possible? At the moment around 0.1 is black. 2) Is it possible to overlay text on the squares of colour? How ould one go about doing that. I am happy to use another heatmap function if ti would be better. I am not using the original heatmap as it does not provide a colour key. Thanks Dan -- ** Daniel Brewer, Ph.D. Institute of Cancer Research Molecular Carcinogenesis Email: daniel.bre...@icr.ac.uk ** The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company Limited by Guarantee, Registered in England under Company No. 534147 with its Registered Office at 123 Old Brompton Road, London SW7 3RP. This e-mail message is confidential and for use by the a...{{dropped:2}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 add a top level title to multiple plots
Jason Rupert wrote: In the example below, is there any way to get the top title, i.e. Distribution Comparisons, in a bit from the top margin? Thanks agian Your par(oma=...) needs to come _before_ plotting; make it the first statement. In addition, title() takes a line= argument; try line=0.5 or even line=-1.0. -Peter Ehlers - Original Message From: Jason Rupert jasonkrup...@yahoo.com To: Peter Ehlers ehl...@ucalgary.ca Cc: R Project Help R-help@r-project.org; Me jasonkrup...@yahoo.com Sent: Sat, November 21, 2009 12:31:04 AM Subject: Re: [R] How to add a top level title to multiple plots Cool. I ended up with the following: par(mfrow = c(2, 2)) # Plot 1 plot(rnorm(10),type=l,col=red) title(main = list(paste(Normal), col=black, cex = 1.0)) # Plot 2 plot(rpois(10, 4),type=l,col=blue) title(main = list(paste(Poison), col=black, cex = 1.0)) # Plot 3 plot(rnbinom(10, mu = 4, size = 100),type=l,col=green) title(main = list(paste(Binomial), col=black, cex = 1.0)) # Plot 4 plot(runif(10),type=l,col=black) title(main = list(paste(Uniform), col=black, cex = 1.0)) title(Distribution Comparisons, outer = TRUE) # c(bottom, left, top, right) par(oma=c(2,2,3,2)) Thanks again. - Original Message From: Peter Ehlers ehl...@ucalgary.ca To: Jason Rupert jasonkrup...@yahoo.com Cc: R-help@r-project.org Sent: Fri, November 20, 2009 5:23:33 PM Subject: Re: [R] How to add a top level title to multiple plots Jason Rupert wrote: How can I add an overall plot title to these four plots? I would like to have something that says, Distribution Comparisons: title(Distribution Comparisons, outer = TRUE) But you may have to make room for it with par(oma=...). -Peter Ehlers par(mfrow = c(2, 2)) # Plot 1 plot(rnorm(10),type=l,col=red) title(main = list(paste(Normal), col=black, cex = 1.0)) # Plot 2 plot(rpois(10, 4),type=l,col=blue) title(main = list(paste(Poison), col=black, cex = 1.0)) # Plot 3 plot(rnbinom(10, mu = 4, size = 100),type=l,col=green) title(main = list(paste(Binomial), col=black, cex = 1.0)) # Plot 4 plot(runif(10),type=l,col=black) title(main = list(paste(Uniform), col=black, cex = 1.0)) Thanks again for any feedback and insights. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] anova() method for coxph objects with robust standard errors
Hi all, what is the reason why the anova() method for coxph objects does not work when robust standard errors have been requested, e.g., fit - coxph(Surv(futime, fustat) ~ resid.ds *rx + ecog.ps, data = ovarian, robust = T) anova(fit) any pointers will be much appreciated. Sincerely, Mura __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] calling R from java eclipse
Dear R Java users I have the problems with calling R from Java (JRE6) on Windows. After running, we have: # # A fatal error has been detected by the Java Runtime Environment: # # EXCEPTION_ACCESS_VIOLATION (0xc005) at pc=0x6c7330c0, pid=1436, tid=6200 # # JRE version: 6.0_17-b04 # Java VM: Java HotSpot(TM) Client VM (14.3-b01 mixed mode, sharing windows-x86 ) # Problematic frame: # C [R.dll+0x330c0] # # An error report file with more information is saved as: # C:\Users\chekouo\workspace\SIM\hs_err_pid1436.log # # If you would like to submit a bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp # The crash happened outside the Java Virtual Machine in native code. # See problematic frame for where to report the bug. help me!Thanks! [[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] find distance between two points with different scale
i have a dataset with x and y values. i want to randomly select a point on the x-axis between the smallest and largest x-value and use a y value of zero for them. Next, for each randomly selected point {x[i],0}i want to find the point in the {x,y} space which is closest to them. However, as seen below, the scale of y-values is not the same as the x-values, using normal distance would always end up in a value that is very close to zero, therefore generating always the same. how can i overcome this problem? My code is; #randomly select 100 values between 0 and 1 y = runif(100,0,1) x = 1:length(x) plot(x,y) #randomly sample 20 values of 'x' x.rand = sample(x, 20) y.rand = rep(0, length(x.rand)) points(x.rand, y.rand, col=blue) #find a point which has minimal distance between the {x,y} and the {x.rand,0} dist.indices = c() for(i in 1:length(x.rand)){ dist.values = ((x.rand[i]-y.rand[i])^2+(x-y)^2)^0.5 dist.indices = c(indices,which(dist.values == min(dist.values))) } This will always end up with one dist.indices that is very close to zero. Thanks in advance, Marten -- View this message in context: http://old.nabble.com/find-distance-between-two-points-with-different-scale-tp26479956p26479956.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] Re adline()
yonosoyelmejor wrote: Hello, I would like to ask you a question.I have a program in R and I use the readline method to ask the user some things,but i don´t use the R console but I use Win console then not appear what I put.I put the code as you look for: cat(1- 24horas\n) cat(2- 12horas\n) cat(3- 8horas\n) selection-readline(prompt=\nSelecciona numero de horas:) if(selection==1){ prediccion=exp(x.reconstruida[1441:1450]) } if(selection==2){ prediccion=exp(x.reconstruida[720:729]) } if(selection==3){ prediccion=exp(x.reconstruida[481:491]) } write.table(prediccion,C:\\Temp\\prePrueba.txt,quote=F,row.names=F,append=T,col.names=F) //end of code. Excuse me but my English is bad, i hope explained me well, A greeting, Ignacio. I think this is a matter of flushing the console before the readline call. See ?flush.console -pd -- O__ Peter Dalgaard Øster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - (p.dalga...@biostat.ku.dk) FAX: (+45) 35327907 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] heatmap.2 adapting the colour scale and text overlay
On Nov 23, 2009, at 10:02 AM, Daniel Brewer wrote: Hello, I am using heatmap.2 from the gplots library to plot a small symmetrical matrix. This is the command: heatmap. 2 (tempHeat ,symm = T ,trace =none,cexRow=0.7,cexCol=0.7,col=redgreen,density.info=none) I have a couple of questions: 1) The range is from -0.2 to 0.4 and the colour scheme I am using is redgreen. What I would like is that a zero value to be black, 0.4 strong green and -0.2 red. Is this possible? At the moment around 0.1 is black. Perhaps: color.palette = colorRampPalette(c(green, black, pink, red)) heatmap.2(tempHeat,symm=T,trace=none,cexRow=0.7,cexCol=0.7, col=color.palette, density.info=none) 2) Is it possible to overlay text on the squares of colour? How ould one go about doing that. I am happy to use another heatmap function if ti would be better. I am not using the original heatmap as it does not provide a colour key. Thanks Dan -- ** Daniel Brewer, Ph.D. Institute of Cancer Research Molecular Carcinogenesis Email: daniel.bre...@icr.ac.uk ** The Institute of Cancer Research: Royal Cancer Hospital, a charitable Company Limited by Guarantee, Registered in England under Company No. 534147 with its Registered Office at 123 Old Brompton Road, London SW7 3RP. This e-mail message is confidential and for use by the a...{{dropped: 2}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Excel-Export
Use the RDCOMClient package from omegahat.org. On Mon, Nov 23, 2009 at 11:02 AM, koj jens.k...@gmx.li wrote: Dear all, i use the following package/syntax to export data to excel: library(xlsReadWrite) write.xls( exportdata,pfad,colNames = TRUE,sheet = 1,from = 1,rowNames = FALSE ) Everything is fine, but the format of the export is not the best. For example, I every time have to adjust the column width. Furthermore there is no possibility to highlight some cell or make them colourful. I create a lot of such outputs and I want to have the sheets in a nicer format to make them better readable, especially for the people, who works with my files. Have you any suggestions to reach this target? Ideally I can do this within R and not in a second step via a VBA-Makro or something like this. Is there a possibility in R, e. g. with a package? I have the same problem with the package xtable for export to Latex. I am very happy about the packages, but it would be perfect, if I can adjust some things in this direction. Probably there are somes ways for a solution. I am very glad about references. Thank you very much in advance, Jens. -- View this message in context: http://old.nabble.com/Excel-Export-tp26477654p26477654.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Excel-Export
On Nov 23, 2009, at 7:02 AM, koj wrote: Dear all, i use the following package/syntax to export data to excel: library(xlsReadWrite) write.xls( exportdata,pfad,colNames = TRUE,sheet = 1,from = 1,rowNames = FALSE ) Everything is fine, but the format of the export is not the best. For example, I every time have to adjust the column width. Furthermore there is no possibility to highlight some cell or make them colourful. I create a lot of such outputs and I want to have the sheets in a nicer format to make them better readable, especially for the people, who works with my files. Have you any suggestions to reach this target? Ideally I can do this within R and not in a second step via a VBA-Makro or something like this. Is there a possibility in R, e. g. with a package? I have the same problem with the package xtable for export to Latex. I am very happy about the packages, but it would be perfect, if I can adjust some things in this direction. Probably there are somes ways for a solution. I am very glad about references. Thank you very much in advance, Jens. The ability to adjust columns widths in a predictable fashion is not easy to implement outside of Excel (or an equivalent application). The Auto-fit function in Excel, for example, is a run-time only feature, which means that Excel must be available and running. The problem is that assumptions have to be made as to the cell content on a per column basis, including the font and font formatting being used and is not guaranteed to be accurate outside of Excel. I had looked at this for the WriteXLS package, but it is problematic. With respect to the formatting of individual cells (colors, borders, etc.), you might want to look at the RDCOMClient package: http://www.omegahat.org/RDCOMClient/ See examples in the Introduction for that package. HTH, Marc Schwartz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] get.gpar, grid.Call
Hi I have been unable to find information on the following problem: Error in get.gpar(): unable to find function grid.Call Reinstalling R-2.10.0, platform: i386-pc-mingw32 did not help. Before this message there was a get.gpar missing. We then transported the source code from another machine and source()-ed it. Any ideas. It seems to belong in the base package, but this is unavailable for install.packages or update.packages. Thanks for help. C.Hoffmann -- Dr. Christian W. Hoffmann, Swiss Federal Research Institute WSL Zuercherstrasse 111, CH-8903 Birmensdorf, Switzerland Tel +41-44-7392-277 (office), -111(exchange), -215 (fax) christian.hoffm...@wsl.ch, www.wsl.ch/personal_homepages/hoffmann/ Jene, die grundlegende Freiheit aufgeben wuerden, um eine geringe voruebergehende Sicherheit zu erwerben, verdienen weder Freiheit noch Sicherheit. - Benjamin Franklin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Friedman test for replicated blocked data
Dear Marco: Look in agricolae package. There is a Friedman test with and without replicates. In this package is used the Conover's book as a reference. Greetings, Dr. D. José Trujillo Carmona Dpt. of Mathematics Fac. of Science of Badajoz Univ. of Extremadura Spain From: Marco Chiarandini machud_at_intellektik.informatik.tu-darmstadt.de mailto:machud_at_intellektik.informatik.tu-darmstadt.de?Subject=Re:%20%5BR%5D%20Friedman%20test%20for%20replicated%20blocked%20data Date: Tue 14 Dec 2004 - 04:20:51 EST Hi, I would need to extend the Friedman test to a replicated design. Currently the function: friedman.test(y, ...) only works for unreplicated designs. I found in Conover 1999 Practical Nonparamteric statistics an extension of the formula to my case. Nevertheless, other sources, like Sheskin 2000 Parametric and Nonparametric statistical Procedures and Daniel 1990 Applied nonparametric statistics give a different formula from that of Conover in the unreplicated case. Since they do not provide the extension of this formula to the replicated case I would like to know if someone could give me a reference where I could find such extension. The formula is indeed very simple: F= z \sqrt{bk(k+1)/6} where z is a quantile from the normal distribution, b the number of blocks and k the number of treatments. Unfortunately, the sources cited do not provide indications from where the formula comes from. Thank you for consideration, Greetings, Marco Marco Chiarandini, Technische Universitaet Darmstadt [[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] List Name help
Hi There, I have a named List object.I want to access all the list elements that has the same name for example The List test - list() $d2 v1 v2 v3 v4 1 2 3 4 5 $d2 v1 v2 v3 v4 1 2 3 4 5 $d3 v1 v2 v3 v4 8 9 19 10 $d1 v1 v2 v3 v4 12 14 15 16 so if i say test[[d2]] or test[d2] i should get the first two that matches the name rite but i am not getting them jus getting the first one. Any suggestions on it Ramya -- View this message in context: http://old.nabble.com/List-Name-help-tp26481873p26481873.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] Natural colours for topographic data
Dear list members I'm currently working on some topographic (elevation) data, and was somewhat surprised that the 'topo.colors' and 'terrain.colors' are of little to no use here. The problem is that these functions only return a palette of colours; they don't map depth values to colours. So if I plot (using 'image', 'persp' or similar functions) and specify these palettes, ocean areas may coloured green (indicating) land, which may be quite confusing. I have looked through various packages, and have found several colour palette functions, but none that do what I need. Basically, I just need a function that takes a vector of elevation values as input, and outputs a vector of 'natural' colours. For negative values (i.e., ocean), the 'blue' colours of 'topo.colors' would be OK, and for positive values either the colours of 'terrain.colors' or the non-blue colours of 'topo.colors' would look nice. It is of course not very difficult to create such a function myself, e.g. using the 'cut' function and a standard palette. But perhaps somebody has already has made one? My ideal topographic colour mapping function would support separate colour levels for water and land (so that you can specifiy for example 5 colours of water, from a depth of 5000 meters to 0 meters, and 20 colours of land, from a depth of 0 meters to 2000 meters), support several nice palettes, and also support logarithmic colour mapping. But I would be happy with a simple one, that just mapped negative values to water colours and positive values to land colours. -- Karl Ove Hufthammer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] List Name help
Try this: test[grep(d2, names(test))] On Mon, Nov 23, 2009 at 2:53 PM, Rajasekaramya ramya.vict...@gmail.com wrote: Hi There, I have a named List object.I want to access all the list elements that has the same name for example The List test - list() $d2 v1 v2 v3 v4 1 2 3 4 5 $d2 v1 v2 v3 v4 1 2 3 4 5 $d3 v1 v2 v3 v4 8 9 19 10 $d1 v1 v2 v3 v4 12 14 15 16 so if i say test[[d2]] or test[d2] i should get the first two that matches the name rite but i am not getting them jus getting the first one. Any suggestions on it Ramya -- View this message in context: http://old.nabble.com/List-Name-help-tp26481873p26481873.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] get.gpar, grid.Call
Christian Hoffmann wrote: Hi I have been unable to find information on the following problem: Error in get.gpar(): unable to find function grid.Call Reinstalling R-2.10.0, platform: i386-pc-mingw32 did not help. Before this message there was a get.gpar missing. We then transported the source code from another machine and source()-ed it. You need to load package grid (which contains both). Uwe Ligges Any ideas. It seems to belong in the base package, but this is unavailable for install.packages or update.packages. Thanks for help. C.Hoffmann __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Natural colours for topographic data
On Nov 23, 2009, at 11:52 AM, Karl Ove Hufthammer wrote: Dear list members I'm currently working on some topographic (elevation) data, and was somewhat surprised that the 'topo.colors' and 'terrain.colors' are of little to no use here. The problem is that these functions only return a palette of colours; they don't map depth values to colours. So if I plot (using 'image', 'persp' or similar functions) and specify these palettes, ocean areas may coloured green (indicating) land, which may be quite confusing. I have looked through various packages, and have found several colour palette functions, but none that do what I need. Basically, I just need a function that takes a vector of elevation values as input, and outputs a vector of 'natural' colours. For negative values (i.e., ocean), the 'blue' colours of 'topo.colors' would be OK, and for positive values either the colours of 'terrain.colors' or the non-blue colours of 'topo.colors' would look nice. It is of course not very difficult to create such a function myself, e.g. using the 'cut' function and a standard palette. But perhaps somebody has already has made one? My ideal topographic colour mapping function would support separate colour levels for water and land (so that you can specifiy for example 5 colours of water, from a depth of 5000 meters to 0 meters, and 20 colours of land, from a depth of 0 meters to 2000 meters), support several nice palettes, and also support logarithmic colour mapping. But I would be happy with a simple one, that just mapped negative values to water colours and positive values to land colours. Searching with the strategy color positive negative zero in r-search and limiting it to r-help replies, I get this Jim Lemon reply using (naturally) plotrix's color.scale: http://finzi.psych.upenn.edu/R/Rhelp02/archive/90837.html The application to your needs looks pretty immediate. -- Karl Ove Hufthammer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Define return values of a function
If you want to control what gets printed in the output of your function, then you need to get into creating classes and methods. Choose a class to return from your function, and create a print method for that class, then when you run your function the output will cause the print method to be called if you don't store the object, but the entire object will be available if stored. E.g.: testfunc - function(x) { out - list( a=summary(x), b=quantile(x), c=range(x) ) class(out) - 'myclass' return(out) } print.myclass - function(x) { cat('my output:\n') print(x$a) cat('\n\n') cat('Q1: ',x$b[2], '\n') return(invisible(x)) } testfunc(rnorm(100)) tmp - testfunc(rnorm(100)) tmp str(tmp) Hope this helps, -- 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-boun...@r- project.org] On Behalf Of soeren.vo...@eawag.ch Sent: Sunday, November 22, 2009 4:27 AM To: r-help@r-project.org Subject: [R] Define return values of a function I have created a function to do something: i - factor(sample(c(A, B, C, NA), 793, rep=T, prob=c(8, 7, 5, 1))) k - factor(sample(c(X, Y, Z, NA), 793, rep=T, prob=c(12, 7, 9, 1))) mytable - function(x){ xtb - x btx - x # do more with x, not relevant here cat(The table has been created, see here:\n) print(xtb) list(table=xtb, elbat=btx) } tbl - table(i, k) mytable(tbl) # (1) z - mytable(tbl) # (2) str(z) # (3) (1) Wanted: outputs the string and the table properly. *Unwanted*: outputs the list elements. (2) and (3) Wanted: outputs the string properly. Wanted: assigns the list properly. How can I get rid of the *unwanted* part? That is, how do I define what the functions prints and -- on the other hand -- what it returns without printing? Thanks Sören -- Sören Vogel, Dipl.-Psych. (Univ.), PhD-Student, Eawag, Dept. SIAM http://www.eawag.ch, http://sozmod.eawag.ch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Fitting a mixture of poisson
Hello, I would like to find out how to get the fit from a mixture of poisson. For example, suppose I know the Y = 0.25*Poisson(2) + 0.75*Poisson(10) then if I have say y = 4, how do I get the fitted value for y? [[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] testing of randomness of residuals in the lm function in R
ashok varma wrote: Hello, I am fitting a Linear model using R. Now, i want to know how to test whether my model is following the homoscadasticity and residuals being random assumptions or not while fitting the model. See ?lm. For accessing residuals, see ?residuals. Or use plot() on a lm object to see diagnostic plots. Uwe Ligges thanks a lot in advance, Ashok Varma [[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] non-intuitive behaviour after type conversion
When you attach() something, it loads it into memory and there it stays. It is not a link, reference, or pointer to the original. Changing the original (the version in the dataframe), which is what you did, does not change the attached copy in memory. In essence, you did a type conversion on one copy, but afterwards started looking at the other copy. See also an interjected comments below. -Don At 8:54 AM + 11/23/09, Alan Kelly wrote: Deal list, I have a data frame (birth) with mixed variables (numeric and alphanumeric). One variable t1stvisit was originally coded as numeric with values 1,2, and 3. After attaching the data frame, this is what I see when I use str(t1stvisit) $ t1stvisit: int 1 1 1 1 1 1 1 1 2 2 ... This is as expected. I then convert t1stvisit to a factor and to avoid creating a second copy of this variable independent of the data frame I use: birth$t1stvisit = as.factor(birth$t1stvisit) if I check that the conversion has worked: is.factor(t1stvisit) [1] FALSE Now the only object present in the workspace in the data frame birth and, as noted, I have not created any new variables. So why does R still treat t1stvisit as numeric? is.factor(t1stvisit) [1] FALSE Yet when I try the following: is.factor(birth$t1stvisit) [1] TRUE So, there appears to be two versions of t1stvisit - the original numeric version and the correct factor version although ls() only shows birth as present in the workspace. Right. find('t1stvisit') will show you there are two of them, and where in memory they are located. If you type t1stvisit at the prompt, you always get the first one. The one in the attached dataframe is the second one. Use the search() function to show you the different locations in memory where objects can be found. When you did the attach(), did you get a message like: attach(tmp) The following object(s) are masked _by_ .GlobalEnv : x (yours would have referred to your variables, not the x in my example). That message tells you you have two variables of the same name, stored in two different locations in the search path. As a general rule, it's just plain confusing to have more than one object of the same name in more than one location. In your situation, I would get rid of the one that's not in the dataframe. But even then, if you change it in the dataframe you'll still need to detach and re-attach the dataframe, so using attach() is probably not the best choice in the long run. Maybe the with() function would meet your needs. If I type: summary(t1stvisit) Min. 1st Qu. MedianMean 3rd Qu.Max.NA's 1.000 1.000 2.000 1.574 2.000 3.000 29.000 I get the numeric version, but if I try summary(birth$t1stvisit) 123 NA's 180 169 22 29 I get the factor version. Frankly I feel that this behaviour is non-intuitive and potentially problematic. Nor have I seen warnings about this in the various text books on R. Can anyone comment on why this should occur? Many thanks, Alan Kelly Dr. Alan Kelly Department of Public Health Primary Care Trinity College Dublin __ R-help@r-project.org mailing list https://*stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://*www.*R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- -- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA 925-423-1062 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] NAs introduced by coercion warning?
I'm running cluster analysis on a data frame but when I calculate the distance I get this warning NAs introduced by coercion. What does this mean? [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error using 32-bit R and RODBC package on 64-bit Windows Server OS with R version 2.10
Thank you for the link to the 32 bit Windows Oracle downloads for the Instant Client. That solved the problem. I'm now able to connect to Oracle database from R using the RODBC library. Thank you Mark! -Melanie On Wed, Nov 18, 2009 at 6:23 PM, Marc Schwartz marc_schwa...@me.com wrote: Just to clarify on your first point, it is not that RODBC cannot work with 64 bit ODBC drivers. Given your particular configuration of 64 bit Windows, 32 bit R and 64 bit ODBC drivers, you are likely running into compatibility issues. From the error message below, it would seem that you are also either missing the requisite Oracle client software, or your system configuration variables are not set or are not set to the proper paths. The 32 bit Windows Oracle downloads are available from: http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/winsoft.html Now, I don't run Windows (have not in a long time), so I am not clear as to the subtleties that may be in play here given that you may be installing 32 bit drivers over an existing 64 bit installation. You may need to remove the 64 bit install, in order to have a clean install of the 32 bit Oracle client apps. If they install into different locations, that might help to solve the problem, in which case, you need to be careful in configuring any system environment variables so that they point to the proper location. If you have access to in-house tech support or an Oracle SysAdmin, I would highly recommend that you seek them out to aid in ensuring that you end up with a clean 32 bit Oracle client installation. As I noted previously, I would be sure that you can connect to the Oracle server using the 32 bit Oracle Instant Client application as a test to ensure that OS and Oracle related configuration issues have been resolved. Then test the RODBC connection within R. That two step process has helped me to debug local configuration issues on both Linux and OSX. HTH, Marc Schwartz On Nov 18, 2009, at 3:12 PM, helpme wrote: Now that I know RODBC only works with 32-bit ODBC drivers this explains the problem I was having. The system has a 64 bit ODBC driver is definitely installed. I can tell because when you go to system32 folder and click on odbcad32.exe it goes to the Microsoft ODBC manager where I can select the driver installed for the 64-bit Oracle system. The system32 folder contains the 64 bit driver for ODBC. When I go to the syswow64 directory and click on the odbcad32.exe it does not take me to the Microsoft ODBC manager. Instead I get this error: Navigate to C:\Windows\syswow64\odbcad32.exe 2.) Select System DSN 3.) Add Microsoft ODBC for Oracle I receive this error: The Oracle(tm) client and networking components were not found. These components are supplied by Oracle Corporation and are part of the Oracle Version 7.3 (or greater) client software installation. You will be unable to use this driver until these components have been installed. I don't believe the 32-bit ODBC driver is present. What is the best way to tell if the 32-bit Oracle client software isn't installed and I'm wondering if anyone has experience to install it on a 64-bit system and call it from RODC? On Mon, Nov 16, 2009 at 4:54 PM, Marc Schwartz marc_schwa...@me.com wrote: On Nov 16, 2009, at 2:39 PM, helpme wrote: I am receiving an error when trying to connect to the Oracle Database using RODBC on a 64-bit Windows Server OS. The version of R is 2.10.0-win32.exe Is this the wrong version. Does RODBC only work with 32-bit ODBC drivers? 've read over all the posts and documentation manuals. The system is Windows Server 2003 with R 2.81. and the latest downloadable RODBC package. The Oracle SID/DSN is mfopdw. I made sure to add it to Control Panel-Administrative Priviledges-Microsoft ODBC system/user DNS. I've also tried the following in no particular order: 1.) Turn on all oracle services in control panel-administrative priviledges. 2.) Checked tsnnames.ora for SID. 3.) Add microsoft ODBC service to Control Panel services for SID 4.) Use Sqldeveler to test connection another way besides R (It was successful) 5.) channel-odbcDriverConnect( connection=Driver={Microsoft ODBC for Oracle}; DSN=abc,UID=abc;PWD=abc;case=oracle) received error drivers SQLAllocHandle on SQL_HANDLE_ENV failed one time; another time I got the error that Oracle client and networking components 7.3 or greater is not found. 6.) tnsping mfopdw lsnrctl start mfopdw tried to add oracle/bin to path Nothing is working. Three quick comments: 1. A better place to post these types of queries would be on the R-SIG-DB e-mail list, which is focused in this domain. More info here: https://stat.ethz.ch/mailman/listinfo/r-sig-db 2. Prof. Ripley will be a more definitive resource, so I would wait until he might respond. 3. If you have not yet, be sure to read the RODBC vignette, which is
Re: [R] How do I specify a partially completed survival analysis model?
On Nov 20, 2009, at 1:27 PM, David Winsemius wrote: On Nov 20, 2009, at 11:07 AM, RWilliam wrote: In reply to suggestion by David W., setting an offset parameter doesn't seem to work as R is not recognizing the X2 part of coxph( Surv(Time,Censor)~X1, offset=log(4.3*X2), data= a ). Also, here's some sample data: The problem, arising as a result of not having a dataset against which to test my memories of syntactic niceties, is that glm and coxph use different methods of supplying offsets. It's been pointed out to me that coxph()'s required syntactic incorporation of offsets is the same as glm()'s preferred inclusion in the formula, and that my erroneous impression that a separate offset argument is necessary might have be the result of SAS poisoning. I suspect that infection is the more correct biomedical analogy, since I copied my use from another who was probably the index case. That usage was also similar to the separate specification of offsets (e.g. $CAL LPY=%LOG(PY) $OFFSET LPY) in GLIM which was my statistical upbringing. -- David. Thereau and Gramsch's book has examples, but if you did not have the book you still had alternatives. A bit of searching with the terms: coxph Therneau offset; produced lots of hits for the occurrence of offset in warning messages so adding -warning to that search then produced a hit to the Google books look at TG's text with a worked example: a$logX2 - log(a$X2) coxph(Surv(Time,Censor)~X1 + offset(logX2), data= a ) Call: coxph(formula = Surv(Time, Censor) ~ X1 + offset(logX2), data = a) coef exp(coef) se(coef) zp X1 -0.885 0.413 1.43 -0.62 0.54 #Or just: coxph(Surv(Time,Censor)~X1 + offset(log(4.3*X2)), data= a ) X1 X2 TimeCensor 1 1 0.40619454 77.00666 0 2 1 0.20717868 100.0 0 3 1 0.77360963 79.03463 1 4 1 0.62221954 100.0 0 5 1 0.32191280 100.0 0 6 1 0.73790704 72.84842 0 7 1 0.65012237 100.0 0 8 1 0.71596105 100.0 0 9 1 0.74787202 84.00172 0 10 1 0.66803790 41.65760 0 11 1 0.79922364 92.41999 0 12 1 0.76433736 90.99983 0 13 1 0.57014524 100.0 0 14 1 0.39642235 100.0 0 15 1 0.55756045 100.0 0 16 0 0.60079340 100.0 0 17 0 0.43630695 100.0 0 18 0 0.09388013 100.0 0 19 0 0.55956791 100.0 0 20 0 0.52491597 97.71884 1 where we set the coefficient of X2 to be 8. RWilliam wrote: Sorry for being impatient but is there really no way of doing this at all? It's quite urgent so any help is very much appreciated. Thank you. RWilliam wrote: Hello, I just started using R to do epidemiologic simulation research using the Cox proportional hazard model. I have 2 covariates X1 and X2 which I want to model as h(t,X)=h0(t)*exp(b1*X1+b2*X2). I assume independence of X from t. After I simulate Time and Censor data vectors denoting the censoring time and status respectively, I can call the following function to fit the data into the Cox model (a is a data.frame containing 4 columns X1, X2, Time and Censor): b = coxph (Surv (Time, Censor) ~ X1 + X2, data = a, method = breslow); Now the purpose of me doing simulation is that I have another mechanism to generate the number b2. From the given b2 (say it's 4.3), Cox model can be fit to generate b1 and check how feasible the new model is. Thus, my question is, how do I specify such a model that is partially completed (as in b2 is known). I tried things like Surv(Time,Censor)~X1+4.3*X2, but it's not working. Thanks very much. -- View this message in context: http://old.nabble.com/How-do-I-specify-a-partially-completed-survival-analysis-model--tp26421391p26443562.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Analyzing XML data
I would like to analyze XML data from MLB's website. I do the following steps: library(XML) dat-http://gd2.mlb.com/components/game/mlb/year_2007/month_05/day_02/gid_2007_05_02_arimlb_lanmlb_1/inning/inning_1.xml; example- xmlTreeParse(dat, useInternalNodes=T) ex-xpathApply(example, //inning, xmlToList) #could also use //atbat This brings information from the first inning of the Arizona/LA game played on 5/2/2007 into R. Now that I have it in R, I don't understand how to 'get at' the data. For example, how could I calculate the average start speed ( [[1]]$top$atbat$pitch[start_speed] ) of all pitches thrown in the inning? Thanks, Skyler -- View this message in context: http://old.nabble.com/Analyzing-XML-data-tp26483962p26483962.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] Loess Fit
I'm working on Loess fit models using R, once I have the fit accomplished, I'm looking to back-out the equation of the fitted non-linear curve, wondering if there is a way to determine this equation in R? I've been looking but can't find any literature. For me, the graph of the function is great, but without the equation of the graph, I'm kinda dead in the water. Christian Miner 503-866-6977 [[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] Different fonts on the same axis
Hi, I need to have both italics and standard font on the y axis. This is my script: plot(x,y,pch=16,xlab=metric,ylab=species CPUE) I want species in italics and CPUE in standard text. Any tips would be appreciated. Thanks. -- View this message in context: http://old.nabble.com/Different-fonts-on-the-same-axis-tp26482460p26482460.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] interaction effects in a Linear model
Hi Cleland and Dennis, thanks a lot for the answer. Ashok Varma On Mon, Nov 23, 2009 at 5:05 PM, Chuck Cleland cclel...@optonline.netwrote: On 11/23/2009 1:06 AM, ashok varma wrote: hello, i am fitting a Linear model using R. I have to fit the model considering all the interaction effects of order 1 of the independent variables. But I have 9 variables. So, it will be difficult for me to write all the 36 combinations in the model. Can anyone please help how to get this done in much smarter way?? This will include all main effects and two-way interactions: lm(Y ~ (A + B + C + D + E + F + G + H + I)^2, data=mydata) thanks a lot, Ashok Varma. [[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. -- Chuck Cleland, Ph.D. NDRI, Inc. (www.ndri.org) 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894 [[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] NAs introduced by coercion
I'm running cluster analysis on a data frame but when I calculate the distance I get this warning NAs introduced by coercion. What does this mean? -- View this message in context: http://old.nabble.com/NAs-introduced-by-coercion-tp26482683p26482683.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] vegan package: goodness.cca function
Hello, I am posting this to R-help and Ecolog-L, in hopes that enough Ecologgers are R users and enough R-help users are ecologists. Please forgive the cross-posting. I deleted a number of species from a canonical correspondence analysis (CCA) model after using the function goodness.cca in vegan. In his explanation of the diagnostic tools for CCA (http://cc.oulu.fi/~jarioksa/softhelp/vegan/html/goodness.cca.html), Jari Oksanen states that It is a common practise to use goodness statistics to remove species from ordination plots. However, I have not been able to find references on this common practice in the literature. I may be using inappropriate search terms?? However, if anybody can point me towards some cite-able references/rules of thumb on this, I would very much appreciate it. And yes, I am also aware that Jari goes on to say that deleting species isn't always a good idea. Thank you! Lauren Quinn _ Hotmail: Trusted email with powerful SPAM protection. [[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] Different fonts on the same axis
Tena koe Michelle ?plotmath For your particular example, try: plot(1:10, 1:10, pch=16, xlab=metric, ylab=quote(~italic(species)~ ' CPUE')) Depending on your default font, you might need to set the family argument of par(): par(family='serif') HTH Peter Alspach -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of MichelleJ Sent: Tuesday, 24 November 2009 6:28 a.m. To: r-help@r-project.org Subject: [R] Different fonts on the same axis Hi, I need to have both italics and standard font on the y axis. This is my script: plot(x,y,pch=16,xlab=metric,ylab=species CPUE) I want species in italics and CPUE in standard text. Any tips would be appreciated. Thanks. -- View this message in context: http://old.nabble.com/Different-fonts-on-the-same-axis-tp26482 460p26482460.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] Check if string has all alphabets or numbers
Here is the way you can use grepl to get the various combinations: mywords- c(harry,met,sally,subway10,1800Movies,12345, + not correct 123, ) numbers - grepl(^[[:digit:]]+$, mywords) letters - grepl(^[[:alpha:]]+$, mywords) both - grepl(^[[:digit:][:alpha:]]+$, mywords) mywords[letters] [1] harry met sally mywords[numbers] [1] 12345 mywords[xor((letters | numbers), both)] # letters numbers mixed [1] subway10 1800Movies On Mon, Nov 23, 2009 at 9:17 AM, hadley wickham h.wick...@gmail.com wrote: mywords- c(harry,met,sally,subway10,1800Movies,12345, not correct 123) all.letters - grep(^[[:alpha:]]*$, mywords) all.numbers - grep(^[[:digit:]]*$, mywords) # numbers mixed - grep(^[[:digit:][:alpha:]]*$, mywords) mywords- c(harry,met,sally,subway10,1800Movies,12345, not correct 123, ) mywords[grepl(^[[:digit:][:alpha:]]*$, mywords)] So maybe you should use mywords[grepl(^[[:digit:][:alpha:]]+$, mywords)] And grepl is highly recommended over grep. Hadley -- http://had.co.nz/ -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loess Fit
On Nov 23, 2009, at 2:03 PM, Christian Miner wrote: I'm working on Loess fit models using R, once I have the fit accomplished, I'm looking to back-out the equation of the fitted non-linear curve, wondering if there is a way to determine this equation in R? I've been looking but can't find any literature. For me, the graph of the function is great, but without the equation of the graph, I'm kinda dead in the water. So you want a global equation from a procedure that does local fitting for each point? Maybe you should re-think your strategy. The points that form the graph _are_ the function. Maybe you should re-think your strategy. Perhaps you want spline fiting. -- David Winsemius, MD Heritage Laboratories West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loess Fit
Hi Christian, Do you have a reference to a publication where this has been done? All the best, Tom On Nov 23, 2009, at 10:15 AM, Christian Miner wrote: it's a tricky maneuver. When I finish the fit, the predict function will give me the values, and I can smooth this out so it looks like a nice non-linear equation. The last thing I need to do is find the equation, knowing I know have the x and y values, as they will relate to each other in a non-linear fashion. Matlab can do this, but I'd rather not go into that realm. On Mon, Nov 23, 2009 at 12:11 PM, Thomas S. Dye t...@tsdye.com wrote: Hi Christian, I haven't seen an equation associated with a loess fit before. Do you have a reference to one of these? All the best, Tom On Nov 23, 2009, at 9:03 AM, Christian Miner wrote: I'm working on Loess fit models using R, once I have the fit accomplished, I'm looking to back-out the equation of the fitted non-linear curve, wondering if there is a way to determine this equation in R? I've been looking but can't find any literature. For me, the graph of the function is great, but without the equation of the graph, I'm kinda dead in the water. Christian Miner 503-866-6977 [[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. -- Christian Miner 503-866-6977 [[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] Loess Fit
Check out the loess.demo function in the TeachingDemos package. Using this function with your data will show the scatterplot with the loess curve. Then if you click in the plot it will show the line/curve used to do the prediction for that x-value, click on another x-value and you will see that the line/curve used there is different from before. There is not a single function created by the loess algorithm, rather a different approximation for every possible x-value (theoretically infinite, practically still a big number). You could fit a function to the results of loess (or approximate the points with a function), but the function will probably be complicated enough that it would not tell you much that the points themselves don't. -- 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-boun...@r- project.org] On Behalf Of Christian Miner Sent: Monday, November 23, 2009 12:04 PM To: r-help@r-project.org Subject: [R] Loess Fit I'm working on Loess fit models using R, once I have the fit accomplished, I'm looking to back-out the equation of the fitted non-linear curve, wondering if there is a way to determine this equation in R? I've been looking but can't find any literature. For me, the graph of the function is great, but without the equation of the graph, I'm kinda dead in the water. Christian Miner 503-866-6977 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] using contents of one column to direct addition of new rows in dataframe
Hello, R gurus. I've been trying to get R to do some data manipulation for me, and so far have been stumped in figuring out any elegant way to do so. Searches through the R-help archive haven't helped, so now I'm trying plan B. Suppose I have a dataframe that summarizes events that took place between some interval of time in days, Time. I want to expand the dataframe to repeat each row the appropriate number of days so that Time is now = 1 for each original record. Actually, I really don't care if Time=1 is displayed in the new dataframe, as it will no longer be relevant. Also, I want to have R keep track of a time-variant variable, Date, so that it advances along one day for each new row. Here's an example of what the starting record would be like, and what I'd like to end up with: foo.df - data.frame(ID=N1, Date=2, Time=3) foo.df ID Date Time 1 N123 # insert R wizardry here to get new.foo.df new.foo.df ID DateTime N1 2 1 N1 3 1 N1 4 1 I know, or at least suspect, that there is a fairly straightforward way of doing so with building some ugly loop. But even after considering versions of apply and related commands, I just can't figure it out. Any help would be greatly appreciated. cheers, Jessi Brown University of Nevada, Reno __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loess Fit
Thanks Christian. The client is always right ... Tom On Nov 23, 2009, at 10:32 AM, Christian Miner wrote: sorry, I don't. I have data that I can estimate, but my client wants to What if... 20 separate scenarios, and that requires a function. On Mon, Nov 23, 2009 at 12:22 PM, Thomas S. Dye t...@tsdye.com wrote: Hi Christian, Do you have a reference to a publication where this has been done? All the best, Tom On Nov 23, 2009, at 10:15 AM, Christian Miner wrote: it's a tricky maneuver. When I finish the fit, the predict function will give me the values, and I can smooth this out so it looks like a nice non-linear equation. The last thing I need to do is find the equation, knowing I know have the x and y values, as they will relate to each other in a non-linear fashion. Matlab can do this, but I'd rather not go into that realm. On Mon, Nov 23, 2009 at 12:11 PM, Thomas S. Dye t...@tsdye.com wrote: Hi Christian, I haven't seen an equation associated with a loess fit before. Do you have a reference to one of these? All the best, Tom On Nov 23, 2009, at 9:03 AM, Christian Miner wrote: I'm working on Loess fit models using R, once I have the fit accomplished, I'm looking to back-out the equation of the fitted non-linear curve, wondering if there is a way to determine this equation in R? I've been looking but can't find any literature. For me, the graph of the function is great, but without the equation of the graph, I'm kinda dead in the water. Christian Miner 503-866-6977 [[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. -- Christian Miner 503-866-6977 -- Christian Miner 503-866-6977 [[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] testing of randomness of residuals in the lm function in R
Hi Ashok, You can try : *shapiro.test(**my.lm$resid**)* But I remember reading that good tests for the normality assumptions (specifically that of the residuals), do not exist as we would have hoped them to. Good luck, 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) -- 2009/11/23 Uwe Ligges lig...@statistik.tu-dortmund.de ashok varma wrote: Hello, I am fitting a Linear model using R. Now, i want to know how to test whether my model is following the homoscadasticity and residuals being random assumptions or not while fitting the model. See ?lm. For accessing residuals, see ?residuals. Or use plot() on a lm object to see diagnostic plots. Uwe Ligges thanks a lot in advance, Ashok Varma [[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. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to make a cartesian pairlist from a vector?
This is very helpful. Thank you very much. Charles C. Berry wrote: On Fri, 20 Nov 2009, newbyr wrote: Hi, I'm looking for a function that will take a list of columns or data.frame and corvert it to cartesian pairlist. For example for this data.frame (see below), I'd like to get a list of all possible pairs: sound cs rs ns 7 5 2 4 5 4 6 3 1 8 4 1 6 4 2 6 7 1 2 2 5 9 2 5 how can I get this? mylist ((cs,rs), (cs,ns), (rs,ns)) str(combn(colnames(df),2,function(x) df[,x],simplify=F)) see ?combn HTH, Chuck p.s. Following the posting guide's hints you might try ?combinations # no go, but it says try ??combinations ??combinations # shows utils:combn ?combn # bingo! This list contains a set of all possible combinations of column pairs. Thank you for your help. -- View this message in context: http://old.nabble.com/How-to-make-a-cartesian-pairlist-from-a-vector--tp26452861p26452861.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. Charles C. Berry(858) 534-2098 Dept of Family/Preventive Medicine E mailto:cbe...@tajo.ucsd.edu UC San Diego http://famprevmed.ucsd.edu/faculty/cberry/ La Jolla, San Diego 92093-0901 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://old.nabble.com/How-to-make-a-cartesian-pairlist-from-a-vector--tp26452861p26485572.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] Loess Fit
If the client is always right, then what do they need us for? If you need a function to reproducibly generate predictions, then use loess to generate a set of predictions for a reasonably dense set of x-values, then use approxfun or splinefun to create a function to interpolate for you. Then this function can give the predictions for various x values. -- 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-boun...@r- project.org] On Behalf Of Thomas S. Dye Sent: Monday, November 23, 2009 1:39 PM To: Christian Miner Cc: r-help@r-project.org Subject: Re: [R] Loess Fit Thanks Christian. The client is always right ... Tom On Nov 23, 2009, at 10:32 AM, Christian Miner wrote: sorry, I don't. I have data that I can estimate, but my client wants to What if... 20 separate scenarios, and that requires a function. On Mon, Nov 23, 2009 at 12:22 PM, Thomas S. Dye t...@tsdye.com wrote: Hi Christian, Do you have a reference to a publication where this has been done? All the best, Tom On Nov 23, 2009, at 10:15 AM, Christian Miner wrote: it's a tricky maneuver. When I finish the fit, the predict function will give me the values, and I can smooth this out so it looks like a nice non-linear equation. The last thing I need to do is find the equation, knowing I know have the x and y values, as they will relate to each other in a non-linear fashion. Matlab can do this, but I'd rather not go into that realm. On Mon, Nov 23, 2009 at 12:11 PM, Thomas S. Dye t...@tsdye.com wrote: Hi Christian, I haven't seen an equation associated with a loess fit before. Do you have a reference to one of these? All the best, Tom On Nov 23, 2009, at 9:03 AM, Christian Miner wrote: I'm working on Loess fit models using R, once I have the fit accomplished, I'm looking to back-out the equation of the fitted non-linear curve, wondering if there is a way to determine this equation in R? I've been looking but can't find any literature. For me, the graph of the function is great, but without the equation of the graph, I'm kinda dead in the water. Christian Miner 503-866-6977 [[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. -- Christian Miner 503-866-6977 -- Christian Miner 503-866-6977 [[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] Loess Fit
Thanks, I'll try that. What is the output of approxfun? On Mon, Nov 23, 2009 at 1:03 PM, Greg Snow greg.s...@imail.org wrote: If the client is always right, then what do they need us for? If you need a function to reproducibly generate predictions, then use loess to generate a set of predictions for a reasonably dense set of x-values, then use approxfun or splinefun to create a function to interpolate for you. Then this function can give the predictions for various x values. -- 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-boun...@r- project.org] On Behalf Of Thomas S. Dye Sent: Monday, November 23, 2009 1:39 PM To: Christian Miner Cc: r-help@r-project.org Subject: Re: [R] Loess Fit Thanks Christian. The client is always right ... Tom On Nov 23, 2009, at 10:32 AM, Christian Miner wrote: sorry, I don't. I have data that I can estimate, but my client wants to What if... 20 separate scenarios, and that requires a function. On Mon, Nov 23, 2009 at 12:22 PM, Thomas S. Dye t...@tsdye.com wrote: Hi Christian, Do you have a reference to a publication where this has been done? All the best, Tom On Nov 23, 2009, at 10:15 AM, Christian Miner wrote: it's a tricky maneuver. When I finish the fit, the predict function will give me the values, and I can smooth this out so it looks like a nice non-linear equation. The last thing I need to do is find the equation, knowing I know have the x and y values, as they will relate to each other in a non-linear fashion. Matlab can do this, but I'd rather not go into that realm. On Mon, Nov 23, 2009 at 12:11 PM, Thomas S. Dye t...@tsdye.com wrote: Hi Christian, I haven't seen an equation associated with a loess fit before. Do you have a reference to one of these? All the best, Tom On Nov 23, 2009, at 9:03 AM, Christian Miner wrote: I'm working on Loess fit models using R, once I have the fit accomplished, I'm looking to back-out the equation of the fitted non-linear curve, wondering if there is a way to determine this equation in R? I've been looking but can't find any literature. For me, the graph of the function is great, but without the equation of the graph, I'm kinda dead in the water. Christian Miner 503-866-6977 [[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. -- Christian Miner 503-866-6977 -- Christian Miner 503-866-6977 [[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. -- Christian Miner 503-866-6977 [[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] serialized plot object (2 years later)
Hi Jack, Jack Tanner wrote: About 2 years ago, Tobias Verbeke asked: I am looking for a way to capture the binary string that in normal use of graphics devices will bewritten to (most commonly) a file connection... Is there a way of capturing the binary `jpeg string' [generated by jpeg()]? http://tolstoy.newcastle.edu.au/R/e2/devel/07/09/4276.html Brian Ripley's answer was Nope, unfortunately, they write to files not connections and no R object is involved. Is this still the case? Yes (assuming your question wasn't a rhetorical question). I still think it would be a useful feature if graphics devices could write to connections. Best, Tobias P.S. Your question seems more appropriate for R-devel. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Loess Fit
approxfun returns a function, give this function an x-value and it will give you the prediction (linear interpolation from the points that you gave to approxfun). The splinefun function also returns a function, but it gives a spline interpolation rather than a linear one. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 From: Christian Miner [mailto:christian.mi...@gmail.com] Sent: Monday, November 23, 2009 2:05 PM To: Greg Snow Cc: Thomas S. Dye; r-help@r-project.org Subject: Re: [R] Loess Fit Thanks, I'll try that. What is the output of approxfun? On Mon, Nov 23, 2009 at 1:03 PM, Greg Snow greg.s...@imail.orgmailto:greg.s...@imail.org wrote: If the client is always right, then what do they need us for? If you need a function to reproducibly generate predictions, then use loess to generate a set of predictions for a reasonably dense set of x-values, then use approxfun or splinefun to create a function to interpolate for you. Then this function can give the predictions for various x values. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.orgmailto:greg.s...@imail.org 801.408.8111 -Original Message- From: r-help-boun...@r-project.orgmailto:r-help-boun...@r-project.org [mailto:r-help-boun...@r-mailto:r-help-boun...@r- project.orghttp://project.org] On Behalf Of Thomas S. Dye Sent: Monday, November 23, 2009 1:39 PM To: Christian Miner Cc: r-help@r-project.orgmailto:r-help@r-project.org Subject: Re: [R] Loess Fit Thanks Christian. The client is always right ... Tom On Nov 23, 2009, at 10:32 AM, Christian Miner wrote: sorry, I don't. I have data that I can estimate, but my client wants to What if... 20 separate scenarios, and that requires a function. On Mon, Nov 23, 2009 at 12:22 PM, Thomas S. Dye t...@tsdye.commailto:t...@tsdye.com wrote: Hi Christian, Do you have a reference to a publication where this has been done? All the best, Tom On Nov 23, 2009, at 10:15 AM, Christian Miner wrote: it's a tricky maneuver. When I finish the fit, the predict function will give me the values, and I can smooth this out so it looks like a nice non-linear equation. The last thing I need to do is find the equation, knowing I know have the x and y values, as they will relate to each other in a non-linear fashion. Matlab can do this, but I'd rather not go into that realm. On Mon, Nov 23, 2009 at 12:11 PM, Thomas S. Dye t...@tsdye.commailto:t...@tsdye.com wrote: Hi Christian, I haven't seen an equation associated with a loess fit before. Do you have a reference to one of these? All the best, Tom On Nov 23, 2009, at 9:03 AM, Christian Miner wrote: I'm working on Loess fit models using R, once I have the fit accomplished, I'm looking to back-out the equation of the fitted non-linear curve, wondering if there is a way to determine this equation in R? I've been looking but can't find any literature. For me, the graph of the function is great, but without the equation of the graph, I'm kinda dead in the water. Christian Miner 503-866-6977 [[alternative HTML version deleted]] __ R-help@r-project.orgmailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. -- Christian Miner 503-866-6977 -- Christian Miner 503-866-6977 [[alternative HTML version deleted]] __ R-help@r-project.orgmailto:R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. -- Christian Miner 503-866-6977 [[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] Loess Fit
What if you wanted to do this with multiple x's, multivariate, rather than just 1 x variable? On Mon, Nov 23, 2009 at 1:09 PM, Greg Snow greg.s...@imail.org wrote: approxfun returns a function, give this function an x-value and it will give you the prediction (linear interpolation from the points that you gave to approxfun). The splinefun function also returns a function, but it gives a spline interpolation rather than a linear one. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.s...@imail.org 801.408.8111 *From:* Christian Miner [mailto:christian.mi...@gmail.com] *Sent:* Monday, November 23, 2009 2:05 PM *To:* Greg Snow *Cc:* Thomas S. Dye; r-help@r-project.org *Subject:* Re: [R] Loess Fit Thanks, I'll try that. What is the output of approxfun? On Mon, Nov 23, 2009 at 1:03 PM, Greg Snow greg.s...@imail.org wrote: If the client is always right, then what do they need us for? If you need a function to reproducibly generate predictions, then use loess to generate a set of predictions for a reasonably dense set of x-values, then use approxfun or splinefun to create a function to interpolate for you. Then this function can give the predictions for various x values. -- 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-boun...@r- project.org] On Behalf Of Thomas S. Dye Sent: Monday, November 23, 2009 1:39 PM To: Christian Miner Cc: r-help@r-project.org Subject: Re: [R] Loess Fit Thanks Christian. The client is always right ... Tom On Nov 23, 2009, at 10:32 AM, Christian Miner wrote: sorry, I don't. I have data that I can estimate, but my client wants to What if... 20 separate scenarios, and that requires a function. On Mon, Nov 23, 2009 at 12:22 PM, Thomas S. Dye t...@tsdye.com wrote: Hi Christian, Do you have a reference to a publication where this has been done? All the best, Tom On Nov 23, 2009, at 10:15 AM, Christian Miner wrote: it's a tricky maneuver. When I finish the fit, the predict function will give me the values, and I can smooth this out so it looks like a nice non-linear equation. The last thing I need to do is find the equation, knowing I know have the x and y values, as they will relate to each other in a non-linear fashion. Matlab can do this, but I'd rather not go into that realm. On Mon, Nov 23, 2009 at 12:11 PM, Thomas S. Dye t...@tsdye.com wrote: Hi Christian, I haven't seen an equation associated with a loess fit before. Do you have a reference to one of these? All the best, Tom On Nov 23, 2009, at 9:03 AM, Christian Miner wrote: I'm working on Loess fit models using R, once I have the fit accomplished, I'm looking to back-out the equation of the fitted non-linear curve, wondering if there is a way to determine this equation in R? I've been looking but can't find any literature. For me, the graph of the function is great, but without the equation of the graph, I'm kinda dead in the water. Christian Miner 503-866-6977 [[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. -- Christian Miner 503-866-6977 -- Christian Miner 503-866-6977 [[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. -- Christian Miner 503-866-6977 -- Christian Miner 503-866-6977 [[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.