Re: [R] Time vs Concentration Graphs by ID
at 12:46 AM, Anh Nguyen eataban...@gmail.com wrote: Hello Dennis, That's a very good suggestion. I've attached a template here as a .png file, I hope you can view it. This is what I've managed to achieve in S-Plus (we use S-Plus at work but I also use R because there's some very good R packages for PK data that I want to take advantage of that is not available in S-Plus). The only problem with this is, unfortunately, I cannot figure out how make the scale non-uniform and I hope to fix that. My data looks like this: ID Dose Time Conc Pred ... 1 5 0 0 0 1 5 0.5 6 8 1 5 1 16 20 ... 1 7 0 0 0 1 7 0.5 10 12 1 7 1 20 19 ... 1 10 3 60 55 ... 2 5 12 4 2 ... ect I don't care if it's ggplot or something else as long as it looks like how I envisioned. On Fri, Oct 15, 2010 at 12:22 AM, Dennis Murphy djmu...@gmail.comwrote: I don't recall that you submitted a reproducible example to use as a template for assistance. Ista was kind enough to offer a potential solution, but it was an abstraction based on the limited information provided in your previous mail. If you need help, please provide an example data set that illustrates the problems you're encountering and what you hope to achieve - your chances of a successful resolution will be much higher when you do. BTW, there's a dedicated newsgroup for ggplot2: look for the mailing list link at http://had.co.nz/ggplot2/ HTH, Dennis On Thu, Oct 14, 2010 at 10:02 PM, Anh Nguyen eataban...@gmail.comwrote: I found 2 problems with this method: - There is only one line for predicted dose at 5 mg. - The different doses are 5, 7, and 10 mg but somehow there is a legend for 5,6,7,8,9,10. - Is there a way to make the line smooth? - The plots are also getting a little crowded and I was wondering if there a way to split it into 2 or more pages? Thanks for your help. On Thu, Oct 14, 2010 at 8:09 PM, Ista Zahn iz...@psych.rochester.edu wrote: Hi, Assuming the data is in a data.frame named D, something like library(ggplot2) # May need install.packages(ggplot2) first ggplot(D, aes(x=Time, y=Concentration, color=Dose) + geom_point() + geom_line(aes(y = PredictedConcentration, group=1)) + facet_wrap(~ID, scales=free, ncol=3) should do it. -Ista On Thu, Oct 14, 2010 at 10:25 PM, thaliagoo eataban...@gmail.com wrote: Hello-- I have a data for small population who took 1 drug at 3 different doses. I have the actual drug concentrations as well as predicted concentrations by my model. This is what I'm looking for: - Time vs Concentration by ID (individual plots), with each subject occupying 1 plot -- there is to be 9 plots per page (3x3) - Observed drug concentration is made up of points, and predicted drug concentration is a curve without points. Points and curve will be the same color for each dose. Different doses will have different colors. - A legend to specify which color correlates to which dose. - Axes should be different for each individual (as some individual will have much higher drug concentration than others) and I want to see in detail how well predicted data fits observed data. Any help would be greatly appreciated. -- View this message in context: http://r.789695.n4.nabble.com/Time-vs-Concentration-Graphs-by-ID-tp2996431p2996431.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org [[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. [[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. -- Ista Zahn Graduate student University of Rochester
Re: [R] feed cut() output into goodness-of-fit tests
On Fri, Oct 15, 2010 at 10:22 AM, Andrei Zorine zoav1...@gmail.com wrote: Hello, My question is assuming I have cut()'ed my sample and look at the table() of it, how can I compute probabilities for the bins? I actually don't know what you mean by this (my own ignorance probably). Do I have to parse table's names() to fetch bin endpoints For equal-width bins you can use seq(min(x), max(x), by = (max(x) - min(x))/10) HTH, Ista to pass them to p[distr-name] functions? i really don't want to input arguments to PDF functions by hand (nor copy-and-paste way). x.fr - table(cut(x,10)) x.fr (0.0617,0.549] (0.549,1.04] (1.04,1.52] (1.52,2.01] (2.01,2.5] 16 28 26 18 6 (2.5,2.99] (2.99,3.48] (3.48,3.96] (3.96,4.45] (4.45,4.94] 3 2 0 0 1 names(x.fr) [1] (0.0617,0.549] (0.549,1.04] (1.04,1.52] (1.52,2.01] [5] (2.01,2.5] (2.5,2.99] (2.99,3.48] (3.48,3.96] [9] (3.96,4.45] (4.45,4.94] -- Andrei Zorine __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Error: object 'short' not found
Hi Viki, On Tue, Oct 19, 2010 at 10:03 AM, Viki S is...@live.com wrote: Hi guys, Can anyone tell me what is the meaning of following command ? paste(execDir,paste(short,myfile,sep=_),sep=\) The command means paste together the values in the variable execDir with the pasted-together values in short and myfile R gives me an error : Error: object 'short' not found I tried to find help about 'short' in R, but could not find any such function/ object. because it does not exist, as the error message informed you. You need to create it, or, if you want the literal string short, then you need to put it in quotes. -Ista Viki [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Part time equity tick data high frequency trading research
Hi Chris, There is a jobs mailing list: https://stat.ethz.ch/mailman/listinfo/r-sig-jobs -Ista On Tue, Oct 19, 2010 at 10:10 AM, aquatrade aquatrade...@gmail.com wrote: Hi, There seems to be no subsection for work related postings, so please excuse me if this is in the wrong place. I am looking for an English speaking person with very strong R Language, statistics and some financial math knowledge to do statistical research into USA stock tick data. You probably have a hard sciences background requiring heavy statistical and maths knowledge and have an interest in stock markets (e.g. you know what a bid and ask is for a stock quote). Probably have a Masters or Phd degree. I am an experienced trader, who is researching some high frequency strategy ideas and need someone who can work part-time for 4 months to help with the research. While I have the tick data and understanding of what to do, it takes me far too long as I am not a maths/stats expert. You should have an interest in stocks, so that you have a basic understanding of market structure and quotes. Must speak very good English and have access to a reliable internet connection and Skype. I do not care which country you are located in. You will be dealing with tick data sets with rows in the millions. Skill Set: R Language (strong) Statistics Mathematics Financial Maths (time series analysis, co-variance, GARCH, etc) Java (basic level) Please include a resume and summary of why you would enjoy doing this. Please indicate your monthly rate for 80+ hours per month for 4 months. I am paying for this out of my own pocket, so am very price sensitive…which is why I am going offshore. There is the potential for extending this longer term. This is a great opportunity for someone to learn about high frequency tick data research and make a little money as well. Please contact me directly at aquatrade...@gmail.com. Thank you for reading and apologies if posted in the wrong area. Thanks, Chris -- View this message in context: http://r.789695.n4.nabble.com/Part-time-equity-tick-data-high-frequency-trading-research-tp3002167p3002167.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] scatter.smooth() fitted by loess
The fundamental problem is that you only have five distinct x values. lowess cannot work in this situation. Try side-by-side boxplots: boxplot(resid.value ~ YMRS_Sum) -Ista On Tue, Oct 19, 2010 at 5:43 PM, phoebe kong sityeek...@gmail.com wrote: Hi there, I would like to draw a scatter plot and fit a smooth line by loess. Below is the data. However, the curve line started from 0, which my resid list doesn't consist of 0 value. It returned some warnings which I don't know if this is the reason affecting such problem. Here I also attached the warning messages. Please let me know if there is a solution to fix this. Thank you very much! YMRS_Sum-c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 0, 1, 1, 4, 0, 0, 2, 0, 1, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 1, 4, 2, 1, 2, 0, 1, 0, 0, 0, 0, 2, 0, 0, 3, 0, 0, 0, 0, 2, 0, 4, 0, 2, 0, 0) resid-c(80.1150, 84.0279, 88.3736, 90.1557, 55.1979, 78.4293, 87.4367, 74.0271, 80.8871, 91.5685, 82.4154, 73.3080, 66.7786, 70.2486, 82.4971, 77.3792, 70.7731, 66.9593, 85.5515 81.4071, 68.6646, 89.8271, 91.6041, 85.1980, 80.6071, 86.4362, 86.2915, 86.4493, 87.8664, 84.5150, 64.4975, 79.1246, 84.9350, 89.1608, 92.7546, 70.0253, 81.4146, 73.2755, 82.5200, 79.7164, 92.0786, 82.5633, 84.4336, 84.0193, 64.8029, 87.4864, 86.3338, 75.6758, 86.8567, 85.1077, 88.9533, 81.7240, 84.1713, 80.0400, 77.6050, 81.4436, 83.8379, 72.5050, 80.5423, 83.2564, 84.1436, 90.0662, 84.5293, 81.6771, 90.6425, 90.3285, 76.2371, 87.3625, 70.7917, 77.0993, 88.3608, 89.7200, 79.1031, 79.7421, 84.2469, 83.9371, 73.8800, 89.3921, 89.3900, 86.8921, 85.7036, 85.2664, 83.8700, 90.5493) scatter.smooth(YMRS_Sum,resid) Warning messages: 1: at -0.02 2: radius 0.0004 3: all data on boundary of neighborhood. make span bigger 4: pseudoinverse used at -0.02 5: neighborhood radius 0.02 6: reciprocal condition number nan 7: zero-width neighborhood. make span bigger 8: There are other near singularities as well. 1 9: at -0.02 10: radius 0.0004 11: all data on boundary of neighborhood. make span bigger 12: pseudoinverse used at -0.02 13: neighborhood radius 0.02 14: reciprocal condition number nan 15: zero-width neighborhood. make span bigger 16: There are other near singularities as well. 1 17: at -0.02 18: radius 0.0004 19: all data on boundary of neighborhood. make span bigger 20: pseudoinverse used at -0.02 21: neighborhood radius 0.02 22: reciprocal condition number nan 23: zero-width neighborhood. make span bigger 24: There are other near singularities as well. 1 25: at -0.02 26: radius 0.0004 27: all data on boundary of neighborhood. make span bigger 28: pseudoinverse used at -0.02 29: neighborhood radius 0.02 30: reciprocal condition number nan 31: zero-width neighborhood. make span bigger 32: There are other near singularities as well. 1 33: In simpleLoess(y, x, w, span, degree, FALSE, FALSE, normalize = FALSE, ... : at -0.02 34: In simpleLoess(y, x, w, span, degree, FALSE, FALSE, normalize = FALSE, ... : radius 0.0004 35: In simpleLoess(y, x, w, span, degree, FALSE, FALSE, normalize = FALSE, ... : all data on boundary of neighborhood. make span bigger 36: In simpleLoess(y, x, w, span, degree, FALSE, FALSE, normalize = FALSE, ... : pseudoinverse used at -0.02 37: In simpleLoess(y, x, w, span, degree, FALSE, FALSE, normalize = FALSE, ... : neighborhood radius 0.02 38: In simpleLoess(y, x, w, span, degree, FALSE, FALSE, normalize = FALSE, ... : reciprocal condition number nan 39: In simpleLoess(y, x, w, span, degree, FALSE, FALSE, normalize = FALSE, ... : zero-width neighborhood. make span bigger 40: In simpleLoess(y, x, w, span, degree, FALSE, FALSE, normalize = FALSE, ... : There are other near singularities as well. 1 Thanks, Phoebe __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to select not continous rows?
Hi, On Wed, Oct 20, 2010 at 9:25 AM, skan juanp...@gmail.com wrote: Hello How can I select several not continuous rows ? If I wanted to select rows 1 to 7 I'll write mydata[,1:7] But what if I need to select rows 1 to 5 and 10 to 15? mydata[, c(1:5, 10:15)] -Ista -- View this message in context: http://r.789695.n4.nabble.com/How-to-select-not-continous-rows-tp3003840p3003840.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Please help: ANOVA with SS Type III for unequal sample sized data
Hi Jeong, On Wed, Oct 20, 2010 at 5:25 AM, BumSeok Jeong bumseok.je...@gmail.com wrote: Dear R experts, I'm beginner. My question about ANOVA for unequal sample sized data should be obsolete but I can not clarify it. I have a dataset from 23 males and 18 females. I measured one condition('cond') with 4 levels. So I'd like to see main effect of gender, cond and gender by cond interaction and also postHoc test. (In fact, I have to do anova 90 times) * 1. Question about constrast stuff for type III* After googling, I found a document ( https://stat.ethz.ch/pipermail/r-help/2001-October/015889.html) and it looked like make sense. This below is what I did on R and I encountered 'error message'. library(car) results_lmanova - list() for(i in 1:90) {sum=subset(ast.ast_coef, ast.ast_coef$coef_thr==i) results_lmanova[[i]] - anova(lm(sum$ast.values ~ sum$gender * sum$cond, contrasts=list(sum$gender='contr.sum', sum$cond='contr.sum'), type='III')) anova calculates only type I SS. You need to replace anova with Anova (notice the capital A). Also, the type argument is in the wrong place (in you code it is an argument to lm() when it should be an argument to Anova(). ) Replace , type='III')) with ), type='III') This is all untested, but try correcting those errors and see what happens. -Ista If remove the row of 'contrasts=', some results showed up and my anxiety also did.. Even if change from 'contr.sum' to 'contr.sum(2)' for gender and to 'contr.sum(4)' for cond, it did not work. And my brain also did not. Please let me know what is error in my command. *2. Question about postHoc test* In my understand, TukeyHSD is for the results of aov() with type I, not anova() with type III which is I used. Please let me know what is the best postHoc test for the results from anova() with type III. Is multcomp a way? thank you, Jeong [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Ordination plot option missing from PCA dialog
Hi Bill, R does not have a standard menu-driven interface, but rather several contributed interfaces including Rcommander, RKward, Deducer, and others. In order or anyone on this list to help you we are going to need to know which one you're using... -Ista On Thu, Oct 21, 2010 at 6:46 PM, William C. Nelson wcnel...@usc.edu wrote: Hello, I am trying to learn how to do PCA. I found a tutorial online, but what I'm seeing in my installation does not match what is in the tutorial. Specifically, if I select Statistics:Dimensional Analysis: Principal-components analysis, the dialog I am presented with does not include an option to create an ordination plot. My question is why not? Is this a problem with my data set, local computer configuration (I am having trouble with the rgl package), or something else? I have R-2.11.1 installed on SuSE SLES 10.1. thanks, Bill -- - William C. Nelson, PhD Research Asst Professor University of Southern California, College of Letters, Arts and Sciences, Department of Biological Sciences, Marine Environmental Biology Division, Wrigley Institute for Environmental Studies 310-510-4097 wcnel...@usc.edu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] mixed effects regression with weights using lme (lme4)
Hi Dimitri, The lme function is not in the lme4 package, so there is some confusion there. But you can use weights with the lmer function in lme4. ?lmer tells you that weights are specified the same way as in the lm function, and refers you to ?lm for details. HTH, Ista On Tue, Oct 26, 2010 at 11:21 AM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Hello! I am sorry if it's a naive/wrong question. But can one run a regression with weights using lme? Thank you! -- Dimitri Liakhovitski Ninah Consulting www.ninah.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] reading multiple XML files into an R table
Hi Jørgen, You will be better served by learning how to find the answers to these kinds of questions on your own. You can either use a general search engine such as google: http://lmgtfy.com/?q=read+multiple+files+in+R http://lmgtfy.com/?q=read+xml+data+in+R or using an R specific search engine. At the R prompt, try RSiteSearch(read multiple files, restrict=NULL) RSiteSearch(read xml, restrict=NULL) If you run into difficulties many people on this list (including myself) will be happy to help. Best, Ista 2010/10/27 Jørgen Blystad Houge jb.ho...@gmail.com: Good morning fellow R users! I need to read multiple .XML files now gathered in one folder and collect them in a table in R. The files have only numeric names and are named nearly continuously (e.g 1.xml, 2.xml, 3.xml . up to about 4.xml) but with a few missing numbers/files. So the code must be able to handle missing files. Can someone suggest a FOR-loop in R that could be able to read all these files and categorize them correctly? I've pasted an example underneath. (For those interested, this is an Urgent Market Message on Nord Pool Spot. I would like to systematize them to observe the power market reserve margin as historic time series. That is estimate how much electricity is actually available for the market. ?xml version=1.0 encoding=ISO-8859-1 ? - # participant_umm effect_after100/effect_after stationVinje/station affected_unitsG1, G2, G3/affected_units - # umm predecessor_id=*0* parent_id=*5244* new_followup=*New*u_id =*5244* event_start19.07.04 hour 11:15/event_start registered19.07.04 hour 11:15/registered event_typeProduction failure/event_type statusApproved and does not have a Followup/status decission19.07.04 hour 11:15/decission event_stop / predefined_remark / approved19.07.04 hour 11:17/approved affected_areasNO1/affected_areas remarksFailure G2, unavailable until further notice./remarks companyStatkraft SF/company /umm effect_before100/effect_before affected_fuelsHydro/affected_fuels effect_during0/effect_during prodconsProduction/prodcons effect_installed300/effect_installed /participant_umm Thanks a lot! Best, Jørgen Blystad Houge MSc student Norwegian University of Science and Technology [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] transforming a dataset for association analysis RESHAPE2
Hi Ajay, I'm not sure what the problem is, and I don't think your description is enough to reproduce it. This works fine for me library(reshape2) dat - read.table(textConnection('Subject Item Score Subject 1 Item 1 1 Subject 1 Item 2 0 Subject 1 Item 3 1 Subject 2 Item 1 1 Subject 2 Item 2 1 Subject 2 Item 3 0'), header=TRUE) closeAllConnections() acast(dat, Subject~Item) sessionInfo() R version 2.12.0 (2010-10-15) Platform: i686-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C [3] LC_TIME=en_US.utf8LC_COLLATE=en_US.utf8 [5] LC_MONETARY=C LC_MESSAGES=en_US.utf8 [7] LC_PAPER=en_US.utf8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] grid stats graphics grDevices utils datasets methods [8] base other attached packages: [1] reshape2_1.0 ggplot2_0.8.8 proto_0.3-8 reshape_0.8.3 plyr_1.2.1 loaded via a namespace (and not attached): [1] stringr_0.4 tools_2.12.0 -Ista On Mon, Nov 1, 2010 at 10:39 AM, Ajay Ohri ohri2...@gmail.com wrote: I get the following message when using the reshape2 package line tDat.m- melt(Dataset) Using Item, Subject as id variables tDatCast- acast(tDat.m,Subject~Item) Aggregation function missing: defaulting to length Note Problem Statement- convert dataframe Subject Item Score 1 Subject 1 Item 1 1 2 Subject 1 Item 2 0 3 Subject 1 Item 3 1 4 Subject 2 Item 1 1 5 Subject 2 Item 2 1 6 Subject 2 Item 3 0 to Subject Item 1 Item 2 Item 3 Item 4 1 Subject 1 1 0 1 1 5 Subject 2 1 1 0 0 Note- when I tried using the wide method the resultant vector went out of memory- its a dataset appox 100,000 lines Websites- http://decisionstats.com http://dudeofdata.com Linkedin- www.linkedin.com/in/ajayohri On Sat, Oct 30, 2010 at 5:41 PM, Rainer Hurling rhur...@gwdg.de wrote: On 30.10.2010 13:50 (UTC+1), Santosh Srinivas wrote: A more usable problem input would definitely help ... use dput to send a reproducible sample to the group Think the below should solve your problem read.csv(Book1.csv) Subject Item Score 1 Subject 1 Item 1 1 2 Subject 1 Item 2 0 3 Subject 1 Item 3 1 4 Subject 2 Item 1 1 5 Subject 2 Item 2 1 6 Subject 2 Item 3 0 library(reshape2) tDat.m- melt(tDat) tDatCast- acast(tDat.m,Subject~Item) tDatCast Item 1 Item 2 Item 3 Subject 1 1 0 1 Subject 2 1 1 0 # Or without using package reshape2, only function reshape from stats: df - data.frame(Subject= c(Subject 1,Subject 1,Subject 1,Subject 1, Subject 2,Subject 2,Subject 2,Subject 2), Item = c(Item 1,Item 2,Item 3,Item 4, Item 1,Item 2,Item 3,Item 4), Score = c(1,0,1,1,1,1,0,0)) df.wide - reshape(df, idvar=Subject, timevar=Item, direction=wide) names(df.wide) - c(Subject,unique(as.character(df$Item))) df.wide Subject Item 1 Item 2 Item 3 Item 4 1 Subject 1 1 0 1 1 5 Subject 2 1 1 0 0 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Ajay Ohri Sent: 30 October 2010 16:27 To: Rhelp Subject: [R] transforming a dataset for association analysis Hi I would like to transform a data frame like Subject Item Score Subject 1 Item 1 1 Subject 1 Item 2 0 Subject 1 Item 3 1 Subject 2 Item 1 1 Subject 2 Item 2 1 Subject 2 Item 3 0 *to * Subject Item1 Item2 Item3 .Item N Subject1 1 0 1 Subject2 1 1 0 SubjectP.. Apologize for the simple nature of my query but I am stuck. How can I do this transformation? Regards Ajay Websites- http://decisionstats.com http://dudeofdata.com Linkedin- www.linkedin.com/in/ajayohri On Sat, Oct 30, 2010 at 2:39 PM, Alaiosala...@yahoo.com wrote: Hello everyone. I have written quite a big function that at the end correctly returns the values I want. I found a rare exception that I want to cover also. The easier for me would be to write something like that function(){ if (rare exception happened) return that value # The comes the code for normal execution # ... # ... return value # Normal values to return } Would that be feasible with R or two returns statements are not accepted? Regards Alex [[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. -- Ista Zahn Graduate
Re: [R] ggplot map bounds
Hi Adrienne, I think usamap + xlim(c(-85, -75)) + ylim(c(33,37)) will do what you want. Best, Ista On Mon, Nov 1, 2010 at 10:52 AM, Adrienne Wootten amwoo...@ncsu.edu wrote: To all, I'm working with code below to produce a map with station data plotted in points, but right now I'm having trouble with the mapping portion of this code states - data.frame(map(state, plot=FALSE,xlim= c(-85,-75),ylim=c(33,37))[c(x,y)]) usamap- ggplot(states)+geom_path(aes(x,y)) usamap When I plot this the problem is that the bounds of the plot is from 31N to 38N and 90W to 75W. The problem is that I only need the bounds of the plot to be from 33N to 37N and 85W to 75W. The way this is now, if I try to subset the states object, I get a garbled mess of lines. The rest of the code provides what I'm trying to do with the attached data. usamap + geom_point(data=obsmeans,aes(x=lon,y=lat,colour = month_1),size=5) + scale_colour_gradientn(data=obsmeans,colour=rev(rainbow(17)),breaks=seq(5,21,by=1),limits=c(5,21)) Any ideas for how I can fix this map would be appreciated! Adrienne -- Adrienne Wootten Graduate Research Assistant State Climate Office of North Carolina Department of Marine, Earth and Atmospheric Sciences North Carolina State 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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot2: facet_grid with different vertical lines on each facet
Hi Scott, You can put the vline data in a separate data.frame: dat - data.frame(x=rnorm(20), y=rnorm(20), z=rep(c(a, b), each=10)) vline.dat - data.frame(z=levels(dat$z), vl=c(0,1)) library(ggplot2) ggplot(dat, aes(x=x, y=y)) + geom_point() + geom_vline(aes(xintercept=vl), data=vline.dat) + facet_grid(.~z) Best, Ista On Tue, Nov 9, 2010 at 4:41 PM, Scott Chamberlain scham...@rice.edu wrote: Hello, I am plotting many histograms together using facet_grid in ggplot2. However, I want to then add a vertical line to each histogram, or facet, each of which vertical lines are at different x-values. The following example adds all vertical lines to each facet: ggplot(data,aes(values)) + geom_histogram() + facet_grid(.~variable) + geom_vline(xintercept=c(5,10,15)) How can I add a vertical line at different x positions on each facet? Thanks very much, Scott Chamberlain [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot2 problem in interacting mode
Hi, Here are a couple of suggestions: -- Start R without loading startup scripts etc. (R --vanilla) and see if it works. If yes, there is something loading in your startup file or restored environment that is causing problems. -- Upgrade to the latest version of R HTH, Ista On Wed, Nov 10, 2010 at 2:51 PM, zhenjiang xu zhenjiang...@gmail.com wrote: Hi all, When running R interactively, I have the problem as following: library(ggplot2) Loading required package: reshape Loading required package: plyr Attaching package: 'reshape' The following object(s) are masked from 'package:plyr': round_any Loading required package: grid Loading required package: proto data(VADeaths) pg - ggplot(melt(VADeaths), aes(value, X1)) + geom_point() + + facet_wrap(~X2) + ylab() print(pg) Error in get(transform, env = ., inherits = TRUE)(., ...) : attempt to apply non-function My R package information is : library(plyr) sessionInfo() R version 2.11.1 (2010-05-31) x86_64-pc-linux-gnu locale: [1] LC_CTYPE=zh_CN.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=C LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=en_US.UTF-8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C attached base packages: [1] grid stats graphics grDevices utils datasets methods [8] base other attached packages: [1] lattice_0.18-8 ggplot2_0.8.8 proto_0.3-8 reshape_0.8.3 plyr_1.2.1 loaded via a namespace (and not attached): [1] tools_2.11.1 The interesting thing is that when I put the codes into an R script, and run with command R CMD BATCH XX.R, it works alright. Does anyone have any idea what the problem is? Thanks~ -- Best, Zhenjiang [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] New Sampling question
This can of course be done, but before I make any attempt to do it I have to ask: why do you want this? On Wed, Nov 17, 2010 at 7:08 PM, wangwallace talentt...@gmail.com wrote: I have another question about drawing samples from a data frame. This might sound really tricky. Let me use a data frame I have posted earlier as an example: SubID CSE1 CSE2 CSE3 CSE4 WSE1 WSE2 WSE3 WSE4 1 6 5 6 2 6 2 2 4 2 6 4 7 2 6 6 2 3 3 5 5 5 5 5 5 4 5 4 5 4 3 4 4 4 5 2 5 5 6 7 5 6 4 4 1 6 5 4 3 6 4 3 7 3 7 3 6 6 3 6 5 2 1 8 3 6 6 3 6 5 4 7 this data frame have two sets of variables. each set simply represent one scale. as shown above, the first scale, say CSE, consists of four items: CSE1, CSE2, CSE3, and CSE4, whereas the second scale, say WSE, also has four items: WSE1, WSE2, WSE3, WSE4. the leftmost column lists the subjects' ID. I wanna create a new data frame through sampling random numbers from the data frame above. Below is the structure of the new data frame. SubID var var var var s c c c c s c c c c s c w w w s c w w w s c w w w s c w w w s c w w w s c w w w in the new data frame: s= SubID range from 1 to 8 var= variables c=CSE numbers w=WSE numbers some rules to construct the new data frame: 1. the top two rows have to be filled with CSE numbers; the numbers in the cells of each row should be randomized. for example, if the first row is an array of numbers from subject 4, they can follow the order: 4(CSE2), 5(CSE1), 3(CSE3), and 4(CSE4). Also, the numbers in the second row does not have to follow the order of the first row. for example, similarly, if the first row is an array of numbers from subject 4 in the order: 4(CSE2), 5(CSE1), 3(CSE3), and 4(CSE4), numbers in the second row (assuming it is from subject 8) does not have to be 6(CSE2), 3(CSE1), 6(CSE3), and 3(CSE4). numbers in these two rows should be drawn without replacement. 2. each of the rest of the rows should include a CSE number in the leftmost cell and three WSE numbers on the right. At the same time, in each row, the three WSE numbers on the right have to be only those numbers that are not corresponding to the CSE number in the leftmost cell. For example, if the CSE number in the leftmost cell is 4, a CSE2 number from subject 6, the three WSE numbers on the right side can only be 4(WSE1), 7(WSE3), and 3(WSE4) from subject 6. 3. the numbers in each row can only be drawn from the same subject. Also, Subjects should be randomized. Specifically, they does have to be in the following order: SubID 1 2 3 4 5 6 7 8 they can be: SubID 2 8 5 4 1 6 7 3 Any ideas? Thanks in advance!! :) -- View this message in context: http://r.789695.n4.nabble.com/New-Sampling-question-tp3047885p3047885.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Sweave Dynamic Graph Question
Hi Cameron, This is a Sweave FAQ: http://www.stat.uni-muenchen.de/~leisch/Sweave/FAQ.html#x1-11000A.9 -Ista On Fri, Nov 19, 2010 at 4:13 PM, cameron raymond...@invesco.com wrote: i have a time Series of IBM closing px from 1/1/2000 to today I want to graph the time serie by dividing the graph by year and month all the monthly graphs with the same year will go to one page. so from 1/1/2000 to 11/19/2010. i will have 11 pages, and each page will have 12 graphs (jan to dec) except for 2010. I am able to do it in R, but when i use sweave, I can only print the last page. any help would be greatly appreciated Thanks Cameron #R code library(fImport) IBM - yahooSeries(IBM, from=2000-01-01) IBM.Close - IBM[,IBM.Close] rng=range(time(IBM.Close)) Syr - as.numeric(format(rng[1],%Y)) Eyr - as.numeric(format(rng[2],%Y)) Smth - as.numeric(format(rng[1],%m)) for( yr in Syr:Eyr){ par(mfrow=c(4,3)) Temp1 - IBM.Close[which(format(time(IBM.Close),%Y)==yr),] Temp3 - tapply(Temp1[,1],as.yearmon(time(Temp1)),FUN=mean) for(i in Smth:length(Temp3)){ i - ifelse(i 10, paste(0,i,sep=),i) Date - paste(i,yr,sep=-) Temp2 - IBM.Close[which(format(time(IBM.Close),%m-%Y)==Date),] plot(time(Temp2),Temp2,type=l,main=paste(factor(as.numeric(i), labels = month.name[as.numeric(i)]),yr,sep=-)) } } # my sweave code (pass in IBM.Close) \pagebreak \subsection{Graph} \begin{figure}[!htbp] \begin{center} plot1, echo = FALSE, results = hide, fig = TRUE, height = 8= rng=range(time(IBM.Close)) Syr - as.numeric(format(rng[1],%Y)) Eyr - as.numeric(format(rng[2],%Y)) Smth - as.numeric(format(rng[1],%m)) for( yr in Syr:Eyr){ par(mfrow=c(4,3)) Temp1 - IBM.Close[which(format(time(IBM.Close),%Y)==yr),] Temp3 - tapply(Temp1[,1],as.yearmon(time(Temp1)),FUN=mean) for(i in Smth:length(Temp3)){ i - ifelse(i 10, paste(0,i,sep=),i) Date - paste(i,yr,sep=-) Temp2 - IBM.Close[which(format(time(IBM.Close),%m-%Y)==Date),] plot(time(Temp2),Temp2,type=l,main=paste(factor(as.numeric(i), labels = month.name[as.numeric(i)]),yr,sep=-)) } } @ -- View this message in context: http://r.789695.n4.nabble.com/Sweave-Dynamic-Graph-Question-tp3051003p3051003.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Alternatives to image(...) and filled.contour(...) for 2-D filled Plots
Hi Jason, You do not say what you want the alternative to do, so its hard to know if this will be helpful. But one alternative is dat - as.data.frame(ak.fan) dat - melt(dat, id.vars=c(x, y)) p - ggplot(dat, aes(x=x, y=variable)) p + geom_tile(aes(fill=value)) -Ista On Sun, Nov 21, 2010 at 9:04 AM, Jason Rupert jasonkrup...@yahoo.com wrote: By any chance are there any alternatives to image(...) and filled.contour(...) I used Rseek to search for that very topic, but didn't turn over any leads... http://www.rseek.org/?cx=010923144343702598753%3Aboaz1reyxd4newwindow=1q=alternative+to+image+and+filled.contoursa=Searchcof=FORID%3A11siteurl=www.rseek.org%252F#1238 I'm sure there are some out there, but curious about some of the favorites and ones folks have had success using. Thanks for any insights and feedback. I would like to use the alternative 2-D fill function with the example I have been messing with in place of image(...) or filled.contour(...): library(akima) hyp_distance-seq(1,15) angle_deg_val-seq(0,15) x_distance_val-NULL y_distance_val-NULL for(ii in 1:length(hyp_distance)) { for(jj in 1:length(angle_deg_val)) { x_distance_tmp-hyp_distance[ii]*cos(angle_deg_val[jj]*pi/180) y_distance_tmp-hyp_distance[ii]*sin(angle_deg_val[jj]*pi/180) x_distance_val-c(x_distance_val, x_distance_tmp) y_distance_val-c(y_distance_val, y_distance_tmp) } } temperature_vals-rnorm(length(x_distance_val), 75, 2) temp_samples-cbind(x_distance_val, y_distance_val, temperature_vals) temp_samples_DF-data.frame(x = x_distance_val, y = y_distance_val, z = temperature_vals) ak.fan - interp(temp_samples[,1], temp_samples[,2], temp_samples[,3] ) length_val-floor(max(temperature_vals) - min(temperature_vals))*2 color_vals_red_to_yellow_to_green-colorRampPalette(c(red, yellow, green), space=Lab)(length_val) color_vals_green_to_yellow_to_red-colorRampPalette(c(green, yellow, red), space=Lab)(length_val) plot(1,1, col = 0, xlim = c(min(x_distance_val), max(x_distance_val)), ylim = c(min(y_distance_val), max(y_distance_val)), xlab = Room X Position (FT), ylab = Room Y Position (FT), main = Room Temp vs Position) grid() # filled.contour(ak.fan, col = color_vals_red_to_yellow_to_green) # filled.contour(ak.fan, col = color_vals_green_to_yellow_to_red) # image(ak.fan, col = color_vals_red_to_yellow_to_green, add = TRUE) image(ak.fan, col = color_vals_green_to_yellow_to_red, add = TRUE) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] negative alpha or custom gradient colors of data dots in scatterplot ?
Hi, I suggest taking a look at the plotting functions in the ggplot2 package. For example: x - rnorm(1) y - x+rnorm(1) dat - data.frame(x,y) library(ggplot2) p - ggplot(dat, aes(x=x, y=y)) p + geom_point() # too much overplotting: compare to dev.new() p + geom_hex(binwidth=c(.1,.1)) Best, Ista On Sun, Nov 21, 2010 at 9:13 AM, madr madra...@interia.pl wrote: I know that by setting alpha to for example col = rgb(0, 0, 0, 0.1) it is possible to see how many overlapping is in the plot. But disadvantage of it is that single points are barely visible on the background. So I wonder if there is possible to make setting that single points would be almost black, but with more and more data on the same spot it would get more and more whiteish. Or maybe it is possible to make sole data points black but overlapped tending to some particular color of choice ? -- View this message in context: http://r.789695.n4.nabble.com/negative-alpha-or-custom-gradient-colors-of-data-dots-in-scatterplot-tp3052394p3052394.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] I need a very specific unique like function and I don't know even how to properly call this
Here is a method for piecing it together using diff and indexing: dat - structure(c(3L, 6L, 7L, 3L, 7L, 5L, 8L, 2L, 7L, 0L, 7L, 5L, 5L, 5L, 5L, 5L, 4L, 4L, 4L, 6L), .Dim = c(10L, 2L), .Dimnames = list( NULL, c(V1, V2))) diffs - abs(diff(dat[,2], 1)) # get the difference between each value and the previous value new.dat - cbind(dat, c(NA, diffs), c(diffs, NA)) # combine the diffs with the original matrix, shifted down (is the next valued the same as the value) and down (is the previous value the same) new.dat - cbind(new.dat, rowSums(new.dat[,3:4], na.rm=TRUE)) # sum the shifted diffs so that the value is 0 if above and below are the same, and greater than zero if the above and below values are not the same final.dat - new.dat[new.dat[,5] !=0 ,1:2] # get rid of rows for which the sum of the shifted diffs is not equal to zero. HTH, Ista On Mon, Nov 22, 2010 at 8:53 PM, madr madra...@interia.pl wrote: consider this matrix: [,1] [,2] [1,] 3 7 [2,] 6 5 [3,] 7 5 [4,] 3 5 [5,] 7 5 [6,] 5 5 [7,] 8 4 [8,] 2 4 [9,] 7 4 [10,] 0 6 I need to delete all rows where column 2 above and below has the same value, so the effect would be: [,1] [,2] [1,] 3 7 [2,] 6 5 [6,] 5 5 [7,] 8 4 [9,] 7 4 [10,] 0 6 is there a built in function for that kind of operation or I must write one from scratch ? Is there a name for that kind of operation ? -- View this message in context: http://r.789695.n4.nabble.com/I-need-a-very-specific-unique-like-function-and-I-don-t-know-even-how-to-properly-call-this-tp3054427p3054427.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to start default browser on R
Hi Stephen, I'm not sure if this is the problem, but you almost certainly do not want the file: part. Try browseURL(http://www.r-project.org;) -Ista On Mon, Nov 22, 2010 at 10:26 PM, Stephen Liu sati...@yahoo.com wrote: Hi David, Thanks for your advice. According to the Example on ?browseURL I tried: 1) browseURL(file:http://www.r-project.org;, browser=C:/Program Files/Internet Explorer/iexplore.exe) It starts a small windows asking for permission to accept ActiveX - OK IE doesn't start 2) browseURL(file:http://d:/R/R-2.5.1/html/index.html;, browser=C:/Program Files/Internet Explorer/iexplore.exe) same result as 1) above What I have missed? TIA B.R. Stephen L - Original Message From: David Scott d.sc...@auckland.ac.nz To: Stephen Liu sati...@yahoo.com Cc: r-help@r-project.org r-help@r-project.org Sent: Tue, November 23, 2010 10:16:04 AM Subject: Re: [R] How to start default browser on R On 23/11/10 14:20, Stephen Liu wrote: Hi folks, Win7 64 bit IE 64 bit How to start IE on R? TIA B.R. Stephen L ?browseURL -- _ David Scott Department of Statistics The University of Auckland, PB 92019 Auckland 1142, NEW ZEALAND Phone: +64 9 923 5055, or +64 9 373 7599 ext 85055 Email: d.sc...@auckland.ac.nz, Fax: +64 9 373 7018 Director of Consulting, Department of Statistics __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Print to console from within Sweave script
Hi Werner, If I remember correctly, message() can be used for this purpose. Best, Ista On Tue, Nov 30, 2010 at 7:16 AM, Werner W. pensterfuz...@yahoo.de wrote: Hi, is it possible to send some message to the console from within a .Rnw Sweave script, ie. when executing Sweave()? The background is that only in particular circumstances my script is doing some lengthy computations and I would like to print some status information to the console. It seems Sweave redirects all output though. Any suggestions? Thanks a lot for considering my question. All the best 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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Minor warning about seq
So you are warning us that you must type zero instead of the letter O when we want to enter the value of zero? Seems pretty obvious... -Ista On Tue, Nov 30, 2010 at 1:49 PM, Prof. John C Nash nas...@uottawa.ca wrote: I spent more time than I should have debugging a script because I wanted x-seq(0,100)*0.1 but typed x-seq(O:100)*0.1 seq(0:100) yields 1 to 101, Clearly my own brain to fingers fumble, but possibly one others may want to avoid it. JN __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Welcome to the R-help mailing list
Hi Bill, You might be working too hard. Consider: weekdays(as.Date('2010-11-30')) == Monday [1] FALSE weekdays(as.Date('2010-11-29')) == Monday [1] TRUE HTH, Ista On Tue, Nov 30, 2010 at 9:40 PM, Bill Yang gy631...@hotmail.com wrote: Hi there, I am having problem of matching string. what i want is when i type a date such as 2010-11-30, the function will return the day (monday, tuesday, wednesday, thursday, friday or staturday). then i want another function will return true if the return of the day is monday, return false if the return of the day is not monday. I already find the weekdays(as.Date('2010-11-30')) function which will tell me exactly what day its gonna be. however, i am having problem of return True or False whether or not the return day has matched. please help me out. I appreciate. Bill P.S the following is the partial codes.if(match(weekdays(as.Date('2010-11-30'), Monday)==1){print(yes)} r-help@r-project.org Subject: Welcome to the R-help mailing list From: r-help-requ...@r-project.org To: gy631...@hotmail.com Date: Wed, 1 Dec 2010 03:34:01 +0100 Welcome to the R-help@r-project.org mailing list! To post to this list, send your email to: r-help@r-project.org General information about the mailing list is at: https://stat.ethz.ch/mailman/listinfo/r-help If you ever want to unsubscribe or change your options (eg, switch to or from digest mode, change your password, etc.), visit your subscription page at: https://stat.ethz.ch/mailman/options/r-help/gy631223%40hotmail.com You can also make such adjustments via email by sending a message to: r-help-requ...@r-project.org with the word `help' in the subject or body (don't include the quotes), and you will get back a message with instructions. You must know your password to change your options (including changing the password, itself) or to unsubscribe. It is: 8711208752 Normally, Mailman will remind you of your r-project.org mailing list passwords once every month, although you can disable this if you prefer. This reminder will also include instructions on how to unsubscribe or change your account options. There is also a button on your options page that will email your current password to you. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to select the column header with \Sexpr{}
list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to select the column header with \Sexpr{}
Hi Felipe, See in line below. On Tue, Jul 13, 2010 at 11:04 AM, Felipe Carrillo mazatlanmex...@yahoo.com wrote: Thanks Izta: I see your point, then I should extract the column names when the dataset is first read because is a dataframe: That might work, but it's definitely not how I would do it. report - structure(list(Date = c(3/12/2010, 3/13/2010, 3/14/2010, 3/15/2010), Run1 = c(33 (119 ? 119), n (0 ? 0), 893 (110 ? 146), 140 (111 ? 150)), Run2 = c(33 (71 ? 71), n (0 ? 0), 337 (67 ? 74), 140 (68 ? 84)), Run3 = c(890 (32 ? 47), n (0 ? 0), 10,602 (32 ? 52), 2,635 (34 ? 66)), Run4 = c(0 ( ? ), n (0 ? 0), 0 ( ? ), 0 ( ? )), Run4 = c(0 ( ? ), n (0 ? 0), 0 ( ? ), 0 ( ? ))), .Names = c(ID_Date, Run1, Run2, Run3, Run4, Run5), row.names = c(NA, 4L), class = data.frame) str(report) 'data.frame': 4 obs. of 6 variables: $ ID_Date: chr 3/12/2010 3/13/2010 3/14/2010 3/15/2010 $ Run1 : chr 33 (119 ? 119) n (0 ? 0) 893 (110 ? 146) 140 (111 ? 150) $ Run2 : chr 33 (71 ? 71) n (0 ? 0) 337 (67 ? 74) 140 (68 ? 84) $ Run3 : chr 890 (32 ? 47) n (0 ? 0) 10,602 (32 ? 52) 2,635 (34 ? 66) $ Run4 : chr 0 ( ? ) n (0 ? 0) 0 ( ? ) 0 ( ? ) $ Run5 : chr 0 ( ? ) n (0 ? 0) 0 ( ? ) 0 ( ? ) names(report)[1] # I can extract the column name here [1] Date But after I use 'stringr to convert the character '?' to '-' 'report' is not a dataframe anymore and returns a NULL when trying to extract the column names. No, it will not report NULL when extracting _column names_. Try colnames(report). It will report NULL when trying to extract the _names_ using names(report), because matrices have colnames and rownames but not names. I was not aware that \Sexpr{} only work on dataframes, thanks for your help. The problem is _not with \Sexpr_. The problem is that you are asking for the names() of a matrix, which do not exist in R. You can use colnames() like this \Sexpr{colnames(report)[1]} or you can convert report to a data.frame and use names, like this \Sexpr{names(as.data.frame(report))[1]} HTH, Ista - Original Message From: Ista Zahn iz...@psych.rochester.edu To: Felipe Carrillo mazatlanmex...@yahoo.com Cc: David Winsemius dwinsem...@comcast.net; r-h...@stat.math.ethz.ch Sent: Tue, July 13, 2010 7:13:39 AM Subject: Re: [R] How to select the column header with \Sexpr{} Hi Felipe, The problem has nothing to do with Sweave or \Sexpr. The problem is that by the time you call \Sexpr report is a matrix, and you cannot access the column names of a matrix with names(). You need to use colnames() or convert the matrix to a data.frame. Perhaps a true useR can write R code in a Sweave file without checking it, but for mere mortals it is best to evaluate the R code in an interactive session to make sure it works before asking Sweave to insert it into your .tex file. If you had tried to evaluate names(report)[1] in an interactive session you would have discovered your problem immediately. Best, Ista On Tue, Jul 13, 2010 at 4:15 AM, Felipe Carrillo mazatlanmex...@yahoo.com wrote: I had tried that earlier and didn't work either, I probably have \Sexpr in the wrong place. See example: Column one header gets blank: \documentclass[11pt]{article} \usepackage{longtable,verbatim,ctable} \usepackage{longtable,pdflscape} \usepackage{fmtcount,hyperref} \usepackage{fullpage} \title{United States} \begin{document} \setkeys{Gin}{width=1\textwidth} \maketitle echo=F,results=hide= report - structure(list(Date = c(3/12/2010, 3/13/2010, 3/14/2010, 3/15/2010), Run1 = c(33 (119 ? 119), n (0 ? 0), 893 (110 ? 146), 140 (111 ? 150)), Run2 = c(33 (71 ? 71), n (0 ? 0), 337 (67 ? 74), 140 (68 ? 84)), Run3 = c(890 (32 ? 47), n (0 ? 0), 10,602 (32 ? 52), 2,635 (34 ? 66)), Run4 = c(0 ( ? ), n (0 ? 0), 0 ( ? ), 0 ( ? )), Run4 = c(0 ( ? ), n (0 ? 0), 0 ( ? ), 0 ( ? ))), .Names = c(ID_Date, Run1, Run2, Run3, Run4, Run5), row.names = c(NA, 4L), class = data.frame) require(stringr) report - t(apply(report, 1, function(x) {str_replace(x, \\?, -)})) #report #latex(report,file=) @ \begin{landscape} \begin{table}[!tbp] \begin{center} \begin{tabular}{ll}\hline\hline \multicolumn{1}{c}{\Sexpr{names(report)[1]}} # Using \Sexpr here \multicolumn{1}{c}{Run1} \multicolumn{1}{c}{Run2} \multicolumn{1}{c}{Run3} \multicolumn{1}{c}{Run4} \multicolumn{1}{c}{Run5}\tabularnewline \hline 13/12/201033 (119 ? 119)33 (71 ? 71)890 (32 ? 47)0 ( ? )0 ( ? )\tabularnewline 23/13/2010n (0 ? 0)n (0 ? 0)n (0 ? 0)n (0 ? 0)n (0 ? 0)\tabularnewline 33/14/2010893 (110 ? 146)337 (67 ? 74)10,602 (32 ? 52)0 ( ? )0 ( ? )\tabularnewline 43/15/2010140 (111 ? 150)140 (68 ? 84)2,635 (34 ? 66)0 ( ? )0 ( ? )\tabularnewline \hline \end{tabular} \end{center} \end{table} \end{landscape} \end{document} Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service
Re: [R] a very particular plot
of the data in the sub frame, the maximum, and the median, as points. AND each x column also displays histogram data, so that the y values which have more density in the subframe are darker, and the ones with less density are lighter. I know this is fairly particular, and may not be possible, but it would be really great for me! If anyone can help - thanks! -- Ian Bentley M.Sc. Candidate Queen's University Kingston, Ontario [[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. -- Assistant Professor / Dobelman Family Junior Chair Department of Statistics / Rice University http://had.co.nz/ -- Ian Bentley M.Sc. Candidate Queen's University Kingston, Ontario -- Ian Bentley M.Sc. Candidate Queen's University Kingston, Ontario -- Ian Bentley M.Sc. Candidate Queen's University Kingston, Ontario [[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. --- Jeff Newmiller The . . Go Live... DCN:jdnew...@dcn.davis.ca.us Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/Batteries O.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Simple question regarding name of column headers
Hi Addi, On Fri, Jul 16, 2010 at 3:22 PM, Addi Wei addi...@gmail.com wrote: names(miceTrainSample) [1] b_double KierA2 KierFlex Q_VSA_POS pID50 In the above code, how do I delete pID50 column to store the resulting object without indicating column 5. The code below does the trick, but I wish to delete the column by specifying -pID50 instead of 5. names(miceTrainSample)[-5] [1] b_double KierA2 KierFlex Q_VSA_POS If I understand you correctly, than this code will not do the trick. All it does is print the column names minus pID50. It does nothing to miceTrainSample. Anyway, I have often wished that something like new.mt.sample - miceTrainSample[, -pID50] would return miceTrainSample without the pID50 column. Here are three alternative ways to do it. # Method 1: Assign NULL to the column new.mt.sample - miceTrainsSample new.mt.sample$pID50 - NULL # Method 2: Use which() new.mt.sample - miceTrainSample[, - which(names(miceTrainSample == pID50)] # Method 3: use %in% (the one I usually use) new.mt.sample - miceTrainSample[, ! names(miceTrainSample) %in% pID50] Hope it helps, Ista -- View this message in context: http://r.789695.n4.nabble.com/Simple-question-regarding-name-of-column-headers-tp2291534p2291534.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to collapse categories or re-categorize variables?
Hi, On Fri, Jul 16, 2010 at 5:18 PM, CC turtysm...@gmail.com wrote: I am sure this is a very basic question: I have 600,000 categorical variables in a data.frame - each of which is classified as 0, 1, or 2 What I would like to do is collapse 1 and 2 and leave 0 by itself, such that after re-categorizing 0 = 0; 1 = 1 and 2 = 1 --- in the end I only want 0 and 1 as categories for each of the variables. Something like this should work for (i in names(dat)) { dat[, i] - factor(dat[, i], levels = c(0, 1, 2), labels = c(0, 1, 1)) } -Ista Also, if possible I would rather not create 600,000 new variables, if I can replace the existing variables with the new values that would be great! What would be the best way to do this? Thank you! -- Thanks, CC [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] a issue about the qutation mark?
Hi Karena, On Fri, Jul 16, 2010 at 11:23 AM, karena dr.jz...@gmail.com wrote: snip So, as we all know, when using read.csv, we need to use qutation mark out side the filename which we wanna read in. At first, for line 8, I wrote: read.csv(trait.file), at last line, I wrote: funcname(folder/hyper.csv), but it did not work in this way. Unless I changed the code to the current one that I showed above, I couldn't get what I want. So, to be straightforward, I will show the difference: 1) the code not working: read.csv(trait.file) #line 8 funcname(folder/hyper.csv) #last line The problem here is that unquoted commands used to refer to objects saved in your R working environment (well I may not be using the right terminology here. But I hope it is clear enough). Also, the / character is an arithmetic function. So when you call funcname(folder/hyper.csv) R will look for an object named folder and try to divide it by an object named hyper.csv). This could sometimes make sense, e.g., test.fun - function(x) { (sqrt(x)) } folder - 8 hyper.csv - 2 test.fun(folder/hyper.csv) but it is not what you want here. In your case, you need to pass a string to the read.csv function containing the filename. Even if you got passed this problem, you have another one, which is that by quoting the argument in read.csv(trait.file) you are asking read.csv to find a file located in the current working directory named trait.file. This is not what you want. You want read.csv to find a file specified by the argument to the funcname() function. 2) the code working: read.csv(trait.file) # line 8 funcname(folder/hyper.csv) # last line anyone can tell me why is the difference? This works because you are correctly passing a string to the read.csv() function. Maybe it helps to try this: dat - data.frame(a=rnorm(10), b=rnorm(10)) write.csv(dat, file=test.csv) file.name - test.csv dat2 - read.csv(file.name) dat2 - read.csv(file.name) Best, Ista thank you, karena -- View this message in context: http://r.789695.n4.nabble.com/a-issue-about-the-qutation-mark-tp2291537p2291537.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Plot error
Hi James, On Sat, Jul 17, 2010 at 2:50 PM, James Platt james-pl...@hotmail.co.uk wrote: Hi guys, I am a newbie to R, so apologies in advance. I created this simple table in excel, saved in tab delimited .txt: name value_1 value_2 1 bill 1 4 2 ben 2 2 3 jane 3 1 test -read.table(\path\to\file, sep=\t, header=TRUE) x -c(seq[value_1]) y -c(seq[value_2]) You lost me here. What is seq[value_1] supposed to do? Please fix your example. plot(x,y) and i get this error Error in xy.coords(x, y, xlabel, ylabel, log) : (list) object cannot be coerced to type 'double' What does this mean and how do i fix it? Thanks for the help, James __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to collapse categories or re-categorize variables?
On Sat, Jul 17, 2010 at 9:03 PM, Peter Dalgaard pda...@gmail.com wrote: Ista Zahn wrote: Hi, On Fri, Jul 16, 2010 at 5:18 PM, CC turtysm...@gmail.com wrote: I am sure this is a very basic question: I have 600,000 categorical variables in a data.frame - each of which is classified as 0, 1, or 2 What I would like to do is collapse 1 and 2 and leave 0 by itself, such that after re-categorizing 0 = 0; 1 = 1 and 2 = 1 --- in the end I only want 0 and 1 as categories for each of the variables. Something like this should work for (i in names(dat)) { dat[, i] - factor(dat[, i], levels = c(0, 1, 2), labels = c(0, 1, 1)) } Unfortunately, it won't: d - 0:2 factor(d, levels=c(0,1,1)) [1] 0 1 NA Levels: 0 1 1 Warning message: In `levels-`(`*tmp*`, value = c(0, 1, 1)) : duplicated levels will not be allowed in factors anymore I stand corrected. Thank you Peter. This effect, I have been told, goes way back to design choices in S (that you can have repeated level names) plus compatibility ever since. It would make more sense if it behaved like d - factor(d); levels(d) - c(0,1,1) and maybe, some time in the future, it will. Meanwhile, the above is the workaround. (BTW, if there are 60 variables, you probably don't want to iterate over their names, more likely for(i in seq_along(dat))...) -- Peter Dalgaard Center for Statistics, Copenhagen Business School Phone: (+45)38153501 Email: pd@cbs.dk Priv: pda...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Reshaping data
On Tue, Jul 20, 2010 at 3:30 AM, John Kane jrkrid...@yahoo.ca wrote: Assuming your data is in data.frame xx library(reshape) mm1 - melt(xx, id=c(ID)) cast(mm1, ID ~ variable ) = That code just goes in a circle! the result of cast(mm1, ID ~ variable) is equal to xx. Here is one way to do it with the melt/cast functions from the reshape package: m.dat - melt(dat, id = ID) m.dat - cbind(m.dat, colsplit(m.dat$variable, split = _, names = c(begin.end,t))) m.dat$variable - NULL dat.final - cast(m.dat, ... ~ begin.end) Hope it helps, Ista --- On Mon, 7/19/10, Thomas Jensen thomas.jen...@eup.gess.ethz.ch wrote: From: Thomas Jensen thomas.jen...@eup.gess.ethz.ch Subject: [R] Reshaping data To: R-help@r-project.org Received: Monday, July 19, 2010, 6:48 PM Dear All, I have some data in the following shape: ID begin_t1 end_t1 begin_t2 end_t2 Thomas 11/03/04 13/05/06 04/02/07 16/05/08 ... ... ... ... ... Jens 24/01/02 23/05/03 07/06/03 14/11/05 I would like to reshape this data to have the following form: ID Begin_Time End_Time Thomas 11/03/04 13/05/06 Thomas 04/02/07 16/05/08 ... ... ... Jens 24/01/02 23/05/03 Jens 07/06/03 14/11/05 I have been doing some google searches and looked at the reshape library, but so far I have not been able to shape the data like I want. If you guys could help, I would greatly appreciate it! Best, Thomas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to test if a vector contain a value?
Hi Hyunchul, See ?match -Ista On Mon, Aug 16, 2010 at 1:06 PM, Hyunchul Kim hyunchul.kim@gmail.com wrote: Hi all, How to convert following simple python script to R if x in a_list: print x OR simply, how to test if a vector contain a value? Thank you in advance, Hyunchul [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to Perform CCA in ??!! Help please
If you read your email back to yourself, you will notice that you never actually describe the problems you are having. There are people on this list who can help you, but you need to tell them what you need help with. We don't need your whole data set and script (in fact sending the whole shebang would be unhelpful). Instead, make sample data sets (just complex enough to illustrate your problems) and R code that you need help working out. We want to help you, but I JUST CAN'T GET IT is much to vague. Best, Ista On Wed, Aug 18, 2010 at 4:38 AM, stompper33 ascaldero...@gmail.com wrote: Performing CCA in R I know they say don't say please... or plead...but I'm sorry but I really need some help with this problem. I have tried to perform CCA in R and I can never do this successfully. Can someone please tell me what I'm doing wrong. I can't attach any file...so Please email me and I'll attach the necessary files. (there's only two) the files will be my CCA R script file, and my data file I use that contains all my data I use for my analyzing. **The files I'll send you are .csv file and a R script. The file all_Data01.csv and Performing_CCA will be the file names PLEASE!! I AM DESPERATE! I'VE BEEN TRYING TO DO THIS FOR A COUPLE OF WEEKS AND I JUST CAN'T GET IT!! If you can help I will really appreciate it. You will need to install the 'CCA' package in R before running it. I am also thinking maybe I may only be able to run the regularized CCA rather than Classical CCA. But I hope to run one or the other. If anyone needs an easy example of CCA please follow the link below: http://www.jstatsoft.org/v23/i12/paper (scroll to about the bottom of page 7 ) I've tried to follow the example as well and still have problems. Thank You...Thank You -- View this message in context: http://r.789695.n4.nabble.com/How-to-Perform-CCA-in-R-Help-please-tp2329336p2329336.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] relimp
Hi John, I'm having some trouble sorting out your request, for the following reasons: 1) I don't know what misdist is (can't find it on CRAN or google) or why you need Rcmdr to run it. Presumably you meant mixdist? 2) relimp is not required by Rcmdr, merely suggested. Rcmdr will work fine without it. 3) I hope that by downloaded from CRAN you do not mean that you manually downloaded it. R has package management, use it! What happens exactly when you try install.packages(Rcmdr dep=TRUE) ? 4) I had no trouble installing Rcmdr (and all dependencies etc., including relimp) using the command above. My session information is below. Please include yours (as well as the actual errors you get, if any) in your reply. sessionInfo() R version 2.11.1 (2010-05-31) i486-pc-linux-gnu locale: [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C [3] LC_TIME=en_US.utf8LC_COLLATE=en_US.utf8 [5] LC_MONETARY=C LC_MESSAGES=en_US.utf8 [7] LC_PAPER=en_US.utf8 LC_NAME=C [9] LC_ADDRESS=C LC_TELEPHONE=C [11] LC_MEASUREMENT=en_US.utf8 LC_IDENTIFICATION=C attached base packages: [1] splines tcltk stats graphics grDevices utils datasets [8] methods base other attached packages: [1] Rcmdr_1.6-0 car_2.0-2 survival_2.35-8 nnet_7.3-1 [5] MASS_7.3-7 loaded via a namespace (and not attached): [1] tools_2.11.1 Best, Ista On Thu, Aug 26, 2010 at 6:39 AM, John Barrett [jzb] j...@aber.ac.uk wrote: I am trying to use Rcmdr 1.5_4 with R-2.11.1 (order to run to run the new version of misdist-0.5.3 which is built under R-2.11.1). however relimp is required for Rcmdr and the version of relimp_1.0.1 downloaded from CRAN will not work with the latest version of Rcmdr (I get error message telling me to reload it). Is there any way round this problem or will there be a new version relimp that is compatible? Any advice would be gratefully received. many thanks John Prof. Barrett Univ. of Aberystwyth [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org [[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] Help with ddply to eliminate a for..loop
A ddply solution is dat.out - ddply(dat, .(time), transform, slope = scale(slope)) but this is not faster than the loop, and slower than the ave() solution: system.time( + for (i in 1:3) { +mat - dat[dat$time==i, ] +outi - data.frame(mat$time, mat$id, slope=scale(mat$slope)) +if (i==1) { +out - outi +} else { +out - rbind(out, outi) +} + } + ) user system elapsed 0.024 0.000 0.025 system.time( + dat.out - ddply(dat, .(time), transform, slope = scale(slope)) + ) user system elapsed 0.032 0.000 0.031 system.time( + cbind(dat, slope = ave(dat$slope, list(dat$time), FUN = scale)) + ) user system elapsed 0.008 0.000 0.007 On Thu, Aug 26, 2010 at 4:33 PM, Bos, Roger roger@rothschild.comwrote: I created a small example to show something that I do a lot of. scale data by month and return a data.frame with the output. id represents repeated observations over time and I want to scale the slope variable. The out variable shows the output I want. My for..loop does the job but is probably very slow versus other methods. ddply seems ideal, but despite playing with the baseball examples quite a bit I can't figure out how to get it to work with my sample dataset. TIA for any help, Roger Here is the sample code: dat - data.frame(id=rep(letters[1:5],3), time=c(rep(1,5),rep(2,5),rep(3,5)), slope=1:15) dat for (i in 1:3) { mat - dat[dat$time==i, ] outi - data.frame(mat$time, mat$id, slope=scale(mat$slope)) if (i==1) { out - outi } else { out - rbind(out, outi) } } out Here is the sample output: dat - data.frame(id=rep(letters[1:5],3), time=c(rep(1,5),rep(2,5),rep(3,5)), slope=1:15) dat id time slope 1 a1 1 2 b1 2 3 c1 3 4 d1 4 5 e1 5 6 a2 6 7 b2 7 8 c2 8 9 d2 9 10 e210 11 a311 12 b312 13 c313 14 d314 15 e315 for (i in 1:3) { + mat - dat[dat$time==i, ] + outi - data.frame(mat$time, mat$id, slope=scale(mat$slope)) + if (i==1) { + out [TRUNCATED] out mat.time mat.id slope 1 1 a -1.2649111 2 1 b -0.6324555 3 1 c 0.000 4 1 d 0.6324555 5 1 e 1.2649111 6 2 a -1.2649111 7 2 b -0.6324555 8 2 c 0.000 9 2 d 0.6324555 102 e 1.2649111 113 a -1.2649111 123 b -0.6324555 133 c 0.000 143 d 0.6324555 153 e 1.2649111 *** This message is for the named person's use only. It ma...{{dropped:22}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Grouping sets of data, performing function and re-assigning values
Hi Johnny, If I understand correctly, I think you can use cut() to create a grouping variable, and then calculate your summaries based on that. Something like dat - read.csv(~/Downloads/exampledata.csv) dat$image.group - cut(dat$a.ImageNumber, breaks = seq(0, max(dat$a.ImageNumber), by = 3)) library(plyr) ddply(dat, .(image.group), transform, measure.median = median(Measurement)) dat.med - ddply(dat, .(image.group), summarize, a.AreaShape_Area.median = median(a.AreaShape_Area), a.Intensity_IntegratedIntensity_OrigRFP.median = median(a.Intensity_IntegratedIntensity_OrigRFP), a.Intensity_IntegratedIntensity_OrigGFP.median = median(a.Intensity_IntegratedIntensity_OrigGFP), b.Intensity_MeanIntensity_OrigGFP.median = median(b.Intensity_MeanIntensity_OrigGFP), EstCytoIntensity.median = median(EstCytoIntensity), TotalIntensity.median = median(TotalIntensity), NucToCytoRatio.median = median(NucToCytoRatio) ) Best, Ista On Fri, Aug 27, 2010 at 5:28 PM, Johnny Tkach johnny.tk...@utoronto.cawrote: Hi all, Since I could not attach a file to my original e-mail request, for those who want to look at an example of a data file I am working with, please use this link: http://dl.dropbox.com/u/4637975/exampledata.csv Thanks again, Johnny. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org [[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] Three-dimensional contingency table
Hi, Your example works fine for me. My guess is that you have one of wd, wv, MP, or Count defined as a global variable. This is the main reason the use of attach() is discouraged by many people on this list. The safer thing to do is model1 - glm(Count~MP+wd+wv,poisson. data = frame) -Ista On Sat, Aug 28, 2010 at 10:58 PM, Randklev, Charles charlesrandk...@my.unt.edu wrote: Hi, I am trying to assemble a three-way contingency table examining the presence/absence of mussels, water depth (Depth1 and Depth 2) and water velocity (Flow vs. No Flow). I have written the following code listed below; however, when run the glm I get the following message, Error in model.frame.default(formula = Count ~ MP + wd + wv, drop.unused.levels = TRUE) : variable lengths differ (found for 'MP'). This may be something simple, if so I apologize. Any help would be greatly appreciated. Best, C.R. numbers - c(1134,956,328,529,435,599,27,99) dim(numbers) - c(2,2,2) numbers dimnames(numbers)[[3]] -list(Mussels, No Mussels) dimnames(numbers)[[2]] - list(Flow, No Flow) dimnames(numbers)[[1]] - list(Depth1, Depth2) ftable(numbers) as.data.frame.table(numbers) frame - as.data.frame.table(numbers) names(frame) - c(wd, wv, MP, Count) frame attach(frame) model1 - glm(Count~MP+wd+wv,poisson) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot sub- and superscript for axis name
Hi Ben, Since you already know LaTeX, I would go with what you know. Try p-p + scale_x_continuous(name='$\\gamma_{fi}$') library(tikzDevice) ## may too to install first tikz(file=foo.tex, standAlone=TRUE) print(p) dev.off() system(pdflatex foo.tex) Best, Ista On Tue, Aug 31, 2010 at 1:29 PM, Benoit Boulinguiez benoit.boulingu...@ensc-rennes.fr wrote: Hi all, For publication purpose, I require to label ggplot figures axes with sub- or superscript text. I tried several ways, but never worked so far, to mix character string, sub- or superscripting on it and even worse, mathematical symbols. Let say I want to write the LateX equivalent of \gamma_{fi} in a ggplot element name, how can I do that? #dumb example foo-data.frame(a=seq(1:100),b=rnorm(100,1,1)) p-ggplot(data=foo,aes(x=a,y=b)) p-p + geom_point() p-p + scale_x_continuous(name='gamma[fi]') print(p) Regards Ben __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] date
Hi Dunia, You need to convert the character strings to Dates. time1 - as.Date(c(21/04/2005,23/05/2005,11/04/2005), %d/%m/%Y) time2 - as.Date(c(15/07/2009, 03/06/2008, 15/10/2005), %d/%m/%Y) time2-time1 Best, Ista On Thu, Sep 2, 2010 at 10:32 AM, Dunia Scheid dunia.sch...@gmail.com wrote: Hello all, I've 2 strings that representing the start and end values of a date and time. For example, time1 - c(21/04/2005,23/05/2005,11/04/2005) time2 - c(15/07/2009, 03/06/2008, 15/10/2005) as.difftime(time1,time2) Time differences in secs [1] NA NA NA attr(,tzone) [1] How can i calculate the difference between this 2 string? Regards, Dunia [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Levels in returned data.frame after subset
Hi Ulrik On Sat, Sep 4, 2010 at 12:52 PM, Ulrik Stervbo ulrik.ster...@gmail.com wrote: Dear List, When I subset a data.frame, the levels are not re-adjusted (see example). Why is this? Am I missing out on some basic stuff here? Only that this issue has come up many times before, and that this list is archived and searchable. Try RSiteSearch(subset drop levels, restrict = c(Rhelp10, Rhelp08, Rhelp02)) -Ista Thanks Ulrik m - data.frame(gender = c(M, M,F), ht = c(172, 186.5, 165), wt = c(91,99, 74)) dim(m) [1] 3 3 levels(m$gender) [1] F M s - subset(m, m$gender == M) dim(s) [1] 2 3 levels(s$gender) [1] F M cat - sapply(s, is.factor); s[cat] - lapply(s[cat], factor) dim(s) [1] 2 3 levels(s$gender) [1] M __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] tail.matrix returns matrix, while tail.mts return vector
Hi Mat, You might be able to use the matrix method to get what you want. head.matrix(EuStockMarkets) -Ista On Sat, Sep 4, 2010 at 1:15 PM, mat matthieu.stig...@gmail.com wrote: Hi I have a few problems with tail/head when applied to multiple time series. I'm not sure as whether I did not understand the function or whether it correspond to an unexpected behavior. When head(a,n) is applied on data.frame or matrix, it returns a data-frame or matrix with first n obs of *each* variable. When applied to a mts object, it returns first n obs of *first* variable only, not of all... The same for tail(). See: head(freeny) ###mts object head(EuStockMarkets) #is equivalent to: head(EuStockMarkets[,1]) I guess it comes from absence of a head method for mts. Does it seem reasonable to have also a head.mts or did I misunderstand something? 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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] converting string vector to integer/numeric vector
See ?numeric ?integer and possible the colClasses argument of read.table -Ista On Sun, Sep 5, 2010 at 12:48 PM, rajesh j akshay.raj...@gmail.com wrote: Hi, Is it possible to convert a string vector to integer or numeric vector? In my situation I receive data in a string vector and have to convert it based on a given type. -- Rajesh.J [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Percentile rank for each element in list
Hi, I think you want ecdf(), but read the help page because it works a little different than you might expect. ecdf.x - ecdf(x) ecdf.x(x) Best, Ista On Tue, Sep 7, 2010 at 8:37 AM, mic mikezia...@gmail.com wrote: Hlp Given this data x - c(1,5,100,300,250,200,550,900,1000) quantile(x) 0% 25% 50% 75% 100% 1 100 250 550 1000 When I run the quantile, I can only know the value of the nth percentile I want to know what's the percentile position of each items in the list Sample 1 = 100% on the list has 1 or more 5 = more than x% on the list has 5 or more 100 = more than x% on the list has 100 or more 250 = more than 50% on the list has 250 or more etc Thanks in advance __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Help with decimal points
Hi Amit, MatchedValues$Value is a factor. Converting factors to numeric is a FAQ: see http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-convert-factors-to-numeric_003f Best, Ista On Tue, Sep 7, 2010 at 4:38 PM, Amit Patel amitrh...@yahoo.co.uk wrote: Hi I have found a little problem with an R script. I am trying to merge some data and am finding something unusual going on. As shown below I am trying to assign (MatchedValues[Value2,Value]) to (ClusteredData[k,Value]) which are two separate dataframes. 1) By the following command you can see that the value im transferring is 481844.03 MatchedValues[Value2,Value] [1] 481844.03 6618 Levels: 1.00E+07 1.01E+07 1.02E+07 1.04E+07 1.05E+07 1.06E+07 ... Raw 2) But when I try to replace the values using the command i get a value of 4420 ClusteredData[k,Value] - MatchedValues[Value2,Value] ClusteredData[k,Value] [1] 4420 3) So what am I not doing. How can I keep that same value of 481844.03 I have tried as.double(MatchedValues[Value2,Value]) [1] 4420 as.numeric(MatchedValues[Value2,Value]) [1] 4420 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Emacs function argument hints
Hi Tim, This works out of the box for me, with ESS 5.11 and Emacs 23.1 -Ista On Thu, Sep 9, 2010 at 4:07 AM, Tim Elwell-Sutton tesut...@hku.hk wrote: Hi I've recently started using Emacs as my text editor for writing R script. I am looking for a feature which I have seen on the standard R text editor for Mac OS. In the Mac OS editor when you start typing a function, the possible arguments for that function appear at the bottom of the window. E.g. if you type table( before you finish typing you can see at the bottom of the window: table(..., exclude = if (useNA == no) c(NA, NaN), useNA = c(no, ifany, always), dnn = list.names(...), deparse.level = 1) I think this feature may be called function argument hints but I'm not sure and searching the archive with that term has not produced anything useful. Is this feature available in Emacs or any other windows text editor for R? Thanks very much Tim (Using Windows XP, R 2.11.1, GNU Emacs 23.2.1) [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Data.frames : difference between x$a and x[, a] ? - How set new values on x$a with a as variable ?
Hi, On Fri, Sep 10, 2010 at 4:05 AM, omerle ome...@laposte.net wrote: Hi, I got two questions : 1st Question a=S b=data.frame(S=3) do.call(`-`,list(do.call(`$`,list(b,S)),5)) I think there is some confusion here. Why are you setting a equal to S but then never using it? = How can I put new values on S column having the column name as a variable ? I'm having trouble parsing this. What exactly do you want to do? 2 nd Question a=S b=data.frame(S=3) b[,S]=list(1:10) #Doesnt works b$S=list(1:10) #Works = Isnt the same thing ? What is the difference between these two things ? I believe b[[S]] is the same as b$S, b[,S] is different. But I have to question your assertion that b$S=list(1:10) Works. This is a very odd construction (putting a list as an element of a data.frame) and is almost certainly not what you want. Thanks, Une messagerie gratuite, garantie à vie et des services en plus, ça vous tente ? Je crée ma boîte mail www.laposte.net [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Data.frames : difference between x$a and x[, a] ? - How set new values on x$a with a as variable ?
On Fri, Sep 10, 2010 at 9:22 AM, omerle ome...@laposte.net wrote: Message du 10/09/10 14:53 De : Ista Zahn A : omerle Copie à : r-help@r-project.org Objet : Re: [R] Data.frames : difference between x$a and x[, a] ? - How set new values on x$a with a as variable ? Hi, On Fri, Sep 10, 2010 at 4:05 AM, omerle wrote: Hi, I got two questions : 1st Question a=S b=data.frame(S=3) do.call(`-`,list(do.call(`$`,list(b,S)),5)) I think there is some confusion here. Why are you setting a equal to S but then never using it? = How can I put new values on S column having the column name as a variable ? I'm having trouble parsing this. What exactly do you want to do? 1 - Put a list as an element of a data.frame. That's quite convenient for my pricing function. I think this is a really bad idea. data.frames are not meant to be used in this way. Why not use a list of lists? 2 nd Question a=S b=data.frame(S=3) b[,S]=list(1:10) #Doesnt works b$S=list(1:10) #Works = Isnt the same thing ? What is the difference between these two things ? I believe b[[S]] is the same as b$S, b[,S] is different. But I have to question your assertion that b$S=list(1:10) Works. This is a very odd construction (putting a list as an element of a data.frame) and is almost certainly not what you want. 2 - That's what I want. I figured out just five minutes ago that b[[S]] works because it's the same thing as b$S. But I still dont know what is b[,S] compared to b[[S]] see ?[ Thanks, Une messagerie gratuite, garantie à vie et des services en plus, ça vous tente ? Je crée ma boîte mail www.laposte.net [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org Une messagerie gratuite, garantie à vie et des services en plus, ça vous tente ? Je crée ma boîte mail www.laposte.net [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot bar geom: control the filling in the colour legend
Sure, just change the color of the fill. ggplot(diamonds, aes(clarity, colour = cut)) + geom_bar(fill=white) -Ista On Fri, Sep 10, 2010 at 2:24 PM, Benoit Boulinguiez benoit.boulingu...@ensc-rennes.fr wrote: Hi all, Is it possible to change the filling of the squares used to represent the colour legend in a bar plot with ggplot? in this example, fillings are raven black, I'd like them white. ggplot(diamonds, aes(clarity, colour = cut)) + geom_bar() Regards -- - Benoit Boulinguiez Ph.D student Ecole de Chimie de Rennes (ENSCR) Bureau 1.20 Equipe CIP UMR CNRS 6226 Sciences Chimiques de Rennes Avenue du Général Leclerc CS 50837 35708 Rennes CEDEX 7 Tel 33 (0)2 23 23 80 83 Fax 33 (0)2 23 23 81 20 http://www.ensc-rennes.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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Where to find R-help options web page
Dear Prof. Harrell, You can manager your subscription settings here: https://stat.ethz.ch/mailman/listinfo/r-help (the link is included in the footer of each message on the list as well). Best, Ista On Fri, Sep 10, 2010 at 5:46 PM, Frank Harrell f.harr...@vanderbilt.edu wrote: Dear Group: I must be missing something obvious but I can't find from www.r-project.org a link to a page for managing my r-help subscription. Due to getting a new smart phone I'm changing to nabble to manage r-help traffic. I need to turn off receiving mail directly to my e-mail address. Nabble sent a link to turn off e-mail but the r-help mail service rejected nabble's command. Thanks Frank - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/Where-to-find-R-help-options-web-page-tp2535123p2535123.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] grouping dataframe entries using a categorical variable
Hi Bastien, You can use match(), or the convenience function %in%, like this (assuming your data.frame is named dat): subset(dat, ESS %in% c(EPB,SAB)) dat[dat$ESS %in% c(EPB,SAB), ] best, Ista On Fri, Sep 17, 2010 at 1:02 PM, Bastien Ferland-Raymond bastien.ferland-raymon...@ulaval.ca wrote: DearR Users, I have a problem which I think you might be able to help. I have a dataframe which I'm trying to filter following different groups I specified. It's a little hard to explain, so here is an example: My dataframe: ESS DHP 1 EPB 22 2 SAB 10 3 SAB 20 4 BOJ 14 5 ERS 28 11 SAB 10 12 SAB 22 13 BOJ 26 20 SAB 10 21 SAB 22 22 BOJ 32 29 SAB 14 30 SAB 22 38 SAB 14 47 SAB 18 I'm trying to filter it by selecting a subgroup of ESS, for example: softwood- c(EPB,SAB) So I can obtain: NEW dataframe: ESS DHP 1 EPB 22 2 SAB 10 3 SAB 20 11 SAB 10 12 SAB 22 20 SAB 10 21 SAB 22 29 SAB 14 30 SAB 22 38 SAB 14 47 SAB 18 (my real groups are actually bigger and so are my dataframe but you get the idea). I have looked at subset and aggregate but it doesn't work and the loop would be totally inefficient. I'm sure there is a function in R that does something like that but I couldn't find the proper keyword to search for it. Thanks for your help, Bastien __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to seperate ? or how to do regression on each variable when I have multiple variables?
Hi Soyeon, Here are a few options: ## Use get() to find the predictor r - rep(0, 13) for(i in 1: 13) { r[i] - summary(lm(MEDV ~ get(name[i]), data = boston))$r.squared } ## Use as.formula(paste()) to construction the model for(i in 1: 13) { r[i] - summary(lm(as.formula(paste(MEDV ~ , name[i], sep=)), data = boston))$r.squared } ## Just square the correlations (this is how I would do it) r - cor(boston)[MEDV,]^2 Best, Ista On Mon, Sep 20, 2010 at 1:03 PM, Soyeon Kim yunni0...@gmail.com wrote: Dear All, I have data which contains 14 variables. And I have to regress one of variables on each variable (simple 13 linear regressions) I try to make a loop and store only R-squared colnames(boston) [1] CRIM ZN INDUS CHAS NOX RM AGE [8] DIS RAD TAX PTRATIO B LSTAT MEDV name - colnames(boston) r - rep(0, 13) for(i in 1: 13) { r[i] - summary(lm(MEDV ~ name[i], data = boston))$r.squared } but this doesn't work because name have for each variable. How to remove for name of each variable? Or do you know the way I can do regression MEDV on each variable? Thank you ahead, Soyeon __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] speeding up regressions using ddply
Hi Alison, On Wed, Sep 22, 2010 at 11:05 AM, Alison Macalady a...@kmhome.org wrote: Hi, I have a data set that I'd like to run logistic regressions on, using ddply to speed up the computation of many models with different combinations of variables. In my experience ddply is not particularly fast. I use it a lot because it is flexible and has easy to understand syntax, not for it's speed. I would like to run regressions on every unique two-variable combination in a portion of my data set, but I can't quite figure out how to do using ddply. I'm not sure ddply is the tool for this job. The data set looks like this, with status as the binary dependent variable and V1:V8 as potential independent variables in the logistic regression: m - matrix(rnorm(288), nrow = 36) colnames(m) - paste('V', 1:8, sep = '') x - data.frame( status = factor(rep(rep(c('D','L'), each = 6), 3)), as.data.frame(m)) You can use combn to determine the combinations you want: Varcombos - combn(names(x)[-1], 2) From there you can do a loop, something like results - list() for(i in 1:dim(Varcombos)[2]) { log.glm - glm(as.formula(paste(status ~ , Varcombos[1,i], + , Varcombos[2,i], sep=)), family=binomial(link=logit), na.action=na.omit, data=x) glm.summary-summary(log.glm) aic - extractAIC(log.glm) coef - coef(glm.summary) results[[i]] - list(Est1=coef[1,2], Est2=coef[3,2], AIC=aic[2]) #or whatever other output here names(results)[i] - paste(Varcombos[1,i], Varcombos[2,i], sep=_) } I'm sure you could replace the loop with something more elegant, but I'm not really sure how to go about it. I used melt to put my data frame into a more workable format require(reshape) xm - melt(x, id = 'status') Here is the basic shape of the function I'd like to apply to every combination of variables in the dataset: h- function(df) { attach(df) log.glm - (glm(status ~ value1+ value2 , family=binomial(link=logit), na.action=na.omit)) #What I can't figure out is how to specify 2 different variables (I've put value1 and value2 as placeholders) from the xm to include in the model glm.summary-summary(log.glm) aic - extractAIC(log.glm) coef - coef(glm.summary) list(Est1=coef[1,2], Est2=coef[3,2], AIC=aic[2]) #or whatever other output here } And then I'd like to use ddply to speed up the computations. require(pplyr) output-dddply(xm, .(variable), as.data.frame.function(h)) output I can easily do this using ddply when I only want to use 1 variable in the model, but can't figure out how to do it with two variables. I don't think this approach can work. You are saying split up xm by variable and then expecting to be able to reference different levels of variable within each split, an impossible request. Hope this helps, Ista Many thanks for any hints! Ali Alison Macalady Ph.D. Candidate University of Arizona School of Geography and Development Laboratory of Tree Ring Research __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Unique subsetting question
Hi Andrew, You can use duplicated() to index the rows you wish to keep, like this: test.dat - data.frame(a=c(1,1:5,5:10), b=1:12, c=letters[1:12]) #make up data duplicated(test.dat$a) # see what duplicated() function does !duplicated(test.dat$a) # see how we can invert using the ! function so that we get non-duplicated test.dat[!duplicated(test.dat$a),] # this is the important bit: use indexing to select non-duplicated rows. Best, Ista On Wed, Sep 22, 2010 at 12:35 PM, AndrewPage savejar...@yahoo.com wrote: I understand how duplicated and unique work for a list where all parts of a given row are duplicated, or how to find duplicated values if I'm just looking at that first column, but in this case the rows for 1954 and 1955 are not completely the same; only quarter 1 is duplicated, so I'm not sure how to apply either duplicated or unique in that case. Thanks, Andrew -- View this message in context: http://r.789695.n4.nabble.com/Unique-subsetting-question-tp2550453p2550651.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Unique subsetting question
Hi Andrew, Perhaps you did not notice my previous email. The answer is still the same (see below): On Wed, Sep 22, 2010 at 1:48 PM, AndrewPage savejar...@yahoo.com wrote: How about this: s = c(aa, bb, cc, , aa, dd, , aa) n = c(2, 3, 5, 6, 7, 8, 9, 3) b = c(TRUE, FALSE, TRUE, TRUE, FALSE, TRUE, TRUE, FALSE) df = data.frame(n, s, b) # df is a data frame I want to display df with no value in s occurring more than once. df - df[!duplicated(df$s),] Also, I want to delete the rows where s contains . Same idea here: df[s != ,] -Ista -- View this message in context: http://r.789695.n4.nabble.com/Unique-subsetting-question-tp2550453p2550769.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Unique subsetting question
I already gave you three examples of how this works. Your last request can be done in exactly the same way. Give it a try and see what happens (use example data of course!). As a last resort you could read the documentation: ?Comparison ?Extract -Ista On Wed, Sep 22, 2010 at 2:22 PM, AndrewPage savejar...@yahoo.com wrote: Thanks-- that works for what I'm trying to do. I was also wondering, in the data frame example you gave, if I just wanted to get rid of rows where the a value is 5, how would I do that? -- View this message in context: http://r.789695.n4.nabble.com/Unique-subsetting-question-tp2550453p2550836.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] formatting data for predict()
Hi Andrew, My inclination would be to put all the variables in a data.frame instead of putting the predictors in a matrix. But if you want to continue down this road, you need to have a column named dat in a the data.frame that contains a matrix. I couldn't figure out how to do such a thing in a single call, so I had to create it in a separate step: newdat - data.frame(y=rep(NA, length(unique(x1 newdat$dat - cbind(unique(x1), x2=0) p2a=predict(mod2, type=response, newdata=newdat) p2a Hope it helps, Ista On Sun, Sep 26, 2010 at 4:38 AM, Andrew Miles rstuff.mi...@gmail.com wrote: I'm trying to get predicted probabilities out of a regression model, but am having trouble with the newdata option in the predict() function. Suppose I have a model with two independent variables, like this: y=rbinom(100, 1, .3) x1=rbinom(100, 1, .5) x2=rnorm(100, 3, 2) mod=glm(y ~ x1 + x2, family=binomial) I can then get the predicted probabilities for the two values of x1, holding x2 constant at 0 like this: p2=predict(mod, type=response, newdata=as.data.frame(cbind(x1, x2=0))) unique(p2) However, I am running regressions as part of a function I wrote, which feeds in the independent variables to the regression in matrix form, like this: dat=cbind(x1, x2) mod2=glm(y ~ dat, family=binomial) The results are the same as in mod. Yet I cannot figure out how to input information into the newdata option of predict() in order to generate the same predicted probabilities as above. The same code as above does not work: p2a=predict(mod2, type=response, newdata=as.data.frame(cbind(x1, x2=0))) unique(p2a) Nor does creating a data frame that has the names datx1 and datx2, which is how the variables appear if you run a summary() on mod2. Looking at the model matrix of mod2 shows that the fitted model only shows two variables, the dependent variable y and one independent variable called dat. It is as if my two variables x1 and x2 have become two levels in a factor variable called dat. names(mod2$model) My question is this: if I have a fitted model like mod2, how do I use the newdata option in the predict function so that I can get the predicted values I am after? I.E. how do I recreate a data frame with one variable called dat that contains two levels which represent my (modified) variables x1 and x2? Thanks in advance! Andrew Miles Department of Sociology Duke 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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] compare a vector and a row of a matrix
Hi, You can use all.equal, like this: all.equal(c(1,1), mtrx[1,], check.attributes=FALSE) If you want to check each row of the matrix (I wasn't clear if you wanted this) you can do something like check.equal - function(x, y) { isTRUE(all.equal(y, x, check.attributes=FALSE)) } apply(mtrx, 1, check.equal, y=c(1,1)) HTH, Ista On Sun, Sep 26, 2010 at 3:25 PM, xinxin xx xxgr...@hotmail.com wrote: From: xxgr...@hotmail.com To: r-help-boun...@r-project.org Subject: compare a vector and a row of a matrix Date: Sun, 26 Sep 2010 23:23:52 +0800 Hi Everyone: I am trying to compare a vector and rows of a matrix for example xn - c(1,2,4,4,5,5,5,6) yn - c(1,2,5,7,1,2,3,1) mtrx - cbind(xn, yn) when I tried, say, c (1,4), the result was TRUE, TRUE. I think the reason is that 1 is compared to xn and 4 is compared to yn seperately. Could anyone tell me how I can get a single result of the comparson between a vector and a row of the matrix? for example, c(1,1) is one row of the matrix but c(1,4) is not. I tried to write a loop but it seems long for this simple problem Thank you very much!!! [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Newbie Correspondence Analysis Question
Hi Vik, You need to load the CA package first: library(CA) -Ista On Sun, Sep 26, 2010 at 4:41 PM, Vik Rubenfeld v...@mindspring.com wrote: I'm experienced in statistics, but I am a first-time R user. I would like to use R for correspondence analysis. I have installed R (Mac OSX). I have used the package installer to install the CA package. I have run the following line with no errors to read in the data for a table: NonLuxury - read.table(/Users/myUserName/Desktop/nonLuxury.data.txt) The R online help appears to suggest that the following line should come next: corresp(NonLuxury) However, I get the error message: Error: could not find function corresp The CA manual appears to suggest that the following line should come next: ca(NonLuxury) Again, I get the error message: Error: could not find function ca What am I missing? Thanks very much in advance to all for any info. -Vik __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Storing CA Results to a Data Frame?
Hi Vik, I suggest reading through some of the introductory documentation. R has several classes of objects, including matrix, list, data.frame etc. and a basic understanding of what these are is essential for effectively using R. An essential function is str() which shows you the structure of an object. Other essential functions include names(), help(), help.search(), and methods() An example session that is similar to your case: library(ca) # load the ca package data(author) # load the authors dataset str(author) # examine the authors data auth.ca - ca(author) # run the ca function on the authors data str(auth.ca) # examin the structure of the auth.ca results. Note that it is a list with class of ca methods(class=class(auth.ca)) # see what methods are defined for this type of object ?plot.ca ## look up the documentation for the plot method for objects of class ca plot(auth.ca) ## call the plot method auth.ca.sum - summary(auth.ca) ## call the summary method str(auth.ca.sum) # examine the structure of the auth.ca.sum object methods(class=class(auth.ca.sum)) ## find out what methods are defined for it ## Hmmn ok, so suppose I want to extract the rows and columns data.frames from auth.ca.sum but don't know how help.search(extract) ## first result is base::Extract ?Extract ## look up documentation for extract auth.ca.rows - auth.ca.sum[[rows]] ## extract the rows data.frame auth.ca.rows - auth.ca.sum[[columns]] ## extract the columns data.frame write.csv(auth.ca.rows) ## write results to a .csv file write.csv(auth.ca.rows) ## HTH, Ista On Sun, Sep 26, 2010 at 6:10 PM, Vik Rubenfeld v...@mindspring.com wrote:, I am successfully performing a correspondence analysis using the commands: NonLuxury - read.table(/Users/myUserName/Desktop/nonLuxury.data.txt) ca(NonLuxury) I would like to store the results to a data frame so that I can write them to disk using write.table. I have tried several things such as: df - data.frame(ca(NonLuxury)) df - data.frame(data(ca(NonLuxury))) etc. ...but clearly this is incorrect as it generates an error message. Is it possible to store the results of a CA to a dataframe, and if so, what is the correct way to do this? Thanks in advance to all for any info. -Vik __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] name ONLY one column
Hi Lorenzo, The problem is that my_matrix does not have dimnames. See below. my_matrix - matrix (1:12,ncol=3) str(my_matrix) ## does not have dimnames dimnames(my_matrix) ## dimnames is NULL colnames(my_matrix) - myname # fails because you are trying to alter the value of something that does not exist ## solution: Set colnames colnames(my_matrix) - 1:dim(my_matrix)[2] str(my_matrix) # my_matrix now has colnames colnames(my_matrix)[1] - myname # and now we can alter them On Mon, Sep 27, 2010 at 8:26 AM, Lorenzo Cattarino l.cattar...@uq.edu.au wrote: Hi R-users I can not change the name of one column only of my matrix. my_matrix - matrix (1:12,ncol=3) colnames(my_matrix)[1] - 'myname' Error in dimnames(x) - dn : length of 'dimnames' [2] not equal to array extent thank you for your help Lorenzo [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] stacked area chart
) # the order of variables on the chart - bottom up ### so, the bottom-most area should be for z, and the second from the bottom area- for y (above z) - they'll be below zero ### and above zero we'll have a first and x second (on top of a). Thanks a lot for your advice! -- Dimitri Liakhovitski Ninah Consulting www.ninah.com -- Dimitri Liakhovitski Ninah Consulting www.ninah.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Standard error of forecast
Hi, predict(model_fit, se.fit=TRUE) see ?predict.lm for details. -Ista On Tue, Sep 28, 2010 at 12:16 PM, Brima adamsteve2...@yahoo.com wrote: Hi all, This is very basic but for a starter nothing is. I have a simple linear regression I am using to predict some values and I need the standard error of the prediction (forecast). Whats the easiest/bestway of getting this error? Best regards -- View this message in context: http://r.789695.n4.nabble.com/Standard-error-of-forecast-tp2717125p2717125.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] String split and concatenation
Hi Steven, This should do it: paste('', unlist(strsplit(x, split=)), c(rep(',', length(x)-1), ), sep=) -Ista On Wed, Sep 29, 2010 at 1:11 AM, Steven Kang stochastick...@gmail.com wrote: Hi R users, I desire to transform the following vector consisting of repeated characters x - rep(letters, 3) into this exact format (i.e a single string containing each characters in quotation mark separated by comma between each; al ). (a, b, c, d, a, b, c, d, ..., a, b, c, d, .z) Any advice would be much appreciated. -- Steven [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Understanding linear contrasts in Anova using R
,] 3.162278e-01 -0.2672612 -6.324555e-01 -0.4780914 #[5,] 6.324555e-01 0.5345225 3.162278e-01 0.1195229 #So, when I use polynomials (either through contr.poly or by supplying a matrix of #coefficients, what do the estimates represent? I hope my examples have clarified this. They represent the increase in y for a one-unit increase in X. What that one-unit increase represents is of course a function of the contrast codes used. # My problem is not restricted to polynomials. If I try a set of orthogonal linear contrasts # on group means I get #contrasts(group) - cbind(c(1,1,0,-1,-1), c(1,-1,0,0,0), c(-0,0,0,1,-1), c(1,1,4,-1,1)) # These are not orthogonal: cor(contrasts(group)) ## fixing that gives us contrasts(group) - cbind(c(1,1,0,-1,-1), c(1,-1,0,0,0), c(-0,0,0,1,-1), c(1,1,-4,1,1)) model3 - lm(dv ~ group) summary(model3) ## These coefficients are functions of the specified contrasts: coefs.by.hand.m3 - c(mean(Means), (mean(Means[1:2]) - mean(Means[4:5]))/2, (Means[1] - Means[2])/2, (Means[4] - Means[5])/2, (mean(Means[c(1,2,4,5)]) - Means[3])/5) ## Note that we divide each mean difference by the difference of the contrasts (coef.check.m3 - rbind(coef(model3), coefs.by.hand.m3)) Hope it helps, Ista #model3 - lm(dv ~ group) #summary(model3) #Coefficients: # Estimate Std. Error t value Pr(|t|) #(Intercept) 1.5335 0.2558 5.995 1.64e-07 *** #group1 0.3168 0.2279 1.390 0.170185 #group2 0.5638 0.3071 1.836 0.071772 . #group3 -1.2840 0.3369 -3.811 0.000352 *** #group4 -0.6115 0.1387 -4.408 4.88e-05 *** #These are not even close to what I would expect. By hand I would compute the contrasts as # .0442, 1.1275, 1.3450, and 8.5608 with different t values. # Any help would be appreciated. Thanks, Dave Howell __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] gridExtra question
Is there some reason you don't want the CRAN version? -Ista On Fri, Oct 1, 2010 at 3:08 PM, Felipe Carrillo mazatlanmex...@yahoo.comwrote: Hi: I get a couple of warnings when trying to download gridExtra: install.packages(gridExtra,repos=http://R-Forge.R-project.org) Warning: unable to access index for repository http://R-Forge.R-project.org/bin/windows/contrib/2.10 Warning message: In getDependencies(pkgs, dependencies, available, lib) : package gridextra is not available I would like to download the binary for windows Felipe D. Carrillo Supervisory Fishery Biologist Department of the Interior US Fish Wildlife Service California, USA __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org [[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] reshape not using as id vars what it is supposed to be using?
Hi Dimitri, The argument names may have changed. Notice that melt.data.frame(smiths, measured = c(age, weight, height)) gives a message saying Using subject as id variables. This is because measured variables need to be specified as measure.vars (or an abbreviation of that: even m will work because no other arguments start with m). args(melt.data.frame) function (data, id.vars, measure.vars, variable_name = variable, na.rm = !preserve.na, preserve.na = TRUE, ...) Bottom line: you need something like melt.data.frame(smiths, measure.vars = c(age, weight, height)) Best, Ista On Tue, Oct 5, 2010 at 11:36 AM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Hellow! I am replicating the example givien in Reshaping Data with the reshape Package (http://www.jstatsoft.org/v21/i12 - see download link on the right), p. 2-3. library(reshape) data(smiths) str(smiths) The text says: If you specify only one of measured and identifier variables, melt assumes that all the other variables are the OTHER sort: Hence, the result of the following 5 lines should be identical: melt.data.frame(smiths, id = c(subject, time), measured = c(age, weight,height)) melt.data.frame(smiths, id = c(subject, time)) melt.data.frame(smiths, id = 1:2) melt.data.frame(smiths, measured = c(age, weight, height)) melt.data.frame(smiths) # If you do not specify them explicitly, melt will assume that any factor or character variables are id variables However, only the first 3 lines produce the same result. I am especially surprised why line 4 uses time as a measured variable, while it should be clear to reshape that time is NOT a measured variable? Thank you! -- Dimitri Liakhovitski Ninah Consulting www.ninah.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] ggplot2 barplot in decreasing frequency
Hi Morten Just order the factor the way you want before plotting: df$v2 - factor(df$v2, levels=c(bb, cc, aa)) p = ggplot(df) p + aes(v2) + geom_bar() Best, Ista On Wed, Oct 6, 2010 at 5:09 AM, Morten morten.lindb...@siv.no wrote: Hi all, I have a large data frame and would like to make a barplot of a categorical variable with the bars sorted in order of decreasing frequency. # Example: v1 = c(1.2, 1.4, 0.9, 1.0, 1.1, 1.0) v2 = c(aa, cc, bb, bb, cc, bb) v3 = c(8, 10, 11, 9, 9, 10) df = data.frame(v1=v1, v2=v2, v3=v3) # How can I tell ggplot to sort the bars? # First bar = bb (3), second bar cc (2) and third bar aa (1) p = gplot(df) p + aes(v2) + geom_bar() Thank you, Morten -- View this message in context: http://r.789695.n4.nabble.com/ggplot2-barplot-in-decreasing-frequency-tp2964511p2964511.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] X11 is not available
HI, It's not clear to me exactly what you did. On Thu, Oct 7, 2010 at 7:49 AM, ogbos okike ogbos.ok...@gmail.com wrote: Dear All, I have just installed a new version of R (Version R-2.11.0) and did install other packages such as raster with ease. However, I could not start the plotting device x11(). I remembered that somewhere at the stage of installation, an error occurred : 'configure: error: --with-x=yes (default) and X11 headers/libs are not available' This makes it sound like you compiled R from source yourself, I tried avoiding this error by using ./configure --with-x=no (i.e. changing the yes to know). Well, the error disappeared but after the installation, I could not start x11(). without X11 support. I have tried to install alien and attempted to use it to install java1.4.rpm Why? Most linux distributions (you never say which one you are using. We need this information in order to help you.) have a standard way to install java... I have also installed r-base-dev , build-dep r-base and libX11-dev But the problem remains. This sounds like you installed R using your package manager. So which is it? -Ista I will glad if somebody can bail me out. Best Ogbos ** [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] venneuler() - customize a few things.
Hi Kari, On Thu, Oct 7, 2010 at 12:05 PM, Karl Brand k.br...@erasmusmc.nl wrote: Esteemed UseRs and DevelopeRs, Just coming to terms with the very attractive proportional venn gernator, venneuler(), but would like to customize a few things. Is it possible to- Say v is a VennDiagram: -suppress all circle labels? v$labels - rep(, length(v$labels) -suppress only certain circle labels? v$labels - c(A, , C) ## don't print label for B -print specific text strings at specified locations within the circles? and unions? text(.5, .5, my text here) will print my text here right in the middle of the graph. Adjusting the coordinates will adjust the location. You can use v$centers and v$diameters to position text relative to the center of the circles, but I'm not sure how to automatically find the unions. You could do it by trial and error. -specify circle colors? v$colors - c(.1, .5, .9) -specify label font, size color? see ?text Best, Ista All thoughts and response's greatly appreciated, cheers, Karl -- Karl Brand k.br...@erasmusmc.nl Department of Genetics Erasmus MC Dr Molewaterplein 50 3015 GE Rotterdam P +31 (0)10 704 3409 | F +31 (0)10 704 4743 | M +31 (0)642 777 268 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Is there a regression surface demo?
There is also wireframe() in lattice and bplot in rms. -Ista On Mon, Oct 11, 2010 at 3:49 PM, G. Jay Kerns gke...@ysu.edu wrote: Dear Josh, On Mon, Oct 11, 2010 at 3:15 PM, Joshua Wiley jwiley.ps...@gmail.com wrote: Hi All, Does anyone know of a function to plot a regression surface for two predictors? RSiteSearch()s and findFn()s have not turned up what I was looking for. I was thinking something along the lines of: http://mallit.fr.umn.edu/fr5218/reg_refresh/images/fig9.gif I like the rgl package because showing it from different angles is nice for demonstrations. I started to write my own, but it has some issues (non functioning code start below), and I figured before I tried to work out the kinks, I would ask for the list's feedback. Any comments or suggestions (about functions or preferred idioms for what I tried below, or...) are greatly appreciated. Josh [snip] I haven't tried to debug your code, but wanted to mention that the Rcmdr:::scatter3d function does 3-d scatterplots (with the rgl package) and adds a regression surface, one of 4 or 5 different types. If nothing else, it might be a good place to start for making your own. A person can play around with the different types in the Rcmdr under the Graphs menu. Or, from the command line: library(Rcmdr) with(rock, scatter3d(area, peri, shape)) I hope that this helps, Jay __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] LME with 2 factors with 3 levels each
Hi Laura, If you want ANOVA output, ask for it! A general strategy that almost always works in R is to fit 2 models, one without the term(s) you want to test, and one with. Then use the anova() function to test them. (models must be nested, and in the lmer() case you need to use REML = FALSE). So, try something like this: m1 - lmer(PTR ~ Test + Group + (1 | student), data=ptr) m2 - lmer(PTR ~ Test * Group + (1 | student), data=ptr) anova(m1, m2) Best, Ista On Tue, Oct 12, 2010 at 11:59 PM, Laura Halderman lk...@pitt.edu wrote: Hello. I am new to R and new to linear mixed effects modeling. I am trying to model some data which has two factors. Each factor has three levels rather than continuous data. Specifically, we measured speech at Test 1, Test 2 and Test 3. We also had three groups of subjects: RepTP, RepNTP and NoRepNTP. I am having a really hard time interpreting this data since all the examples I have seen in the book I am using (Baayen, 2008) either have continuous variables or factors with only two levels. What I find particularly confusing are the interaction terms in the output. The output doesn't present the full interaction (3 X 3) as I would expect with an ANOVA. Instead, it only presents an interaction term for one Test and one Group, presumably comparing it to the reference Test and reference Group. Therefore, it is hard to know what to do with the interactions that aren't significant. In the book, non-significant interactions are dropped from the model. However, in my model, I'm only ever seeing the 2 X 2 interactions, not the full 3 X 3 interaction, so it's not clear what I should do when only two levels of group and two levels of test interact but the third group doesn't. If anyone can assist me in interpreting the output, I would really appreciate it. I may be trying to interpret it too much like an ANOVA where you would be looking for main effects of Test (was there improvement from Test 1 to Test 2), main effects of Group (was one of the Groups better than the other) and the interactions of the two factors (did one Group improve more than another Group from Test 1 to Test 2, for example). I guess another question to pose here is, is it pointless to do an LME analysis with more than two levels of a factor? Is it too much like trying to do an ANOVA? Alternatively, it's possible that what I'm doing is acceptable, I'm just not able to interpret it correctly. I have provided output from my model to hopefully illustrate my question. I'm happy to provide additional information/output if someone is interested in helping me with this problem. Thank you, Laura Linear mixed model fit by REML Formula: PTR ~ Test * Group + (1 | student) Data: ptr AIC BIC logLik deviance REMLdev -625.7 -559.8 323.9 -706.5 -647.7 Random effects: Groups Name Variance Std.Dev. student (Intercept) 0.0010119 0.03181 Residual 0.0457782 0.21396 Number of obs: 2952, groups: studentID, 20 Fixed effects: Estimate Std. Error t value (Intercept) 0.547962 0.016476 33.26 Testtest2 -0.007263 0.015889 -0.46 Testtest1 -0.050653 0.016305 -3.11 GroupNoRepNTP 0.008065 0.022675 0.36 GroupRepNTP -0.018314 0.025483 -0.72 Testtest2:GroupNoRepNTP 0.006073 0.021936 0.28 Testtest1:GroupNoRepNTP 0.013901 0.022613 0.61 Testtest2:GroupRepNTP 0.046684 0.024995 1.87 Testtest1:GroupRepNTP 0.039994 0.025181 1.59 Note: The reference level for Test is Test3. The reference level for Group is RepTP. The interaction p value (after running pvals.fnc with the MCMC) for Testtest2:GroupRepNTP is p = .062 which I'm willing to accept and interpret since speech data with English Language Learners is particularly variable. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] R on a ma c
In my experience R runs just fine on the Mac. For basic use you don't need to do anything special whatsoever. Just install R as you would any other program. If you need to install packages from source you will probably want to install Xcode. Other Mac FAQs are at http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html -Ista On Thu, Oct 14, 2010 at 12:25 PM, Tiffany Kinder tiffany.kin...@aggiemail.usu.edu wrote: Hello, Is R very compatible with a Mac? A colleague of mine indicated that everyone he knows with a Mac has problems with R. What can you tell me about using R with a Mac. What do I need to download? I have downloaded the basic R package. Thanks, -- Tiffany Kinder MS Student Department of Watershed Science Utah State University tiffany.kin...@aggiemail.usu.edu [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Time vs Concentration Graphs by ID
Hi, Assuming the data is in a data.frame named D, something like library(ggplot2) # May need install.packages(ggplot2) first ggplot(D, aes(x=Time, y=Concentration, color=Dose) + geom_point() + geom_line(aes(y = PredictedConcentration, group=1)) + facet_wrap(~ID, scales=free, ncol=3) should do it. -Ista On Thu, Oct 14, 2010 at 10:25 PM, thaliagoo eataban...@gmail.com wrote: Hello-- I have a data for small population who took 1 drug at 3 different doses. I have the actual drug concentrations as well as predicted concentrations by my model. This is what I'm looking for: - Time vs Concentration by ID (individual plots), with each subject occupying 1 plot -- there is to be 9 plots per page (3x3) - Observed drug concentration is made up of points, and predicted drug concentration is a curve without points. Points and curve will be the same color for each dose. Different doses will have different colors. - A legend to specify which color correlates to which dose. - Axes should be different for each individual (as some individual will have much higher drug concentration than others) and I want to see in detail how well predicted data fits observed data. Any help would be greatly appreciated. -- View this message in context: http://r.789695.n4.nabble.com/Time-vs-Concentration-Graphs-by-ID-tp2996431p2996431.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Condition to factor (easy to remember)
An extremely verbose, but (in my view) easy to understand approach is: data.f - data; data.f[which(data = 10)] - levs[1]; data.f[which(data 10)] - levs[2]; data.f - factor(data.f) -Ista On Wed, Sep 30, 2009 at 8:31 AM, Dieter Menne dieter.me...@menne-biomed.de wrote: David Winsemius wrote: # Typical C-Programmer style factor(levs[as.integer(data 10)+1], levels=levs) In your code the as.integer function is superfluous Oops... done too much c# lately, getting invalid cast challenged. Dieter -- View this message in context: http://www.nabble.com/Condition-to-factor-%28easy-to-remember%29-tp25676411p25680111.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Rounding error in seq(...)
For my own edification more than anything (I never took computer science): is a = seq(0.1,0.9,by=0.1) a - as.character(a) a[3] == 0.3 [1] TRUE safe? -Ista On Wed, Sep 30, 2009 at 3:46 PM, cls59 ch...@sharpsteen.net wrote: Martin Batholdy wrote: hum, can you explain that a little more detailed? Perhaps I miss the background knowledge - but it seems just absurd to me. 0.1+0.1+0.1 is 0.3 - there is no rounding involved, is there? Unfortunately this comes as an utter shock to many people who never take a Computer Science course. I watch it nail engineering students all the time. Basically, if you have a fraction and the denominator is not equal to 2^n for some integer n, that fraction will NEVER be stored as an exact floating point number-- instead it will contain some error due to concessions that must be made in order to use an efficient binary number scheme. These errors are generally small, but they do propagate-- especially if you are carrying the same numbers through a large computation. A good example is large-scale numerical solutions to nonlinear problems where iterative algorithms are employed repetitively at each solution step. As the calculation progresses the roundoff error can rot away the computational soundness of the algorithm. If this concerns you, I would suggest reading up on common internal representations of floating point numbers as well as the propagation of roundoff error. At the very least I hope this revelation will instill an appropriate sense of paranoia concerning the numbers calculated by those magic boxes sitting on our desks. -Charlie - Charlie Sharpsteen Undergraduate Environmental Resources Engineering Humboldt State University -- View this message in context: http://www.nabble.com/Rounding-error-in-seq%28...%29-tp25686630p25687626.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Compress (gzip) a pdf device - [ ] Message is from an unknown sender
I guess I don't understand what your're trying to do. gzip-ing a file from within R is easy enough: pdf(file=CompressMe.pdf) plot(rnorm(100)) dev.off() system(gzip CompressMe.pdf) I think you want something more complicated, but I'm not sure what. -Ista On Thu, Oct 1, 2009 at 6:41 AM, Daniele Amberti daniele.ambe...@ors.it wrote: By now It seems nobody have idea. zz - gzfile(C:/gzpdftest.gz, wb) pdf(file = zz) plot(USArrests) dev.off() close(zz) produce a file named 3 without any extension in my working directory. Also I don't have any news on how to gzip the pdf afterward (without using an external executable). Daniele From: Rainer M Krug [mailto:r.m.k...@gmail.com] Sent: 30 September 2009 10:26 To: Daniele Amberti Cc: r-help@r-project.org Subject: Re: [R] Compress (gzip) a pdf device - [ ] Message is from an unknown sender 2009/9/30 Daniele Amberti daniele.ambe...@ors.itmailto:daniele.ambe...@ors.it I have not found an easy way to compress a file on filesystem. Especially I'd like to compress a pdf from pdf() function/device. Is it possible to compress It on the flight? I'd like to do something like: pdf(gzipconnection()) dev.off() I guess this boils down to a question I asked some time ago concerning getting the filename of a pdf() device, as I wanted to create a compressed pdf from the uncompressed pdf created by R (not zipping the pdf). It does not seem to be possible, at least I did not get any response which I could use to implement my idea (create my dev.off(), which calls dev.off() and afterwards compresses the pdf by using the file name). If you find a solution, please let me know. Cheers, Rainer If It is not possible, how can I create a gzip with the pdf? Thanks Daniele A. ORS Srl Via Agostino Morando 1/3 12060 Roddi (Cn) - Italy Tel. +39 0173 620211 Fax. +39 0173 620299 / +39 0173 433111 Web Site www.ors.it Qualsiasi utilizzo non autorizzato del presente messaggio e dei suoi allegati ? vietato e potrebbe costituire reato. Se lei avesse ricevuto erroneamente questo messaggio, Le saremmo grati se provvedesse alla distruzione dello stesso e degli eventuali allegati. Opinioni, conclusioni o altre informazioni riportate nella e-mail, che non siano relative alle attivit? e/o alla missione aziendale di O.R.S. Srl si intendono non attribuibili alla societ? stessa, n? la impegnano in alcun modo. [[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. -- Ista Zahn Graduate student University of Rochester http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to plot a Quadratic Model?
I hardly use base graphics so I'm no help there. You can do this easily with ggplot2 though: library(ggplot2) X - rnorm(100) Y - rnorm(100) - X^2 qplot(x=X, y=Y, geom=c(point, smooth), method=lm, formula = y ~ poly(x, 2)) Note that X is not x and Y is not y in the sense that formula = Y ~ poly(X, 2) will not work (this tripped me up at first). qplot is taking x to mean the first argument (X in this case) and y to mean the second argument (Y in this case). -Ista On Mon, Oct 5, 2009 at 11:42 AM, Juliano van Melis jvme...@gmail.com wrote: Good day for all, I'm a beginner aRgonaut, thus I'm having a problem to plot a quadratic model of regression in a plot. First I wrote: plot(Y~X) and then I tried: abline(lm(Y~X+I(X^2)) but abline only uses the first two of three regression coefficients, thus I tried: line(lm(Y~X+I(X^2)) but a message error is showed (insufficient observations). Therefore, I want to know: how could I plot a quadratic line in my plot graph? 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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Ubuntu, Revolutions, R
at www.revolution-computing.com/events __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] histogram
Or the right argument: t1 - hist(1:5, right=false) t1[1:2] $breaks [1] 1 2 3 4 5 $counts [1] 1 1 1 2 The issue has to do with what hist() does with the points that fall right on the break points. -Ista On Thu, Oct 8, 2009 at 3:58 PM, Henrique Dallazuanna www...@gmail.com wrote: Change the breaks argument: t1 - hist(1:5, 0:5) t1$counts On Thu, Oct 8, 2009 at 4:47 PM, Khanh Nguyen kngu...@cs.umb.edu wrote: Hi all, I have a question about hist() 1) t1 - hist(c(1,2,3,4,5)) t1 $breaks [1] 1 2 3 4 5 $counts [1] 2 1 1 1 why is there 2 counts for 1? And should the counts be '1 1 1 1 1' ? Is there any other function to count frequency of discrete data? Thanks. -k [[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. -- Henrique Dallazuanna Curitiba-Paraná-Brasil 25° 25' 40 S 49° 16' 22 O __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] how to plot a data by different group
Hi Catherine, Assuming your variables are in a dataframe called myData, some variation of the following may be what you want: library(ggplot2) myData.m - melt(myData, measure.vars=c(Y1, Y2)) qplot(X, value, colour=variable, shape=groupf3, facets=groupf1~groupf2, geom=point, data=myData.m) -Ista On Mon, Oct 12, 2009 at 4:36 PM, catherineLF cath...@hotmail.com wrote: Dear everyone, sorry to bother you. I have a big data, suppose it has 200 groups and each group has 100 data. So the data have 2 observations in total. The variables are groupf1 groupf2 groupf3 X Y1 Y2 1 1 1 1 0.5 0.5 groupf1, groupf2 and groupf3 are defining the 200 groups. I want to make 200 graphs for each group. For each group, graph Y1 and Y2 vs X. Is there any easy way to do that? Thank you very much for your help! Catherine -- View this message in context: http://www.nabble.com/how-to-plot-a-data-by-different-group-tp25862739p25862739.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] splitting dataframe, assign to new dataframe, add new rows to new dataframe
I'm sure there's a really cool way to do this with plyr, although I don't know if my particular plyr version is much better. Anyway here it is: cmbine - read.csv(textConnection('names, mass, classes apple,0.50,1 tiger,100.00,2 pencil,0.01,3 chicken,1.00,2 banana,0.15,1 pear,0.30,1')) library(plyr) dfl - list() for(i in 1:max(cmbine$classes)) { dfl[[i]] - ddply(cmbine, .(classes), function(x) {x[i,]}) } dfl Hope it helps, Ista On Mon, Oct 12, 2009 at 10:02 PM, cls59 ch...@sharpsteen.net wrote: wk yeo wrote: Hi, all, My objective is to split a dataframe named cmbine according to the value of classes. After the split, I will take the first instance from each class and bin them into a new dataframe, df1. In the 2nd iteration, I will take the 2nd available instance and bin them into another new dataframe, df2. My apologies, I did not read the first lines of your question carefully. Say we split the data frame by class using by(): byClass - by( cmbine, cmbine[['classes']], function( df ){ return(df) } ) We could then determine the maximum number of rows in all the returned data frames: maxRows - max(sapply( byClass, nrow )) Then, I usually resort to a gratuitous application of lapply() and do.call(): # Loop over each value between 1 and the maximum number of rows, return results as a list. lapply( 1:maxRow, function(i){ # Loop over each data frame, extract the ith rows and rbind the results # together. ithRows - do.call(rbind,lapply(byClass,function(df){ return( df[i,] ) })) # Remove all NA rows ithRows - ithRows[ !is.na(ithRows[,1]), ] return(ithRows) }) [[1]] names mass classes 1 apple 5e-01 1 2 tiger 1e+02 2 3 pencil 1e-02 3 [[2]] names mass classes 1 banana 0.15 1 2 chicken 1.00 2 [[3]] names mass classes 1 pear 0.3 1 There's definitely a more elegant way to do this, perhaps using some routines in the plyr package. Good luck! -Charlie - Charlie Sharpsteen Undergraduate Environmental Resources Engineering Humboldt State University -- View this message in context: http://www.nabble.com/splitting-dataframe%2C-assign-to-new-dataframe%2C-add-new-rows-to-new-dataframe-tp25865409p25866082.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Installing R on Ubuntu ( 8.10 ) ?
It's not glitchy, and you install it just like any other program. If you want the latest version you can follow the instructions here: http://cran.r-project.org/bin/linux/ubuntu/. Otherwise sudo aptitude install r-base r-base-dev will do the trick. On Tue, Oct 13, 2009 at 7:46 AM, Robert Wilkins robst...@gmail.com wrote: installing on Ubuntu, how to do it and have people found it to be glitchy? sudo aptitude update sudo aptitude install r-base No. which is easier , binary install or from source ? ??? Usually binary is easier (that's kind of the point of binaries...) With the source install, are you less likely to have a dependencies issue ? No, let the apt system handle this for you. ( Ubuntu does the GCC install seamlessly, but has no mention of 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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] installing R on Ubuntu, can ignore warning messages?
Hi, Instructions for authenticating the cran repositories are here: http://cran.r-project.org/bin/linux/ubuntu/ r-base comes with whatever the base R libraries are (stats, graphics etc.). I don't know if MASS in particular is in base because I don't use it directly. As far as I know it's safe to ignore the warnings, but they annoy me so I always following the instructions linked above. The list of packages regularly updated in the cran repo are also listed on the webpage linked above. A couple of further tips: 1) I usually install packages with sudo aptitude install r-cran-xxx and then make sure they are up-to date by running update.packages() in R. 2) You can also install packages using the regular install.packages() in an R session. Hope that helps, -Ista On Wed, Oct 14, 2009 at 10:11 PM, robstdev robst...@gmail.com wrote: Installing R on Ubuntu 8.10, ( using sudo apt-get install r-base , and using one of the cran sites (cran.cnr.berkeley.edu)) the installation process says something about not having some gpg public key and are you sure you want to download non-authenticated stuff [y/n] (to which I answered yes). I'm assuming this warning can be ignored? Also: even though the Ubuntu install and online update did a GCC install the other day, the R installation did an update of some GCC files, which I thought was odd. Probably I can ignore that too. Once you've installed R, does that automatically include some data examples ( such as that MASS library ? )? Or does that require further downloads? Also, thanks for the previous tips __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] installing R on Ubuntu, can ignore warning messages?
On Wed, Oct 14, 2009 at 11:01 PM, Robert Wilkins robst...@gmail.com wrote: It does, thank you. I was able to understand enough of it to do the install successfully . Still trying to understand the later paragraphs such as install.package() and the r-cran-foo build dependencies. (the site you pointed me to is the same site i did a printout of yesterday to try to do an install, the readme file prints to 3 pages). Is there an easy way to: 1: List the R-related packages and add-ons that are already installed? no point in trying to install what you already got! Open a terminal and type sudo aptitude update sudo aptitude search r-cran The packages marked with an i on the leftmost column are installed. Those marked with a p are not installed. 2: List the R-related packages and add-ons that are available? Probably a big number of them? sudo aptitude search r-cran will give you the list of packages available through the apt package management system. Additional packages are listed on the CRAN website, and can be installed using install.packages(PackageName) at the R command line. Also, for people who try Ubuntu out for the first time could be thrown for a loop by the weird way it handles the root account: https://help.ubuntu.com/community/RootSudo Depends on what your're used to. I've been using Ubuntu long enough that sudo is second nature... thanks again. Glad to help. -Ista On Wed, Oct 14, 2009 at 10:38 PM, Ista Zahn istaz...@gmail.com wrote: Hi, Instructions for authenticating the cran repositories are here: http://cran.r-project.org/bin/linux/ubuntu/ r-base comes with whatever the base R libraries are (stats, graphics etc.). I don't know if MASS in particular is in base because I don't use it directly. As far as I know it's safe to ignore the warnings, but they annoy me so I always following the instructions linked above. The list of packages regularly updated in the cran repo are also listed on the webpage linked above. A couple of further tips: 1) I usually install packages with sudo aptitude install r-cran-xxx and then make sure they are up-to date by running update.packages() in R. 2) You can also install packages using the regular install.packages() in an R session. Hope that helps, -Ista On Wed, Oct 14, 2009 at 10:11 PM, robstdev robst...@gmail.com wrote: Installing R on Ubuntu 8.10, ( using sudo apt-get install r-base , and using one of the cran sites (cran.cnr.berkeley.edu)) the installation process says something about not having some gpg public key and are you sure you want to download non-authenticated stuff [y/n] (to which I answered yes). I'm assuming this warning can be ignored? Also: even though the Ubuntu install and online update did a GCC install the other day, the R installation did an update of some GCC files, which I thought was odd. Probably I can ignore that too. Once you've installed R, does that automatically include some data examples ( such as that MASS library ? )? Or does that require further downloads? Also, thanks for the previous tips __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] installing R on Ubuntu, can ignore warning messages?
I should have also mentioned that you can search for r-cran in the synaptic package manage if you're more comfortable with that than the command line. This will also show you which packages are installed/available. -Ista On Wed, Oct 14, 2009 at 11:25 PM, Ista Zahn istaz...@gmail.com wrote: On Wed, Oct 14, 2009 at 11:01 PM, Robert Wilkins robst...@gmail.com wrote: It does, thank you. I was able to understand enough of it to do the install successfully . Still trying to understand the later paragraphs such as install.package() and the r-cran-foo build dependencies. (the site you pointed me to is the same site i did a printout of yesterday to try to do an install, the readme file prints to 3 pages). Is there an easy way to: 1: List the R-related packages and add-ons that are already installed? no point in trying to install what you already got! Open a terminal and type sudo aptitude update sudo aptitude search r-cran The packages marked with an i on the leftmost column are installed. Those marked with a p are not installed. 2: List the R-related packages and add-ons that are available? Probably a big number of them? sudo aptitude search r-cran will give you the list of packages available through the apt package management system. Additional packages are listed on the CRAN website, and can be installed using install.packages(PackageName) at the R command line. Also, for people who try Ubuntu out for the first time could be thrown for a loop by the weird way it handles the root account: https://help.ubuntu.com/community/RootSudo Depends on what your're used to. I've been using Ubuntu long enough that sudo is second nature... thanks again. Glad to help. -Ista On Wed, Oct 14, 2009 at 10:38 PM, Ista Zahn istaz...@gmail.com wrote: Hi, Instructions for authenticating the cran repositories are here: http://cran.r-project.org/bin/linux/ubuntu/ r-base comes with whatever the base R libraries are (stats, graphics etc.). I don't know if MASS in particular is in base because I don't use it directly. As far as I know it's safe to ignore the warnings, but they annoy me so I always following the instructions linked above. The list of packages regularly updated in the cran repo are also listed on the webpage linked above. A couple of further tips: 1) I usually install packages with sudo aptitude install r-cran-xxx and then make sure they are up-to date by running update.packages() in R. 2) You can also install packages using the regular install.packages() in an R session. Hope that helps, -Ista On Wed, Oct 14, 2009 at 10:11 PM, robstdev robst...@gmail.com wrote: Installing R on Ubuntu 8.10, ( using sudo apt-get install r-base , and using one of the cran sites (cran.cnr.berkeley.edu)) the installation process says something about not having some gpg public key and are you sure you want to download non-authenticated stuff [y/n] (to which I answered yes). I'm assuming this warning can be ignored? Also: even though the Ubuntu install and online update did a GCC install the other day, the R installation did an update of some GCC files, which I thought was odd. Probably I can ignore that too. Once you've installed R, does that automatically include some data examples ( such as that MASS library ? )? Or does that require further downloads? Also, thanks for the previous tips __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Can R do specific factor analysis?
On Wed, Oct 14, 2009 at 7:00 PM, Tiger Guo tigerguou...@gmail.com wrote: Hello, Can R do factor analysis using eigenvalue greater than one to automatically determine the number of factors to extract? You could write code automate this, but it's easy enough to look at the scree plot and use that as to identify the number of factors that meet this criterion. I am afraid that R cannot provide the function we want. Unlikely! R is also a programing language, so it if the function you want doesn't exist yet you can write it yourself. But I can use R to write a function to do the specific factor analysis. Because the functions needed for developing the factor analysis is provided by R, it should be easy to write the factor analysis. Yes, I'm confident you will be able to do the analysis in R, although... I'm not sure exactly what it is that you want to do. I appreciate if someone can give me some comment about the specific factor analysis. I'm not sure what specific factor analysis means. I personally use the fa() function in the psych package. If your concern is with determining the number of factors to extract, you may be interested in the fa.parallel function in the same package. -Ista Thanks. Gencheng Guo ECE, University of Alberta, Edmonton, Alberta, Canada [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Cannot calculate mean() for double vector
On Fri, Oct 16, 2009 at 2:01 PM, Reuben Bellika rube...@gmail.com wrote: OK. It looks like I just have several NA values at the start of my array: which (is.na(x_ema)) [1] 1 2 3 4 5 6 7 8 9 That make sense, because the moving average is not defined for those positions. I'll just have to set those values to zero: x_ema = replace(x_ema, which(is.na(x_ema)), 0) No! Your mean is now biased toward zero! see ?mean and read the part about na.rm. -Ista which (is.na(x_ema)) integer(0) The mean() call works now and I can get on with my work. I'll have to remember to condition the data like this in the future. Thanks for the help! Reuben Bellika __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Recommendation on a probability textbook (conditional probability)
On Fri, Oct 16, 2009 at 9:37 PM, Peng Yu pengyu...@gmail.com wrote: What's the title? Introduction to Probability. On Fri, Oct 16, 2009 at 8:16 PM, Yi Du abraham...@gmail.com wrote: Hogg's book is enough for you considering your problems. Yi On Fri, Oct 16, 2009 at 7:12 PM, Peng Yu pengyu...@gmail.com wrote: I need to refresh my memory on Probability Theory, especially on conditional probability. In particular, I want to solve the following two problems. Can somebody point me some good books on Probability Theory? Thank you! 1. Z=X+Y, where X and Y are independent random variables and their distributions are known. Now, I want to compute E(X | Z = z). 2.Suppose that I have $I \times J$ random number in I by J cells. For the random number in the cell on the i'th row and the j's column, it follows Poisson distribution with the parameter $\mu_{ij}$. I want to compute P(n_{i1},n_{i2},...,n_{iJ} | \sum_{j=1}^J n_{ij}), which the probability distribution in a row conditioned on the row sum. Some book directly states that the conditional distribution is a multinomial distribution with parameters (p_{i1},p_{i2},...,p_{iJ}), where p_{ij} = \mu_{ij}/\sum_{j=1}^J \mu_{ij}. But I'm not sure how to derive it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Yi Du __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] function to convert lm model to LaTeX equation
Dear list, I've tried several times to wrap my head around the Design library, without much success. It does some really nice things, but I'm often uncomfortable because I don't understand exactly what it's doing. Anyway, one thing I really like is the latex.ols() function, which converts an R linear model formula to a LaTeX equation. So, I started writing a latex.lm() function (not actually using classes at this point, I just named it that for consistency). This turned out to be easy enough for simple cases (see code below), but now I'm wondering a) if anyone knows of existing functions that do this (again, for lm() models, I know I'm reinventing the wheel in as far as the Design library goes), or if not, b) if anyone has suggestions for improving the function below. Thanks, Ista ### Function to create LaTeX formula from lm() model. Needs amsmath package in LaTeX. ### latex.lm - function(object, file=, math.env=c($,$), estimates=none, abbreviate = TRUE, abbrev.length=8, digits=3) { # Get and format IV names co - c(Int, names(object$coefficients)[-1]) co.n - gsub(p.*), , co) if(abbreviate == TRUE) { co.n - abbreviate(gsub(p.*), , co), minlength=abbrev.length) } # Get and format DV m.y - strsplit((as.character(object$call[2])), ~ )[[1]][1] # Write coefficent labels b.x - paste(\\beta_{, co.n ,}, sep=) # Write error term e - \\epsilon_i # Format coefficint x variable terms m.x - sub(}Int,}, paste(b.x, co.n, + , sep=, collapse=)) # If inline estimates convert coefficient labels to values if(estimates == inline) { m.x - sub(Int, , paste(round(object$coefficients,digits=digits), co.n, + , sep=, collapse=)) m.x - gsub(\\+ \\-, -, m.x) } # Format regression equation eqn - gsub(:, \\times , paste(math.env[1], m.y, = , m.x, e, sep=)) # Write the opening math mode tag and the model cat(eqn, file=file) # If separae estimates format estimates and write them below the model if(estimates == separate) { est - gsub(:, \\times , paste(b.x, = , round(object$coefficients, digits=digits), , , sep=, collapse=)) cat(, \n \\text{where }, substr(est, 1, (nchar(est)-2)), file=file) } # Write the closing math mode tag cat(math.env[2], \n, file=file) } # END latex.lm Xvar1 - rnorm(20) Xvar2 - rnorm(20) Xvar3 - factor(rep(c(A,B),10)) Y.var - rnorm(20) D - data.frame(Xvar1, Xvar2, Xvar3, Y.var) x1 - lm(Y.var ~ pol(Xvar1, 3) + Xvar2*Xvar3, data=D) latex.lm(x1) -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] function to convert lm model to LaTeX equation
On Sun, Oct 18, 2009 at 9:09 AM, Frank E Harrell Jr f.harr...@vanderbilt.edu wrote: Ista Zahn wrote: Dear list, I've tried several times to wrap my head around the Design library, without much success. It does some really nice things, but I'm often uncomfortable because I don't understand exactly what it's doing. Anyway, one thing I really like is the latex.ols() function, which converts an R linear model formula to a LaTeX equation. So, I started writing a latex.lm() function (not actually using classes at this point, I just named it that for consistency). This turned out to be easy enough for simple cases (see code below), but now I'm wondering a) if anyone knows of existing functions that do this (again, for lm() models, I know I'm reinventing the wheel in as far as the Design library goes), or if not, b) if anyone has suggestions for improving the function below. Thanks, Ista ### Function to create LaTeX formula from lm() model. Needs amsmath package in LaTeX. ### latex.lm - function(object, file=, math.env=c($,$), estimates=none, abbreviate = TRUE, abbrev.length=8, digits=3) { # Get and format IV names co - c(Int, names(object$coefficients)[-1]) co.n - gsub(p.*), , co) if(abbreviate == TRUE) { co.n - abbreviate(gsub(p.*), , co), minlength=abbrev.length) } # Get and format DV m.y - strsplit((as.character(object$call[2])), ~ )[[1]][1] # Write coefficent labels b.x - paste(\\beta_{, co.n ,}, sep=) # Write error term e - \\epsilon_i # Format coefficint x variable terms m.x - sub(}Int,}, paste(b.x, co.n, + , sep=, collapse=)) # If inline estimates convert coefficient labels to values if(estimates == inline) { m.x - sub(Int, , paste(round(object$coefficients,digits=digits), co.n, + , sep=, collapse=)) m.x - gsub(\\+ \\-, -, m.x) } # Format regression equation eqn - gsub(:, \\times , paste(math.env[1], m.y, = , m.x, e, sep=)) # Write the opening math mode tag and the model cat(eqn, file=file) # If separae estimates format estimates and write them below the model if(estimates == separate) { est - gsub(:, \\times , paste(b.x, = , round(object$coefficients, digits=digits), , , sep=, collapse=)) cat(, \n \\text{where }, substr(est, 1, (nchar(est)-2)), file=file) } # Write the closing math mode tag cat(math.env[2], \n, file=file) } # END latex.lm Xvar1 - rnorm(20) Xvar2 - rnorm(20) Xvar3 - factor(rep(c(A,B),10)) Y.var - rnorm(20) D - data.frame(Xvar1, Xvar2, Xvar3, Y.var) x1 - lm(Y.var ~ pol(Xvar1, 3) + Xvar2*Xvar3, data=D) latex.lm(x1) It's not reinventing the wheel, in the sense that you are not attempting to handle the most needed features (simplifying regression splines and factoring out interaction terms with brackets). I don't think you followed the posting guide though. You didn't state your exact problem with Design and you didn't include any code. Also note that the Design package is replaced with the rms package although latex features have not changed. Thank you for your response Prof. Harrell. Sorry my original post didn't meet the guidelines -- it was poorly worded I'm afraid. The question was not about the Design package, but about how to represent a lm() model as a LaTeX equation, and specifically whether anyone had already written code for this task, and if not how the function I wrote could be improved. Thank you for you're suggestions about needing to handle regression splines and factoring out interaction terms, that's very helpful. Thanks again, Ista -- Frank E Harrell Jr Professor and Chair School of Medicine Department of Biostatistics Vanderbilt University -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to plot multiple data sets with different colors (also with legend)?
Hi Peng, Comments below. On Sun, Oct 18, 2009 at 9:22 PM, Peng Yu pengyu...@gmail.com wrote: On Sun, Oct 18, 2009 at 5:42 PM, Matthieu Dubois matth...@gmail.com wrote: Hi, the blue point is not shown simply because it is printed outside the current plot area. If you want to use the base graphics, you have to manually define the xlim and ylim of the plot. Legend is added with the command legend. E.g. x=rbind(c(10,11),c(10,11)) y=cbind(-1:0,-1:0) plot(y,col='yellow', xlim=c(-1,11), ylim=c(-1,11)) points(x,col='blue') legend(topleft, c(x,y), col=c('blue', 'yellow'), pch=1) This is nevertheless most easily done in ggplot2. E.g. library(ggplot2) # put the whole data in a data frame # and add a new variable to distinguish both dat - data.frame(rbind(x,y), var=rep(c('x','y'), each=2)) qplot(x=X1,y=X2, colour=var, data=dat) qplot generates a figure with some background grid. If I just want a blank background (as in plot), what options should I specify? How to specific the color like 'red' and 'blue' explicitly? You can get a more traditional look by issuing theme_set(theme_bw()) before the call to qplot(). The colors are controlled by the a scale, which you can override as follows: qplot(x=X1,y=X2, colour=var, data=dat) + scale_colour_manual(values = c(red,green)) I have read the review for ggplot2 book on amazon. The rates are unanimously high. I want to know how much effort I should spend to learn ggplot2 versus conventional graphics R packages. Can ggplot2 do all the graphics tasks? Is it much easier to learn than conventional graphics packages? ggplot2 can do most things that can be done in base graphics. It makes many things that are difficult in base easy, like faceting and mapping variables to a wide variety of scales. I myself use ggplot2 almost exclusively. I don't know base graphics at all, and I'm able to accomplish all my graphing needs with ggplot2. I would not say its easier than base graphics, just different. Some things are easier with base graphics, other things are easier with ggplot. I use it because I like the consistent and rational user interface (and the default theme is nice to look at). The place to start learning ggplot2 (while your're waiting for the book to be shipped perhaps) is http://had.co.nz/ggplot2/. -Ista __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to create MULTILEVELS in a dataset??
Hi Saurav, I was waiting for someone else to answer you, because I'm not sure I'll be able to explain clearly. But since no one is jumping on it, I'll take a stab. On Sun, Oct 18, 2009 at 5:52 PM, saurav pathak pathak.sau...@gmail.com wrote: Dear R users I have a data set which has five variables. One depenedent variable y, and 4 Independent variables (education-level, householdincome, countrygdp and countrygdpsquare). The first two are data corresponding to the individual and the next two coorespond to the country to which the individual belongs to. My data set does not make this distinction between individual level and country level. Is there a way such that I can make R make countrygdp and countrygdpsquare at a different level than the individual level data. In other words I wish to transform my dataset such that it recognizes two individual level variables to be at Level-1 and the other two country level variables at Level-2. If you're using lmer I don't think you need to do anything special in terms of data preparation. You will need an explicit country code I think. I need to run a multilevel model, but first I must make my dataset recognise data at Level-1 and Level-2. How can I create this country level group (gdp and gdp^2) such that I can perform a multilevel model as follows: lmer(y ~ education-level + householdincome + countrygdp + countrygdpsquare + (1 I Level2),family=binomial(link=probit),data=dataset) I think you just need to specify country as the grouping variable: lmer(y ~ education-level + householdincome + countrygdp + countrygdpsquare + (1 I country),family=binomial(link=probit),data=dataset) Please kindly help me with the relevant commands for creating this Level2 (having two variables) I hope this helps -- I thinks it's less complicated than you were assuming. -Ista Thanks Saurav Dr.Saurav Pathak PhD, Univ.of.Florida Mechanical Engineering Doctoral Student Innovation and Entrepreneurship Imperial College Business School s.patha...@imperial.ac.uk 0044-7795321121 [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How to create MULTILEVELS in a dataset??
HI, Please keep r-help copied on the reply -- hopefully someone will pick up this thread and help us out. On Mon, Oct 19, 2009 at 2:17 AM, saurav pathak pathak.sau...@gmail.com wrote: Dear Ista Thanks for answering, the previous question was a primer to what I wanted, I did just what you said with yearctry below as the country code or group variable, ie yearctry (data grouped by yearctry) was the variable I was using to pass as the country id. I suggested using country as the grouping variable. what is yearcty? From the name it sounds like a composite of year and country. Kindly notice that after running the lmer model, it recognises yearctry as the group, but shows no of groups :Groups: yearctry,1, this means it did not recognise yearctry as the variable by which the data is grouped. The number should be 239 and not 1 That's weird. What does str(e) say? But please see below: My data set is e names(e) [1] yearctry discent age gender gemeduc gemhhinc ref_group fearfail_ref knowent_ref nbgoodc_ref [11] nbstatus_ref estbbuso_ref lngdp lngdpsq es_gdppcppp sq_gdppcppp estbbo_m es_gdpchg hear I have variables representing two levels, namely individual level and country level. My data is thus a 2 level data. the country level variables (level-2) are lngdp lngdpsq es_gdppcppp sq_gdppcppp estbbo_m es_gdpchg grouped by yearctry and the rest of the variables are individual level (level-1). the number of Individual observations are 655078 and number of yearctry ie groups =239, however when I model a probit to see the influence of 4 individual level var (ie age gender gemeduc and gemhhinc) and one country level var (es_gdppcppp) using prb1-lmer(discent~age+gender+gemeduc+gemhhinc+es_gdppcppp+(1 | yearctry),family=binomial(link=probit),data=e) I get Generalized linear mixed model fit by the Laplace approximation Formula: discent ~ age + gender + gemeduc + gemhhinc + es_gdppcppp + (1 | yearctry) Data: e AIC BIC logLik deviance 194043 194122 -97014 194029 Random effects: Groups Name Variance Std.Dev. yearctry (Intercept) 4.0708e-06 0.0020176 Number of obs: 655078, groups: yearctry, 1 Fixed effects: Estimate Std. Error z value Pr(|z|) (Intercept) -7.578e-01 1.839e-02 -41.20 2e-16 *** age -2.441e-03 2.990e-04 -8.16 3.30e-16 *** gender -2.886e-01 7.710e-03 -37.43 2e-16 *** gemeduc 9.244e-05 6.930e-06 13.34 2e-16 *** gemhhinc -8.938e-07 1.359e-07 -6.58 4.75e-11 *** es_gdppcppp -2.459e-05 2.691e-07 -91.40 2e-16 *** --- Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1 Correlation of Fixed Effects: (Intr) age gender gemedc gmhhnc age -0.580 gender -0.563 -0.138 gemeduc -0.373 0.166 0.011 gemhhinc -0.009 -0.132 -0.024 -0.201 es_gdppcppp -0.490 0.071 0.314 -0.297 0.256 The model did not recognise group to be yearctry and shows 1 instead of 239, can somebody help me as to how to make my model recognise es_gdppcppp as a country level variable grouped by yearctry (such that yeractry no of obs should be 239) I think we need more information. How many levels does str(e) say yearctry has? Also do you really have data from 239 countries, or is yearctry a composite of year and country? If the later it might make sense to split it out int separate year and country variables. hope it helps, Ista On Mon, Oct 19, 2009 at 5:00 AM, Ista Zahn istaz...@gmail.com wrote: Hi Saurav, I was waiting for someone else to answer you, because I'm not sure I'll be able to explain clearly. But since no one is jumping on it, I'll take a stab. On Sun, Oct 18, 2009 at 5:52 PM, saurav pathak pathak.sau...@gmail.com wrote: Dear R users I have a data set which has five variables. One depenedent variable y, and 4 Independent variables (education-level, householdincome, countrygdp and countrygdpsquare). The first two are data corresponding to the individual and the next two coorespond to the country to which the individual belongs to. My data set does not make this distinction between individual level and country level. Is there a way such that I can make R make countrygdp and countrygdpsquare at a different level than the individual level data. In other words I wish to transform my dataset such that it recognizes two individual level variables to be at Level-1 and the other two country level variables at Level-2. If you're using lmer I don't think you need to do anything special in terms of data preparation. You will need an explicit country code I think. I need to run a multilevel model, but first I must make my dataset recognise data at Level-1 and Level-2. How can I create this country level group (gdp and gdp^2) such that I can perform a multilevel model as follows: lmer(y ~ education-level + householdincome
Re: [R] How to create MULTILEVELS in a dataset??
Hi, I wouldn't combine the year and country codes in the first place, and certainly not as a numeric value. Do you have the raw data with country and year listed separately? From the output you listed it looks like you indeed have a single value (2e+07) for yearctry. You can check with unique(e$yearctry) to see how many unique values there are. But combined with the fact that lmer is telling you that you only have one, I'm guessing there really is only one value. You've got your data in an unmanageable state I think. Go back to the raw data. How many countries do you have? How many years does the data span? On Mon, Oct 19, 2009 at 11:43 AM, saurav pathak pathak.sau...@gmail.com wrote: Hi Ista You got that correct, yearctry is a composite created as yearctry = year*1+country, so that say for example USA with country code 1 and year 2000 will be 201, for year 2005, it will be 2005001, the years are listed from 2000 to 2008, for many countries, for UK say it will be 244 and 2005044 and so on for various years from 2000-2008 and various countries, I am listing the result of str(e) here, 'data.frame': 902533 obs. of 18 variables: $ yearctry : num 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 ... $ discent : int 0 0 0 NA 0 1 0 0 0 NA ... $ age : int 51 46 26 24 19 18 20 19 25 19 ... $ gender : int 1 2 1 1 1 1 1 1 1 1 ... $ gemeduc : int 0 0 111 111 111 111 111 111 111 111 ... $ gemhhinc : int 33 33 33 33 33 33 33 33 33 33 ... $ ref_group : int 1 2 3 3 3 3 3 3 3 3 ... $ fearfail_ref: num 1 NA 0.473 0.473 0.473 ... $ knowent_ref : num 0 NA 0.484 0.484 0.484 ... $ nbgoodc_ref : num NA 0 0.84 0.84 0.84 0.84 0.84 0.84 0.84 0.84 ... $ nbstatus_ref: num NA 1 0.846 0.846 0.846 ... $ estbbuso_ref: num 0 0 0.0172 0.0172 0.0172 ... $ lngdp : num 8.99 9.08 9.29 9.13 8.99 ... $ lngdpsq : num 19.5 19.4 19.2 19.4 19.5 ... $ es_gdppcppp : num 7995 8804 10872 9189 7995 ... $ sq_gdppcppp : num 3.01e+08 2.74e+08 2.10e+08 2.61e+08 3.01e+08 2.74e+08 2.10e+08 3.01e+08 2.10e+08 2.61e+08 ... $ estbbo_m : num 0.1063 0.078 0.049 0.0355 0.1063 ... $ es_gdpchg : num -10.9 8.837 9.179 -0.789 -10.9 ... a portion of yearctry is also listed 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 [65391] 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 [65417] 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 [65443] 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 [65469] 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 [65495] 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 [65521] 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 [65547] 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 [65573] 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 2e+07 [65599] 2e+07 2e+07 2e+0 By looking at the above I dont know whether R recognises them as different numbers, here the exponential format of representing yearctry does not reveal whether it takes yearctry as I explained above( ie whether it recognises 201 different from 2005001 , all of them appear to be 2e+07), if that is the case how do I make R to recognise it as the number 201 and so on, Stata too lists as an exponential format but I know that it recognises yearctry values different for different yeras and countries, please help I have to shift to R because Stata is taking days and days to run gllamm Kindly help On Mon, Oct 19, 2009 at 2:19 PM, Ista Zahn istaz...@gmail.com wrote: HI, Please keep r-help copied on the reply -- hopefully someone will pick up this thread and help us out. On Mon, Oct 19, 2009 at 2:17 AM, saurav pathak pathak.sau...@gmail.com wrote: Dear Ista Thanks for answering, the previous question was a primer to what I wanted, I did just what you said with yearctry below as the country code or group variable, ie yearctry (data grouped by yearctry) was the variable I was using to pass as the country id. I suggested using country
Re: [R] Sweave file generation
I'm not sure I understand. Why not just take your existing R script and wrap it in \begin{document} = ... @ \end{document} and run it through Sweave? -Ista On Mon, Oct 19, 2009 at 2:40 PM, Gabriel Koutilellis kgabr...@in.com wrote: Dear list,I have read really a lot the past few days, but I haven't found a matching solution for my problem.I have R 2.9.2 on Windows XP and MikTex 2.8 installed.What I want to do is to automate the sweave file generation.I thought I could use the R2Sweave, RweaveLatex, and Sweave in a combination so thatI won't need to do anything.Perhaps some minor modifications at the last step.My purpose is to print text (summaries) and plots on the same pdf file, fast and easily.If later I need to produce a much more elegant paper I know I will need to fix the latexpart of my code.Let's say I have a file of R code script.Rso in R R2Sweave(script.R) RweaveLatex() Sweave(script.Rnw) texi2dvi(script.tex, pdf=T)would produce of something like the pdf with the summaries and plots coded inside the script.RThank you [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Problem using the source-function within R-functions
Hi Johan, Although it's not clear to my why you're putting this in a function in the first place... The way you've written your function it will only work if your working directory is the same as the directory where file1.r and file2.r are stored, and I suspect this is the problem. You can 1) set the working directory in your function or 2) specify the full path to file1.r and file2.r in your function. Option 1 will look like myfunction - function(...){ setwd(/path/where/files/are/saved) source('file1.r') source('file2.r') and option 2 will look like myfunction - function(...){ source('/path/where/files/are/saved/file1.r') source('/path/where/files/are/saved/file2.r') source() also has a chdir option that you could investigate. See ?source -Ista On Tue, Oct 20, 2009 at 7:00 AM, Johan Lassen jle...@gmail.com wrote: Dear R community, You may have the solution to how to construct a function using the function source() to build the function; i.e. myfunction - function(...){ source('file1.r') source('file2.r') } After compiling and installing the myfunction in R, then calling the myfunction gives an error because the content of 'file1.r' and 'file2.r' seems to be missing. Anyone has the trick to overcome this problem? Thanks in advance! best wishes, Johan PS: My function is: run_accumm_value - function(ind_noder_0, ind_loc_val,ind_retention,downstream){ ## Preprocessing of looping calculations: koersel_uden_ret - length(unique(ind_noder_0$oplid)) opsaml_b_0_2 - numeric(koersel_uden_ret) opsaml_b_0_2_1 - numeric(koersel_uden_ret) opsaml_b_0_2_2 - seq(1:koersel_uden_ret) ## Preprocessing of topology and local values to be summed: source('preproces_topology.r', local = T) source('preproces_loc_val.r', local = T) # Loop for each grouping factor (column in ind_noder_0: oplid): for(j in 1:koersel_uden_ret){ source('matrix_0.r', local = T) source('matrix.r', local = T) source('local_value.r', local = T) source('fordeling.r', local = T) source('fordeling_manuel.r', local = T) source('local_ret.r', local = T) source('Ax=b.r', local = T) source('opsamling_x_0_acc.r', local = T) } source('opsamling_b_1.r', local = T) opsaml_b_2 } -- Johan Lassen Environment Center Nykøbing F Denmark [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] rbind with different columns
Nice! I was going to recommend merge(merge(myList[[1]], myList[[2]], all=TRUE, sort=FALSE), myList[[3]], all=TRUE, sort=FALSE) but rbind.fill is better. -Ista On Tue, Oct 20, 2009 at 10:05 AM, Karl Ove Hufthammer k...@huftis.org wrote: In article 4addc1d0.2040...@yahoo.de, niederlein-rs...@yahoo.de says... In every list entry is a data.frame but the columns are only partially the same. If I have exactly the same columns, I could do the following command to combine my data: do.call(rbind, myList) but of course it does not work with differnt column names. Is there any easy way to retrieve a combined table like this: You're in luck. 'rbind.fill' in the 'plyr' package does exactly what you want. -- Karl Ove Hufthammer __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] TukeyHSD no longer working with aov output?
Hi Clayton, I don't think you need summary(). TukeyHSD(data1.aov) should work. -Ista On Tue, Oct 20, 2009 at 4:17 PM, Clayton Coffman clayton.coff...@gmail.com wrote: I can prove I've done this before, but I recently installed Rexcel (and it was easiest to reinstall R and some other bits to make it work) and now its no longer working. Before I would do an ANOVA and a tukey post-hoc like this: data1.aov=aov(result~factor1*factor2, data=data1) then... TukeyHSD(summary(data1.aov)) and it would give me a nice tukey table of all the pairwise comparisons, now though it gives me: in UseMethod(TukeyHSD) : no applicable method for TukeyHSD Has something changed? Does TukeyHSD no longer accept aov results? Is there a package I'm missing? I am very frustrated. Thanks, Clayton [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Bootstrapping confidence intervals
John Fox has a nice explanation here: http://cran.r-project.org/doc/contrib/Fox-Companion/appendix-bootstrapping.pdf -Ista On Wed, Oct 21, 2009 at 6:38 AM, Charlotta Rylander z...@nilu.no wrote: Hello, We are a group of PhD students working in the field of toxicology. Several of us have small data sets with N=10-15. Our research is mainly about the association between an exposure and an effect, so preferrably we would like to use linear regression models. However, most of the time our data do not fulfill the model assumptions for linear models ( no normality of y-varible achieved even after log transformation). We have been told that we can use bootstrapping to derive a confidence interval for the original parameter estimate ( Beta 1) from the linear regression model and if the confidence interval do not include 0, we can trust the result from the original linear model ( of couse only if a scatter plot of the variables looks ok). What is your opinion about this method? Is that ok? I have problems understanding how it is possible to resample several times from an already poor distribution ( that do not fulfill the model assumptions for linear models) to achieve a confidence interval that validates the use of these linear models? I would really appriciate a simple explanation about this! Many thanks, Charlotta Rylander [[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. -- Ista Zahn Graduate student University of Rochester Department of Clinical and Social Psychology http://yourpsyche.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.