Re: [R] sas.get under Linux
Dear Ayah, On Saturday 31 January 2009, Ajay ohri wrote: Hi, have you looked at the third party SAS language compilers WPS ( 600 dollars per desktop version http://www.teamwpc.co.uk/home/ ) and Carolina ( http://dullesopen.com/) http://dullesopen.com/ http://dullesopen.com/ if you need just base SAS. Acually... no. I don't plan to use SAS in the future (I use R! :), just need it for the moment to extract some value labels. Best wishes, Adrian -- Adrian Dusa Romanian Social Data Archive 1, Schitu Magureanu Bd. 050025 Bucharest sector 5 Romania Tel.:+40 21 3126618 \ +40 21 3120210 / int.101 Fax: +40 21 3158391 [[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] Personal invitation from srinivasa raghavan
Personal invitation from srinivasa raghavan [[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] sas.get under Linux
Dear Frank, I understand. Never used SAS before, so I don't have it installed anywhere. StatTransfer is a very useful tool indeed, but maybe I don't know how to use it properly. What I have is a mydata.sas7bdat file, along with a formats.sas7bcat file. I specified reading SAS value labels Read directly from a catalog file, but nothing appears in the output, neither in the R workspace nor in an intermediate SPSS file. I also tried exporting to a SAS portable file to import directly in R, but there is probably something obvious that I miss because value labels are not there, whatever I do... Thanks for your help, Adrian On Saturday 31 January 2009, Frank E Harrell Jr wrote: Adrian Dusa wrote: Dear all, I am trying to import a SAS file into R (in fact I only need the value labels from the formats file), using Hmisc package, but I get this error: my.sas - sas.get(/home/adi/3, fis1_sgg) sh: sas: not found Error in sas.get(/home/adi/3, fis1_sgg) : SAS job failed with status 32512 I read some past discussions and I get the impression that sas.get() needs the full path to the SAS executable, but I don't have that because I am using Linux. Is it possible to use sas.get() without having SAS installed? Since sas.get is trying to execute sas the answer is a definite no unless you use the sas.get option to run SAS on another machine to produce the input ASCII files needed by sas.get. Also investigate sasxport.get if you have SAS version 5 transport files to import. See also http://biostat.mc.vanderbilt.edu/SASexportHowto As SAS never got it right in allowing for full metadata to be included in a SAS dataset, you often have to run PROC FORMAT CNTLOUT=... to convert format libraries to SAS datasets so that programs such as sasxport.get can assign value labels [if you have SAS installed, sas.get runs PROC CONTENTS for you.]. SPSS and Stata have always been ahead of SAS in this regard. Note that the excellent Stat/Transfer commercial product will convert from almost any SAS dataset format to compact R binary objects, including variable labels the way the Hmisc package handles them. If you have another way to convert from SAS to Stata or SPSS, R is great at readying those formats. Frank Or alternatively, is there another function to import the formats into R? Thanks in advance for any hint, Adrian -- Adrian Dusa Romanian Social Data Archive 1, Schitu Magureanu Bd. 050025 Bucharest sector 5 Romania Tel.:+40 21 3126618 \ +40 21 3120210 / int.101 Fax: +40 21 3158391 [[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] thurston case 5
John, I installed the psych package and all it's dependencies. Then following the psych manual, I type thurstone(x, ranks = FALSE, digits = 2) the result is Error: could not find function thurstone Any suggestions? Best, Jared John Fox-6 wrote: Dear Jared, See ?thurstone in the psych package. RSiteSearch(Thurstone) turns this up as the first hit. Also see the BradleyTerry package for the similar Bradley-Terry model. Regards, John -- John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of japomani Sent: January-31-09 5:04 PM To: r-help@r-project.org Subject: [R] thurston case 5 Hi, I hope some one can help. I need to compute Thurston's case 5 on a large set of data. I have gotten as far as computing the proportional preference matrix but the next math is beyond me. Here us my matrix 0.5000.472 0.486 0.587 0.366 0.483 0.496 0.434 0.5280.500 0.708 0.578 0.633 0.554 0.395 0.620 0.5140.292 0.500 0.370 0.557 0.580 0.615 0.329 0.4130.422 0.630 0.500 0.783 0.641 0.731 0.663 0.6340.367 0.443 0.217 0.500 0.351 0.907 0.686 0.5170.446 0.420 0.359 0.649 0.500 0.325 0.559 0.5040.605 0.385 0.269 0.093 0.675 0.500 0.625 0.5660.380 0.671 0.337 0.314 0.441 0.375 0.500 Can someone help me write an R script to compute the Thurston Case 5 values? The result should be the scale values for each item. I found three web pages that might be useful in this, but again, I didn't know enough to translate them into a result. http://marketing.byu.edu/htmlpages/books/pcmds/THURSTONE.html http://www.personality-project.org/r/thurstone.html http://en.wikipedia.org/wiki/Law_of_comparative_judgment Thanks, Jared -- View this message in context: http://www.nabble.com/thurston-case-5- tp21768835p21768835.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://www.nabble.com/thurston-case-5-tp21768835p21781083.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] problem of importing files into R
I am using R 2.8.1...Sometimes it is happening that I am trying to import some text files into R but it is not working...But sometime it is working..I am using the syntax: mydata = read.table( file.choose(), skip = 1 )..someone please help me..you can also suggest a better syntax for importing data from other sources..Thank you. Arup -- View this message in context: http://www.nabble.com/problem-of--importing-files-into-R-tp21784574p21784574.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] error message with roxygen
I have found something there : https://lists.r-forge.r-project.org/pipermail/roxygen-devel/2009-January/16.html In order to do static callgraphs, the package itself has to be loadable; that's unfortunate in the sense that you may have to install the package before generating the docs. But I can't understand what I must do in my short example... Thank you for any help. david 2009/1/30 David Hajage dhajag...@gmail.com Hello useRs, I'm trying to use the Roxygen package. Here my code file : #' A packge to check Roxygen's sanity #' @name helloRoxygen-package #' @docType package NA And my R code to generate the package : library(roxygen) package.skeleton(helloRoxygen, code_files = roxy.r, force = T) roxygenize(helloRoxygen, helloRoxygen, copy.package = F, unlink.target = F, overwrite = T) I obtain this error message : Writing helloRoxygen-package to helloRoxygen/man/helloRoxygen-package.Rd Writing namespace directives to helloRoxygen/NAMESPACE Merging collate directive with helloRoxygen/DESCRIPTION to helloRoxygen/DESCRIPTION *Avis dans load.dependencies() : Package(s) 'helloRoxygen' wouldn't load; callgraphs might be incomplete. * I don't understand what this means. I'm doing something wrong? Thank you for your help. Best regards, david [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with foreign package
On 2/2/2009 8:46 AM, Kevin E. Thorpe wrote: I tried to use write.foreign() to export to SAS this morning and got an error. When I looked at the code for writeForeignSAS() I saw this line: dfn -df which I think should be dfn - df So, I tried to run update.packages() to see if there was an updated version and got the following result. That bug was fixed a few weeks ago, but a new version has not been released yet. You can get the latest source from svn: https://svn.r-project.org/R-packages/trunk/foreign update.packages(c(foreign)) Warning message: In list.files(lib) : list.files: 'foreign' is not a readable directory I ran the above command as root. Is this because the foreign package is a core package and not a CRAN one? It is a recommended package, which means it is on CRAN, but is also included in binary distributions of R. But the reason you got that error is because update.packages() doesn't take a package name as the first arg, the first arg is lib.loc. You need to answer the interactive questions if you don't want to update everything. Duncan Murdoch My sessionInfo() is R version 2.8.0 (2008-10-20) i686-pc-linux-gnu locale: LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=en_US;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.8.0 and my version of foreign is 0.8-30 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] concatenating 2 text columns in a data.frame
Hi, I'm trying to concatenate values from two columns in a data frame. For example, I have the following data.frame: C1 C2 C3 C4 C5 A B *F C* Q G H *I J* T K D *R S* E P L *M N* O I'd like to concatenate text from columns C3 and C4, to yield either a list or vector, like so: NewCol FC IJ RS MN Is this feasible in R? Thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Defining plot colors based on a variable
Dear Andrew, Have a look at ggplot2 library(ggplot2) ggplot(curr_assoc, aes(x = BP, y = P, colour = FILE)) + geom_point() + scale_y_log10() HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher The plural of anecdote is not data. ~ Roger Brinner The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data. ~ John Tukey -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Andrew Singleton Verzonden: maandag 2 februari 2009 15:56 Aan: r-help@r-project.org Onderwerp: [R] Defining plot colors based on a variable Hi, I have been trying unsuccessfully to plot data using different colors based on a variable within a subset of an imported file. The file I am reading is about 2 lines long and has a column (in the example called FILE) that contains approximately 100 unique entries. I would like to plot a subset of the data from the file and key the color from the FILE column, This is what my file looks like : CHR SNP BPNMISS BETA SE R2 TPREGIONFILERANDOM 1 rs17035189 10519610 135 0.3518 1.928 0.0002501 0.1824 0.8555 TCTX47303410.284627081 6 rs3763311 32484154 109 -2.05 1.6240.01467 -1.262 0.2096 TCTX6706030.083147673 6 rs3892710 32790839 106 0.5695 4.743 0.0001386 0.1201 0.9047 TCTX71504030.549192815 6 rs3864300 32379785 102 9.208 6.4160.02018 1.435 0.1544 TCTX72100170.837265988 6 rs6912002 32873245 13 -1.295 5.043 0.005963 -0.25690.802 TCTX27104410.170566699 5rs4024109 359553749 26.19 31.010.09245 0.8444 0.4263 TCTX26506530.298573497 6 rs3129719 32769757 16 10.35 7.44 0.1215 1.391 0.1859 TCTX29005040.378538235 6rs476885 32402690 109 -0.09378 1.552 3.411e-05 -0.06041 0.9519 TCTX6706030.017970964 10 rs125707665602540 139 0.6182 6.66 6.289e-05 0.09283 0.9262 TCTX45607670.004973939 etc And this is the code that I have: assoc_data - read.table(master.out, header =TRUE) par(fig=c(0, 10, 0, 10 )/10, mar=c(10,8,2,8),xpd=NA, cex.axis=2) attach(assoc_data) curr_assoc - assoc_data[CHR == 1 BP 50 BP 100, ] #these criteria change based on input from another file #count the number of transcripts transcripts - length(unique(curr_assoc$FILE)) #generate that number of unique ³FILE² entries in my subset of data my_colors - rainbow(transcripts) plot(curr_assoc$BP, log10(curr_assoc$P)*-1, pch=20, col=c(my_colors)[curr_assoc$FILE], ylim=c(-15, 15),xaxs=i, xlab=NA, cex=0.7, cex.lab=2) detach(assoc_data) The problem is that when I plot this I only see (for example) 2 colors instead of the expected 10. I believe that the problem I am having is that the FILE column is being recoded when I read the table (as a factor?) and that only factors within the range of my colors are being plotted (so if I have 10 colors but there are 100 unique entries in my FILE column, and the variables recoded 2, 7, 12, 34, 60, 64, 65, 70 and 71 are used, only 2 and 7 will be plotted). Many thanks for any suggestions/pointers, I have dug around in the help archives for a couple of hours but no joy. --- Andrew Singleton [[alternative HTML version deleted]] Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document. The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Outliers package function scores question
Dear R-experts, I'm having some doubts concernig the scores function of the outliers package. I don´t understand the results when I select the p-value option on a sample, ie, when I use scores(x,(method),1). The help on the function says that the output are the p-values associatted to the sample. But for example: ser[[8]] Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec 2005 82 2006 3139 2380 1462 2897 2961 6501 686 1550 2124 2743 2652 2807 2007 2759 2974 3235 2928 606 6113 3493 2796 3607 2008 2544 3517 2008 1791 5132 3558 2898 1730 3352 2338 2462 scores(ser[[8]],mad,1) Jan Feb Mar Apr May 2005 2006 0.6613307497 0.3069006015 0.0527997798 0.5487581386 0.5793236926 2007 0.4820994162 0.5854804388 0.7028297078 0.5636110196 0.0039452802 2008 0.1113882364 0.9977003225 0.8223588740 0.5492384458 0.0979746949 Jun Jul Aug Sep Oct 2005 2006 0.965147 0.0052386075 0.0653256352 0.2074755271 0.4743676743 2007 0.713783 0.8010952047 0.50 0.8374015640 0.1695530561 2008 0.753207 0.2892402178 0.3426727125 Nov Dec 2005 0.0004967017 2006 0.4306622988 0.5053234242 2007 0.3799148443 0.8091190064 2008 but when I choose the significance: scores(ser[[8]],mad,0.99) Jan Feb Mar Apr May Jun Jul Aug Sep OctNov Dec 2005 TRUE 2006 FALSE FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE FALSE FALSE FALSE 2007 FALSE FALSE FALSE FALSE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE 2008 FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE Note that the higer values get p-value-scores around 0.99 and above, but small values like 83 get a score of 0.0004967017. So, first, which is the null hypothesis for these calculations??, now second, why the p-values have these values???, and third, how must I interpreter the p values returned by this function? 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.
Re: [R] Problems in Recommending R
We often get emails like the first in this thread that R could do with an update on homepage design (I fully agree) ... but actually nobody volunteers to do it. Hence, we still have what I did when the worldwide number of R users was probably less than 1000. Well I've volunteered a couple of times but no one took me up on the offer... I'm not sure a competition to redesign the homepage is the best way to go. Why not start a fund to hire a professional designer to look at all aspects of the R website? 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] error message with roxygen
On Fri, Jan 30, 2009 at 3:49 AM, David Hajage dhajag...@gmail.com wrote: Hello useRs, I'm trying to use the Roxygen package. Here my code file : #' A packge to check Roxygen's sanity #' @name helloRoxygen-package #' @docType package NA And my R code to generate the package : library(roxygen) package.skeleton(helloRoxygen, code_files = roxy.r, force = T) roxygenize(helloRoxygen, helloRoxygen, copy.package = F, unlink.target = F, overwrite = T) I obtain this error message : Writing helloRoxygen-package to helloRoxygen/man/helloRoxygen-package.Rd Writing namespace directives to helloRoxygen/NAMESPACE Merging collate directive with helloRoxygen/DESCRIPTION to helloRoxygen/DESCRIPTION *Avis dans load.dependencies() : Package(s) 'helloRoxygen' wouldn't load; callgraphs might be incomplete.* I don't understand what this means. I'm doing something wrong? That's not an error - just a warning. You can't get complete call graphs (if you need them) unless you've already installed your helloRoxygen package. If you're not using the call graphs, don't worry about it. 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] error message with roxygen
Thank you Hadley! 2009/2/2 hadley wickham h.wick...@gmail.com On Fri, Jan 30, 2009 at 3:49 AM, David Hajage dhajag...@gmail.com wrote: Hello useRs, I'm trying to use the Roxygen package. Here my code file : #' A packge to check Roxygen's sanity #' @name helloRoxygen-package #' @docType package NA And my R code to generate the package : library(roxygen) package.skeleton(helloRoxygen, code_files = roxy.r, force = T) roxygenize(helloRoxygen, helloRoxygen, copy.package = F, unlink.target = F, overwrite = T) I obtain this error message : Writing helloRoxygen-package to helloRoxygen/man/helloRoxygen-package.Rd Writing namespace directives to helloRoxygen/NAMESPACE Merging collate directive with helloRoxygen/DESCRIPTION to helloRoxygen/DESCRIPTION *Avis dans load.dependencies() : Package(s) 'helloRoxygen' wouldn't load; callgraphs might be incomplete.* I don't understand what this means. I'm doing something wrong? That's not an error - just a warning. You can't get complete call graphs (if you need them) unless you've already installed your helloRoxygen package. If you're not using the call graphs, don't worry about it. Hadley -- http://had.co.nz/ [[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] Matrix
Hi, I have a very basic question on merging two matrices by alternating the rows. For illustration, assume two matrices - A looks like: 10 10 10 10 B looks like: 20 20 20 20 How do I combine them such that I get alternating rows from A and B? My final result should be C which looks like: 10 10 20 20 10 10 20 20 Thanks very much, and I am sorry for such a newbie question. Shruthi -- View this message in context: http://www.nabble.com/Matrix-tp21792064p21792064.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem with foreign package
Prof Brian Ripley wrote: On Mon, 2 Feb 2009, Duncan Murdoch wrote: On 2/2/2009 8:46 AM, Kevin E. Thorpe wrote: I tried to use write.foreign() to export to SAS this morning and got an error. When I looked at the code for writeForeignSAS() I saw this line: dfn -df which I think should be dfn - df So, I tried to run update.packages() to see if there was an updated version and got the following result. That bug was fixed a few weeks ago, but a new version has not been released yet. You can get the latest source from svn: https://svn.r-project.org/R-packages/trunk/foreign Yes, and there is a good reason. No less than 3 people reported problems in 0.8-29 without reproducible examples. When I releaseed 0.8-30, I asked them to test it. Despite reminders, I am still waiting for any answer, and will wait another week. It really is unhelpful to report problems and not be prepared to answer follow-up questions nor test solutions. Well, I installed the new version, and my export to SAS worked. -- Kevin E. Thorpe Biostatistician/Trialist, Knowledge Translation Program Assistant Professor, Dalla Lana School of Public Health University of Toronto email: kevin.tho...@utoronto.ca Tel: 416.864.5776 Fax: 416.864.6057 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Defining plot colors based on a variable
Hadley and Thierry, thank you ggplot2 is a great package and this worked perfectly. On 2/2/09 10:10 AM, hadley wickham h.wick...@gmail.com wrote: On Mon, Feb 2, 2009 at 8:56 AM, Andrew Singleton singl...@mail.nih.gov wrote: Hi, I have been trying unsuccessfully to plot data using different colors based on a variable within a subset of an imported file. The file I am reading is about 2 lines long and has a column (in the example called FILE) that contains approximately 100 unique entries. I would like to plot a subset of the data from the file and key the color from the FILE column, This is what my file looks like : CHR SNP BPNMISS BETA SE R2 TPREGIONFILERANDOM 1 rs17035189 10519610 135 0.3518 1.928 0.0002501 0.1824 0.8555 TCTX47303410.284627081 6 rs3763311 32484154 109 -2.05 1.6240.01467 -1.262 0.2096 TCTX6706030.083147673 6 rs3892710 32790839 106 0.5695 4.743 0.0001386 0.1201 0.9047 TCTX71504030.549192815 6 rs3864300 32379785 102 9.208 6.4160.02018 1.435 0.1544 TCTX72100170.837265988 6 rs6912002 32873245 13 -1.295 5.043 0.005963 -0.25690.802 TCTX27104410.170566699 5rs4024109 359553749 26.19 31.010.09245 0.8444 0.4263 TCTX26506530.298573497 6 rs3129719 32769757 16 10.35 7.44 0.1215 1.391 0.1859 TCTX29005040.378538235 6rs476885 32402690 109 -0.09378 1.552 3.411e-05 -0.06041 0.9519 TCTX6706030.017970964 10 rs125707665602540 139 0.6182 6.66 6.289e-05 0.09283 0.9262 TCTX45607670.004973939 etc And this is the code that I have: assoc_data - read.table(master.out, header =TRUE) par(fig=c(0, 10, 0, 10 )/10, mar=c(10,8,2,8),xpd=NA, cex.axis=2) attach(assoc_data) curr_assoc - assoc_data[CHR == 1 BP 50 BP 100, ] #these criteria change based on input from another file #count the number of transcripts transcripts - length(unique(curr_assoc$FILE)) #generate that number of unique ³FILE² entries in my subset of data my_colors - rainbow(transcripts) plot(curr_assoc$BP, log10(curr_assoc$P)*-1, pch=20, col=c(my_colors)[curr_assoc$FILE], ylim=c(-15, 15),xaxs=i, xlab=NA, cex=0.7, cex.lab=2) detach(assoc_data) You might find it easier to use ggplot2: install.packages(ggplot2) library(ggplot2) qplot(BP, P, data = curr_assoc, colour = FILE, log=y) To ensure that you always have the same colours, you can set the limits for the colour scale (in analogous way to setting the limits for the x axis): qplot(BP, P, data = curr_assoc, colour = FILE, log=y) + scale_colour_hue(limits = c(2, 7, 12, 34, 60, 64, 65, 70, 71)) Hadley -- http://had.co.nz/ Dear Andrew, Have a look at ggplot2 library(ggplot2) ggplot(curr_assoc, aes(x = BP, y = P, colour = FILE)) + geom_point() + scale_y_log10() HTH, Thierry ir. Thierry Onkelinx Instituut voor natuur- en bosonderzoek / Research Institute for Nature and Forest Cel biometrie, methodologie en kwaliteitszorg / Section biometrics, methodology and quality assurance Gaverstraat 4 9500 Geraardsbergen Belgium tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher [[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] Odp: Matrix
Hi r-help-boun...@r-project.org napsal dne 02.02.2009 16:52:06: Hi, I have a very basic question on merging two matrices by alternating the rows. For illustration, assume two matrices - A looks like: 10 10 10 10 B looks like: 20 20 20 20 How do I combine them such that I get alternating rows from A and B? My final result should be C which looks like: 10 10 20 20 10 10 20 20 I would rbind both matrices and then indexed the resulting matrix. x-rep(10,4) y-rep(20,4) dim(x)-c(2,2) dim(y)-c(2,2) z-rbind(x,y) z [,1] [,2] [1,] 10 10 [2,] 10 10 [3,] 20 20 [4,] 20 20 ind-c(seq(1,4,2), seq(2,4,2)) z[ind,] z[ind,] [,1] [,2] [1,] 10 10 [2,] 20 20 [3,] 10 10 [4,] 20 20 Regards Petr Thanks very much, and I am sorry for such a newbie question. Shruthi -- View this message in context: http://www.nabble.com/Matrix-tp21792064p21792064.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] how to generate multiple random variables that are correlated
Hi. I have two variables, x and y, that are each normally distributed with mean 0 and have known standard deviations. The variables also have a known correlation, so I can represent their correlations in a matrix like so: a - array(c(0.3,0.1,0.1,0.2),c(2,2)) a Is there an R function that generates random values for my two variables given the correlation? I'd like to do this for up to 5 variables and I'm running version 2.7.2 on a windows platform. Thanks. eric __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 generate multiple random variables that are correlated
Dear Eric, See ?mvrnorm in the MASS package. HTH, Jorge On Mon, Feb 2, 2009 at 11:15 AM, eric lee ericlee...@gmail.com wrote: Hi. I have two variables, x and y, that are each normally distributed with mean 0 and have known standard deviations. The variables also have a known correlation, so I can represent their correlations in a matrix like so: a - array(c(0.3,0.1,0.1,0.2),c(2,2)) a Is there an R function that generates random values for my two variables given the correlation? I'd like to do this for up to 5 variables and I'm running version 2.7.2 on a windows platform. Thanks. eric __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error message when executing summary() with dataset diamonds in ggplot2
Hi: I am experiencing a problem with dataset diamonds in ggplot2. When trying execute the summary(diamonds) statement, the following error message is displayed: Error in summary(diamonds) : Cannot open file 'C:/Users/James/R_Pgms/R/R-2.8.1/library/ggplot2/data/Rdata.rdb': No such file or directory Can you please advise me? A complete history of commands leading up to this problem is as follows. I have also included in this history a set of parallel statements (involving a different dataset, Davis, in a different package, car) for which the summary command executed OK. My first three commands were as follows: library(car) library(ggplot2) search() The displayed results of the search command confirmed that both packages were now in the search path. The next three commands were as follows: data(Davis) data(diamonds) ls() The displayed results of the list command confirmed that both datasets were in the workspace. Next, the following statement provided the expected dataframe summary summary(Davis) However, a similar statement for the dataframe diamonds resulted in the error message described above. I am running on a PC with Vista and SP1 The sessionInfo() command displayed the following: R version 2.8.1 (2008-12-22) i386-pc-mingw32 locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 attached base packages: [1] grid stats graphics grDevices datasets utils methods [8] base other attached packages: [1] ggplot2_0.8.1 reshape_0.8.2 plyr_0.1.4 proto_0.3-8 [5] car_1.2-11 rcom_2.0-4 rscproxy_1.0-12 loaded via a namespace (and not attached): [1] tools_2.8.1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Specifying the gap between dodge'd bins groups?
I'm looking at ggplot-static\position_dodge.html For ggplot(diamonds, aes(x=price, fill=cut)) + geom_bar(position=dodge) , is it possible to specify the spacing between the dodge'd bin groupings? That is, I would like for there to be a small separation (horizontal space) between the Ideal and the Fair bars on the plot. That way the reader can get a better idea of when each bin ends and the other begins. I think this horizontal spacing naturally occurs for discrete data, but for continuous data as is shown in the second figure, the bins all seem to right beside each other. It would be nice if a small space could be added. Thank you agian for your help and feedback. [[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 generate multiple random variables that are correlated
eric lee ericlee100 at gmail.com writes: [snip] Is there an R function that generates random values for my two variables given the correlation? I'd like to do this for up to 5 variables and I'm running version 2.7.2 on a windows platform. Thanks. ?MASS::mvrnrom __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Selectively Removing objects
On 02/02/2009 8:16 AM, Paulo Grahl wrote: Dear list members, Does anyone know how to use rm() to remove only variables but not declared functions from the environment ? I understand I could name all the functions with, let's say f_something, make sure that all variables do not start with f_ and then remove all BUT objects starting with f_. However, I have already defined all the functions and it would be troublesome to change all of them to a new name. Any hint ? Here's a list of functions: lsf.str() And here's a list of everything: ls() So here are non-functions: setdiff(ls(), lsf.str()) And here they go: rm(list = setdiff(ls(), lsf.str()) ) 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] Specifying the gap between dodge'd bins groups?
Hi Jason, On Mon, Feb 2, 2009 at 9:10 AM, Jason Rupert jasonkrup...@yahoo.com wrote: I'm looking at ggplot-static\position_dodge.html For ggplot(diamonds, aes(x=price, fill=cut)) + geom_bar(position=dodge) , is it possible to specify the spacing between the dodge'd bin groupings? That is, I would like for there to be a small separation (horizontal space) between the Ideal and the Fair bars on the plot. That way the reader can get a better idea of when each bin ends and the other begins. I think this horizontal spacing naturally occurs for discrete data, but for continuous data as is shown in the second figure, the bins all seem to right beside each other. It would be nice if a small space could be added. You can do something like this: ggplot(diamonds, aes(x=price, fill=cut)) + geom_bar(position=position_dodge(width=400), binwidth=500) 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] Odp: Matrix
Hi, Perhaps this can help if you don't want to manually specify the permutation of indices, A=matrix(10,ncol=2,nrow=2) B - 2*A C - rbind(A, B) C[ as.vector(t(matrix(seq(1,nrow(C)),ncol=2))), ] # trick to create the vector of permutations [,1] [,2] [1,] 10 10 [2,] 20 20 [3,] 10 10 [4,] 20 20 The transpose operation might slow down the process on very large matrices, I'm not sure how to improve this. Hope this helps, baptiste On 2 Feb 2009, at 17:02, Paul Smith wrote: On Mon, Feb 2, 2009 at 4:05 PM, Petr PIKAL petr.pi...@precheza.cz wrote: Hi r-help-boun...@r-project.org napsal dne 02.02.2009 16:52:06: Hi, I have a very basic question on merging two matrices by alternating the rows. For illustration, assume two matrices - A looks like: 10 10 10 10 B looks like: 20 20 20 20 How do I combine them such that I get alternating rows from A and B? My final result should be C which looks like: 10 10 20 20 10 10 20 20 I would rbind both matrices and then indexed the resulting matrix. x-rep(10,4) y-rep(20,4) dim(x)-c(2,2) dim(y)-c(2,2) z-rbind(x,y) z [,1] [,2] [1,] 10 10 [2,] 10 10 [3,] 20 20 [4,] 20 20 ind-c(seq(1,4,2), seq(2,4,2)) z[ind,] z[ind,] [,1] [,2] [1,] 10 10 [2,] 20 20 [3,] 10 10 [4,] 20 20 Another solution: m1 - matrix(10,4,2) m2 - matrix(20,2,2) m1[seq(2,4,2),] - m2 Paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. _ Baptiste Auguié School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] bootstrapping in regression
Others have confirmed that you use the predicted values plus permuted residuals is the new y variable and also referred you to some other articles. On the question of does this work for mixed effects models: That is a good question, and it depends on what question you are trying to answer and what assumptions you are trying to make. The mixed effects model is more complicated in that you not only have residuals that you are permuting, but possibly also random effects, depending on your question(s) of interest. Then to further complicate things, you need to take into account any correlations between the different residuals/effects. If you can work out a reduced model of interest under your null hypothesis, and see how to permute the other pieces in a way that preserves the correlation or works with assumed orthogonality. Then it should work for you (but not be simple). I would suggest that you try doing a bunch of simulations where you first create data sets that follow your null hypothesis (reduced model), then do the permutation test on them. If everything is working correctly, then the p-values should follow a roughly uniform distribution (if not, then the permutation test is not working for your situation, your assumptions are not holding, or something else is messed up). Doing the simulations will force you to think about all the pieces that go into the analysis and how reasonable your assumptions are. If this works, then try simulating under the alternative (full model) to see what type of power you have to see the difference and compare that to other approaches. 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 Thomas Mang Sent: Thursday, January 29, 2009 3:52 PM To: r-h...@stat.math.ethz.ch Subject: Re: [R] bootstrapping in regression Greg Snow wrote: What you are describing is actually a permutation test rather than a bootstrap (related concepts but with a subtle but important difference). The way to do a permutation test with multiple x's is to fit the reduced model (use all x's other than x1 if you want to test x1) on the original data and store the fitted values and the residuals. Permute the residuals (randomize their order) and add them back to the fitted values and fit the full model (including x1 this time) to the permuted data set. Do this a bunch of times and it will give you the sampling distribution for the slope on x1 (or whatever your set of interest is) when the null hypothesis that it is 0 given the other variables in the model is true. Hi, Thanks to you and Tom for the correction regarding bootstrapping vs permutation, and to Chuck for the cool link. Yes of course I described a permutation. I have a question here: I am not sure if I understand your 'fit the full model ... to the permuted data set'. Am I correct to suppose that once the residuals of the reduced-model fit have been permuted and added back to the fitted values, the values obtained this way (fitted + permuted residuals) now constitute the new y-values to which the full model is fitted? Is that correct ? Do you know if this procedure is also valid for a mixed-effects model ? thanks a lot, Thomas Permuting just x1 only works if x1 is orthogonal to all the other predictors, otherwise the permuting destroys the relationship with the other predictors and does not do the test you want. Bootstrapping depends on sampling with replacement, not permuting, and is used more for confidence intervals than for tests (the reference by John Fox given to you in another reply can help if that is the approach you want to take). Hope this helps, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Matrix
Try this: matrix(rbind(x, y), nc = 2, byrow = TRUE) On Mon, Feb 2, 2009 at 10:52 AM, Shruthi Jayaram shruthi.jayaram...@gmail.com wrote: Hi, I have a very basic question on merging two matrices by alternating the rows. For illustration, assume two matrices - A looks like: 10 10 10 10 B looks like: 20 20 20 20 How do I combine them such that I get alternating rows from A and B? My final result should be C which looks like: 10 10 20 20 10 10 20 20 Thanks very much, and I am sorry for such a newbie question. Shruthi -- View this message in context: http://www.nabble.com/Matrix-tp21792064p21792064.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] Matrix
Sorry, there was an error. Try this: x - matrix(1:4, 2) y - 10 * x matrix(t(cbind(x, y)), nc = 2, byrow = TRUE) On Mon, Feb 2, 2009 at 12:32 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Try this: matrix(rbind(x, y), nc = 2, byrow = TRUE) On Mon, Feb 2, 2009 at 10:52 AM, Shruthi Jayaram shruthi.jayaram...@gmail.com wrote: Hi, I have a very basic question on merging two matrices by alternating the rows. For illustration, assume two matrices - A looks like: 10 10 10 10 B looks like: 20 20 20 20 How do I combine them such that I get alternating rows from A and B? My final result should be C which looks like: 10 10 20 20 10 10 20 20 Thanks very much, and I am sorry for such a newbie question. Shruthi -- View this message in context: http://www.nabble.com/Matrix-tp21792064p21792064.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] New to R
Hello All, A colleague of mine started working with R and out of curiosity I did some research on the language. Very nice. In my opinion this is one of the best languages I've found for getting tasks I'm interested in done. I wrote this simple die roller and was curious to know if it is R enough. ## # # Input: # die_size - 4, 6, 8, 10, 20 # number_of_dice - How many dice to roll # number_of_rolls - How many times to roll the dice # # Output: #rolls - The array holding the values of the dice # ## # function(die_size, number_of_dice, number_of_rolls) { rolls - array(0, dim=c(number_of_rolls, number_of_dice)) for (i in 1:number_of_rolls) { rolls[i,] - sample(die_size, number_of_dice, replace=TRUE) } return(rolls) } Any thoughts on this function? Is there a better way of doing it in R? Can you tell I used to play ADD? Thanks, Joe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Specifying the gap between dodge'd bins groups?
This appears to work great. However, is there a way to programmatically to extract the bin size that ggplot selected in order to be able to change this for multiple data sets? Similarly, is there a way to determine the number of count in each bin that ggplot establish? I wanted to change the axis a bit based on the count size, but I needed to do it programmatically give the large number of samples. For the example below, it would be something like the following: ggplot(diamonds, aes(x=price, fill=cut)) + geom_bar(position=position_dodge(width=default_ggplotbinwidth*0.75), binwidth=default_ggplotbinwidth) + ylim(0, ggplotmaxcount*1.1) I would like to have access to the calculated ggplotbin and ggplotmaxcount for the data set. Thank you again for your help. --- On Mon, 2/2/09, hadley wickham h.wick...@gmail.com wrote: From: hadley wickham h.wick...@gmail.com Subject: Re: [R] Specifying the gap between dodge'd bins groups? To: jasonkrup...@yahoo.com Cc: Date: Monday, February 2, 2009, 11:10 AM Hi Jason, On Mon, Feb 2, 2009 at 9:10 AM, Jason Rupert jasonkrup...@yahoo.com wrote: I'm looking at ggplot-static\position_dodge.html For ggplot(diamonds, aes(x=price, fill=cut)) + geom_bar(position=dodge) , is it possible to specify the spacing between the dodge'd bin groupings? That is, I would like for there to be a small separation (horizontal space) between the Ideal and the Fair bars on the plot. That way the reader can get a better idea of when each bin ends and the other begins. I think this horizontal spacing naturally occurs for discrete data, but for continuous data as is shown in the second figure, the bins all seem to right beside each other. It would be nice if a small space could be added. You can do something like this: ggplot(diamonds, aes(x=price, fill=cut)) + geom_bar(position=position_dodge(width=400), binwidth=500) Hadley -- http://had.co.nz/ [[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] Tunnelling X for R graphics
On Saturday 31 January 2009, Erik Iverson wrote: Dylan, Can you confirm that you've done that before while tunneling R graphics over ssh? I thought I'd tried and screen and failed with a similar message when using graphics as Adam had. I could be wrong though. Ack. Maybe I spoke too soon. I haven't encountered the error before and *expected* screen to take care of connection problems... However I cannot confirm that it would work for your case... Sorry! Dylan Dylan Beaudette wrote: Try starting your R session after starting a 'screen' session. Like this: $ screen $ R # do stuff, when taking a break do CTRL-A D to disconnect # use as normal See the man page for screen, it is basically a terminal multiplexer that can gracefully accommodate connection failures. If you get disconnected, re-connect, and then re-attach the screen process: $ screen -r and you should be ok. Cheers, Dylan On 1/31/09, Adam D. I. Kramer a...@ilovebacon.org wrote: Dear colleagues, I run R on a few different machines, and view graphs and the like by tunnelling X through SSH to my local machine. This is useful for me because my local machine can't easily handle some of the data sets I work with. However, when an ssh connection dies, the tunnelled X session also dies, which breaks R's device connection, generating this error: Error: X11 fatal IO error: please save work and shut down R ...that's kinda scary, so I quit(save=yes) and then run R again. The problem, and maybe I'm just whining here, is that because the data sets are large this takes several minutes where I'm basically just sitting around. This happens once every other day as the VPN software I'm using times out after about 24 hours and thus the ssh session dies. I can't really guess at why a broken X session would corrupt a running session of R so severely that it would need to be completely restarted. Can anyone explain this to me? Or perhaps (hopefully) someone has enough knowledge of the X11 device to be able to tell me that I can ignore this message, and just use dev.off() and then X11(localhost:10) to open a new working X11 connection? Cordially, Adam Kramer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- Dylan Beaudette Soil Resource Laboratory http://casoilresource.lawr.ucdavis.edu/ University of California at Davis 530.754.7341 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] quantiles for sorted pairs of data
Hi everybody, Suppose I have continuous measurements of an energy waveform that is sampled discretely for different heights every 0.5m. Let's say I want to find out the height for which I have equal amount of energy above and below. My colleague did the following: a. calculate the cumulative sum of the energy b. calculate the median of the cumulative energy c. find out what is the height for which this median corresponds. My take on this is: Since the heights are already sorted from min to max, and the cumulative energy is by default sorted from min to max …. it does not matter if I calculate the median of the cumulative energy and see which height it belongs to when I can calculate directly the median of the height and get actually same result. I think the same holds if I calculate any other quantile if I am interested in the corresponding height of that cumulative energy quantile. I did some simulations to see if this is true, and I have simulated the energy values as a random sample of a normal distribution, gamma, f distribution or random sample of a combination of normal and gamma distributions. My question is: do any of you know of any reference that proves that? Paper, math property of already ordered sequences, anything to prove that this is not just a coincidence? Following is an example, with n = 15 just for convenience to see with naked eye which value should be the median (I will also use only examples from a normal distribution, but the results prove the same does not matter which distribution I use for energy) ### code starts set.seed = 123 xn - rnorm(15) xn - xn+3 #to have only positive numbers yn - seq(1, 8, 0.5) zn - cumsum(xn) dfn - data.frame(energy = xn, elevation = yn, cum.energ = zn) percent - apply(dfn,2, function(x) quantile(x, probs = c(0.1, 0.25, 0.5, 0.75, 0.95))) percent dfn f - approxfun(yn, zn) f(percent[1,2]) ## code ends As you can see quantiles for the cumulative energy corresponds to the respective quantiles of elevation, but quantiles of the energy waveform itself correspond to different heights than the elevation quantiles. Any help for references will be very much appreciated. Thanks for any help, Monica _ 12009 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Defining plot colors based on a variable
On Mon, Feb 2, 2009 at 8:56 AM, Andrew Singleton singl...@mail.nih.gov wrote: Hi, I have been trying unsuccessfully to plot data using different colors based on a variable within a subset of an imported file. The file I am reading is about 2 lines long and has a column (in the example called FILE) that contains approximately 100 unique entries. I would like to plot a subset of the data from the file and key the color from the FILE column, This is what my file looks like : CHR SNP BPNMISS BETA SE R2 TPREGIONFILERANDOM 1 rs17035189 10519610 135 0.3518 1.928 0.0002501 0.1824 0.8555 TCTX47303410.284627081 6 rs3763311 32484154 109 -2.05 1.6240.01467 -1.262 0.2096 TCTX6706030.083147673 6 rs3892710 32790839 106 0.5695 4.743 0.0001386 0.1201 0.9047 TCTX71504030.549192815 6 rs3864300 32379785 102 9.208 6.4160.02018 1.435 0.1544 TCTX72100170.837265988 6 rs6912002 32873245 13 -1.295 5.043 0.005963 -0.25690.802 TCTX27104410.170566699 5rs4024109 359553749 26.19 31.010.09245 0.8444 0.4263 TCTX26506530.298573497 6 rs3129719 32769757 16 10.35 7.44 0.1215 1.391 0.1859 TCTX29005040.378538235 6rs476885 32402690 109 -0.09378 1.552 3.411e-05 -0.06041 0.9519 TCTX6706030.017970964 10 rs125707665602540 139 0.6182 6.66 6.289e-05 0.09283 0.9262 TCTX45607670.004973939 etc And this is the code that I have: assoc_data - read.table(master.out, header =TRUE) par(fig=c(0, 10, 0, 10 )/10, mar=c(10,8,2,8),xpd=NA, cex.axis=2) attach(assoc_data) curr_assoc - assoc_data[CHR == 1 BP 50 BP 100, ] #these criteria change based on input from another file #count the number of transcripts transcripts - length(unique(curr_assoc$FILE)) #generate that number of unique ³FILE² entries in my subset of data my_colors - rainbow(transcripts) plot(curr_assoc$BP, log10(curr_assoc$P)*-1, pch=20, col=c(my_colors)[curr_assoc$FILE], ylim=c(-15, 15),xaxs=i, xlab=NA, cex=0.7, cex.lab=2) detach(assoc_data) You might find it easier to use ggplot2: install.packages(ggplot2) library(ggplot2) qplot(BP, P, data = curr_assoc, colour = FILE, log=y) To ensure that you always have the same colours, you can set the limits for the colour scale (in analogous way to setting the limits for the x axis): qplot(BP, P, data = curr_assoc, colour = FILE, log=y) + scale_colour_hue(limits = c(2, 7, 12, 34, 60, 64, 65, 70, 71)) 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] New to R
Try this: matrix(sample(dsize, nrolls * ndice, replace = FALSE), nrolls, ndice) On Mon, Feb 2, 2009 at 12:39 PM, Joe Hughes joe.hug...@earthlink.net wrote: Hello All, A colleague of mine started working with R and out of curiosity I did some research on the language. Very nice. In my opinion this is one of the best languages I've found for getting tasks I'm interested in done. I wrote this simple die roller and was curious to know if it is R enough. ## # # Input: # die_size - 4, 6, 8, 10, 20 # number_of_dice - How many dice to roll # number_of_rolls - How many times to roll the dice # # Output: #rolls - The array holding the values of the dice # ## # function(die_size, number_of_dice, number_of_rolls) { rolls - array(0, dim=c(number_of_rolls, number_of_dice)) for (i in 1:number_of_rolls) { rolls[i,] - sample(die_size, number_of_dice, replace=TRUE) } return(rolls) } Any thoughts on this function? Is there a better way of doing it in R? Can you tell I used to play ADD? Thanks, Joe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] survfit using quantiles to group age
I am using the package Design for survival analysis. I want to plot a simple Kaplan-Meier fit of survival vs. age, with age grouped as quantiles. I can do this: survplot(survfit(Surv(time,status) ~ cut(age,3), data=veteran) but I would like to do something like this: survplot(survfit(Surv(time,status) ~ quantile(age,3), data=veteran) #will not work ideally I would like to superimpose estimates from cph models, which automatically fit the 2nd to 4rth quantiles for age, so I need the age groups to be grouped the same. Any help greatly appreciated! Eleni Rapsomaniki __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] New to R
Gabor, Shouldn't the replace be TRUE instead of FALSE? I get this error Error in sample(6, 28, replace = FALSE) : cannot take a sample larger than the population when 'replace = FALSE' when I use FALSE. I don't get the error when it is TRUE. Examining my mental model of what is going on you can't remove a number from a die thus each sample(value of the die) when selected has to be replaced. Or am I missing something? Thanks, Joe On Feb 2, 2009, at 1:00 PM, Gabor Grothendieck wrote: Try this: matrix(sample(dsize, nrolls * ndice, replace = FALSE), nrolls, ndice) On Mon, Feb 2, 2009 at 12:39 PM, Joe Hughes joe.hug...@earthlink.net wrote: Hello All, A colleague of mine started working with R and out of curiosity I did some research on the language. Very nice. In my opinion this is one of the best languages I've found for getting tasks I'm interested in done. I wrote this simple die roller and was curious to know if it is R enough. ## # # Input: # die_size - 4, 6, 8, 10, 20 # number_of_dice - How many dice to roll # number_of_rolls - How many times to roll the dice # # Output: #rolls - The array holding the values of the dice # ## # function(die_size, number_of_dice, number_of_rolls) { rolls - array(0, dim=c(number_of_rolls, number_of_dice)) for (i in 1:number_of_rolls) { rolls[i,] - sample(die_size, number_of_dice, replace=TRUE) } return(rolls) } Any thoughts on this function? Is there a better way of doing it in R? Can you tell I used to play ADD? Thanks, Joe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 get my IT department to bless R?
There has already been good discussion on this topic, but here are a couple of other things to think about: 1. is it your job to convince your IT department, or is it your job to convince your boss, and your boss's job to convince/dictate to the IT department (getting your boss on your side could be easier and very beneficial (or not depending on the boss)). 2. Why not do a simple cost analysis comparing what you do now using R compared to what it will cost if you do not use R, be honest in all the costs, but include how optional pieces will affect your productivity. I would start with a cost for a single license of S-PLUS (most similar to R out there), then include the annual license fee for S-PLUS. Do you only use R on your single work computer? Or do you use it at home/laptop/other computers? Include the cost for the additional licenses, or how your work would be impacted by only being able to use it when sitting at the one computer. Next, what packages do you use in R that are not available in S-PLUS currently? How often do you use them and for what? Include this information in the cost analysis, because any tools not available will either limit your productivity, take time for you to learn an alternative, or will require time/money for someone to convert them to work with S-PLUS (either you estimate your time needed, IT (how much time would it take them to get up to speed enough to do the conversion), or hiring an outside programmer (cost?)). List those things out with details, costs (needed and optional), and the effects of having or not having optional pieces. Also include discussions on the concerns that Stavros has mentioned (and any other that your IT department is likely to have). Present all of that to your boss and he/she may just become your advocate for blessing R (saving money can be more of a motivation than parts of the workflow that you see as important, but they don't understand). 3. Being a Microsoft shop, do they allow you to use MSExcel?, would they allow you to install a plug-in for Excel? (An interface and full R implementation are available as a plugin, this could be a back door for installing R that does not need a policy change). 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 Daniel Viar Sent: Thursday, January 29, 2009 3:29 PM To: r-help@r-project.org Subject: [R] How do I get my IT department to bless R? I currently use R at work under the radar, but there's a chance I could loose that access. I'd like to get our company to feel comfortable with open source and R in particular. Does anyone have any experience with their company's IT department and management that they would be willing to share? How does one get an all Microsoft shop on board with allowing users to user R? I know about the recent NY Times article and recent news. I'm afraid I may need some case studies or examples of what other companies have done. Any help would be greatly appreciated. Thanks Dan Viar Chesapeake, VA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] New to R
Yes, it should be TRUE. On Mon, Feb 2, 2009 at 1:16 PM, Joe Hughes joe.hug...@earthlink.net wrote: Gabor, Shouldn't the replace be TRUE instead of FALSE? I get this error Error in sample(6, 28, replace = FALSE) : cannot take a sample larger than the population when 'replace = FALSE' when I use FALSE. I don't get the error when it is TRUE. Examining my mental model of what is going on you can't remove a number from a die thus each sample(value of the die) when selected has to be replaced. Or am I missing something? Thanks, Joe On Feb 2, 2009, at 1:00 PM, Gabor Grothendieck wrote: Try this: matrix(sample(dsize, nrolls * ndice, replace = FALSE), nrolls, ndice) On Mon, Feb 2, 2009 at 12:39 PM, Joe Hughes joe.hug...@earthlink.net wrote: Hello All, A colleague of mine started working with R and out of curiosity I did some research on the language. Very nice. In my opinion this is one of the best languages I've found for getting tasks I'm interested in done. I wrote this simple die roller and was curious to know if it is R enough. ## # # Input: # die_size - 4, 6, 8, 10, 20 # number_of_dice - How many dice to roll # number_of_rolls - How many times to roll the dice # # Output: #rolls - The array holding the values of the dice # ## # function(die_size, number_of_dice, number_of_rolls) { rolls - array(0, dim=c(number_of_rolls, number_of_dice)) for (i in 1:number_of_rolls) { rolls[i,] - sample(die_size, number_of_dice, replace=TRUE) } return(rolls) } Any thoughts on this function? Is there a better way of doing it in R? Can you tell I used to play ADD? Thanks, Joe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Event sequence analysis
Dear R help, I am analyzing sequences of events described by time and a unique event tag. And I am searching for recurring patterns where patterns have to show up in a certain time window, e.g. 5 or 10 minutes. Of course, inbetween these events other events may occur. I have applied basket analysis approaches like apriori or 'frequent item set' algorithms with interesting results but these methods do not take into account the exact succession of events. I also looked into the 'Generalized Sequential Pattern' function of Weka, but the implementation in Weka does not allow for a time window (as far as I understand). Are there other sequence analysis implementations available in R? -- For instance in the realm of the 1997 paper Discovery of frequent episodes in event sequences by H. Mannila et al. Please no BioConductor hints as they are meaning something different with (genetic) sequence analysis. Very best, Hans Werner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Selectively Removing objects
If you want to keep the functions, why not move them to a different environment so that they don't get deleted when you delete everything else (this will also work better if you want to use these same functions in other R sessions). The most comprehensive way to do this is to create a package with the functions (package.skeleton will get you started). One of the simplest ways to do this (if the package idea is overkill, though if you expand this, the package solution may not be overkill in the long run) is to use the 'save' command to save your functions into a file, delete everything including the functions, then use 'attach' to attach the file you saved the functions in. Now you can still use the functions (just be careful if you try to edit them), but they are not in the main environment where the data is stored and when you delete 'everything' the next time, the attached functions will not be affected. 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 Paulo Grahl Sent: Monday, February 02, 2009 6:17 AM To: r-help@r-project.org Subject: [R] Selectively Removing objects Dear list members, Does anyone know how to use rm() to remove only variables but not declared functions from the environment ? I understand I could name all the functions with, let's say f_something, make sure that all variables do not start with f_ and then remove all BUT objects starting with f_. However, I have already defined all the functions and it would be troublesome to change all of them to a new name. Any hint ? Thanks Paulo Gustavo Grahl, CFA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Now - how to fix the overlap
Yikes. On closer inspection this causes there to be a noticeable amount of overlap of the various vertical bars. Speccifically, it appears that the second overlaps the first, the third overlaps the second, etc. This is much more noteable for a data set with a smaller x-axis. Thanks again for any feedback. --- On Mon, 2/2/09, hadley wickham h.wick...@gmail.com wrote: From: hadley wickham h.wick...@gmail.com Subject: Re: [R] Specifying the gap between dodge'd bins groups? To: jasonkrup...@yahoo.com Cc: Date: Monday, February 2, 2009, 11:10 AM Hi Jason, On Mon, Feb 2, 2009 at 9:10 AM, Jason Rupert jasonkrup...@yahoo.com wrote: I'm looking at ggplot-static\position_dodge.html For ggplot(diamonds, aes(x=price, fill=cut)) + geom_bar(position=dodge) , is it possible to specify the spacing between the dodge'd bin groupings? That is, I would like for there to be a small separation (horizontal space) between the Ideal and the Fair bars on the plot. That way the reader can get a better idea of when each bin ends and the other begins. I think this horizontal spacing naturally occurs for discrete data, but for continuous data as is shown in the second figure, the bins all seem to right beside each other. It would be nice if a small space could be added. You can do something like this: ggplot(diamonds, aes(x=price, fill=cut)) + geom_bar(position=position_dodge(width=400), binwidth=500) Hadley -- http://had.co.nz/ [[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] importing data from a disc or HDD [SEC=UNCLASSIFIED]
I hope this is not a stupid question, but I am having difficulty importing data from sources like CDs, HDD, or flashcards. Can anyone help ? Joe [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] [R-pkgs] RMySQL 0.7-3
Dear R users, RMySQL 0.7-3 has been released. Expect it to hit the CRAN mirrors shortly, but in the mean time please get it here: http://biostat.mc.vanderbilt.edu/RMySQL From the NEWS file: Version 0.7-3 * Added mysqlClientLibraryVersions() which returns the compiled and loaded client library versions as a vector. * RMySQL will now check for MySQL minor version consistency and throw an error when the client and loaded library versions don't match. Best, Jeff -- http://biostat.mc.vanderbilt.edu/JeffreyHorner ___ R-packages mailing list r-packa...@r-project.org https://stat.ethz.ch/mailman/listinfo/r-packages __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Tunnelling X for R graphics
On Sat, 31-Jan-2009 at 03:16PM -0800, Adam D. I. Kramer wrote: [] The problem, and maybe I'm just whining here, is that because the data sets are large this takes several minutes where I'm basically just sitting around. This happens once every other day as the VPN software I'm using times out after about 24 hours and thus the ssh session dies. Is it possible to do anything about the VPN software? I use tightVNC to do something similar and it doesn't time out after 24 hours. Even closing the desktop machine down altogether does not lose the ssh connexion. Restarting the desktop a week later will still find the X session without loss. HTH -- ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. ___Patrick Connolly {~._.~} Great minds discuss ideas _( Y )_ Average minds discuss events (:_~*~_:) Small minds discuss people (_)-(_) . Eleanor Roosevelt ~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~.~. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problems in Recommending R
Plain HTML coding is simple enough for this list ( I think)...but aesthetic designhmm But a contest would the best way to get the best design and can be publicly asked from the graphics community ( not just the R community)..remember Tom Sawyer and the fence :) - I volunteer in both cases :) Winner of Design Contest should get some bragging rights in a small hyperlink (with nofollow tag -so no seo) on main page ,French Wine in the user conference location , etc etc... On Mon, Feb 2, 2009 at 5:26 PM, friedrich.lei...@stat.uni-muenchen.dewrote: On Mon, 02 Feb 2009 08:44:21 +0100, Thomas Petzoldt (TP) wrote: Hi, you are probably right, though I must say that I like *spartanic and efficient* homepages and I don't think that the example given by the first mail is a good prototype for the R homepage. But, yes, occasional face lifting may be adequate. Anti-aliasing is of course simple, but that's probably not the point. (And I know that there are graphics experts with a masters in psychology between us.) So, why not a new Homepage Graphics Competition 2009? There is still some time until useR!2009 in Rennes: http://www2.agrocampus-ouest.fr/math/useR-2009/ Perhaps we should extend that to a competition for the complete design of the homepage? We often get emails like the first in this thread that R could do with an update on homepage design (I fully agree) ... but actually nobody volunteers to do it. Hence, we still have what I did when the worldwide number of R users was probably less than 1000. For technical reasons there are some conditions: the homepage is maintained via SVN like the R sources, so all should be plain HTML, no content management system etc. Ad frames: the main reason that I used them in the first place is to have the menus etc in only one file, no need for updating several files when a link changes. Today I would probably use iframes, but any other soultion is fine, too. Another plus would be if we could use the same design for CRAN, and that means no server-trickery like server-side includes etc (because we do not control the server setup of the mirrors). Best, Fritz -- --- Prof. Dr. Friedrich Leisch Institut für Statistik Tel: (+49 89) 2180 3165 Ludwig-Maximilians-Universität Fax: (+49 89) 2180 5308 Ludwigstraße 33 D-80539 München http://www.statistik.lmu.de/~leisch --- Journal Computational Statistics --- http://www.springer.com/180 Münchner R Kurse --- http://www.statistik.lmu.de/R __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] xyplot with lowess curves
I am trying to change the attributes of the lowess lines fit to an xyplot command, but have been unsuccessful in my search of the online help. Right now, both the points and lowess line come out in the same color (blue). I am unsure how I can change the properties of the lowess line separately. xyplot ( SnowLineElevation ~ Year | Model, data = data, ylim = c(0,1800), type = c('p','smooth'), col = 'blue', pch = 21, xlab = 'Year', ylab = 'Snowline Elevation [m]' ) Any help would be much appreciated, Dave [[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] New to R
If you are interested in rolling dice with R (as opposed to using this as a simple test case to start writing your own programs), then you may want to look at the dice function from the TeachingDemos package. The core line in this function is basically the same as Gabor's suggestion, but with the added option of weighting the dice (you don't like how I graded your exam? I am happy to let these computerized dice regrade it for you :-). There is also an option to plot the results (for 6-sided dice). There is also the plot.rgl.die and roll.rgl.die functions in the same package that give an animated rolling of the die (I really need to rewrite it to get a better animation, the coin flip works ok as is). 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 Joe Hughes Sent: Monday, February 02, 2009 10:40 AM To: R-help@r-project.org Subject: [R] New to R Hello All, A colleague of mine started working with R and out of curiosity I did some research on the language. Very nice. In my opinion this is one of the best languages I've found for getting tasks I'm interested in done. I wrote this simple die roller and was curious to know if it is R enough. ### ### # # Input: # die_size - 4, 6, 8, 10, 20 # number_of_dice - How many dice to roll # number_of_rolls - How many times to roll the dice # # Output: #rolls - The array holding the values of the dice # ### ### # function(die_size, number_of_dice, number_of_rolls) { rolls - array(0, dim=c(number_of_rolls, number_of_dice)) for (i in 1:number_of_rolls) { rolls[i,] - sample(die_size, number_of_dice, replace=TRUE) } return(rolls) } Any thoughts on this function? Is there a better way of doing it in R? Can you tell I used to play ADD? Thanks, Joe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] R: Trellis Graph
?lattice::shingle Hope that helps, if not, give more detail/example. -- 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 KA Sent: Sunday, February 01, 2009 2:37 PM To: r-help@r-project.org Subject: [R] R: Trellis Graph I would like to plot X against Y in a trellis graph, wherein Y is the conditioning variable. Y represents time, but instead of distinct categories (eg, 0-10,11-20,21-30,...) I would like to use overlapping categories (0-10,0-20,0-30,...). Does anyone know how to do this, either via options in R graphics or by manipulating the data ? Thank you. Kieran Burnett __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] New to R
Joe Hughes wrote: # function(die_size, number_of_dice, number_of_rolls) { you may want to replace rolls - array(0, dim=c(number_of_rolls, number_of_dice)) for (i in 1:number_of_rolls) { rolls[i,] - sample(die_size, number_of_dice, replace=TRUE) } with, e.g. rolls = t(replicate(number_of_rolls, sample(die_size, number_of_dice, replace=TRUE))) to have it more r-ish return(rolls) } Any thoughts on this function? as soon as you start wrapping something like subset, lm, or the like inside your functions, all hell breaks loose. welcome to the r inferno, that is. vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 get my IT department to bless R?
I won't burden the list with copies of earlier posts -- all of us have experienced the frustration of dealing with folk who want to make their life easier by making ours difficult. However, I have noted that a few folk are starting to change attitudes. I was hired to give a training session last June to a fairly large unit in the Canadian government that realized a mix of Excel and SAS and SPSS and ... were leading to an unmaintainable mess of small applications needed to handle the information needed for core responsibilities. When an employee leaves a large spreadsheet that contains the analytic and prediction model, it is generally a VERY big job to maintain. The boss of the unit realized that small R scripts could do a lot of the work and that dataframes and spreadsheets are relatively easy to interchange if one avoids fancy features. Thus it was feasible to use spreadsheets for data entry -- reducing training costs and I don't know R etc., though with some risks -- and have some youngish new hires write the scripts to do the analysis and reports that were needed every few days. If the folk involved are reading this, I'll apologize in advance for over-simplifying. The central theme here is economic, in that it is making life easier for all. John Nash __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problems in Recommending R
friedrich.lei...@stat.uni-muenchen.de wrote: On Mon, 2 Feb 2009 18:14:03 +0530, Ajay ohri (Ao) wrote: Plain HTML coding is simple enough for this list ( I think)...but aesthetic designhmm In most cases one can do more than most think using HTML and CSS: Our universities corporate design was done by professionals and is backed by a CMS: http://www.uni-muenchen.de Our dpertment didn't want to use the CMS, so we emulated it using HTML, CSS and iframes: http://www.stat.uni-muenchen.de/ which is *much* more convenient to maintain for us: I have a copy of my page on my laptop, I can work on it while offline on a train, etc. I don't want to discuss whether the above examples are aesthetic or not (we are required to follow the coporate design, so have no choice). The main point I want to make is: that everything is static HTML makes life very easy for command line junkies like me ;-) Apart from making life easy for command line junkies, plain HTML is also very search engine friendly. Best, Tobias __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] survfit using quantiles to group age
Eleni Rapsomaniki wrote: I am using the package Design for survival analysis. I want to plot a simple Kaplan-Meier fit of survival vs. age, with age grouped as quantiles. I can do this: survplot(survfit(Surv(time,status) ~ cut(age,3), data=veteran) but I would like to do something like this: survplot(survfit(Surv(time,status) ~ quantile(age,3), data=veteran) #will not work ideally I would like to superimpose estimates from cph models, which automatically fit the 2nd to 4rth quantiles for age, so I need the age groups to be grouped the same. Any help greatly appreciated! Eleni Rapsomaniki This will result in a poor fitting model and residual confounding (by only partially adjusting for a variable; you are assuming a piecewise flat model). Use Surv( ) ~ strat(cut2(age,g=3)) ... For Design it is often better to do ageg - cut2(age,g=3) # Donald Rumsfeld approach to using information f - cph(Surv( ) ~ strat(ageg), ...) Frank -- 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] sas.get under Linux
Adrian Dusa wrote: Dear Frank, I understand. Never used SAS before, so I don't have it installed anywhere. StatTransfer is a very useful tool indeed, but maybe I don't know how to use it properly. What I have is a mydata.sas7bdat file, along with a formats.sas7bcat file. I specified reading SAS value labels Read directly from a catalog file, but nothing appears in the output, neither in the R workspace nor in an intermediate SPSS file. I also tried exporting to a SAS portable file to import directly in R, but there is probably something obvious that I miss because value labels are not there, whatever I do... Thanks for your help, Adrian Stat/Transfer has a menu option to read the SAS format catalog but I haven't tried it. Frank On Saturday 31 January 2009, Frank E Harrell Jr wrote: Adrian Dusa wrote: Dear all, I am trying to import a SAS file into R (in fact I only need the value labels from the formats file), using Hmisc package, but I get this error: my.sas - sas.get(/home/adi/3, fis1_sgg) sh: sas: not found Error in sas.get(/home/adi/3, fis1_sgg) : SAS job failed with status 32512 I read some past discussions and I get the impression that sas.get() needs the full path to the SAS executable, but I don't have that because I am using Linux. Is it possible to use sas.get() without having SAS installed? Since sas.get is trying to execute sas the answer is a definite no unless you use the sas.get option to run SAS on another machine to produce the input ASCII files needed by sas.get. Also investigate sasxport.get if you have SAS version 5 transport files to import. See also http://biostat.mc.vanderbilt.edu/SASexportHowto As SAS never got it right in allowing for full metadata to be included in a SAS dataset, you often have to run PROC FORMAT CNTLOUT=... to convert format libraries to SAS datasets so that programs such as sasxport.get can assign value labels [if you have SAS installed, sas.get runs PROC CONTENTS for you.]. SPSS and Stata have always been ahead of SAS in this regard. Note that the excellent Stat/Transfer commercial product will convert from almost any SAS dataset format to compact R binary objects, including variable labels the way the Hmisc package handles them. If you have another way to convert from SAS to Stata or SPSS, R is great at readying those formats. Frank Or alternatively, is there another function to import the formats into R? Thanks in advance for any hint, Adrian -- Adrian Dusa Romanian Social Data Archive 1, Schitu Magureanu Bd. 050025 Bucharest sector 5 Romania Tel.:+40 21 3126618 \ +40 21 3120210 / int.101 Fax: +40 21 3158391 -- 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] xyplot with lowess curves
You'll need a custom panel function. It would also help if you provided a reproducible example: xyplot ( SnowLineElevation ~ Year | Model, data = data, panel = function(x, y, col, ...) { col - ifelse(panel.number() == 1, red, green) panel.xyplot(x, y, col = blue, ...) panel.loess(x, y, col = col) }, ylim = c(0,1800), pch = 21, xlab = 'Year', ylab = 'Snowline Elevation [m]' ) Alternatively, you can use the group argument in conjunction with the panels: xyplot(SnowLineElevation ~ Year | Model, data, groups = Model, type = c(p, smooth)) if you want the points and the lines to be the same color. --sundar On Mon, Feb 2, 2009 at 10:20 AM, Hutchinson,David [PYR] david.hutchin...@ec.gc.ca wrote: I am trying to change the attributes of the lowess lines fit to an xyplot command, but have been unsuccessful in my search of the online help. Right now, both the points and lowess line come out in the same color (blue). I am unsure how I can change the properties of the lowess line separately. xyplot ( SnowLineElevation ~ Year | Model, data = data, ylim = c(0,1800), type = c('p','smooth'), col = 'blue', pch = 21, xlab = 'Year', ylab = 'Snowline Elevation [m]' ) Any help would be much appreciated, Dave [[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] Selectively Removing objects
Thanks Greg. I did in the past looked into the details of how to create a package. I did not seem too complicated, but it would be time consuming -- an then when one thinks in creating a package (even for his own use) it always a good idea to check for wrong inputs, to have all functions well documented, etc. The functions I've developed so far are not yet in this stage. But i liked the idea of using attach(). I had overlooked this point in the attach() description. Thanks. Paulo Gustavo Grahl, CFA On Mon, Feb 2, 2009 at 4:41 PM, Greg Snow greg.s...@imail.org wrote: If you want to keep the functions, why not move them to a different environment so that they don't get deleted when you delete everything else (this will also work better if you want to use these same functions in other R sessions). The most comprehensive way to do this is to create a package with the functions (package.skeleton will get you started). One of the simplest ways to do this (if the package idea is overkill, though if you expand this, the package solution may not be overkill in the long run) is to use the 'save' command to save your functions into a file, delete everything including the functions, then use 'attach' to attach the file you saved the functions in. Now you can still use the functions (just be careful if you try to edit them), but they are not in the main environment where the data is stored and when you delete 'everything' the next time, the attached functions will not be affected. 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 Paulo Grahl Sent: Monday, February 02, 2009 6:17 AM To: r-help@r-project.org Subject: [R] Selectively Removing objects Dear list members, Does anyone know how to use rm() to remove only variables but not declared functions from the environment ? I understand I could name all the functions with, let's say f_something, make sure that all variables do not start with f_ and then remove all BUT objects starting with f_. However, I have already defined all the functions and it would be troublesome to change all of them to a new name. Any hint ? Thanks Paulo Gustavo Grahl, CFA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] New to R
All, Thanks for taking the time to reply. I understand a bit more about R and the R way then I did before.The final function looks like this: ## # # Input: # die_size - 4, 6, 8, 10, 20 # number_of_dice - How many dice to roll # number_of_rolls - How many times to roll the dice # # Output: #The array holding the results of the rolls # ## # function(die_size, number_of_dice, number_of_rolls=1) { return(t(replicate(number_of_rolls, sample(die_size, number_of_dice, replace=TRUE } Before I take a look at the teaching demos, I have one question left. Here is a sequence of commands and the output sample(6, 4, replace=TRUE) [1] 3 4 5 4 replicate(7, sample(6, 4, replace=TRUE)) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,]3364566 [2,]4465516 [3,]5145656 [4,]4631122 Why does replicate transpose the vector before assigning it to the array? The way I would output it would be this [,1] [,2] [,3] [,4] [1,]3454 [2,]3416 [3,]6643 [4,]4551 [5,]5561 [6,]6152 [7,]6662 Thanks, Joe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 get my IT department to bless R?
On 2/02/2009, at 4:29 PM, Murray Cooper wrote: I was about to post a similar reply. Stavros's reply was very eloquent and should be taken to heart! I would just like to say that in my very humble opinion Stavros's reply was utter nonsense. It was the sort of excuse-making favoured by tyrants since time immemorial. cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problems in Recommending R
On 2/02/2009, at 3:52 PM, Ajay ohri wrote: Dear List, One persistent feedback I am getting to people who are newly introduced to R ( especially in this cost cutting recession) is - 1) The website looks a bit old. While the current website does have a lot of hard work behind it, should n't a world class statistics package have a better website instead. You can check out www.knime.org which is an open source software , and free, and supports R---and notice the change in perception . I think the R website is just fine as it is. Effort should be put into content and not into cosmetics. Those (potential) users who would be likely to be influenced by such trivialities as the appearance of the web page are unlikely to be the sort of people who would use R anyway. cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 get my IT department to bless R?
Perhaps rather than globally saying it is utter nonsense you would care to refute what you think is wrong about it? -s PS Tyrants? Wow, we are really dramatizing life at work now On Mon, Feb 2, 2009 at 3:14 PM, Rolf Turner r.tur...@auckland.ac.nz wrote: On 2/02/2009, at 4:29 PM, Murray Cooper wrote: I was about to post a similar reply. Stavros's reply was very eloquent and should be taken to heart! I would just like to say that in my very humble opinion Stavros's reply was utter nonsense. It was the sort of excuse-making favoured by tyrants since time immemorial. cheers, Rolf Turner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Tunnelling X for R graphics
Indeed, I am running R in screen. That is the context in which this error occurs. The problem is that screen passes $DISPLAY as the $DISPLAY for the actual terminal. So when the ssh session dies, the X11 connection is broken. The REST of R works fine...which is why I use screen in the first place. My data is not lost, etc., however it tells me I need to save and quit immediately. That is my concern. --Adam On Sat, 31 Jan 2009, Dylan Beaudette wrote: Try starting your R session after starting a 'screen' session. Like this: $ screen $ R # do stuff, when taking a break do CTRL-A D to disconnect # use as normal See the man page for screen, it is basically a terminal multiplexer that can gracefully accommodate connection failures. If you get disconnected, re-connect, and then re-attach the screen process: $ screen -r and you should be ok. Cheers, Dylan On 1/31/09, Adam D. I. Kramer a...@ilovebacon.org wrote: Dear colleagues, I run R on a few different machines, and view graphs and the like by tunnelling X through SSH to my local machine. This is useful for me because my local machine can't easily handle some of the data sets I work with. However, when an ssh connection dies, the tunnelled X session also dies, which breaks R's device connection, generating this error: Error: X11 fatal IO error: please save work and shut down R ...that's kinda scary, so I quit(save=yes) and then run R again. The problem, and maybe I'm just whining here, is that because the data sets are large this takes several minutes where I'm basically just sitting around. This happens once every other day as the VPN software I'm using times out after about 24 hours and thus the ssh session dies. I can't really guess at why a broken X session would corrupt a running session of R so severely that it would need to be completely restarted. Can anyone explain this to me? Or perhaps (hopefully) someone has enough knowledge of the X11 device to be able to tell me that I can ignore this message, and just use dev.off() and then X11(localhost:10) to open a new working X11 connection? Cordially, Adam Kramer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] xyplot with lowess curves
I haven't had much luck with a custom panel function; mainly because I don't truly understand how to embedd the functionality into the xyplot command. Here's a reproducible example if you can help out. Thanks, Dave library (lattice) d - NULL models - c('A','B','C','D') n = 100 for (i in seq(along = models)){ d - rbind( d, data.frame ( Model = models[i], Year = seq(1960, length.out=n, by = 1), SnowLineElevation = runif(n, 0, 100) ) ) } xyplot ( SnowLineElevation ~ Year | Model, data = d, ylim = c(0,100), type = c('p','smooth'), col = 'blue', pch = 21, xlab = 'Year', ylab = 'Snowline Elevation [m]' ) -Original Message- From: Sundar Dorai-Raj [mailto:sdorai...@gmail.com] Sent: Monday, February 02, 2009 11:43 AM To: Hutchinson,David [PYR] Cc: r-help@r-project.org Subject: Re: [R] xyplot with lowess curves You'll need a custom panel function. It would also help if you provided a reproducible example: xyplot ( SnowLineElevation ~ Year | Model, data = data, panel = function(x, y, col, ...) { col - ifelse(panel.number() == 1, red, green) panel.xyplot(x, y, col = blue, ...) panel.loess(x, y, col = col) }, ylim = c(0,1800), pch = 21, xlab = 'Year', ylab = 'Snowline Elevation [m]' ) Alternatively, you can use the group argument in conjunction with the panels: xyplot(SnowLineElevation ~ Year | Model, data, groups = Model, type = c(p, smooth)) if you want the points and the lines to be the same color. --sundar On Mon, Feb 2, 2009 at 10:20 AM, Hutchinson,David [PYR] david.hutchin...@ec.gc.ca wrote: I am trying to change the attributes of the lowess lines fit to an xyplot command, but have been unsuccessful in my search of the online help. Right now, both the points and lowess line come out in the same color (blue). I am unsure how I can change the properties of the lowess line separately. xyplot ( SnowLineElevation ~ Year | Model, data = data, ylim = c(0,1800), type = c('p','smooth'), col = 'blue', pch = 21, xlab = 'Year', ylab = 'Snowline Elevation [m]' ) Any help would be much appreciated, Dave [[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] parsing problem
venkata kirankumar kiran4u2all at gmail.com writes: I am trying to parse a vector for caliculating minimum in that vector the vector having values like 1Kontrolle 2 Placebo 3 125mg/kg 4 250mg/kg 5 500mg/kg 61000mg/kg hear i tries for comverting it into numeric with using as.numaric() function but i got values like 5 6 2 3 4 1 can anyone suggest how I will solve it thanks in advance regards; kiran Your Kontrolle is being treated as a factor so you are seeing only the codes of the levels. There is probably something more elegant, but you need something like, as.numeric(sapply(with(dd, strsplit(levels(Placebo)[Placebo], m)), [[, 1)) -- Ken Knoblauch Inserm U846 Institut Cellule Souche et Cerveau Département Neurosciences Intégratives 18 avenue du Doyen Lépine 69500 Bron France tel: +33 (0)4 72 91 34 77 fax: +33 (0)4 72 91 34 61 portable: +33 (0)6 84 10 64 10 http://www.sbri.fr __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] New to R
It is not transposing (it just looks that way). The first result is a vector which is 1 dimensional, but is neither a row or a column. The printed version of it looks like a row, because that is a more compact representation. If you sample enough points you will see it wrap around and be represented as several rows. If it printed as a single column, then the first values would scroll off the screen with only a moderate number of values. The replicate function then takes these vectors and combines them into a matrix and just happens to use each vector as a column of the new matrix, this is standard, matrices by default are filled by column, look at the output of as.matrix( sample( 6, 4, replace=TRUE ) ) and you will see your vector converted to a matrix of 1 column. It could have been done the other way, but way back the decision was made to do it this way and there are probably a lot of things that would break if it were changed now, so we get to live with it. A single call to 't' is not too much effort to get what we expect. So in short, a vector is neither a column or a row, but prints as a row for practical reasons, and is converted to a column by default if made into a matrix. 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 Joe Hughes Sent: Monday, February 02, 2009 1:09 PM To: R help Subject: Re: [R] New to R All, Thanks for taking the time to reply. I understand a bit more about R and the R way then I did before.The final function looks like this: ### ### # # Input: # die_size - 4, 6, 8, 10, 20 # number_of_dice - How many dice to roll # number_of_rolls - How many times to roll the dice # # Output: #The array holding the results of the rolls # ### ### # function(die_size, number_of_dice, number_of_rolls=1) { return(t(replicate(number_of_rolls, sample(die_size, number_of_dice, replace=TRUE } Before I take a look at the teaching demos, I have one question left. Here is a sequence of commands and the output sample(6, 4, replace=TRUE) [1] 3 4 5 4 replicate(7, sample(6, 4, replace=TRUE)) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,]3364566 [2,]4465516 [3,]5145656 [4,]4631122 Why does replicate transpose the vector before assigning it to the array? The way I would output it would be this [,1] [,2] [,3] [,4] [1,]3454 [2,]3416 [3,]6643 [4,]4551 [5,]5561 [6,]6152 [7,]6662 Thanks, Joe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] xyplot with lowess curves
Does this do what you want? The panel argument has the custom pane function I referred to before. Col - c(red, green, blue, purple) xyplot ( SnowLineElevation ~ Year | Model, data = d, panel = function(x, y, col, ...) { Col - Col[panel.number()] panel.xyplot(x, y, col = blue, ...) panel.loess(x, y, col = Col) }, ylim = c(0,100), type = c('p','smooth'), col = 'blue', pch = 21, xlab = 'Year', ylab = 'Snowline Elevation [m]' ) On Mon, Feb 2, 2009 at 12:18 PM, Hutchinson,David [PYR] david.hutchin...@ec.gc.ca wrote: I haven't had much luck with a custom panel function; mainly because I don't truly understand how to embedd the functionality into the xyplot command. Here's a reproducible example if you can help out. Thanks, Dave library (lattice) d - NULL models - c('A','B','C','D') n = 100 for (i in seq(along = models)){ d - rbind( d, data.frame ( Model = models[i], Year = seq(1960, length.out=n, by = 1), SnowLineElevation = runif(n, 0, 100) ) ) } xyplot ( SnowLineElevation ~ Year | Model, data = d, ylim = c(0,100), type = c('p','smooth'), col = 'blue', pch = 21, xlab = 'Year', ylab = 'Snowline Elevation [m]' ) -Original Message- From: Sundar Dorai-Raj [mailto:sdorai...@gmail.com] Sent: Monday, February 02, 2009 11:43 AM To: Hutchinson,David [PYR] Cc: r-help@r-project.org Subject: Re: [R] xyplot with lowess curves You'll need a custom panel function. It would also help if you provided a reproducible example: xyplot ( SnowLineElevation ~ Year | Model, data = data, panel = function(x, y, col, ...) { col - ifelse(panel.number() == 1, red, green) panel.xyplot(x, y, col = blue, ...) panel.loess(x, y, col = col) }, ylim = c(0,1800), pch = 21, xlab = 'Year', ylab = 'Snowline Elevation [m]' ) Alternatively, you can use the group argument in conjunction with the panels: xyplot(SnowLineElevation ~ Year | Model, data, groups = Model, type = c(p, smooth)) if you want the points and the lines to be the same color. --sundar On Mon, Feb 2, 2009 at 10:20 AM, Hutchinson,David [PYR] david.hutchin...@ec.gc.ca wrote: I am trying to change the attributes of the lowess lines fit to an xyplot command, but have been unsuccessful in my search of the online help. Right now, both the points and lowess line come out in the same color (blue). I am unsure how I can change the properties of the lowess line separately. xyplot ( SnowLineElevation ~ Year | Model, data = data, ylim = c(0,1800), type = c('p','smooth'), col = 'blue', pch = 21, xlab = 'Year', ylab = 'Snowline Elevation [m]' ) Any help would be much appreciated, Dave [[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] sem package and AMOS
Hello- I am using R to build my initial models, but need to use AMOS to compare the models of two groups (adults vs. kids). The problem is I am getting different results with R and AMOS for the initial models of the separate groups (and the R results make more sense). The parameter estimates (path coefficients and variances) from both programs are nearly identical, but the model chi-squares (and significance estimates of the parameter estimates) are different. I am using Maximum Likelihood in AMOS. R I think defaults to two-stage-least squares estimate, and AMOS 16 does not implement 2SLS. I am using fMRI data, so the error variances are likely correlated, and the data non-normal to varying degrees. Is 2SLS the better way to go for these kinds of data? Is there a way to change the default method for R sem? I couldn't find this in the ?help. I note I have run some of the AMOS examples in R and have gotten identical results across platforms, so I believe the problem is not in specifying things incorrectly across platforms. Also, the dfs are identical for both analyses. I must use AMOS to do model comparison (and thus maximum likelihood), but would like to achieve similar results across platforms for the basic models before I proceed, and would like to track down the reason for the difference. Thanks, Anthony -- Anthony Steven Dick, Ph.D. Post-Doctoral Fellow Human Neuroscience Laboratory Department of Neurology The University of Chicago 5841 S. Maryland Ave. MC-2030 Chicago, IL 60637 Phone: (773)-834-7770 Email: ad...@uchicago.edu Web: http://home.uchicago.edu/~adick/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] xyplot with lowess curves
Sundar, That is exactly what I was hoping for. Thanks for your help! Dave -Original Message- From: Sundar Dorai-Raj [mailto:sdorai...@gmail.com] Sent: Monday, February 02, 2009 12:47 PM To: Hutchinson,David [PYR] Cc: r-help@r-project.org Subject: Re: [R] xyplot with lowess curves Does this do what you want? The panel argument has the custom pane function I referred to before. Col - c(red, green, blue, purple) xyplot ( SnowLineElevation ~ Year | Model, data = d, panel = function(x, y, col, ...) { Col - Col[panel.number()] panel.xyplot(x, y, col = blue, ...) panel.loess(x, y, col = Col) }, ylim = c(0,100), type = c('p','smooth'), col = 'blue', pch = 21, xlab = 'Year', ylab = 'Snowline Elevation [m]' ) On Mon, Feb 2, 2009 at 12:18 PM, Hutchinson,David [PYR] david.hutchin...@ec.gc.ca wrote: I haven't had much luck with a custom panel function; mainly because I don't truly understand how to embedd the functionality into the xyplot command. Here's a reproducible example if you can help out. Thanks, Dave library (lattice) d - NULL models - c('A','B','C','D') n = 100 for (i in seq(along = models)){ d - rbind( d, data.frame ( Model = models[i], Year = seq(1960, length.out=n, by = 1), SnowLineElevation = runif(n, 0, 100) ) ) } xyplot ( SnowLineElevation ~ Year | Model, data = d, ylim = c(0,100), type = c('p','smooth'), col = 'blue', pch = 21, xlab = 'Year', ylab = 'Snowline Elevation [m]' ) -Original Message- From: Sundar Dorai-Raj [mailto:sdorai...@gmail.com] Sent: Monday, February 02, 2009 11:43 AM To: Hutchinson,David [PYR] Cc: r-help@r-project.org Subject: Re: [R] xyplot with lowess curves You'll need a custom panel function. It would also help if you provided a reproducible example: xyplot ( SnowLineElevation ~ Year | Model, data = data, panel = function(x, y, col, ...) { col - ifelse(panel.number() == 1, red, green) panel.xyplot(x, y, col = blue, ...) panel.loess(x, y, col = col) }, ylim = c(0,1800), pch = 21, xlab = 'Year', ylab = 'Snowline Elevation [m]' ) Alternatively, you can use the group argument in conjunction with the panels: xyplot(SnowLineElevation ~ Year | Model, data, groups = Model, type = c(p, smooth)) if you want the points and the lines to be the same color. --sundar On Mon, Feb 2, 2009 at 10:20 AM, Hutchinson,David [PYR] david.hutchin...@ec.gc.ca wrote: I am trying to change the attributes of the lowess lines fit to an xyplot command, but have been unsuccessful in my search of the online help. Right now, both the points and lowess line come out in the same color (blue). I am unsure how I can change the properties of the lowess line separately. xyplot ( SnowLineElevation ~ Year | Model, data = data, ylim = c(0,1800), type = c('p','smooth'), col = 'blue', pch = 21, xlab = 'Year', ylab = 'Snowline Elevation [m]' ) Any help would be much appreciated, Dave [[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] all subset of a data frame column
Dear All, I have a data frame (mydata), with let say 5 columns V1,V2,...,V5. (we know the power set of {V1,V2,..,V5} has 2^5-1 elements). I need to construct a vector T of length 5 which its i-th element is the maximum of (let say) mean values obtained based on the columns subset of size i. I mean: T[1]=max(mean(mydata[,1]),...,mean(mydata[,5])) T[2]=max(mean(mydata[,c(1,2)],mean(mydata[,c(1,3)],...,mean(mydata[,c(1,5]) T[3]=max(mean(mydata[,c(1,2,3)],mean(mydata[,c(1,2,4)],...,mean(mydata[,c(3,4,5)]) T[5]=max(mean(mydata[,c(1,2,3,4,5)] Many thanks in advance. Hamid __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] thurston case 5
Never mind, as you can tell I am new at R, I had to load the package. Best, Jared japomani wrote: John, I installed the psych package and all it's dependencies. Then following the psych manual, I type thurstone(x, ranks = FALSE, digits = 2) the result is Error: could not find function thurstone Any suggestions? Best, Jared John Fox-6 wrote: Dear Jared, See ?thurstone in the psych package. RSiteSearch(Thurstone) turns this up as the first hit. Also see the BradleyTerry package for the similar Bradley-Terry model. Regards, John -- John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada web: socserv.mcmaster.ca/jfox -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of japomani Sent: January-31-09 5:04 PM To: r-help@r-project.org Subject: [R] thurston case 5 Hi, I hope some one can help. I need to compute Thurston's case 5 on a large set of data. I have gotten as far as computing the proportional preference matrix but the next math is beyond me. Here us my matrix 0.500 0.472 0.486 0.587 0.366 0.483 0.496 0.434 0.528 0.500 0.708 0.578 0.633 0.554 0.395 0.620 0.514 0.292 0.500 0.370 0.557 0.580 0.615 0.329 0.413 0.422 0.630 0.500 0.783 0.641 0.731 0.663 0.634 0.367 0.443 0.217 0.500 0.351 0.907 0.686 0.517 0.446 0.420 0.359 0.649 0.500 0.325 0.559 0.504 0.605 0.385 0.269 0.093 0.675 0.500 0.625 0.566 0.380 0.671 0.337 0.314 0.441 0.375 0.500 Can someone help me write an R script to compute the Thurston Case 5 values? The result should be the scale values for each item. I found three web pages that might be useful in this, but again, I didn't know enough to translate them into a result. http://marketing.byu.edu/htmlpages/books/pcmds/THURSTONE.html http://www.personality-project.org/r/thurstone.html http://en.wikipedia.org/wiki/Law_of_comparative_judgment Thanks, Jared -- View this message in context: http://www.nabble.com/thurston-case-5- tp21768835p21768835.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://www.nabble.com/thurston-case-5-tp21768835p21781463.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] parsing problem
Hi all, I am trying to parse a vector for caliculating minimum in that vector the vector having values like 1Kontrolle 2 Placebo 3 125mg/kg 4 250mg/kg 5 500mg/kg 61000mg/kg hear i tries for comverting it into numeric with using as.numaric() function but i got values like 5 6 2 3 4 1 it gives 1000mg/kg is the least one but i have toget 125mg/kg as the minimum value for that i have to remove all the strings and spetial charecters from that for that i used parse() but i am not able to get the out put can anyone suggest how I will solve it thanks in advance regards; kiran [[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] Sweave
I'm trying to (re)learn Sweave and run into some problems. I use now ubuntu (8.10), emacs + ess. Slowly getting upto speed on ess. I have a complete (hopefully) .Rnw file, but the resulting .tex will not compile. The file does not contain anything exotic, but it produces pdf figures, and that is where the problems come: library(tools) Sweave(varioCoo.Rnw) Writing to file varioCoo.tex Processing code chunks ... 1 : echo term verbatim (label=read) Loading required package: coda ... . . You can now run LaTeX on 'varioCoo.tex' Warning messages: ... don think this are important texi2dvi(varioCoo.tex, pdf=T) Error in texi2dvi(varioCoo.tex, pdf = T) : Running 'texi2dvi' on 'varioCoo.tex' failed. LaTeX errors: ! You can't use `macro parameter character #' in horizontal mode. argument ... sys...@active\string \endcsname ## l.111 bubble(NURE.orig, ppm, col = c(# 00ff0088, #00ff0088)) ! You can't use `macro parameter character #' in horizontal mode. argument ... sys...@active\string \endcsname ## l.111 ...NURE.orig, ppm, col = c(#00ff0088, # 00ff0088)) !pdfTeX error: pdflatex (file ./varioCoo-fig2.pdf): PDF inclusion: required pag e does not exist 0 == Fatal error occurred, no output PDF file produced! Sweave(varioCoo.Rnw) Writing to file varioCoo.tex Processing code chunks ... 1 : echo term verbatim (label=read) 2 : echo term verbatim (label=prep1) 3 : echo term verbatim (label=prep2) 4 : echo term verbatim eps pdf (label=fig2) 5 : echo term verbatim eps pdf (label=fig3) 6 : echo term verbatim eps pdf (label=fig4) You can now run LaTeX on 'varioCoo.tex' Warning message: In readLines(f[1]) : incomplete final line found on 'varioCoo.Rnw' texi2dvi(varioCoo.tex, pdf=T) Error in texi2dvi(varioCoo.tex, pdf = T) : Running 'texi2dvi' on 'varioCoo.tex' failed. LaTeX errors: ! You can't use `macro parameter character #' in horizontal mode. argument ... sys...@active\string \endcsname ## l.102 bubble(NURE.orig, ppm, col = c(# 00ff0088, #00ff0088)) ! You can't use `macro parameter character #' in horizontal mode. argument ... sys...@active\string \endcsname ## l.102 ...NURE.orig, ppm, col = c(#00ff0088, # 00ff0088)) !pdfTeX error: pdflatex (file ./varioCoo-fig2.pdf): PDF inclusion: required pag ---: well, list.files() say that file exists. e does not exist 0 == Fatal error occurred, no output PDF file produced! The other problem refered to above comes from this source lines: \begin{figure} \centering label=fig1,fig=TRUE,echo=TRUE= bubble(NURE.orig, ppm, col = c(#00ff0088, #00ff0088)) @ \caption{Contenido de uranio (ppm)} ??? Kjetil \end{figure} [[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 do I get my IT department to bless R?
Rolf Turner wrote: On 2/02/2009, at 4:29 PM, Murray Cooper wrote: I was about to post a similar reply. Stavros's reply was very eloquent and should be taken to heart! I would just like to say that in my very humble opinion Stavros's reply was utter nonsense. It was the sort of excuse-making favoured by tyrants since time immemorial. the troll has been fed. imho, your responses are more often than not patronizing puffery from a narcissistic self-admirer. following your posts, virtually anyone who's not on the r team is an idiot. sigh. vQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problems in Recommending R
On Tue, 3 Feb 2009, Rolf Turner wrote: I think the R website is just fine as it is. Effort should be put into content and not into cosmetics. Those (potential) users who would be likely to be influenced by such trivialities as the appearance of the web page are unlikely to be the sort of people who would use R anyway. I respectfully disagree. In my repeated experience, I have seen colleagues in industry and university simply write R off as too difficult or not worth the effort based on purely cosmetic grounds, and then at my urging and after some instruction embrace R as being a fantastic piece of software. The reality of the situation is that before you read a book, you only have its cover to judge. Suggesting that people should read every book regardless of the cover does not make sense for people who have other things to do. In the ecological context of open-source software, the cover or cosmetics of a software program, its documentation, and its support structure are actually quite correlated with overall ease of use, and if functionality is modeled as the factorial interaction of information produced with the amount of time it takes to produce the information, then functionality correlates with ease of use, and so the appearance of the webpage is not a triviality. Cordially, -- Adam D. I. Kramer Ph.D. Student, Social Psychology University of Oregon __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Upgrading to TINN - R 2.1.1.6
I know this has been addressed before, but I'm still confused by the solution. When running TINN - R (ver 2.1.1.6) with R (2.8.0) I have lost the functionality of TINN-R It returns an error source(.trPaths[5], echo=TRUE, max.deparse.length=150) I modified the RProfile.site file as follows: options(pager=interal) .trPaths=c( 'C:/Documents and Settings/username/Application Data/Tinn-R/tmp/', 'C:/Documents and Settings/username/Application Data/Tinn-R/tmp/search.txt', 'C:/Documents and Settings/username/Application Data/Tinn-R/tmp/objects.txt', 'C:/Documents and Settings/username/Application Data/Tinn-R/tmp/file.r', 'C:/Documents and Settings/username/Application Data/Tinn-R/tmp/selection.r', 'C:/Documents and Settings/username/Application Data/Tinn-R/tmp/block.r', 'C:/Documents and Settings/username/Application Data/Tinn-R/tmp/lines.r') what am I missing ? Thanks in advance. Steve Friedman Ph. D. Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 steve_fried...@nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 get my IT department to bless R?
On 3/02/2009, at 9:59 AM, Wacek Kusnierczyk wrote: Rolf Turner wrote: On 2/02/2009, at 4:29 PM, Murray Cooper wrote: I was about to post a similar reply. Stavros's reply was very eloquent and should be taken to heart! I would just like to say that in my very humble opinion Stavros's reply was utter nonsense. It was the sort of excuse-making favoured by tyrants since time immemorial. the troll has been fed. imho, your responses are more often than not patronizing puffery from a narcissistic self-admirer. following your posts, virtually anyone who's not on the r team is an idiot. sigh. I shall not feed the troll any further. cheers, Rolf Turner ## Attention:\ This e-mail message is privileged and confid...{{dropped:9}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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 Information from the Stats4 package in base envir
Hi. Thank you very much in advance for your help. I have generated data from two simple linear models and used k-means clustering (stats4) to identify two clusters in the generated data. Next, I would like to do simple linear regression for each separate cluster. I can do this if I first use the cluster labels to define two separate data frames with the subset function. However, I would ideally like to use the subset option in lm to identify the data for regression rather than creating separate data frames. When I try to do it this way, I get the error, Error in eval(expr, envir, enclos) : invalid 'envir' argument. The code for this is given below. If is is not possible to do this as an option within lm, is there another way rather than creating new data frames that are defined by a given cluster label? Thanks again for your help. library(stats4) #Define the Models #Two simple linear models: #Model A: respA = a0 + a1x + e(a), e(a) ~N(0, sigma^2(a)) #Model B: respB = b0 + b1x + e(b), e(b) ~N(0, sigma^2(b)) a0= 0; a1 = 1.5; sigmaA=4; b0=50; b1=-2; sigmaB=4; n=250; min=0; max=50; #Generate Data from the Models x1 = runif(n, min, max); #Explanatory variable eA = rnorm(n, 0, sigmaA); eB = rnorm(n, 0, sigmaB); respA = a0 +a1*x1 + eA; respB = b0 +b1*x1 + eB; #Responses #K-Means Clustering resp1 = c(respA, respB);#Put response into single vector for k-means x12 = rep(x1,nummod); #Put explanatory into a single vector data1 = data.frame(resp1, x12) #Data frame for kmeans cluster1 = kmeans(data1, 2, nstart=25)$cluster #Obtain cluster labels data1 = data.frame(data1 ,cluster1)#Cluster labels in third column data10 = subset(data1, cluster1==1) data11 = subset(data1, cluster1==2) model10 = lm(resp1 ~ x12, data10)#It works using the subset data frame model1 = lm(resp1 ~ x12, cluster1 == 1, data1); #Gives the following error Error in eval(expr, envir, enclos) : invalid 'envir' argument __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] all data frame columns SUBSET
Dear All, I have a data frame (mydata), with let say 5 columns V1,V2,...,V5. (we know the power set of {V1,V2,..,V5} has 2^5-1 elements). I need to construct a vector T of length 5 which its i-th element is the maximum of (let say) mean values obtained based on the columns subset of size i. (MY FUNCTION TO APPLY ON COLUMNS SUBSET IS NOT SO SIMPLE AS MEAN AND I WILL REPLACE IT.) I mean: T[1]=max(mean(mydata[,1]),...,mean(mydata[,5])) T[2]=max(mean(mydata[,c(1,2)],mean(mydata[,c(1,3)],...,mean(mydata[,c(1,5]) T[3]=max(mean(mydata[,c(1,2,3)],mean(mydata[,c(1,2,4)],...,mean(mydata[,c(3,4,5)]) T[5]=max(mean(mydata[,c(1,2,3,4,5)] Many thanks in advance. Hamid __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Weighing cases
Hi, The package ineq for the measurement of inequality, concentration and poverty does not allow a weighing variable to be included. However, this variable makes your sample representative to the population from which it was drawn, and therefore is indispensable for any analysis to be statistically correct. Is a new version of this package going to include a weighing variable as argument or is there another way to circumvent this problem? Thanks W [[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] Problems in Recommending R
On Mon, 02 Feb 2009 08:44:21 +0100, Thomas Petzoldt (TP) wrote: Hi, you are probably right, though I must say that I like *spartanic and efficient* homepages and I don't think that the example given by the first mail is a good prototype for the R homepage. But, yes, occasional face lifting may be adequate. Anti-aliasing is of course simple, but that's probably not the point. (And I know that there are graphics experts with a masters in psychology between us.) So, why not a new Homepage Graphics Competition 2009? There is still some time until useR!2009 in Rennes: http://www2.agrocampus-ouest.fr/math/useR-2009/ Perhaps we should extend that to a competition for the complete design of the homepage? We often get emails like the first in this thread that R could do with an update on homepage design (I fully agree) ... but actually nobody volunteers to do it. Hence, we still have what I did when the worldwide number of R users was probably less than 1000. For technical reasons there are some conditions: the homepage is maintained via SVN like the R sources, so all should be plain HTML, no content management system etc. Ad frames: the main reason that I used them in the first place is to have the menus etc in only one file, no need for updating several files when a link changes. Today I would probably use iframes, but any other soultion is fine, too. Another plus would be if we could use the same design for CRAN, and that means no server-trickery like server-side includes etc (because we do not control the server setup of the mirrors). Best, Fritz -- --- Prof. Dr. Friedrich Leisch Institut für Statistik Tel: (+49 89) 2180 3165 Ludwig-Maximilians-Universität Fax: (+49 89) 2180 5308 Ludwigstraße 33 D-80539 München http://www.statistik.lmu.de/~leisch --- Journal Computational Statistics --- http://www.springer.com/180 Münchner R Kurse --- http://www.statistik.lmu.de/R __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Is the SARMA forcasting formula correct?
Hello, Guys: I'm from China, my English is poor and I'm new to R. This is my first time to use R-help. Hope that I can get useful suggestions from you warm-hearted guys. Thanks. I builded a multiplicative seasonal ARMA model to a series named cDownRange. And the order is (1,1)*(0,1)45 I fitted the model in R and get the result as below: Call:arima(x = cDownRange, order = c(1, 0, 1), seasonal = list(order = c(0, 1, 1), period = 45))Coefficients: ar1 ma1 sma1 0.7364 -0.5046 -0.9511s.e. 0.0458 0.0594 0.0130When I use the predict command of this model in R, it gives the right forcasting. So I think the forcast formula of this SARMA model should be written as below:X(t)=ar1*X(t-1)-ma1*a(t-1)-sma1*a(t-45)+ma1*sma1*a(t-46)But when I use this forcast formula in Excel, it gives a totally different predict from R. And I don't know why? I guess the expression of the forcast formula of this SARMA(1,1)*(0,1)45 is wrong, but I don't know the right form. Can anybody help me with this?Thank, again! saji from Shanghai _ [[elided Hotmail spam]] [[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] Odp: Matrix
On Mon, Feb 2, 2009 at 4:05 PM, Petr PIKAL petr.pi...@precheza.cz wrote: Hi r-help-boun...@r-project.org napsal dne 02.02.2009 16:52:06: Hi, I have a very basic question on merging two matrices by alternating the rows. For illustration, assume two matrices - A looks like: 10 10 10 10 B looks like: 20 20 20 20 How do I combine them such that I get alternating rows from A and B? My final result should be C which looks like: 10 10 20 20 10 10 20 20 I would rbind both matrices and then indexed the resulting matrix. x-rep(10,4) y-rep(20,4) dim(x)-c(2,2) dim(y)-c(2,2) z-rbind(x,y) z [,1] [,2] [1,] 10 10 [2,] 10 10 [3,] 20 20 [4,] 20 20 ind-c(seq(1,4,2), seq(2,4,2)) z[ind,] z[ind,] [,1] [,2] [1,] 10 10 [2,] 20 20 [3,] 10 10 [4,] 20 20 Another solution: m1 - matrix(10,4,2) m2 - matrix(20,2,2) m1[seq(2,4,2),] - m2 Paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Power analysis for MANOVA?
Hi Rick, I understand the authors' point and also agree that post-hoc power analysis is basically not telling me anything more than the p-value and initial statistic for the test I am interested in computing power for. Beta is a simple function of alpha, p, and the statistic. My intention is, as I mentioned in my response to Stephan Kolassa, to transform my p-value and statistic into a form of effect size--sample size necessary to attain significance at alpha=.05. This will communicate no more information, it is just a mathematical re-representation of my data in a way I believe my readers will find more informative and useful. In other words, there is no more information *encoded*, but there is more information *communicated,* just like for any effect size measure. If you have any suggestions on a more reliable effect size for MANOVA which is *also* commonly known in the social psychology community (e.g., a correlation or Cohen's d analogue), I'm interested--but the multivariate nature of the beast makes these more or less impossible to translate. The poster I was asking for is now printed, and we reported the multivariate R-squared using the techniques in Cohen (1988), though I'm expecting to spend a lot of time explaining what that means to people in a multivariate context, rather than describing the results of the study. Cordially, Adam D. I. Kramer On Sun, 1 Feb 2009, Rick Bilonick wrote: On Wed, 2009-01-28 at 21:21 +0100, Stephan Kolassa wrote: Hi Adam, first: I really don't know much about MANOVA, so I sadly can't help you without learning about it an Pillai's V... which I would be glad to do, but I really don't have the time right now. Sorry! Second: you seem to be doing a kind of post-hoc power analysis, my result isn't significant, perhaps that's due to low power? Let's look at the power of my experiment! My impression is that post-hoc power analysis and its interpretation is, shall we say, not entirely accepted within the statistical community, see: Hoenig, J. M., Heisey, D. M. (2001, February). The abuse of power: The pervasive fallacy of power calculations for data analysis. The American Statistician, 55 (1), 1-6 And this: http://staff.pubhealth.ku.dk/~bxc/SDC-courses/power.pdf However, I am sure that lots of people can discuss this more competently than me... Best wishes Stephan The point of the article was that doing a so-called retrospective power analysis leads to logical contradictions with respect to the confidence intervals and p-values from the analysis of the data. In other words, DON'T DO IT! All the information is contained in the confidence intervals which are based on the observed data - an after the fact power analysis cannot provide any insight - it's not data analysis. Rick B. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] concatenating 2 text columns in a data.frame
yes, try this: dat - read.table(textConnection( C1 C2 C3 C4 C5 A B F C Q G H I J T K D R S E P L M N O ), header = TRUE) closeAllConnections() dat$NewCol - do.call(paste, c(dat[c(C3, C4)], sep = )) dat I hope it helps. Best, Dimitris Shaun Grannis wrote: Hi, I'm trying to concatenate values from two columns in a data frame. For example, I have the following data.frame: C1 C2 C3 C4 C5 A B *F C* Q G H *I J* T K D *R S* E P L *M N* O I'd like to concatenate text from columns C3 and C4, to yield either a list or vector, like so: NewCol FC IJ RS MN Is this feasible in R? Thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problems in Recommending R
On Mon, 2 Feb 2009 18:14:03 +0530, Ajay ohri (Ao) wrote: Plain HTML coding is simple enough for this list ( I think)...but aesthetic designhmm In most cases one can do more than most think using HTML and CSS: Our universities corporate design was done by professionals and is backed by a CMS: http://www.uni-muenchen.de Our dpertment didn't want to use the CMS, so we emulated it using HTML, CSS and iframes: http://www.stat.uni-muenchen.de/ which is *much* more convenient to maintain for us: I have a copy of my page on my laptop, I can work on it while offline on a train, etc. I don't want to discuss whether the above examples are aesthetic or not (we are required to follow the coporate design, so have no choice). The main point I want to make is: that everything is static HTML makes life very easy for command line junkies like me ;-) Best, Fritz -- --- Prof. Dr. Friedrich Leisch Institut für Statistik Tel: (+49 89) 2180 3165 Ludwig-Maximilians-Universität Fax: (+49 89) 2180 5308 Ludwigstraße 33 D-80539 München http://www.statistik.lmu.de/~leisch --- Journal Computational Statistics --- http://www.springer.com/180 Münchner R Kurse --- http://www.statistik.lmu.de/R __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Specifying the gap between dodge'd bins groups?
However, is there a way to programmatically to extract the bin size that ggplot selected in order to be able to change this for multiple data sets? Well the default is 30 bins - i.e. range(x) / 30 - in practice you'd want to choose something a bit more informative! Similarly, is there a way to determine the number of count in each bin that ggplot establish? I wanted to change the axis a bit based on the count size, but I needed to do it programmatically give the large number of samples. For the example below, it would be something like the following: ggplot(diamonds, aes(x=price, fill=cut)) + geom_bar(position=position_dodge(width=default_ggplotbinwidth*0.75), binwidth=default_ggplotbinwidth) + ylim(0, ggplotmaxcount*1.1) I would like to have access to the calculated ggplotbin and ggplotmaxcount for the data set. Just set binwidth yourself. And why do you want ggplotmaxcount? (it would be round_any(max(df$x), binwidth, ceiling)) 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.
[R] Beveridge Nelson Decomposition
Hi, Would anyone know if it is possible to run a Beveridge Nelson decomposition of a univariate time series object in R? I searched in the help files but didn't come across any potential methods. Thanks very much, Shruthi -- View this message in context: http://www.nabble.com/Beveridge-Nelson-Decomposition-tp21789452p21789452.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] Problem with foreign package
I tried to use write.foreign() to export to SAS this morning and got an error. When I looked at the code for writeForeignSAS() I saw this line: dfn -df which I think should be dfn - df So, I tried to run update.packages() to see if there was an updated version and got the following result. update.packages(c(foreign)) Warning message: In list.files(lib) : list.files: 'foreign' is not a readable directory I ran the above command as root. Is this because the foreign package is a core package and not a CRAN one? My sessionInfo() is R version 2.8.0 (2008-10-20) i686-pc-linux-gnu locale: LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=en_US;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C attached base packages: [1] stats graphics grDevices utils datasets methods base loaded via a namespace (and not attached): [1] tools_2.8.0 and my version of foreign is 0.8-30 -- Kevin E. Thorpe Biostatistician/Trialist, Knowledge Translation Program Assistant Professor, Dalla Lana School of Public Health University of Toronto email: kevin.tho...@utoronto.ca Tel: 416.864.5776 Fax: 416.864.6057 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] hatching part of an area under curve
Alphonse Monkamg amonkamg at yahoo.fr writes: I have drawn a kernel density curve and I would like to hatch a part of it: where value is less than -2, P(Z -2). I only know how to hatch the entire area under the curve. Please, does any one know how to hatch part of it. See http://finzi.psych.upenn.edu/R/Rhelp08/archive/140811.html and responses. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] paste together object names to pass it on to a function
Hello y'll, thanks a lot for your hints. The easiest solution was the one from Jim, using [[ whose true function I did not realize fully. About apply and the sorts: I agree that if you get them to work the are much faster and yield nice, compact code. But I have never fully understood the inner workings and I think the provided examples (even in most books) rush over them. If I use them successfully, it is - at least in my case - more the result of trial and error and this does not make them a weapon of first choice. If someone has a good hint where they are explained accessibly, please share it. Thanks again and have a great week! Best, Stefan On Fri, Jan 30, 2009 at 7:54 PM, David Winsemius dwinsem...@comcast.net wrote: Perhaps this will help: #Data Example gnuff-list() gnuff$IHD$LE-66 gnuff$LUNG$LE -55 #This is the list, where I collect data for different diseases at the #second level of the list #Now I want to do calcualtions just for these two diseases and the #sub-list LE within these diseases nam - c(LUNG,IHD) for(i in nam) print(gnuff[[i]]) # use the elements of nam as the index values # the lack of output from an evaluation done within the for-loop might be one of Burns' Infernal examples. # here's see one of my mistakes: for(i in nam) (gnuff[[i]]) #---returns a list--- #$LE #[1] 55 #$LE #[1] 66 #--- for(i in nam) print(gnuff[[i]]$LE) #use list extraction to get the values #[1] 55 #[1] 66 On Jan 30, 2009, at 12:06 PM, stefan.d...@gmail.com wrote: Hello, I have a maybe trivial question, but I simply don't understand well enought how to work with text/strings: I have a rather compelx data structure, a big list with several sub-lists/dataframes and for certain calculations (which I do in loops), I only need a certain group of sub-lists/dataframes, which I want to specify with a name vector and paste together the object name and pass it on to a function. Here an (hopefully) instructive example #Data Example gnuff-list() gnuff$IHD$LE-66 gnuff$LUNG$LE -55 #This is the list, where I collect data for different diseases at the second level of the list #Now I want to do calcualtions just for these two diseases and the sub-list LE within these diseases nam - c(LUNG,IHD) for(i in 1:2) x[i] - paste(gnuff,nam[i],LE,sep=$) /2 x #So I try to paste the name of the object which I mean (gnuff$IHD$LEand gnuff$LUNG$LE, respectivly), but R treats them as a string and not as the name of an object. # I tried seveal commands to make it treat like an object name (the get() looked most promising), but so far to no avail #commands I have tried j - eval(paste(gnuff,nam[i],LE,sep=$)) parse(paste(gnuff,nam[i],sep=$)) quote(paste(gnuff,nam[i],sep=$)) get(paste(gnuff,nam[i],sep=$)) Anybody any hints where to look? Thanks and have a great weekend! Best, Stefan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] repeated measures with gls
I am using the gls function of the nlme package to analyze data sets of soil respiration which have the following design: 3 complete blocks x 5 sampling dates (time from fertilization) x 3 fertilization levels. The fertilization dates are equal for all subjects (blocks) but not periodical (-46, 10, 24, 53, 123 days from the event). The code that I've been using is: fit.csnC- gls(dno.C ~ block+Fertil*factor(Samp), data=dDakot, method=ML, corr=corCompSymm(, form=~1|block)) fit.arhnC-update(fit.csnC, corr=corAR1(, form=~1|block), weight=varIdent(form =~1|Samp)) I've plotted the model with : plot(fit.csnC) plot(fit.csnC,dno.C ~ fitted(.), abline = c(0,1)) and residuals look fine, same as observed vs. fitted values. I would like to make sure that the model specification and the gls function are correct for this design. Then, if the model is OK, how do I do to test for main and simple effects, ie. how can I apply contrasts to the model? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Assigning colnames in loop
Dear R-listers, I am trying to assign colnames to a data frame within a loop, but I keep getting a target of assignment expands to non-language object-error. I need to split up a large dataset into about 20 smaller ones, and I would like to assign colnames within the loop, so I won't have to type the same thing 20 times over. I have concocted this really goofy example which constructs two datasets: - male - rep(0:1, each=5) age - factor(c(10:14,10:14)) DF - data.frame(male, age, res1=rnorm(10), res2=rnorm(10), res3=rnorm(10)) for(n in 0:1) { assign(paste(test,n, sep=.), as.data.frame(t(subset(DF, male==n, select=c(res1, res2, res3) colnames(get(paste(test,n, sep=.))) - paste(age,levels(age), m, n, sep=) # This line gives an error. assign(colnames(paste(test,n, sep=.))) - paste(age,levels(age), m, n, sep=) # This line gives the same error. } --- The following command assigns the right colnames to the 'test.0' data frame, but I want this line inside the loop so I won't have to type it 20 times over. colnames(test.0) - paste(age,levels(age), m, 0, sep=) Thank you in advance for any assistance. Peter. sessionInfo() R version 2.8.1 (2008-12-22) i386-pc-mingw32 locale: LC_COLLATE=Danish_Denmark.1252;LC_CTYPE=Danish_Denmark.1252;LC_MONETARY= Danish_Denmark.1252;LC_NUMERIC=C;LC_TIME=Danish_Denmark.1252 attached base packages: [1] tools stats graphics grDevices utils datasets methods base other attached packages: [1] epiR_0.9-14 maptools_0.7-18 sp_0.9-29 foreign_0.8-30 chron_2.3-28 loaded via a namespace (and not attached): [1] grid_2.8.1 lattice_0.17-20 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] wilcoxon test with bonferroni correction
On 2/1/2009 8:32 PM, Laura Lucia Prieto Godino wrote: Hi! I need to run a wilcoxon (Mann-whitly, in fact) test with bonferroni correction, as I am running 10 consecutive wilcoxon test not independent, and I know that bonferroni will partially correct for this problem, but I have no idea how to do it with R, I have been looking in the archive but couldn't understand how to do it. The format I am using at the moment is r4_o - [1] 1.05 2.60 1.57 3.07 1.20 1.00 2.11 1.10 0.10 r4_m - [1] 0 0 0 0 0 0 0 0 0 wilcoxon.test (r4_o, r3_m) Does any body know how to make the bonferroni correction when I compare them with the wilcoxon test? # Ten p-values X - seq(.001, .10, len=10) X [1] 0.001 0.012 0.023 0.034 0.045 0.056 0.067 0.078 0.089 0.100 # Same ten p-values adjusted by the Bonferroni method p.adjust(X, method=bonferroni) [1] 0.01 0.12 0.23 0.34 0.45 0.56 0.67 0.78 0.89 1.00 ?p.adjust Thank you very much. Lucia Lucia Prieto Godino PhD student. Department of Zoology, Downing street University of Cambridge. UK __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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.
Re: [R] Problem with foreign package
On Mon, 2 Feb 2009, Duncan Murdoch wrote: On 2/2/2009 8:46 AM, Kevin E. Thorpe wrote: I tried to use write.foreign() to export to SAS this morning and got an error. When I looked at the code for writeForeignSAS() I saw this line: dfn -df which I think should be dfn - df So, I tried to run update.packages() to see if there was an updated version and got the following result. That bug was fixed a few weeks ago, but a new version has not been released yet. You can get the latest source from svn: https://svn.r-project.org/R-packages/trunk/foreign Yes, and there is a good reason. No less than 3 people reported problems in 0.8-29 without reproducible examples. When I releaseed 0.8-30, I asked them to test it. Despite reminders, I am still waiting for any answer, and will wait another week. It really is unhelpful to report problems and not be prepared to answer follow-up questions nor test solutions. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing data from a disc or HDD [SEC=UNCLASSIFIED]
Kisch, Joe wrote: I hope this is not a stupid question, but I am having difficulty importing data from sources like CDs, HDD, or flashcards. Can anyone help ? Joe [[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. Hi Joe, If you are not specific about your system and about the exact problem you have (please read the posting guide), it is very hard for us to give advice. cheers, Paul -- Drs. Paul Hiemstra Department of Physical Geography Faculty of Geosciences University of Utrecht Heidelberglaan 2 P.O. Box 80.115 3508 TC Utrecht Phone: +31302535773 Fax:+31302531145 http://intamap.geo.uu.nl/~paul __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] parsing problem
Ken Knoblauch ken.knoblauch at inserm.fr writes: venkata kirankumar kiran4u2all at gmail.com writes: I am trying to parse a vector for caliculating minimum in that vector the vector having values like 1Kontrolle 2 Placebo 3 125mg/kg 4 250mg/kg 5 500mg/kg 61000mg/kg hear i tries for comverting it into numeric with using as.numaric() function but i got values like 5 6 2 3 4 1 can anyone suggest how I will solve it thanks in advance regards; kiran Your Kontrolle is being treated as a factor so you are seeing only the codes of the levels. There is probably something more elegant, but you need something like, as.numeric(sapply(with(dd, strsplit(levels(Placebo)[Placebo], m)), [[, 1)) I should have specified that when I read in your data, my data frame looked like this dd X2 Placebo 1 3 125mg/kg 2 4 250mg/kg 3 5 500mg/kg 4 6 1000mg/kg and str(dd) 'data.frame': 4 obs. of 2 variables: $ X2 : int 3 4 5 6 $ Placebo: Factor w/ 4 levels 1000mg/kg,125mg/kg,..: 2 3 4 1 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Assigning colnames in loop
It's always best to do this with list operations (e.g. lapply) rather than a loop: DF1 - split(DF, DF$male) DF2 - lapply(DF1, function(x) { x2 - t(as.matrix(x[3:5], dimnames = list(levels(x$age), NULL))) as.data.frame(x2) }) Then DF2[[0]] and DF2[[1]] are the data.frames you want. HTH, --sundar On Mon, Feb 2, 2009 at 2:30 PM, Peter Jepsen p...@dce.au.dk wrote: Dear R-listers, I am trying to assign colnames to a data frame within a loop, but I keep getting a target of assignment expands to non-language object-error. I need to split up a large dataset into about 20 smaller ones, and I would like to assign colnames within the loop, so I won't have to type the same thing 20 times over. I have concocted this really goofy example which constructs two datasets: - male - rep(0:1, each=5) age - factor(c(10:14,10:14)) DF - data.frame(male, age, res1=rnorm(10), res2=rnorm(10), res3=rnorm(10)) for(n in 0:1) { assign(paste(test,n, sep=.), as.data.frame(t(subset(DF, male==n, select=c(res1, res2, res3) colnames(get(paste(test,n, sep=.))) - paste(age,levels(age), m, n, sep=) # This line gives an error. assign(colnames(paste(test,n, sep=.))) - paste(age,levels(age), m, n, sep=) # This line gives the same error. } --- The following command assigns the right colnames to the 'test.0' data frame, but I want this line inside the loop so I won't have to type it 20 times over. colnames(test.0) - paste(age,levels(age), m, 0, sep=) Thank you in advance for any assistance. Peter. sessionInfo() R version 2.8.1 (2008-12-22) i386-pc-mingw32 locale: LC_COLLATE=Danish_Denmark.1252;LC_CTYPE=Danish_Denmark.1252;LC_MONETARY= Danish_Denmark.1252;LC_NUMERIC=C;LC_TIME=Danish_Denmark.1252 attached base packages: [1] tools stats graphics grDevices utils datasets methods base other attached packages: [1] epiR_0.9-14 maptools_0.7-18 sp_0.9-29 foreign_0.8-30 chron_2.3-28 loaded via a namespace (and not attached): [1] grid_2.8.1 lattice_0.17-20 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Selectively Removing objects
Slightly related to this (I think Mr. Rydevik's code solved the question), is a silly thing I wrote up one weekend. It started out as a clone of the unix rm -i command, and kept on going out of control :-) I'm not claiming this is clean, or the best way to do this, but it does let you apply a wide variety of functions to your collection of 'items' Carl - askrm-function(items,fn=rm,ask=TRUE){ killed-NA thecall-vector('list') j-1 for (thenam in c(items)){ if(ask==TRUE){ prmpt-paste(Do ,fn, on ,thenam,? ) readline(prompt=prmpt)-theans } else theans=y if(theans==y){ #have to get to parent envir. to find the object of interest #as.name() gets rid of quotes... # paste() dumps all output into a single element of list # Note that,e.g., str() returns nothing, just cats to screen. eval(call(fn,as.name(thenam)),envir=parent.frame(1))-evout paste(evout,collapse= )-thecall[j] cat(the result is , as.character(thecall[j]),'\n') killed[j]-thenam j-j+1 } } #keeping track of what happened outs-list(killed=killed, calls=thecall) return(invisible(outs)) } __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] sem package and AMOS
Dear Anthony, sem() does FIML estimation, not 2SLS, and so it's hard to understand why you're getting nearly identical parameter estimates but very different coefficient standard errors and model chi-squares. In fact, unless the problem is very ill-conditioned, the parameter estimates should be the same within rounding error, as should the model chi-square. There is some room for small differences in the standard errors -- sem() uses a numerical Hessian and I'm not sure what AMOS does -- but large differences are indicative of some problem. I suspect that you're not fitting quite the same model in sem() and AMOS. I hope this helps, John On Mon, 02 Feb 2009 14:50:26 -0600 Anthony Dick ad...@uchicago.edu wrote: Hello- I am using R to build my initial models, but need to use AMOS to compare the models of two groups (adults vs. kids). The problem is I am getting different results with R and AMOS for the initial models of the separate groups (and the R results make more sense). The parameter estimates (path coefficients and variances) from both programs are nearly identical, but the model chi-squares (and significance estimates of the parameter estimates) are different. I am using Maximum Likelihood in AMOS. R I think defaults to two-stage-least squares estimate, and AMOS 16 does not implement 2SLS. I am using fMRI data, so the error variances are likely correlated, and the data non-normal to varying degrees. Is 2SLS the better way to go for these kinds of data? Is there a way to change the default method for R sem? I couldn't find this in the ?help. I note I have run some of the AMOS examples in R and have gotten identical results across platforms, so I believe the problem is not in specifying things incorrectly across platforms. Also, the dfs are identical for both analyses. I must use AMOS to do model comparison (and thus maximum likelihood), but would like to achieve similar results across platforms for the basic models before I proceed, and would like to track down the reason for the difference. Thanks, Anthony -- Anthony Steven Dick, Ph.D. Post-Doctoral Fellow Human Neuroscience Laboratory Department of Neurology The University of Chicago 5841 S. Maryland Ave. MC-2030 Chicago, IL 60637 Phone: (773)-834-7770 Email: ad...@uchicago.edu Web: http://home.uchicago.edu/~adick/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. John Fox, Professor Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Upgrading to TINN - R 2.1.1.6
Hi Steve: I upgraded to the same Tinn-R version a few days ago and I didn't have any problems at all. Just follow the link below for the instructions. Good luck http://sourceforge.net/forum/forum.php?forum_id=864071 Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA --- On Mon, 2/2/09, steve_fried...@nps.gov steve_fried...@nps.gov wrote: From: steve_fried...@nps.gov steve_fried...@nps.gov Subject: [R] Upgrading to TINN - R 2.1.1.6 To: r-help@r-project.org Date: Monday, February 2, 2009, 1:02 PM I know this has been addressed before, but I'm still confused by the solution. When running TINN - R (ver 2.1.1.6) with R (2.8.0) I have lost the functionality of TINN-R It returns an error source(.trPaths[5], echo=TRUE, max.deparse.length=150) I modified the RProfile.site file as follows: options(pager=interal) .trPaths=c( 'C:/Documents and Settings/username/Application Data/Tinn-R/tmp/', 'C:/Documents and Settings/username/Application Data/Tinn-R/tmp/search.txt', 'C:/Documents and Settings/username/Application Data/Tinn-R/tmp/objects.txt', 'C:/Documents and Settings/username/Application Data/Tinn-R/tmp/file.r', 'C:/Documents and Settings/username/Application Data/Tinn-R/tmp/selection.r', 'C:/Documents and Settings/username/Application Data/Tinn-R/tmp/block.r', 'C:/Documents and Settings/username/Application Data/Tinn-R/tmp/lines.r') what am I missing ? Thanks in advance. Steve Friedman Ph. D. Spatial Statistical Analyst Everglades and Dry Tortugas National Park 950 N Krome Ave (3rd Floor) Homestead, Florida 33034 steve_fried...@nps.gov Office (305) 224 - 4282 Fax (305) 224 - 4147 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] New to R
Also you don't need return since it automatically returns the value produced by the last statement that it executes. On Mon, Feb 2, 2009 at 3:44 PM, Greg Snow greg.s...@imail.org wrote: It is not transposing (it just looks that way). The first result is a vector which is 1 dimensional, but is neither a row or a column. The printed version of it looks like a row, because that is a more compact representation. If you sample enough points you will see it wrap around and be represented as several rows. If it printed as a single column, then the first values would scroll off the screen with only a moderate number of values. The replicate function then takes these vectors and combines them into a matrix and just happens to use each vector as a column of the new matrix, this is standard, matrices by default are filled by column, look at the output of as.matrix( sample( 6, 4, replace=TRUE ) ) and you will see your vector converted to a matrix of 1 column. It could have been done the other way, but way back the decision was made to do it this way and there are probably a lot of things that would break if it were changed now, so we get to live with it. A single call to 't' is not too much effort to get what we expect. So in short, a vector is neither a column or a row, but prints as a row for practical reasons, and is converted to a column by default if made into a matrix. 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 Joe Hughes Sent: Monday, February 02, 2009 1:09 PM To: R help Subject: Re: [R] New to R All, Thanks for taking the time to reply. I understand a bit more about R and the R way then I did before.The final function looks like this: ### ### # # Input: # die_size - 4, 6, 8, 10, 20 # number_of_dice - How many dice to roll # number_of_rolls - How many times to roll the dice # # Output: #The array holding the results of the rolls # ### ### # function(die_size, number_of_dice, number_of_rolls=1) { return(t(replicate(number_of_rolls, sample(die_size, number_of_dice, replace=TRUE } Before I take a look at the teaching demos, I have one question left. Here is a sequence of commands and the output sample(6, 4, replace=TRUE) [1] 3 4 5 4 replicate(7, sample(6, 4, replace=TRUE)) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [1,]3364566 [2,]4465516 [3,]5145656 [4,]4631122 Why does replicate transpose the vector before assigning it to the array? The way I would output it would be this [,1] [,2] [,3] [,4] [1,]3454 [2,]3416 [3,]6643 [4,]4551 [5,]5561 [6,]6152 [7,]6662 Thanks, Joe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problems in Recommending R
On Mon, 2 Feb 2009 13:43:23 +0100, ONKELINX, Thierry (OT) wrote: Dear Fritz, I'm wondering if the use of plain HTML is a conditio sine qua non. Just not to be mistaken: with plain HTML I mostly meant text files, of course including CSS etc. What are the advantages of maintaining the website via SVN? IMO maintaining a website and source code are two separate things. Sure, but it makes life easier for us: this way all of R core can modify the webpage, and access rights etc are easier to maintain if all is done using the same system (in our case, SVN). It is simply very convenient that I don't have learn and remember different tools for different aspects of the R project. Most of us have almost everything under version control (from source code to HTML pages, to latex files, etc), it simply is the groupware we use. Best, Fritz -- --- Prof. Dr. Friedrich Leisch Institut für Statistik Tel: (+49 89) 2180 3165 Ludwig-Maximilians-Universität Fax: (+49 89) 2180 5308 Ludwigstraße 33 D-80539 München http://www.statistik.lmu.de/~leisch --- Journal Computational Statistics --- http://www.springer.com/180 Münchner R Kurse --- http://www.statistik.lmu.de/R __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.