Re: [R] Sorting order of reorder with multiple variables
On Thu, Aug 25, 2011 at 6:15 PM, markm0705 markm0...@gmail.com wrote: I've been building a ranked dot plot for several days now and am sorting the data using the reorder command. What I don't understand is how reorder works when mutiple varibles are plotted by grouping. In the example below I'm using re-order to sort by a variable name Resv_Prop, but I'm plotting up to three different values of Resv_prop (different Year values) for each factor. The results are not what i expected and I would like to control the sorting by the 2010 Year values. reorder() does have a FUN argument that let's you define a summary measure that is used for sorting when multiple observations are present per group. Unfortunately, this will not help you here. However, once you realize that all you really need are the levels() of your y-variable in the right order, you can finesse the problem as follows: Cal_dat_2010 - subset(Cal_dat, Year == 2010) tmp - with(Cal_dat_2010, reorder(paste(Mine,Company), Resv_Prop)) with(Cal_dat, dotplot(factor(paste(Mine,Company), levels = levels(tmp)) ~ Resv_Prop, groups = factor(Year), auto.key = TRUE)) -Deepayan __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 vectorize a function to handle two vectors
Isn't a vector of vectors usually considered a matrix? So if you want to vectorize a vector function you would normally rewrite it to operate on matrices. --- 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. Newbie lille_kn...@hotmail.com wrote: Thank you for the quick response! I think you are on the right track - but is there any way of calling (is that the word for it) the function price_call in the mapply, so that this price_call function is changed to handle vectors. I believe that this should, in theory if it is correct, make the result be values. I have part of a code that works for only one vector. So maybe some where in the line of: callOptionkVec - function(phi, kVec, t) { sapply(kVec,function(k) {callOption(phi,k,t)}) } is what I need to do. Do you have any ideas on how to do this? -- View this message in context: http://r.789695.n4.nabble.com/How-to-vectorize-a-function-to-handle-two-vectors-tp3771705p3771902.html Sent from the R help mailing list archive at Nabble.com. _ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] hopelessly overdispersed?
dear list! i am running an anlysis on proportion data using binomial (quasibinomial family) error structure. My data comprises of two continuous vars, body size and range size, as well as of feeding guild, nest placement, nest type and foragig strata as factors. I hope to model with these variables the preference of primary forests (#successes) by certain bird species. My code therefore looks like: y-cbind(n_forest,n_trials-n_forest) model-glm(y~range+body+nstrata+ntype+forage+feed,family=quasibinomial(link=logit),data=dat) however plausible the approach may look, overdispersion is prevalent (dispersion estimated at 6.5). I read up on this and learned that in case of multiple factors, not all levels may yield good results with logistic regression (Crawley The R Book). I subsequently try to analyse each feeding guild seperately, but to no avail.overdispersion remains. Given the number of categorical variables in my study, is there a convenient way to handle the overdispersion? I was trying tree models to see the most influential variables but again, to no avail. BTW: It may well be that the data is just bad... thanks a lot! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 variables in a data frame
On Sat, Aug 27, 2011 at 7:26 AM, Andra Isan andra_i...@yahoo.com wrote: Hi All, I have a data frame as follow: user_id time age location gender . and I learn a logistic regression to learn the weights (glm with family= (link = logit))), my response value is either zero or one. I would like to group the users based on user_id and time and see the y values and predicted y values at the same time. Or plot them some how. Is there any way to somehow group them together so that I can learn more about my data by grouping them? It's very difficult to help you because you haven't followed the posting guide. But I suspect you're looking for the following: require(plyr) Loading required package: plyr data(mtcars) ##considering 'gear' as 'id' and 'carb' as time ddply(mtcars, .(gear, carb), function(x) mean(x$hp)) gear carbV1 1 31 104.0 2 32 162.5 3 33 180.0 4 34 228.0 5 41 72.5 6 42 79.5 7 44 116.5 8 52 102.0 9 54 264.0 1056 175.0 1158 335.0 This will compute the mean of 'hp' for each group of id time. Liviu I would like to get these at the end user_id time y predicted_y Thanks a lot, Andra __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Do you know how to read? http://www.alienetworks.com/srtest.cfm http://goodies.xfce.org/projects/applications/xfce4-dict#speed-reader Do you know how to write? http://garbl.home.comcast.net/~garbl/stylemanual/e.htm#e-mail __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Degrees of freedom in the Ljung-Box test
Dear list members, I have 982 quotations of a given stock index and I want to run a Ljung-Box test on these data to test for autocorrelation. Later on I will estimate 8 coefficients. I do not know how many degrees of freedom should I assume in the formula for Ljung-Box test. Could anyone tell me please? Below the formula: Box.test(x, lag = , type = c(Ljung-Box), fitdf = 0) Thank you very much in advance. Best regards Marcin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Asking Favor For Remove element with Particular Value In Vector
Dear All. I am Chuan. I am beginner for R.I facing some problem in remove element from vector.I have a vector with size 238 element as follow(a part) [1] 0 18 24 33 44..[238] 255 Let the vector label as x,I want remove element 0 and 255.I try use such function: x[x0 x255] However, I am fail since same results are give even try it for many times.I also try with shorter vector with 10 element. It is successfully resulted. So,want can I do for it. Kindly asking favor for expert here. Thank you very much. Chuan -- View this message in context: http://r.789695.n4.nabble.com/Asking-Favor-For-Remove-element-with-Particular-Value-In-Vector-tp3772779p3772779.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] gplot data manipulation question
i have this data with me...i am only copying part of data here... date time 2011-05-2304:31:17 2011-05-2304:31:20 2011-05-2304:31:22 2011-05-2304:31:25 2011-05-2304:31:27 2011-05-2304:31:18 2011-05-2304:31:20 2011-05-2304:31:22 2011-05-2304:31:25 2011-05-2304:31:27 2011-05-2304:31:26 2011-05-2304:31:28 2011-05-2808:16:14 2011-05-2808:16:58 2011-05-2808:16:22 2011-05-2808:16:24 2011-05-2808:16:27 2011-05-2808:16:29 2011-05-2808:16:32 2011-05-2808:16:19 2011-05-2808:16:21 2011-05-2808:16:24 2011-05-2808:16:26 and other data hours.1 -[1] 4.5 3.4 hours.1 data is the total no.of hours of data on those particular dates. i have the data on 2011-05-23 for 4.5 hours and data on 2011-05-28 for 3.4 hours. for representing the count data using gglots i am using the following command ggplot(dat,aes(factor(date))+ geom_bar(position=dodge). now i am looking for representing the normalized data. i want to represent the table(data)/hours.1 output with ggplot. i can use the barplot function, but the graphics are good in and labeling x-axis is easy in ggplots. i would appreciate if someone can reply asap.. thank you .. -- View this message in context: http://r.789695.n4.nabble.com/gplot-data-manipulation-question-tp3772664p3772664.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] separate mfrow region with line
Dear R users, I have six plots in one figure, created with par(mfrow=c(2,3)). I would like to add two lines to the figure outside the plotting regions, separating the figure into 3 columns. Is this possible? Thanks -- View this message in context: http://r.789695.n4.nabble.com/separate-mfrow-region-with-line-tp3772758p3772758.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] rmongodb released
The source code to a new package, rmongodb (http://cnub.org/rmongodb.ashx), has just been released. This is a full-featured driver to MongoDB ( http://www.mongodb.org) for the R language. Just out of development, I would like some feedback from some real world usage before submitting the package to CRAN. Please contact me at ger...@cnub.org or gerald.lind...@gmail.com to let me know your experiences. Thank you, Gerald Lindsly [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] comparing GLM coefficients repeatability
Many thanks for taking the time to read this! I am looking at the repeatability of behaviour between re-sighted individuals across discrete time periods (annual breeding seasons). My approach was to run a GLM (with a logit link - the data are proportional, presence v. absence of behaviour) for each breeding season. I included the re-sighted individuals as a factor (categorical variable) (i.e. the models only contained individuals that were seen in all of the breeding seasons). Inevitably the variables that are retained in the best models are not the same for each breeding season and in one (out of 3 cases) individual is not retained within the best model (although I suspect that is a product of a considerably smaller sample size for that breeding season). I use the best model that has retained individual id and extract the coefficients of the individuals. I then use the ICC command in the package psych to test for repeatability in these values over the three breeding seasons. The results are in fact repeatable, which does support the basic analyses using just the behaviour (without trying to account for potential covariates), which is encouraging. However, I have had a look on nabble and other forms to see if this is at all statistically sound or if I am making a fundamental error in how I am treating the coefficients. I have found a couple of posts, but I don't think that they relate directly to my question. I appreciate that some may suggest using mixed-effects modelling with individual as a random effect. My issue is that the behaviours I am interested in are very rare and are best suited for a beta-binomial distribution (tested using Ben Bolker's script/e.g. in his book). And such a distribution is not available in lme4. Therefore, I'm trying to find another approach to assess whether individual is important in predicting a behaviour, and whether individuals are repeatable/consistent in this respect. Any advice would be most appreciated, Best wishes, Ross -- View this message in context: http://r.789695.n4.nabble.com/comparing-GLM-coefficients-repeatability-tp3772844p3772844.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Asking Favor For Remove element with Particular Value In Vector
Not sure whether I understand your question right but here is what I would do: # Sample data x - seq( 1, 100, by=6) x [1] 1 7 13 19 25 31 37 43 49 55 61 67 73 79 85 91 97 # remove element with value 19 x - x[ x != 19 ] x [1] 1 7 13 25 31 37 43 49 55 61 67 73 79 85 91 97 If you want to remove values smaller / larger than a certain threshold, your way should work well: # Sample data x - seq( 1, 100, by=6) x[9] - 155 x [1] 1 7 13 19 25 31 37 43 155 55 61 67 73 79 85 91 97 # Remove elements smaller than 20 or larger than 80: x - x[ x 20 x 80 ] x [1] 25 31 37 43 55 61 67 73 79 So there is probably an issue with your data vector - why don't you dput() it? Rgds, Rainer On Saturday 27 August 2011 02:31:29 chuan_zl wrote: Dear All. I am Chuan. I am beginner for R.I facing some problem in remove element from vector.I have a vector with size 238 element as follow(a part) [1] 0 18 24 33 44..[238] 255 Let the vector label as x,I want remove element 0 and 255.I try use such function: x[x0 x255] However, I am fail since same results are give even try it for many times.I also try with shorter vector with 10 element. It is successfully resulted. So,want can I do for it. Kindly asking favor for expert here. Thank you very much. Chuan -- View this message in context: http://r.789695.n4.nabble.com/Asking-Favor-For-Remove-element-with-Particul ar-Value-In-Vector-tp3772779p3772779.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Make a function work on an environemnt
A previous attempt at this question resulted in the message running together, making the message difficult to read and the code lines hard to distinquinsh. In my R learning I've come across a situation in which a piece of code that works on the work space outside a function does not work inside the function. WARNING THIS EMAIL CONTAINES THE CODE:#rm(list=ls()) THIS WILL CLEAR ALL OBJECTS FROM YOUR WORKSPACE! When I use rm(list=ls()) and then ls() it shows character(0) So I tried to make a quick function to speed this up as follows: # #ATTEMPT 1 # clear - function()rm(list=ls())clear() ls() #all objects are still attached # #ATTEMPT 2 # clear - function(){ {CLEAR - function()rm(list=ls())} eapply(globalenv(),CLEAR) }clear()ls() # #ERROR MESSAGE FRPM ATTEMPT 2 # clear() Error in FUN(list(function (x) : unused argument(s) (list(function (x) QUESTIONS:Why does this code not work inside the function? Please critique both my attempts. What would I need to do to make the pieces of code work inside the function? Windows 7 R version 2.14 beta Thanks in advance, Tyler Rinker [[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] Degrees of freedom in the Ljung-Box test
Please fix your email settings: your 'From:' field is not in the correct encoding, so I had to manually copy the ASCII part. (The header as received here said it was UTF-8, but it is not valid UTF-8. Most likely no encoding was declared your end.) On Sat, 27 Aug 2011, Marcin Pciennik wrote: Dear list members, I have 982 quotations of a given stock index and I want to run a Ljung-Box test on these data to test for autocorrelation. Later on I will estimate 8 coefficients. I do not know how many degrees of freedom should I assume in the formula for Ljung-Box test. Could anyone tell me please? Nor does anyone else without knowing what 'x' is. But from the help page: fitdf: number of degrees of freedom to be subtracted if ‘x’ is a series of residuals. Details: These tests are sometimes applied to the residuals from an ‘ARMA(p, q)’ fit, in which case the references suggest a better approximation to the null-hypothesis distribution is obtained by setting ‘fitdf = p+q’, provided of course that ‘lag fitdf’. So is 'x' a set of residuals from an ARMA fit? If so, the help page told you how, and if it is a not a fit note the word 'if' in the description of 'fitdf'. Below the formula: Box.test(x, lag = , type = c(Ljung-Box), fitdf = 0) Thank you very much in advance. Best regards Marcin [[alternative HTML version deleted]] Please don't send HTML as you were explicitly asked in the posting guide. Very likely that exacerbated the encoding confusion. PLEASE do read the posting guide http://www.R-project.org/posting-guide.html -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595__ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] separate mfrow region with line
On Aug 27, 2011, at 5:01 AM, dood wrote: Dear R users, I have six plots in one figure, created with par(mfrow=c(2,3)). I would like to add two lines to the figure outside the plotting regions, separating the figure into 3 columns. Is this possible? The xpd parameter used with the segments function should provide that. The tricky bit will be establishing the proper endpoints, but without an example that cannot be illustrated. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Asking Favor For Remove element with Particular Value In Vector
On Aug 27, 2011, at 5:31 AM, chuan_zl wrote: Dear All. I am Chuan. I am beginner for R.I facing some problem in remove element from vector.I have a vector with size 238 element as follow(a part) [1] 0 18 24 33 44..[238] 255 Let the vector label as x,I want remove element 0 and 255.I try use such function: x[x0 x255] I am not completely clear but it appears that you want to remove the first and last elements. You can use negative indexing vectors. x[ -c(1, length(x) ) ] However, I am fail Perhaps your vector is a factor? Try this and see what you get: str(x) since same results are give even try it for many times.I also try with shorter vector with 10 element. It is successfully resulted. So,want can I do for it. Kindly asking favor for expert here. Thank you very much. Chuan -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] hopelessly overdispersed?
Kilo Bismarck tweedie-d at web.de writes: i am running an anlysis on proportion data using binomial (quasibinomial family) error structure. My data comprises of two continuous vars, body size and range size, as well as of feeding guild, nest placement, nest type and foragig strata as factors. I hope to model with these variables the preference of primary forests (#successes) by certain bird species. My code therefore looks like: y-cbind(n_forest,n_trials-n_forest) model-glm(y~range+body+nstrata+ntype+forage+feed, family=quasibinomial(link=logit),data=dat) however plausible the approach may look, overdispersion is prevalent (dispersion estimated at 6.5). I read up on this and learned that in case of multiple factors, not all levels may yield good results with logistic regression (Crawley The R Book). I subsequently try to analyse each feeding guild seperately, but to no avail.overdispersion remains. Given the number of categorical variables in my study, is there a convenient way to handle the overdispersion? I was trying tree models to see the most influential variables but again, to no avail. BTW: It may well be that the data is just bad... Sometimes overdispersion comes from a poorly fitting model, sometimes it is just there (i.e. intrinsic or caused by a non-measured predictor which you can't do anything about). Examine your data and the fits of the model to your data for outliers or obvious deviations from the model. If the fit generally looks OK but there is just consistently more variation than expected from the binomial distribution then you can probably proceed with your inferences from the quasibinomial model. (Do make sure that you are not overfitting, i.e. if you are going to fit a model with 12 or so parameters [I'm guessing here: it depends on the numbers of levels in your categorical predictors], you really need at least 120 (preferably more) observations ...] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Error: package 'lsei' is not installed for 'arch=i386'
Hi guys, I am having problem loading a package that I have installed. I have searched some old thread but they were no help in terms of solving the problem. I uninstalled every possible component of R and installed R 2.13 and followed the R-faqs installation steps. Then I installed the package (lsei) from local zip file which was installed successfully but can not be loaded and returns the error message as titled. The zip file can be downloaded below, it used to work fine on my old version of R (I think it was 2.9). http://www.stat.auckland.ac.nz/~yongwang/ I've check .libPaths() as some suggested and remove the copy in the first directory but that was the only copy that I have on the machine. Can someone give me a direction on how I can solve this problem? Thanks in advance. MK R version 2.13.1 (2011-07-08) Copyright (C) 2011 The R Foundation for Statistical Computing ISBN 3-900051-07-0 Platform: i386-pc-mingw32/i386 (32-bit) R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. Natural language support but running in an English locale R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. library(lsei) Error in library(lsei) : there is no package called 'lsei' utils:::menuInstallLocal() package 'lsei' successfully unpacked and MD5 sums checked library(lsei) Error: package 'lsei' is not installed for 'arch=i386' .libPaths() [1] C:/Users/user/R/win-library/2.13C:/Program Files/R/R-2.13.1/library -- View this message in context: http://r.789695.n4.nabble.com/Error-package-lsei-is-not-installed-for-arch-i386-tp3773012p3773012.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Make a function work on an environemnt
Well, here's one way you could do it: # Don't run this unless you really mean it clear - function(){rm(list=ls(.GlobalEnv), envir = .GlobalEnv)} Both calls to .GlobalEnv seem necessary so that both rm() and ls() go everywhere with it. However, this certainly isn't the most useful code because it clears itself... I'm not the best with environments so I'll let someone else work out the problems with your other attempts, but I believe the problem with the first is that it only executes inside the function environment and not the global environment. Not sure about the second... Michael Weylandt On Sat, Aug 27, 2011 at 9:25 AM, Tyler Rinker tyler_rin...@hotmail.comwrote: A previous attempt at this question resulted in the message running together, making the message difficult to read and the code lines hard to distinquinsh. In my R learning I've come across a situation in which a piece of code that works on the work space outside a function does not work inside the function. WARNING THIS EMAIL CONTAINES THE CODE:#rm(list=ls()) THIS WILL CLEAR ALL OBJECTS FROM YOUR WORKSPACE! When I use rm(list=ls()) and then ls() it shows character(0) So I tried to make a quick function to speed this up as follows: # #ATTEMPT 1 # clear - function()rm(list=ls())clear() ls() #all objects are still attached # #ATTEMPT 2 # clear - function(){ {CLEAR - function()rm(list=ls())} eapply(globalenv(),CLEAR) }clear()ls() # #ERROR MESSAGE FRPM ATTEMPT 2 # clear() Error in FUN(list(function (x) : unused argument(s) (list(function (x) QUESTIONS:Why does this code not work inside the function? Please critique both my attempts. What would I need to do to make the pieces of code work inside the function? Windows 7 R version 2.14 beta Thanks in advance, Tyler Rinker [[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.
Re: [R] Make a function work on an environemnt
Michael, Thank you for that information. It was very insightful. Anyone else with why my second attempt does not work (using eapply)? ThanksTylerFrom: michael.weyla...@gmail.com Date: Sat, 27 Aug 2011 12:01:02 -0400 Subject: Re: [R] Make a function work on an environemnt To: tyler_rin...@hotmail.com CC: r-help@r-project.org Well, here's one way you could do it: # Don't run this unless you really mean it clear - function(){rm(list=ls(.GlobalEnv), envir = .GlobalEnv)} Both calls to .GlobalEnv seem necessary so that both rm() and ls() go everywhere with it. However, this certainly isn't the most useful code because it clears itself... I'm not the best with environments so I'll let someone else work out the problems with your other attempts, but I believe the problem with the first is that it only executes inside the function environment and not the global environment. Not sure about the second... Michael Weylandt On Sat, Aug 27, 2011 at 9:25 AM, Tyler Rinker tyler_rin...@hotmail.com wrote: A previous attempt at this question resulted in the message running together, making the message difficult to read and the code lines hard to distinquinsh. In my R learning I've come across a situation in which a piece of code that works on the work space outside a function does not work inside the function. WARNING THIS EMAIL CONTAINES THE CODE:#rm(list=ls()) THIS WILL CLEAR ALL OBJECTS FROM YOUR WORKSPACE! When I use rm(list=ls()) and then ls() it shows character(0) So I tried to make a quick function to speed this up as follows: # #ATTEMPT 1 # clear - function()rm(list=ls())clear() ls() #all objects are still attached # #ATTEMPT 2 # clear - function(){ {CLEAR - function()rm(list=ls())} eapply(globalenv(),CLEAR) }clear()ls() # #ERROR MESSAGE FRPM ATTEMPT 2 # clear() Error in FUN(list(function (x) : unused argument(s) (list(function (x) QUESTIONS:Why does this code not work inside the function? Please critique both my attempts. What would I need to do to make the pieces of code work inside the function? Windows 7 R version 2.14 beta Thanks in advance, Tyler Rinker [[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.
Re: [R] Make a function work on an environemnt
Michael, Michael wrote: However, this certainly isn't the most useful code because it clears itself... If you were to put this code in a package, .Rdata file, or .First() script it could be recalled in that way. So it could serve a purpose. The exercise was more about me learning how to apply the function to global environment though. You were certainly helpful there. From: michael.weyla...@gmail.com Date: Sat, 27 Aug 2011 12:01:02 -0400 Subject: Re: [R] Make a function work on an environemnt To: tyler_rin...@hotmail.com CC: r-help@r-project.org Well, here's one way you could do it: # Don't run this unless you really mean it clear - function(){rm(list=ls(.GlobalEnv), envir = .GlobalEnv)} Both calls to .GlobalEnv seem necessary so that both rm() and ls() go everywhere with it. However, this certainly isn't the most useful code because it clears itself... I'm not the best with environments so I'll let someone else work out the problems with your other attempts, but I believe the problem with the first is that it only executes inside the function environment and not the global environment. Not sure about the second... Michael Weylandt On Sat, Aug 27, 2011 at 9:25 AM, Tyler Rinker tyler_rin...@hotmail.com wrote: A previous attempt at this question resulted in the message running together, making the message difficult to read and the code lines hard to distinquinsh. In my R learning I've come across a situation in which a piece of code that works on the work space outside a function does not work inside the function. WARNING THIS EMAIL CONTAINES THE CODE:#rm(list=ls()) THIS WILL CLEAR ALL OBJECTS FROM YOUR WORKSPACE! When I use rm(list=ls()) and then ls() it shows character(0) So I tried to make a quick function to speed this up as follows: # #ATTEMPT 1 # clear - function()rm(list=ls())clear() ls() #all objects are still attached # #ATTEMPT 2 # clear - function(){ {CLEAR - function()rm(list=ls())} eapply(globalenv(),CLEAR) }clear()ls() # #ERROR MESSAGE FRPM ATTEMPT 2 # clear() Error in FUN(list(function (x) : unused argument(s) (list(function (x) QUESTIONS:Why does this code not work inside the function? Please critique both my attempts. What would I need to do to make the pieces of code work inside the function? Windows 7 R version 2.14 beta Thanks in advance, Tyler Rinker [[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.
Re: [R] Sicherheitszertifikat für R-Pakete unter Windows [Security Certificates for R Packages in Windows]
On 26.08.2011 19:36, R. Michael Weylandt wrote: To save anyone else 30 seconds, here's how google translates the below: Ladies and Gentlemen, I would like to inform me whether there is the possibility of security certificates for R packages are. Impressingly accurate given the original text is grammatically as wrong as the outcome of the translation. The answer is: Not that I know - unless you pay money to someone who you trust and will write some certificate. Uwe Ligges Sincerely, Christopher W. Weinberger 2011/8/26 Christoph W. Weinbergercwein...@edu.uni-klu.ac.at Sehr geehrte Damen und Herren, ich würde mich gerne informieren, ob es die Möglichkeit gibt Sicherheitszertifikate für R-Pakete gibt. Mit freundlichen Grüßen Christoph W. Weinberger __** R-help@r-project.org mailing list https://stat.ethz.ch/mailman/**listinfo/r-helphttps://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/** posting-guide.htmlhttp://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] all combinations of the elements of two vectors
Dear R-help readers, I'm sure this problem has been answered but I can't find the solution. I have two vectors v1 - c(a,b) v2 - c(1,2,3) I want an easy way to produce every possible combination of v1, v2 elements Ie I want to produce c(a1,a2,a3, b1,b2,b3) regards Desmond Desmond Campbell Dept of Biostatistics and Computing, Institute of Psychiatry (KCL), PO Box 20, De Crespigny Park, Denmark Hill London, SE5 8AF Tel 020 7848 0309 Email d.campb...@iop.kcl.ac.ukmailto:d.campb...@iop.kcl.ac.uk [[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] eRm/raschsampler error message
Hi, this error message is due to a bug in RaschSampler. I corrected it and sent it to CRAN. RaschSampler version 0.8-5 should be available from there soon. Thanks for the hint and please apologize for any inconveniences. Reinhold -- View this message in context: http://r.789695.n4.nabble.com/eRm-raschsampler-error-message-tp3770265p3773171.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] to represent color range on plot segment
Dear R community, With an advantage of being NEW to R, I would like to post a very basic query here, I am in need of representing gene expression data which ranges from -0.09 to +4, on plot segment. please find below the data df, the expression values are in df[,2]. kindly help me with the code, so that I can represent the values with a clear color gradient (something like -0.09 to 0 as red gradient and 0 to +4 as green gradient) location value 15 chr+:14001-15001 0.99749499 16 chr+:15001-16001 0.99957360 17 chr+:16001-17001 0.99166481 18 chr+:17001-18001 0.97384763 19 chr+:18001-19001 0.94630009 20 chr+:19001-20001 0.90929743 21 chr+:20001-21001 0.86320937 22 chr+:21001-22001 0.80849640 23 chr+:22001-23001 0.74570521 24 chr+:23001-24001 0.67546318 25 chr+:24001-25001 0.59847214 26 chr+:25001-26001 0.51550137 27 chr+:26001-27001 0.42737988 28 chr+:27001-28001 0.33498815 29 chr+:28001-29001 0.23924933 30 chr+:29001-30001 0.14112001 31 chr+:30001-31001 0.04158066 32 chr+:31001-32001 -0.05837414 33 chr+:32001-33001 -0.15774569 34 chr+:33001-34001 -0.25554110 35 chr+:34001-35001 -0.35078323 36 chr+:35001-36001 -0.44252044 37 chr+:36001-37001 -0.52983614 38 chr+:37001-38001 -0.61185789 39 chr+:38001-39001 -0.68776616 40 chr+:39001-40001 -0.75680250 41 chr+:40001-41001 -0.81827711 42 chr+:41001-42001 -0.87157577 43 chr+:42001-43001 -0.91616594 44 chr+:43001-44001 -0.95160207 Thanks in advance, regards, karthick -- View this message in context: http://r.789695.n4.nabble.com/to-represent-color-range-on-plot-segment-tp3773392p3773392.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] all combinations of the elements of two vectors
Hi Desmond, You might try sort(apply(expand.grid(v1, v2), 1, paste, collapse = , sep = )) [1] a1 a2 a3 b1 b2 b3 HTH, Jorge On Sat, Aug 27, 2011 at 12:54 PM, Campbell, Desmond wrote: Dear R-help readers, I'm sure this problem has been answered but I can't find the solution. I have two vectors v1 - c(a,b) v2 - c(1,2,3) I want an easy way to produce every possible combination of v1, v2 elements Ie I want to produce c(a1,a2,a3, b1,b2,b3) regards Desmond Desmond Campbell Dept of Biostatistics and Computing, Institute of Psychiatry (KCL), PO Box 20, De Crespigny Park, Denmark Hill London, SE5 8AF Tel 020 7848 0309 Email d.campb...@iop.kcl.ac.ukmailto:d.campb...@iop.kcl.ac.uk [[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.
Re: [R] all combinations of the elements of two vectors
x-letters[1:3] y-1:3 d-expand.grid(x,y) g-apply(d,1,function(x) paste(x[1],x[2],sep=)) HTH, Daniel Campbell, Desmond-2 wrote: Dear R-help readers, I'm sure this problem has been answered but I can't find the solution. I have two vectors v1 - c(a,b) v2 - c(1,2,3) I want an easy way to produce every possible combination of v1, v2 elements Ie I want to produce c(a1,a2,a3, b1,b2,b3) regards Desmond Desmond Campbell Dept of Biostatistics and Computing, Institute of Psychiatry (KCL), PO Box 20, De Crespigny Park, Denmark Hill London, SE5 8AF Tel 020 7848 0309 Email d.campb...@iop.kcl.ac.uklt;mailto:d.campb...@iop.kcl.ac.ukgt; [[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. -- View this message in context: http://r.789695.n4.nabble.com/all-combinations-of-the-elements-of-two-vectors-tp3773397p3773472.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Overdispersed GLM
Hi all, I have the following data: rep1_treat rep2_treat rep1_control rep2_control 2 3 4 5 100 20 98 54 0 1 2 3 23 3227 28 Two replicates for the treatment and control groups. I want to simulate from the null where the null is: Ho:there is no difference between control and treatment groups. Can R do a glm to do this? Another point is my data is overdispersed, so I would like to fit a negative binomial glm for each variable. Each row is a variable. -- Thanks, Jim. [[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] all combinations of the elements of two vectors
Dear Jorge Yes expand.grid() is exactly what I wanted. This problem keeps cropping up, and I've never known a simple way to implement it. Thanks very much. Regards Desmond From: Jorge I Velez [mailto:jorgeivanve...@gmail.com] Sent: 27 August 2011 19:19 To: Campbell, Desmond Cc: r-help@R-project.org Subject: Re: [R] all combinations of the elements of two vectors Hi Desmond, You might try sort(apply(expand.grid(v1, v2), 1, paste, collapse = , sep = )) [1] a1 a2 a3 b1 b2 b3 HTH, Jorge On Sat, Aug 27, 2011 at 12:54 PM, Campbell, Desmond wrote: Dear R-help readers, I'm sure this problem has been answered but I can't find the solution. I have two vectors v1 - c(a,b) v2 - c(1,2,3) I want an easy way to produce every possible combination of v1, v2 elements Ie I want to produce c(a1,a2,a3, b1,b2,b3) regards Desmond Desmond Campbell Dept of Biostatistics and Computing, Institute of Psychiatry (KCL), PO Box 20, De Crespigny Park, Denmark Hill London, SE5 8AF Tel 020 7848 0309 Email d.campb...@iop.kcl.ac.ukmailto:d.campb...@iop.kcl.ac.uk [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Ordered probit model -marginal effects and relative importance of each predictor-
Hi, I have a problem with the ordered probit model -polr function (library MASS). My independent variables are countinuos. I am not able to understand two main points: a) how to calculate marginal effects b) how to calculate the relative importance of each independent variables If required i will attach my model output. Thanks Franco __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] to represent color range on plot segment
On Sat, Aug 27, 2011 at 11:07 AM, karthicklakshman karthick.laksh...@gmail.com wrote: Dear R community, With an advantage of being NEW to R, I would like to post a very basic query here, Really? I found two posts with your name on it dating from October and November of 2010. http://r-project.markmail.org/search/?q=karthicklakshman I am in need of representing gene expression data which ranges from -0.09 to +4, on plot segment. please find below the data df, the expression values are in df[,2]. kindly help me with the code, so that I can represent the values with a clear color gradient (something like -0.09 to 0 as red gradient and 0 to +4 as green gradient) Please read the posting guide, linked at the bottom of this mail, especially the part about 'reproducible example'. You provided the data, but no code to show that you made a serious effort to solve this problem on your own. Moreover, since this is related to gene expression data, the Bioconductor list may be more appropriate for future questions re gene expression: http://www.bioconductor.org/help/mailing-list/ although this one is within the purview of R-help IMO. Use the sign of value (?sign) as an indicator variable to which you can map colors. I'd also think about creating a value for location (midpoint, maybe?) to simplify the plot call. It shouldn't be too difficult to do this in any of base graphics, lattice or ggplot2. Dennis location value 15 chr+:14001-15001 0.99749499 16 chr+:15001-16001 0.99957360 17 chr+:16001-17001 0.99166481 18 chr+:17001-18001 0.97384763 19 chr+:18001-19001 0.94630009 20 chr+:19001-20001 0.90929743 21 chr+:20001-21001 0.86320937 22 chr+:21001-22001 0.80849640 23 chr+:22001-23001 0.74570521 24 chr+:23001-24001 0.67546318 25 chr+:24001-25001 0.59847214 26 chr+:25001-26001 0.51550137 27 chr+:26001-27001 0.42737988 28 chr+:27001-28001 0.33498815 29 chr+:28001-29001 0.23924933 30 chr+:29001-30001 0.14112001 31 chr+:30001-31001 0.04158066 32 chr+:31001-32001 -0.05837414 33 chr+:32001-33001 -0.15774569 34 chr+:33001-34001 -0.25554110 35 chr+:34001-35001 -0.35078323 36 chr+:35001-36001 -0.44252044 37 chr+:36001-37001 -0.52983614 38 chr+:37001-38001 -0.61185789 39 chr+:38001-39001 -0.68776616 40 chr+:39001-40001 -0.75680250 41 chr+:40001-41001 -0.81827711 42 chr+:41001-42001 -0.87157577 43 chr+:42001-43001 -0.91616594 44 chr+:43001-44001 -0.95160207 Thanks in advance, regards, karthick -- View this message in context: http://r.789695.n4.nabble.com/to-represent-color-range-on-plot-segment-tp3773392p3773392.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Am having trouble calling a function
In my main R program, I have source(retaanalysis/Functions/doAirport.R) stuff to read data and calculate ads sapply(ads,function(x) {doAirport(x, base)} ) And doAirport has # analyze the flights for a given airport doAirport = function(df, base) { # Get rid of unused runway factor levels (from other airports) df$lrw - drop.levels(df$lrw) # In gdata package # Drop messages from after the landing time df = df[df$PredTime = 0.0,] airport = as.character(df[1,Dest]) #print it out airport date = strptime(df[1,on], format=%Y-%m-%d) rwys = factor(unique(df$lrw), ordered=TRUE)# Get the names of the runways rwys = as.vector(rwys) nrwys = length(rwys) # Make a data frame with the correct index for the runway rdf = data.frame(lrw=rwys, rwyidx=seq(1:nrwys)) df = merge(df, rdf, all.x=TRUE) #colours - c(RF = brown, AF =383, PH=red,PF = black, #BA = green, FI = blue, FF = 56, PS = magenta, TC=94) colours - c(0=red,1=black, 2=green, 3=blue,4=magenta,5=orange) shapes - c(RF = R, AF = f, PH=H, PF = P, BA = B, FI = I, FF = F, PS = S, TC=T) #Plot individual flight data dfm = df dfm = dfm[!df$MsgType==AS,] # Eliminate AS messages dfm$MsgType=drop.levels(dfm$MsgType) dfm = dfm[as.numeric(dfm$PredTime) 60.0,] dfm$tc= as.factor(floor(dfm$PredTime/10.0)) # get 10-minute bin dfm$flightfact = drop.levels(dfm$flightfact) row.names(dfm) = seq(1:dim(dfm)[1]) #Find max and min error for each flight library(zoo) maxes = tapply(dfm$dt,dfm$flightfact,FUN=max) # Returns a list mins = tapply(dfm$dt,dfm$flightfact,FUN=min) mdf = data.frame(flight=index(maxes), maxes=as.numeric(maxes), mins=as.numeric(mins)) # Add a column for colors mdf$clr = as.factor((mdf$flight - 1) %% 5) mc = c(red,cyan,green,blue,magenta,black) # Plot these outfile = paste(base, airport, /, airport, ErrorRange, date, .pdf, sep=) pdf(file=outfile, width=14, height=7, par(lwd=.5)) # Get only ones that span 0 lblx = dim(mdf)[1]/2 } And if I manually set df = ads[[j]] doAirport runs OK. But when called from the main program, I always get sapply(ads,function(x) {doAirport(df, base)} ) Error in eval(expr, envir, enclos) : object 'lblx' not found In addition: Warning message: 'mode(onefile)' differs between new and previous == NOT changing 'onefile' sapply(ads,function(x) {doAirport(x, base)} ) Error in eval(expr, envir, enclos) : object 'lblx' not found In addition: Warning message: 'mode(onefile)' differs between new and previous == NOT changing 'onefile' What am I doing wrong? Thanks, Jim E-mail: jamesr...@gmail.com URL: http://jamesrome.net __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Counting non-missing values XXXX
Hello everyone, What is the most elegant and efficient way to count non-missing values of a vector? Thanks! Dan [[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] Counting non-missing values XXXX
sum(!is.na(x)) Michael On Aug 27, 2011, at 4:39 PM, Dan Abner dan.abne...@gmail.com wrote: Hello everyone, What is the most elegant and efficient way to count non-missing values of a vector? Thanks! Dan [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How download Yahoo Quote?
Hi Michael: I tried to simplify the code, but still failed. *con - url(http://quote.yahoo.com;) if(!inherits(try(open(con), silent = TRUE), try-error)) { close(con) x - get.hist.quote(instrument = ibm, quote = c(Cl, Vol)) plot(x, main = International Business Machines Corp) }* It says: * Warning message: In open.connection(con) : too many redirects, aborting ...* The more, it doesn't accept library(quantmod) and says: *Error in library(quantmod) : there is no package called 'quantmod'* Please help me! -- View this message in context: http://r.789695.n4.nabble.com/How-download-Yahoo-Quote-tp3769563p3773622.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Exception while using NeweyWest function with doMC
Dear R users, I am using R right now for a simulation of a model that needs a lot of memory. Therefore I use the *bigmemory* package and - to make it faster - the *doMC* package. See my code posted on http://pastebin.com/dFRGdNrG Now, if I use the foreach loop with the addon %do% (for sequential run) I have no problems at all - only here and there some singularities in regressor matrices which should be ok. BUT if I run the loop on multiple cores I get very often a bad exception. I have posted the exception on http://pastebin.com/eMWF4cu0 The exception comes from the NeweyWest function loaded within the sandwich library. I have no clue, what it want to say me and why it is so weirdly printed to the terminal. I am used to receive here and there errorsbut the messages never look like this. Does anyone have a useful answer for me, where to look for the cause of this weird error? Here some additional information: Hardware: MacBook Pro 2.66 GHz Intel Core Duo, 4 GB Memory 1067 MHz DDR3 Software System: Mac Os X Lion 10.7.1 (11B26) Software App: R64 version 2.11.1 run via Mac terminal I hope someone has a good suggestion! Thank u all! Simon [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How download Yahoo Quote?
Did you install the package quantmod? install.packages(quantmod) Michael On Sat, Aug 27, 2011 at 4:32 PM, Yumin zpx...@gmail.com wrote: Hi Michael: I tried to simplify the code, but still failed. *con - url(http://quote.yahoo.com;) if(!inherits(try(open(con), silent = TRUE), try-error)) { close(con) x - get.hist.quote(instrument = ibm, quote = c(Cl, Vol)) plot(x, main = International Business Machines Corp) }* It says: * Warning message: In open.connection(con) : too many redirects, aborting ...* The more, it doesn't accept library(quantmod) and says: *Error in library(quantmod) : there is no package called 'quantmod'* Please help me! -- View this message in context: http://r.789695.n4.nabble.com/How-download-Yahoo-Quote-tp3769563p3773622.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Placing a column name in a variable XXXX
Hi everyone, How does one place an object name (in this case a vector name) into another object (while essentially masking the values of the first object? For example: JOBSAT-rnorm(40) CI-function(x,alpha){ + result-cbind(x,mean=mean(x),alpha) + print(result) + } CI(JOBSAT,.05) I want this to return: Variablemean alpha JOBSTAT 0.02844131 0.05 Instead, I am getting: x mean alpha [1,] -1.07694997 0.02844131 0.05 [2,] -1.13910850 0.02844131 0.05 [3,] -0.21922026 0.02844131 0.05 [4,] 0.38618008 0.02844131 0.05 [5,] -1.24303799 0.02844131 0.05 [6,] -0.74903752 0.02844131 0.05 [7,] 0.96136975 0.02844131 0.05 [8,] -0.38891237 0.02844131 0.05 [9,] -0.20195871 0.02844131 0.05 [10,] 0.78104508 0.02844131 0.05 [11,] 0.87468778 0.02844131 0.05 [12,] -1.89131480 0.02844131 0.05 Thank you! Dan [13,] 0.74377795 0.02844131 0.05 [14,] -0.60006285 0.02844131 0.05 [15,] -0.76661652 0.02844131 0.05 [16,] 1.06005258 0.02844131 0.05 [17,] 0.02173877 0.02844131 0.05 [18,] -0.36558980 0.02844131 0.05 [19,] -1.92481588 0.02844131 0.05 [20,] -0.50337507 0.02844131 0.05 [21,] 0.82205272 0.02844131 0.05 [22,] 1.59277572 0.02844131 0.05 [23,] 0.59965718 0.02844131 0.05 [[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] Overdispersed GLM
Jim Silverton jim.silverton at gmail.com writes: Hi all, I have the following data: rep1_treat rep2_treat rep1_control rep2_control 2 3 4 5 100 20 98 54 0 1 2 3 23 3227 28 Two replicates for the treatment and control groups. I want to simulate from the null where the null is: Ho:there is no difference between control and treatment groups. Can R do a glm to do this? Another point is my data is overdispersed, so I would like to fit a negative binomial glm for each variable. Each row is a variable. Your data look a little weird. Do you really have (0,2) and (100,23) as responses for rep1_treat, or are those indices that got mangled somehow? In any case, you need to rearrange your data to long format: d - data.frame(rep1_treat=c(2,100,0,23), rep2_treat=c(3,20,1,32), rep1_control=c(4,98,2,27), rep2_control=c(5,54,3,28)) library(reshape) d2 - melt(d) d3 - data.frame(d2,colsplit(d2$variable,_,c(rep,ttt))) library(lattice) xyplot(value~ttt:rep,data=d3) library(MASS) g1 - glm.nb(value~1,data=d3) simulate(g1) ## simulate from null model g2 - glm.nb(value~ttt,data=d3) You may need to consider the possibility that rep1 and rep2 are different. In principle 'rep' should be treated as a random effect, but with only two reps that's not really feasible, so try including it as an interaction instead (i.e. value~rep*ttt) __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 download Yahoo Quote?
- Original Message - From: Yumin [via R] To: Yumin Sent: Saturday, August 27, 2011 3:32 PM Subject: Re: How download Yahoo Quote? Hi Michael: I tried to simplify the code, but still failed. con - url(http://quote.yahoo.com;) if(!inherits(try(open(con), silent = TRUE), try-error)) { close(con) x - get.hist.quote(instrument = ibm, quote = c(Cl, Vol)) plot(x, main = International Business Machines Corp) } It says: Warning message: In open.connection(con) : too many redirects, aborting ... The more, it doesn't accept library(quantmod) and says: Error in library(quantmod) : there is no package called 'quantmod' Please help me! -- If you reply to this email, your message will be added to the discussion below: http://r.789695.n4.nabble.com/How-download-Yahoo-Quote-tp3769563p3773622.html To unsubscribe from How download Yahoo Quote?, click here. -- View this message in context: http://r.789695.n4.nabble.com/How-download-Yahoo-Quote-tp3769563p3773703.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Am having trouble calling a function
First of all, please replace your = with - per general R-usage rules. Next: you need to provide a clear listing of doAirport.R so we can tell what it actually is, and what you've done outside the function. That said, my suspicion is that your parent function (the one which calls doAirport) isn't providing a proper set of inputs to create the mdf data frame. Hence dim(mdf) returns something bad and lblx doesn't exist. quote In my main R program, I have source(retaanalysis/Functions/doAirport.R) stuff to read data and calculate ads sapply(ads, function(x) {doAirport(x, base)} ) And doAirport has # analyze the flights for a given airport doAirport = function(df, base) { # Get rid of unused runway factor levels (from other airports) df$lrw - drop.levels(df$lrw) # In gdata package # Drop messages from after the landing time df = df[df$PredTime = 0.0,] airport = as.character(df[1,Dest]) #print it out airport date = strptime(df[1,on], format=%Y-%m-%d) rwys = factor(unique(df$lrw), ordered=TRUE) # Get the names of the runways rwys = as.vector(rwys) nrwys = length(rwys) # Make a data frame with the correct index for the runway rdf = data.frame(lrw=rwys, rwyidx=seq(1:nrwys)) df = merge(df, rdf, all.x=TRUE) #colours - c(RF = brown, AF =383, PH=red,PF = black, #BA = green, FI = blue, FF = 56, PS = magenta, TC=94) colours - c(0=red,1=black, 2=green, 3=blue,4=magenta,5=orange) shapes - c(RF = R, AF = f, PH=H, PF = P, BA = B, FI = I, FF = F, PS = S, TC=T) #Plot individual flight data dfm = df dfm = dfm[!df$MsgType==AS,] # Eliminate AS messages dfm$MsgType=drop.levels(dfm$MsgType) dfm = dfm[as.numeric(dfm$PredTime) 60.0,] dfm$tc= as.factor(floor(dfm$PredTime/10.0)) # get 10-minute bin dfm$flightfact = drop.levels(dfm$flightfact) row.names(dfm) = seq(1:dim(dfm)[1]) #Find max and min error for each flight library(zoo) maxes = tapply(dfm$dt,dfm$flightfact,FUN=max) # Returns a list mins = tapply(dfm$dt,dfm$flightfact,FUN=min) mdf = data.frame(flight=index(maxes), maxes=as.numeric(maxes), mins=as.numeric(mins)) # Add a column for colors mdf$clr = as.factor((mdf$flight - 1) %% 5) mc = c(red,cyan,green,blue,magenta,black) # Plot these outfile = paste(base, airport, /, airport, ErrorRange, date, .pdf, sep=) pdf(file=outfile, width=14, height=7, par(lwd=.5)) # Get only ones that span 0 lblx = dim(mdf)[1]/2 } And if I manually set df = ads[[j]] doAirport runs OK. But when called from the main program, I always get sapply(ads, function(x) {doAirport(df, base)} ) Error in eval(expr, envir, enclos) : object 'lblx' not found In addition: Warning message: 'mode(onefile)' differs between new and previous == NOT changing 'onefile' sapply(ads, function(x) {doAirport(x, base)} ) Error in eval(expr, envir, enclos) : object 'lblx' not found In addition: Warning message: 'mode(onefile)' differs between new and previous == NOT changing 'onefile' What am I doing wrong? Thanks, Jim E-mail: jamesrome_at_gmail.com URL: http://jamesrome.net -- - Sent from my Cray XK6 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Am having trouble calling a function
Add the following to your script: options(error=utils::recover) (actually put it in you Startup script), then learn how to use the debugging in R. On the error, this should provide a trace of the stack so that we know where the error occurs. By learning how to use debug/browser, you will be able to see what the environment is at the point of the error, then maybe some assistance can be given. On Sat, Aug 27, 2011 at 4:34 PM, James Rome jamesr...@gmail.com wrote: In my main R program, I have source(retaanalysis/Functions/doAirport.R) stuff to read data and calculate ads sapply(ads, function(x) {doAirport(x, base)} ) And doAirport has # analyze the flights for a given airport doAirport = function(df, base) { # Get rid of unused runway factor levels (from other airports) df$lrw - drop.levels(df$lrw) # In gdata package # Drop messages from after the landing time df = df[df$PredTime = 0.0,] airport = as.character(df[1,Dest]) #print it out airport date = strptime(df[1,on], format=%Y-%m-%d) rwys = factor(unique(df$lrw), ordered=TRUE) # Get the names of the runways rwys = as.vector(rwys) nrwys = length(rwys) # Make a data frame with the correct index for the runway rdf = data.frame(lrw=rwys, rwyidx=seq(1:nrwys)) df = merge(df, rdf, all.x=TRUE) #colours - c(RF = brown, AF =383, PH=red,PF = black, #BA = green, FI = blue, FF = 56, PS = magenta, TC=94) colours - c(0=red,1=black, 2=green, 3=blue,4=magenta,5=orange) shapes - c(RF = R, AF = f, PH=H, PF = P, BA = B, FI = I, FF = F, PS = S, TC=T) #Plot individual flight data dfm = df dfm = dfm[!df$MsgType==AS,] # Eliminate AS messages dfm$MsgType=drop.levels(dfm$MsgType) dfm = dfm[as.numeric(dfm$PredTime) 60.0,] dfm$tc= as.factor(floor(dfm$PredTime/10.0)) # get 10-minute bin dfm$flightfact = drop.levels(dfm$flightfact) row.names(dfm) = seq(1:dim(dfm)[1]) #Find max and min error for each flight library(zoo) maxes = tapply(dfm$dt,dfm$flightfact,FUN=max) # Returns a list mins = tapply(dfm$dt,dfm$flightfact,FUN=min) mdf = data.frame(flight=index(maxes), maxes=as.numeric(maxes), mins=as.numeric(mins)) # Add a column for colors mdf$clr = as.factor((mdf$flight - 1) %% 5) mc = c(red,cyan,green,blue,magenta,black) # Plot these outfile = paste(base, airport, /, airport, ErrorRange, date, .pdf, sep=) pdf(file=outfile, width=14, height=7, par(lwd=.5)) # Get only ones that span 0 lblx = dim(mdf)[1]/2 } And if I manually set df = ads[[j]] doAirport runs OK. But when called from the main program, I always get sapply(ads, function(x) {doAirport(df, base)} ) Error in eval(expr, envir, enclos) : object 'lblx' not found In addition: Warning message: 'mode(onefile)' differs between new and previous == NOT changing 'onefile' sapply(ads, function(x) {doAirport(x, base)} ) Error in eval(expr, envir, enclos) : object 'lblx' not found In addition: Warning message: 'mode(onefile)' differs between new and previous == NOT changing 'onefile' What am I doing wrong? Thanks, Jim E-mail: jamesr...@gmail.com URL: http://jamesrome.net __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Placing a column name in a variable XXXX
The function is doing exactly what you are telling it to do. You have 'cbind(x, mean(x), alpha)' which is creating a matrix where the first column is all the values in 'x' and the next two are the recycled values of mean and alpha. Is this what you want: JOBSAT-rnorm(10) CI-function(x,alpha){ + cbind(x,mean=mean(x),alpha) + } CI(JOBSAT,.05) x mean alpha [1,] 0.8592324 -0.1240675 0.05 [2,] -0.3128362 -0.1240675 0.05 [3,] -2.0042218 -0.1240675 0.05 [4,] -0.4675232 -0.1240675 0.05 [5,] -0.5776273 -0.1240675 0.05 [6,] 1.5696650 -0.1240675 0.05 [7,] 0.8070593 -0.1240675 0.05 [8,] -0.8257525 -0.1240675 0.05 [9,] 0.6167636 -0.1240675 0.05 [10,] -0.9054347 -0.1240675 0.05 # new function that does not return 'x' CInew -function(x,alpha){ + c(mean=mean(x), alpha = alpha) + } CInew(JOBSAT,.05) mean alpha -0.1240675 0.050 On Sat, Aug 27, 2011 at 5:38 PM, Dan Abner dan.abne...@gmail.com wrote: Hi everyone, How does one place an object name (in this case a vector name) into another object (while essentially masking the values of the first object? For example: JOBSAT-rnorm(40) CI-function(x,alpha){ + result-cbind(x,mean=mean(x),alpha) + print(result) + } CI(JOBSAT,.05) I want this to return: Variable mean alpha JOBSTAT 0.02844131 0.05 Instead, I am getting: x mean alpha [1,] -1.07694997 0.02844131 0.05 [2,] -1.13910850 0.02844131 0.05 [3,] -0.21922026 0.02844131 0.05 [4,] 0.38618008 0.02844131 0.05 [5,] -1.24303799 0.02844131 0.05 [6,] -0.74903752 0.02844131 0.05 [7,] 0.96136975 0.02844131 0.05 [8,] -0.38891237 0.02844131 0.05 [9,] -0.20195871 0.02844131 0.05 [10,] 0.78104508 0.02844131 0.05 [11,] 0.87468778 0.02844131 0.05 [12,] -1.89131480 0.02844131 0.05 Thank you! Dan [13,] 0.74377795 0.02844131 0.05 [14,] -0.60006285 0.02844131 0.05 [15,] -0.76661652 0.02844131 0.05 [16,] 1.06005258 0.02844131 0.05 [17,] 0.02173877 0.02844131 0.05 [18,] -0.36558980 0.02844131 0.05 [19,] -1.92481588 0.02844131 0.05 [20,] -0.50337507 0.02844131 0.05 [21,] 0.82205272 0.02844131 0.05 [22,] 1.59277572 0.02844131 0.05 [23,] 0.59965718 0.02844131 0.05 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] to represent color range on plot segment
?colorRamp On Sat, Aug 27, 2011 at 2:07 PM, karthicklakshman karthick.laksh...@gmail.com wrote: Dear R community, With an advantage of being NEW to R, I would like to post a very basic query here, I am in need of representing gene expression data which ranges from -0.09 to +4, on plot segment. please find below the data df, the expression values are in df[,2]. kindly help me with the code, so that I can represent the values with a clear color gradient (something like -0.09 to 0 as red gradient and 0 to +4 as green gradient) location value 15 chr+:14001-15001 0.99749499 16 chr+:15001-16001 0.99957360 17 chr+:16001-17001 0.99166481 18 chr+:17001-18001 0.97384763 19 chr+:18001-19001 0.94630009 20 chr+:19001-20001 0.90929743 21 chr+:20001-21001 0.86320937 22 chr+:21001-22001 0.80849640 23 chr+:22001-23001 0.74570521 24 chr+:23001-24001 0.67546318 25 chr+:24001-25001 0.59847214 26 chr+:25001-26001 0.51550137 27 chr+:26001-27001 0.42737988 28 chr+:27001-28001 0.33498815 29 chr+:28001-29001 0.23924933 30 chr+:29001-30001 0.14112001 31 chr+:30001-31001 0.04158066 32 chr+:31001-32001 -0.05837414 33 chr+:32001-33001 -0.15774569 34 chr+:33001-34001 -0.25554110 35 chr+:34001-35001 -0.35078323 36 chr+:35001-36001 -0.44252044 37 chr+:36001-37001 -0.52983614 38 chr+:37001-38001 -0.61185789 39 chr+:38001-39001 -0.68776616 40 chr+:39001-40001 -0.75680250 41 chr+:40001-41001 -0.81827711 42 chr+:41001-42001 -0.87157577 43 chr+:42001-43001 -0.91616594 44 chr+:43001-44001 -0.95160207 Thanks in advance, regards, karthick -- View this message in context: http://r.789695.n4.nabble.com/to-represent-color-range-on-plot-segment-tp3773392p3773392.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] data manipulation and summaries with few million rows
Factors are you friend here: myData mydate gender mygroup id mygrp.f 1 2012-03-25 F A 1 1 2 2005-05-23 F B 2 2 3 2005-09-08 F B 2 2 4 2005-12-07 F B 2 2 5 2006-02-26 F C 2 3 6 2006-05-13 F C 2 3 7 2006-09-01 F C 2 3 8 2006-12-12 F D 2 4 9 2006-02-19 F D 2 4 10 2006-05-03 F D 2 4 11 2006-04-23 F D 2 4 12 2007-12-08 F D 2 4 13 2011-03-19 F D 2 4 14 2007-12-20 M A 3 1 15 2008-06-15 M A 3 1 16 2008-12-16 M A 3 1 17 2009-06-07 M B 3 2 18 2009-10-09 M B 3 2 19 2010-01-28 M B 3 2 20 2007-06-05 M A 4 1 # change 'mygroup' to a factor so you can use 'diff' to count the changes myData$mygrp.f - as.integer(factor(myData$mygroup)) # count the changes for each 'id' changes - tapply(myData$mygrp.f, myData$id, function(x){ + sum(diff(x) != 0) + }) changes 1 2 3 4 0 2 1 0 On Wed, Aug 24, 2011 at 12:48 PM, Juliet Hannah juliet.han...@gmail.com wrote: I have a data set with about 6 million rows and 50 columns. It is a mixture of dates, factors, and numerics. What I am trying to accomplish can be seen with the following simplified data, which is given as dput output below. head(myData) mydate gender mygroup id 1 2012-03-25 F A 1 2 2005-05-23 F B 2 3 2005-09-08 F B 2 4 2005-12-07 F B 2 5 2006-02-26 F C 2 6 2006-05-13 F C 2 For each id, I want to count the number of changes of the variable 'mygroup' that occur. For example, id=1 has 0 changes because it is observed only once. id=2 has 2 changes (B to C, and C to D). I also need to calculate the total observation time for each id using the variable mydate. In the end, I am trying to have a new data set in which each row has an id, days observed, number of changes, and gender. I made some simple summaries using data.table and plyr, but I'm stuck on this reformatting. Thanks for your help. myData - structure(list(mydate = c(2012-03-25, 2005-05-23, 2005-09-08, 2005-12-07, 2006-02-26, 2006-05-13, 2006-09-01, 2006-12-12, 2006-02-19, 2006-05-03, 2006-04-23, 2007-12-08, 2011-03-19, 2007-12-20, 2008-06-15, 2008-12-16, 2009-06-07, 2009-10-09, 2010-01-28, 2007-06-05), gender = c(F, F, F, F, F, F, F, F, F, F, F, F, F, M, M, M, M, M, M, M), mygroup = c(A, B, B, B, C, C, C, D, D, D, D, D, D, A, A, A, B, B, B, A), id = c(1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 4L)), .Names = c(mydate, gender, mygroup, id), class = data.frame, row.names = c(NA, -20L )) sessionInfo() R version 2.13.1 (2011-07-08) Platform: x86_64-unknown-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.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] stats graphics grDevices utils datasets methods base __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Placing a column name in a variable XXXX
In this case you want to use a 'list' since you want character and numerics returned: JOBSTAT-rnorm(10) # new function that does not return 'x' CInew -function(x,alpha){ + list(variable = deparse(substitute(x)), mean=mean(x), alpha = alpha) + } CInew(JOBSTAT, 0.05) $variable [1] JOBSTAT $mean [1] -1.113034 $alpha [1] 0.05 On Sat, Aug 27, 2011 at 6:58 PM, Dan Abner dan.abne...@gmail.com wrote: I want to it return: Variable Mean alpha JOBSTAT -0.1240675 0.05 How do I get the function parameter x to equal the name of the object that is specified as x as a character string? On Sat, Aug 27, 2011 at 6:41 PM, jim holtman jholt...@gmail.com wrote: The function is doing exactly what you are telling it to do. You have 'cbind(x, mean(x), alpha)' which is creating a matrix where the first column is all the values in 'x' and the next two are the recycled values of mean and alpha. Is this what you want: JOBSAT-rnorm(10) CI-function(x,alpha){ + cbind(x,mean=mean(x),alpha) + } CI(JOBSAT,.05) x mean alpha [1,] 0.8592324 -0.1240675 0.05 [2,] -0.3128362 -0.1240675 0.05 [3,] -2.0042218 -0.1240675 0.05 [4,] -0.4675232 -0.1240675 0.05 [5,] -0.5776273 -0.1240675 0.05 [6,] 1.5696650 -0.1240675 0.05 [7,] 0.8070593 -0.1240675 0.05 [8,] -0.8257525 -0.1240675 0.05 [9,] 0.6167636 -0.1240675 0.05 [10,] -0.9054347 -0.1240675 0.05 # new function that does not return 'x' CInew -function(x,alpha){ + c(mean=mean(x), alpha = alpha) + } CInew(JOBSAT,.05) mean alpha -0.1240675 0.050 On Sat, Aug 27, 2011 at 5:38 PM, Dan Abner dan.abne...@gmail.com wrote: Hi everyone, How does one place an object name (in this case a vector name) into another object (while essentially masking the values of the first object? For example: JOBSAT-rnorm(40) CI-function(x,alpha){ + result-cbind(x,mean=mean(x),alpha) + print(result) + } CI(JOBSAT,.05) I want this to return: Variable mean alpha JOBSTAT 0.02844131 0.05 Instead, I am getting: x mean alpha [1,] -1.07694997 0.02844131 0.05 [2,] -1.13910850 0.02844131 0.05 [3,] -0.21922026 0.02844131 0.05 [4,] 0.38618008 0.02844131 0.05 [5,] -1.24303799 0.02844131 0.05 [6,] -0.74903752 0.02844131 0.05 [7,] 0.96136975 0.02844131 0.05 [8,] -0.38891237 0.02844131 0.05 [9,] -0.20195871 0.02844131 0.05 [10,] 0.78104508 0.02844131 0.05 [11,] 0.87468778 0.02844131 0.05 [12,] -1.89131480 0.02844131 0.05 Thank you! Dan [13,] 0.74377795 0.02844131 0.05 [14,] -0.60006285 0.02844131 0.05 [15,] -0.76661652 0.02844131 0.05 [16,] 1.06005258 0.02844131 0.05 [17,] 0.02173877 0.02844131 0.05 [18,] -0.36558980 0.02844131 0.05 [19,] -1.92481588 0.02844131 0.05 [20,] -0.50337507 0.02844131 0.05 [21,] 0.82205272 0.02844131 0.05 [22,] 1.59277572 0.02844131 0.05 [23,] 0.59965718 0.02844131 0.05 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] issue with available.packages() and download.file()
On 11-08-25 9:52 PM, Seth Schommer wrote: Dear R-Users, I think I have encountered a potential bug (or at least unwanted behavior), but I'm not sure so I wanted to post here first. Lately I've been I'd say it's a bug with your network setup: when a URL is not found, an error should be generated. Helpful servers that give you ads or a search page instead are not following the rules. Unfortunately, this is a pretty common misconfiguration, so perhaps R should try to work around it. If you want to put together a suggested patch, I'll take a look. The source is in https://svn.r-project.org/R/trunk/src/library/utils/R/packages.R. Duncan Murdoch encountering an error when running a package I put together. I have my package set up to check for updates when it loads but this error occurs and stops the package from loading: Error : .onLoad failed in loadNamespace() for 'rNMR', details: call: read.dcf(file = tmpf) error: Line starting 'SCRIPT language=Jav ...' is malformed! Error: package/namespace load failed for 'rNMR' I tracked to the following line of code from my package: available.packages(contrib.url(repos = http://rnmr.nmrfam.wisc.edu/R/;, type = win.binary)) I dug a little deeper and found the following line of code from available.packages() to be causing the problem: z- tryCatch(download.file(url = paste(repos, PACKAGES.gz, sep = /), destfile = tmpf, method = method, cacheOK = FALSE, quiet = TRUE, mode = wb), error = identity) The problem occurs because PACKAGES.gz does not exist in the repository, so my router redirects the invalid URL to a search page and some JavaScript is downloaded instead. The error is generated when R tries to read the downloaded file: res0- read.dcf(file = tmpf) Error in read.dcf(file = tmpf) : Line starting 'SCRIPT language=Jav ...' is malformed! The repository does have a PACKAGES file, but it never gets read because download.file() does not generate an error. I've fixed the issue by uploading a PACKAGES.gz file to the repository, but I wanted to point out the issue in case anybody else has encountered this problem. This problem may be unique to my particular system configuration, in which case a fix may not be justified. Otherwise, it may be a good idea to check for a PACKAGES file in the repository if an error is encountered when trying to read the downloaded PACKAGES.gz file. Thanks, Seth R Version: platform = i386-pc-mingw32 arch = i386 os = mingw32 system = i386, mingw32 status = Patched major = 2 minor = 13.1 year = 2011 month = 08 day = 19 svn rev = 56771 language = R version.string = R version 2.13.1 Patched (2011-08-19 r56771) Windows 7 (build 7601) Service Pack 1 Locale: LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252 Search Path: .GlobalEnv, package:tcltk, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, package:methods, Autoloads, package:base [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] control line break behavior of R output
Hi, Is it possible to define at which point a line-break is happening in R-output? I for example would rather like to scroll horizontally in a data-frame with a lot of columns instead of having a lot of breakpoints in the data.frame (to fit the screen). Can you control that? Can you tell R to do a line-break after x symbols of output for example? thanks! __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] calculating avg silhouette with fpc package
All, Excuse me for being a newbie. I'm trying to calculate the average silhouette, a measure of cluster validity. I've already brought my spss data in. It's 1008 cases with 8 variables, no missing data. So far I've run this: fit - agnes(mydata, diss= FALSE, metric = euclidean, stand=FALSE, method = ward) When I look at the results for this command it appears to be more than just the distance matrix I need to plug into cluster.stats in the fpc package. How do I isolate the distance matrix so that I can then run cluster.stats? Any help is much appreciated. If you need me to clarify with more info please ask. Thanks matt __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 download Yahoo Quote?
Hi Michael: I installed: install. packages(quantmod) and now it accept library(quantmod) sentence. BUT after input: * con - url(http://quote.yahoo.com;) if(!inherits(try(open(con), silent = TRUE), try-error)) { close(con) x - get.hist.quote(instrument = ibm, quote = c(Cl, Vol)) plot(x, main = International Business Machines Corp) }* The result is the same: *Warning message: In open.connection(con) : too many redirects, aborting ...* ps: the 1st line of my code is: library(quantmod) -- View this message in context: http://r.789695.n4.nabble.com/How-download-Yahoo-Quote-tp3769563p3773771.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Legent to the Periodogram
How Can I add a legent (showing x1, x2, x3, x4) to the last plot? require(TSA) require(graphics) require(stats) t-1986:2011 x1-cos(t*1990/2011) x2-cos(t*2000/20011) x3-sin(t*1990/2011) x4-sin(t*2000/2011) y-cbind(t,x1,x2, x3,x4) y.time = ts(y.time, start=1986, frequency=1) y.spc-spec.pgram(y.time, spans = c(3,3), detrend=FALSE,log=no,plot = TRUE, kernel(modified.daniell, c(5,7))) plot(y.spc, plot.type = marginal, main=Smoothed Periodogram) Peter Maclean Department of Economics UDSM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 download Yahoo Quote?
What is wrong with the getSymbols(IBM) command I originally suggested to you? Michael On Sat, Aug 27, 2011 at 6:23 PM, Yumin zpx...@gmail.com wrote: Hi Michael: I installed: install. packages(quantmod) and now it accept library(quantmod) sentence. BUT after input: * con - url(http://quote.yahoo.com;) if(!inherits(try(open(con), silent = TRUE), try-error)) { close(con) x - get.hist.quote(instrument = ibm, quote = c(Cl, Vol)) plot(x, main = International Business Machines Corp) }* The result is the same: *Warning message: In open.connection(con) : too many redirects, aborting ...* ps: the 1st line of my code is: library(quantmod) -- View this message in context: http://r.789695.n4.nabble.com/How-download-Yahoo-Quote-tp3769563p3773771.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Ordered probit model -marginal effects and relative importance of each predictor-
On Aug 27, 2011, at 3:15 PM, franco salerno wrote: Hi, I have a problem with the ordered probit model -polr function (library MASS). My independent variables are countinuos. I am not able to understand two main points: a) how to calculate marginal effects b) how to calculate the relative importance of each independent variables If required i will attach my model output. It is a great puzzle to me that people think that the output of a statistical program can be interpreted without a clear and complete description of the input. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] control line break behavior of R output
On Aug 27, 2011, at 8:19 PM, Martin Batholdy wrote: Hi, Is it possible to define at which point a line-break is happening in R-output? I for example would rather like to scroll horizontally in a data- frame with a lot of columns instead of having a lot of breakpoints in the data.frame (to fit the screen). Can you control that? Can you tell R to do a line-break after x symbols of output for example? options() with a width argument ... and whatever GUI you uae may have further setting, but per usual none of that information was provided. -- David Winsemius, MD West Hartford, CT __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Legent to the Periodogram
plot.spec uses matplot. see ?matplot for default col lty and use legend as usual. P.S. You can add plot=FALSE to spec.pgram to prevent it from plotting On 08/27/2011 05:39 PM, Peter Maclean wrote: How Can I add a legent (showing x1, x2, x3, x4) to the last plot? require(TSA) require(graphics) require(stats) t-1986:2011 x1-cos(t*1990/2011) x2-cos(t*2000/20011) x3-sin(t*1990/2011) x4-sin(t*2000/2011) y-cbind(t,x1,x2, x3,x4) y.time = ts(y.time, start=1986, frequency=1) y.spc-spec.pgram(y.time, spans = c(3,3), detrend=FALSE,log=no,plot = TRUE, kernel(modified.daniell, c(5,7))) plot(y.spc, plot.type = marginal, main=Smoothed Periodogram) Peter Maclean Department of Economics UDSM __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Trying to extract probabilities in CARET (caret) package with a glmStepAIC model
Dear developers, I have jutst started working with caret and all the nice features it offers. But I just encountered a problem: I am working with a dataset that include 4 predictor variables in Descr and a two-category outcome in Categ (codified as a factor). Everything was working fine I got the results, confussion matrix etc. BUT for obtaining the AUC and predicted probabilities I had to add classProbs = TRUE, in the trainControl. Thereafter everytime I run train I get this message: undefined columns selected I copy the syntax: fitControl - trainControl(method = cv, number = 10, classProbs = TRUE,returnResamp = all, verboseIter = FALSE) glmFit - train(Descr, Categ, method = glmStepAIC,tuneLength = 4,trControl = fitControl) Thank you. Best regards, Jon Toledo, MD Postdoctoral fellow University of Pennsylvania School of Medicine Center for Neurodegenerative Disease Research 3600 Spruce Street 3rd Floor Maloney Building Philadelphia, Pa 19104 [[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.