[R] Error when running coeftest in plm
Dear R-helpers, I am using plm package to run panel data analysis for different models with different dependent variables. After running the PLM, I run the COEFTEST(plm1, vcovBK) to get the panel corrected standard errors. I got the PCSEs for some of the models but some tests produce error message. In one of the COEFTEST, the error message is: Error in solve.default(crossprod(demX)) : system is computationally singular: reciprocal condition number = 1.404e-017 What should I do to fix it and get the PCSEs? Thanks a lot, Hien Nguyen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 question: strategy
Just a heads up: I'm pretty sure Josh and the other QS developers have access to intra-day data, but they can't provide an example using it in the package because the EULAs of most data providers won't allow direct redistribution of their data. The examples included all go online and download data from a free source, but they don't provide it directly because even the free providers like Yahoo don't allow that. [There's a whole beer vs speech thing at play here] If you do put truly free intraday numbers online, you'll be doing a big service to the community, but make sure it's legal before you start. You'll also note that the older packages in the quant(mod|strat) universe like TTR don't use real data for their examples: rather they use simulated data to avoid all such issues. I imagine full quanstrat documentation will appear in time, but it's still under (very) active development so the mailing list archive examples are the best currently available. Once the system and the API are finalized, then it will make sense to document them. Hope this helps, Michael On Sat, Apr 7, 2012 at 10:15 PM, sysot1t syso...@gmail.com wrote: yes, I would have expected documented samples for something simple.. as I said, I am not asking for anything complex but something rather simple that I can use to learn from and build upon.. not a highly complex example that provides me with little explanation of what is going on... quanstrat is great, and it simplifies things, but hard to use if it is not clearly and extensively documented.. the demos are good, but again... one line describing what a block of 5-10 lines do.. that drives one to look into what the functions are actually doing and it can drive one nuts... just my 2 cents given I believe you are one of the experts on qstrat... with regard to intraday... I didn't realize that most people dont have access to intraday sources for data... I figure if you are using R for quant work, then you have access to RT data... btw, I am not a quant, I am an IT architect who trades his own retirement account... in any event, I will create a website and publish csv's for any universe of instruments and markets... for free ... in the same spirit of opensource that R was written on ... I just registered quantstrat-rt.com... both minute and tick data will be posted.. for all to use for analysis.. with the obvious disclaimers about the data of course. lastly, I dont mind putting in the time and effort to learn something, as long as proper and adequate learning resources are available... a few hours ago I ordered more books about R from springer this time... all those books are great to learn R itself, but useless to learn all the custom modules that are out there... quantmod has good docs, so does timesac and performanceanalytics... and one can go line by line (as I have done today) to see what all the samples do and how they are altering the information... but nothing formalized for learning to leverage them, just trial and error (which can be frustrating) I didnt ask for anyone to do my work for me, but rather I expected anyone that had done something similar to share what they had done so that I could learn from it... simple and straight forward... anyhow, feel free to send me a pm with your email contact information and I will reach out ... your reply is much appreciated. -- View this message in context: http://r.789695.n4.nabble.com/newbie-question-strategy-tp4538818p4540381.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] Avoid loop with the integrate function
On 08-04-2012, at 08:28, Navin Goyal wrote: Dear R users, I am running a loop with the integrate function. I have pasted the code below. I am integrating a function from time=0 to the time value in every row. I have to perform this integration over thousands of rows with different parameters in each row. Could someone please suggest if there is an efficient/faster/easier way to do this by avoiding the loops ? Thank you so much for your help and time. -- Navin Goyal # dose-10 time-0:5 id-1:5 data1-expand.grid(id,time,dose) names(data1)-c(ID,TIME, DOSE) data1-data1[order(data1$ID,data1$TIME),] ed-data1[!duplicated(data1$ID) , c(ID,DOSE)] set.seed(5324123) for (k in 1:length(ed$ID)) { ed$base[k]-100*exp(rnorm(1,0,0.05)) ed$drop[k]-0.2*exp(rnorm(1,0,0.01)) ed$frac[k]-0.5*exp(rnorm(1,0,0.1)) } Why not ed$base - 100*exp(rnorm(length(ed$ID), 0, 0.05)) etc. comb1-merge(data1[, c(ID,TIME)], ed) comb2-comb1 comb2$score-comb2$base*exp(-comb2$drop*comb2$TIME) func1-function(t,cov1,beta1, change,other) { ifelse(t==0,cov1, cov1*exp(beta1*change+other)) } AFAICS, cov1, beta1, change and other are scalars. So when an item of t is == 0 then the function value is cov1 and in all other cases it is the same scalar and does not depend on t. So func1 is a step function. You could calculate the integral directly. Berend __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Need help interpreting output from rcorrp.cens with Cox regression
Dear R-listers, I am an MD and clinical epidemiologist developing a measure of comorbidity severity for patients with liver disease. Having developed my comorbidity score as the linear predictor from a Cox regression model I want to compare the discriminative ability of my comorbidity measure with the old comorbidity measure, Charlson's Comorbidity Index. I have nearly 10,000 deaths and 36 candidate comorbidities. I wish to compare the discrimination of the two comorbidity measures, i.e. I have two non-nested Cox models. I get the following output with rcorrp.cens(myscore.lp, charlson.lp, Surv(time, dead), method=1): x1 = My comorbidity score, x2 = Charlson [,1] Dxy-0.0605 S.D. 0.00648 x1 more concordant 0.4697 x2 more concordant 0.5302 n 1.369e+04 missing0 uncensored 9411 Relevant Pairs 1.587e+08 Uncertain 2.861e+07 C X1 0.395 C X2 0.401 Dxy X1 -0.21 Dxy X2 -0.198 I am aware that because a high hazard means short survival I must subtract C X1 and C X2 from 1, so my comorbidity score has marginally better discrimination than the Charlson score (C = 0.605 vs. 0.599; with correction for optimism bias using the rms package my model's C falls to 0.602). Question: Is it true that my score is more discriminative than the Charlson score in 53% of patient pairs? I have done the same analysis with 'method = 2', i.e. rcorrp.cens(myscore.lp, charlson.lp, Surv(time, dead), method=2): x1 = My comorbidity score, x2 = Charlson [,1] Dxy-0.006002 S.D. 0.001102 x1 more concordant 0.04018 x2 more concordant 0.04618 n 1.369e+04 missing0 uncensored 9411 Relevant Pairs 1.587e+08 Uncertain 2.861e+07 C X1 0.395 C X2 0.401 Dxy X1 -0.21 Dxy X2 -0.198 Question: How do I interpret the 'x1/x2 more concordant' numbers in a Cox regression setting? My guess: My comorbidity score concordant in 4.6% of pairs but Charlson's score is not. And Charlson's score is concordant in 4.0% of pairs but my comorbidity score is not. Thank you in advance for your insight and help. Best regards, Peter Jepsen Aarhus, 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.
[R] xyplot() does not plot legends with relation=free scales
Hi all, I have this problem with lattice that xyplot() won't draw some of my axis labels if the type (i.e. the relation argument) of scales is set as free. For example, in the plot below, I would want it to also show: 1. the labels E1,...E6 below the 10th panel (i.e. 3rd row, 2 col)just as it is now done below the 12th panel 2. as well as the labels (2,4,6,8) on the top of panels 1 and 3 (by on top, i mean above the strips, as xyplot normally does by default but can't seem to be willing to do in the example below). PS: i had originally posted this question on stackoverlow but since i didn't get an answer there i've deleted it there and posting it here. Happy Easter, B-structure(list(yval = c(0.7, 0.61, 0.65, 0.63, 6.08, 0.64, 5.68, 6.77, 1.48, 7.71, 0.82, 1.15, 0.54, 1.01, 0.59, 4.84, 0.69, 0.71, 8.7, 0.48, 0.69, 4.81, 1.42, 1.19, 0.84, 4.89, 0.85, 0.67, 7.07, 0.66, 7.93, 0.69, 5.94, 0.47, 0.7, 0.73, 0.5, 3.62, 9.55, 4.48, 9.44, 1.06, 0.36, 0.73, 0.67, 1.4, 0.56, 7.07, 0.69, 0.42, 3.72, 0.8, 0.94, 0.66, 0.48, 6.94, 3.19, 0.84, 1.27, 1.85, 5.23, 0.75, 0.55, 4.69, 8.51, 3.98, 0.65, 4.72, 0.94, 0.86, 6.27, 3.42, 1.03, 1.83, 0.86, 8.59, 0.72, 7.92, 0.84, 0.49, 0.78, 7.31, 5.15, 0.88, 0.57, 0.95, 0.69, 8.77, 0.86, 0.82, 2.02, 6.99, 5.01, 0.84, 1.09, 1.02, 0.66, 9.23, 0.74, 2.21), xval = c(0.7, 0.61, 0.65, 0.63, 6.08, 0.64, 5.68, 6.77, 1.48, 7.71, 0.82, 1.15, 0.54, 1.01, 0.59, 4.84, 0.69, 0.71, 8.7, 0.48, 0.69, 4.81, 1.42, 1.19, 0.84, 4.89, 0.85, 0.67, 7.07, 0.66, 7.93, 0.69, 5.94, 0.47, 0.7, 0.73, 0.5, 3.62, 9.55, 4.48, 9.44, 1.06, 0.36, 0.73, 0.67, 1.4, 0.56, 7.07, 0.69, 0.42, 3.72, 0.8, 0.94, 0.66, 0.48, 6.94, 3.19, 0.84, 1.27, 1.85, 5.23, 0.75, 0.55, 4.69, 8.51, 3.98, 0.65, 4.72, 0.94, 0.86, 6.27, 3.42, ! 1.03, 1.83, 0.86, 8.59, 0.72, 7.92, 0.84, 0.49, 0.78, 7.31, 5.15, 0.88, 0.57, 0.95, 0.69, 8.77, 0.86, 0.82, 2.02, 6.99, 5.01, 0.84, 1.09, 1.02, 0.66, 9.23, 0.74, 2.21), gval = c(1, 3, 4, 4, 1, 5, 5, 4, 6, 4, 2, 6, 4, 3, 4, 4, 3, 5, 1, 5, 1, 5, 6, 6, 6, 1, 1, 1, 1, 5, 1, 3, 4, 5, 4, 3, 5, 1, 5, 4, 5, 6, 3, 4, 3, 6, 3, 1, 2, 1, 3, 2, 1, 3, 4, 5, 4, 6, 6, 6, 5, 2, 1, 4, 5, 5, 4, 1, 1, 1, 3, 2, 2, 6, 2, 3, 3, 4, 1, 3, 2, 1, 3, 6, 5, 2, 6, 4, 2, 2, 1, 1, 5, 2, 6, 6, 3, 1, 4, 3), type = structure(c(2L, 3L, 3L, 3L, 2L, 3L, 3L, 2L, 2L, 2L, 2L, 1L, 3L, 2L, 1L, 3L, 3L, 2L, 1L, 1L, 3L, 2L, 1L, 2L, 3L, 2L, 3L, 3L, 2L, 1L, 2L, 1L, 2L, 3L, 1L, 2L, 3L, 2L, 1L, 3L, 1L, 2L, 3L, 2L, 1L, 1L, 1L, 2L, 3L, 2L, 3L, 3L, 1L, 3L, 2L, 2L, 2L, 3L, 1L, 2L, 2L, 3L, 1L, 2L, 1L, 3L, 3L, 2L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 1L, 3L, 1L, 3L, 1L, 2L, 2L, 2L, 3L, 3L, 2L, 3L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 3L, 1L, 3L, 2L), .Label = c(0, 1, 5), class = factor), cr = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L! , 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(0.2, 0.3, 0.4), class = factor), p = structure(c(1L, 2L, 1L, 1L, 2L, 1L, 4L, 4L, 2L, 4L, 3L, 1L, 2L, 2L, 1L, 4L, 1L, 1L, 3L, 1L, 1L, 3L, 3L, 4L, 3L, 2L, 4L, 1L, 4L, 1L, 4L, 1L, 4L, 3L, 1L, 1L, 3L, 3L, 4L, 4L, 4L, 4L, 2L, 1L, 2L, 1L, 1L, 3L, 1L, 1L, 3L, 2L, 3L, 1L, 1L, 3L, 2L, 3L, 3L, 1L, 2L, 1L, 1L, 3L, 3L, 4L, 3L, 2L, 4L, 4L, 4L, 3L, 3L, 1L, 4L, 4L, 2L, 3L, 3L, 1L, 2L, 4L, 2L, 3L, 1L, 2L, 4L, 4L, 3L, 3L, 4L, 3L, 2L, 3L, 4L, 4L, 1L, 3L, 2L, 4L), .Label = c(4, 8, 12, 20), class = factor), grp = c(4, 2, 2, 2, 4, 2, 2, 4, 4, 4, 4, 5, 2, 4, 5, 2, 2, 4, 5, 5, 2, 4, 5, 4, 2, 4, 2, 2, 4, 5, 4, 5, 4, 2, 5, 4, 2, 4, 5, 2, 5, 4, 2, 4, 5, 5, 5, 4, 2, 4, 2, 2! , 5, 2, 4, 4, 4, 2, 5, 4, 4, 2, 5, 4, 5, 2, 2, 4, 2, 2, 4, 4, 4, 4, 4, 5, 2, 5, 2, 5, 4, 4, 4, 2, 2, 4, 2, 5, 4, 4, 4, 4, 4, 4, 4, 5, 2, 5, 2, 4)), .Names = c(yval, xval, gval, type, cr, p, grp), row.names = c(NA, -100L), class = data.frame) And the code: library(lattice) library(robustbase) library(latticeExtra) typis - c(A,B,C) types - 1:4 mypanel - function(...){ if(current.row()3){ panel.grid(v=-1,h=-1,col=dark grey) panel.xyplot(...) } else { panel.grid(v=-1,h=-1,col=dark grey) cl - trellis.par.get()$superpose.line$col panel.bwplot(...,pch=-,cex=3,fill=cl,horizontal=FALSE,stats=adjboxStats) } } cl - trellis.par.get()$superpose.line$col lmi - rep(list(c(0,10)),12) lbl - rep(list(NULL),12) lbl[[9]] - lbl[[12]]-c(E1,E2,E3,E4,E5,E6) lbl[[1]] - lbl[[3]]-c(2,4,6,8) aty - rep(list(NULL),12) aty[[1]] - aty[[9]] - TRUE atx - rep(list(NULL),12) atx[[12]] - atx[[10]] - seq(1.5,9,by=1.5) rtl - c(45,0)
Re: [R] xyplot() does not plot legends with relation=free scales
Sorry, the B data.frame() didn't copy/paste well. Here is a working version (hopefully) B-structure(list(yval = c(0.7, 0.61, 0.65, 0.63, 6.08, 0.64, 5.68,6.77, 1.48, 7.71, 0.82, 1.15, 0.54, 1.01, 0.59, 4.84, 0.69, 0.71, 8.7, 0.48, 0.69, 4.81, 1.42, 1.19, 0.84, 4.89, 0.85, 0.67, 7.07, 0.66, 7.93, 0.69, 5.94, 0.47, 0.7, 0.73, 0.5, 3.62, 9.55, 4.48, 9.44, 1.06, 0.36, 0.73, 0.67, 1.4, 0.56, 7.07, 0.69, 0.42, 3.72, 0.8, 0.94, 0.66, 0.48, 6.94, 3.19, 0.84, 1.27, 1.85, 5.23, 0.75, 0.55, 4.69, 8.51, 3.98, 0.65, 4.72, 0.94, 0.86, 6.27, 3.42, 1.03, 1.83, 0.86, 8.59, 0.72, 7.92, 0.84, 0.49, 0.78, 7.31, 5.15, 0.88, 0.57, 0.95, 0.69, 8.77, 0.86, 0.82, 2.02, 6.99, 5.01, 0.84, 1.09, 1.02, 0.66, 9.23, 0.74, 2.21), xval = c(0.7, 0.61, 0.65, 0.63, 6.08, 0.64, 5.68, 6.77, 1.48, 7.71, 0.82, 1.15, 0.54, 1.01, 0.59, 4.84, 0.69, 0.71, 8.7, 0.48, 0.69, 4.81, 1.42, 1.19, 0.84, 4.89, 0.85, 0.67, 7.07, 0.66, 7.93, 0.69, 5.94, 0.47, 0.7, 0.73, 0.5, 3.62, 9.55, 4.48, 9.44, 1.06, 0.36, 0.73, 0.67, 1.4, 0.56, 7.07, 0.69, 0.42, 3.72, 0.8, 0.94, 0.66, 0.48, 6.94, 3.19, 0.84, 1.27, 1.85, 5.23, 0.75, 0.55, 4.69, 8.51, 3.98, 0.65, 4.72, 0.94, 0.86, 6.27, 3.42, 1.03, 1.83, 0.86, 8.59, 0.72, 7.92, 0.84, 0.49, 0.78, 7.31, 5.15, 0.88, 0.57, 0.95, 0.69, 8.77, 0.86, 0.82, 2.02, 6.99, 5.01, 0.84, 1.09, 1.02, 0.66, 9.23, 0.74, 2.21), gval = c(1, 3, 4, 4, 1, 5, 5, 4, 6, 4, 2, 6, 4, 3, 4, 4, 3, 5, 1, 5, 1, 5, 6, 6, 6, 1, 1, 1, 1, 5, 1, 3, 4, 5, 4, 3, 5, 1, 5, 4, 5, 6, 3, 4, 3, 6, 3, 1, 2, 1, 3, 2, 1, 3, 4, 5, 4, 6, 6, 6, 5, 2, 1, 4, 5, 5, 4, 1, 1, 1, 3, 2, 2, 6, 2, 3, 3, 4, 1, 3, 2, 1, 3, 6, 5, 2, 6, 4, 2, 2, 1, 1, 5, 2, 6, 6, 3, 1, 4, 3), type = structure(c(2L, 3L, 3L, 3L, 2L, 3L, 3L, 2L, 2L, 2L, 2L, 1L, 3L, 2L, 1L, 3L, 3L, 2L, 1L, 1L, 3L, 2L, 1L, 2L, 3L, 2L, 3L, 3L, 2L, 1L, 2L, 1L, 2L, 3L, 1L, 2L, 3L, 2L, 1L, 3L, 1L, 2L, 3L, 2L, 1L, 1L, 1L, 2L, 3L, 2L, 3L, 3L, 1L, 3L, 2L, 2L, 2L, 3L, 1L, 2L, 2L, 3L, 1L, 2L, 1L, 3L, 3L, 2L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 1L, 3L, 1L, 3L, 1L, 2L, 2L, 2L, 3L, 3L, 2L, 3L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 3L, 1L, 3L, 2L), .Label = c(0, 1, 5), class = factor), cr = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L , 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(0.2, 0.3, 0.4), class = factor), p = structure(c(1L, 2L, 1L, 1L, 2L, 1L, 4L, 4L, 2L, 4L, 3L, 1L, 2L, 2L, 1L, 4L, 1L, 1L, 3L, 1L, 1L, 3L, 3L, 4L, 3L, 2L, 4L, 1L, 4L, 1L, 4L, 1L, 4L, 3L, 1L, 1L, 3L, 3L, 4L, 4L, 4L, 4L, 2L, 1L, 2L, 1L, 1L, 3L, 1L, 1L, 3L, 2L, 3L, 1L, 1L, 3L, 2L, 3L, 3L, 1L, 2L, 1L, 1L, 3L, 3L, 4L, 3L, 2L, 4L, 4L, 4L, 3L, 3L, 1L, 4L, 4L, 2L, 3L, 3L, 1L, 2L, 4L, 2L, 3L, 1L, 2L, 4L, 4L, 3L, 3L, 4L, 3L, 2L, 3L, 4L, 4L, 1L, 3L, 2L, 4L), .Label = c(4, 8, 12, 20), class = factor), grp = c(4, 2, 2, 2, 4, 2, 2, 4, 4, 4, 4, 5, 2, 4, 5, 2, 2, 4, 5, 5, 2, 4, 5, 4, 2, 4, 2, 2, 4, 5, 4, 5, 4, 2, 5, 4, 2, 4, 5, 2, 5, 4, 2, 4, 5, 5, 5, 4, 2, 4, 2, 2 , 5, 2, 4, 4, 4, 2, 5, 4, 4, 2, 5, 4, 5, 2, 2, 4, 2, 2, 4, 4, 4, 4, 4, 5, 2, 5, 2, 5, 4, 4, 4, 2, 2, 4, 2, 5, 4, 4, 4, 4, 4, 4, 4, 5, 2, 5, 2, 4)), .Names = c(yval, xval, gval, type, cr, p, grp), row.names = c(NA, -100L), class = data.frame) -- View this message in context: http://r.789695.n4.nabble.com/xyplot-does-not-plot-legends-with-relation-free-scales-tp4540782p4540857.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] Coloring comments differently
Hi I use outline mode in ESS and was wondering if it is possible to change the color of the comments depending on the level. E.g. # Green Red ### Blue Cheers Renger Modelworks Gewerbestrasse 15 3600 Thun - Switzerland +41 79 818 53 73 i...@modelworks.ch blog.modelworks.ch __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How to produce serveral plots with pairs of vectors
Dear R-Users, I have a newbie-question about producing several plots with five variable pairs within in one code (loop). Problem: I define two objects, erveryone has five vectors (columns /variables): dimensionen - data.frame(meinspss$attr_diff_gesamt, meinspss$finanz_diff_gesamt, meinspss$leist_diff_gesamt, meinspss$soz_diff_gesamt, meinspss$wert_diff_gesamt) gruppe - data.frame(meinspss$R1_02, meinspss$R2_02, meinspss$R3_02,meinspss$R4_02,meinspss$R5_02) Now I would like to plot five similar graphs (beanplots, boxplots) for every pair of vectors (dimension by gruppe) . This works: box plot (dimensioned) - I receive a plot with 5 boxes. This does not work: boxplot (Dimensionen ~ Gruppe) - I would like to receive 5 plots I get the error message: Fehler in model.frame.default(formula = dimensionen ~ gruppe) : ungültiger Typ (list) für die Variable 'Dimensionen' Any help is very much appreciated! Happy Easter slyrs66 -- View this message in context: http://r.789695.n4.nabble.com/How-to-produce-serveral-plots-with-pairs-of-vectors-tp4540968p4540968.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] .Rhistory in R.app
On Apr 8, 2012, at 12:56 AM, Berend Hasselman wrote: On 08-04-2012, at 03:31, nkschmidt wrote: Hi Maria, you need to name your history file somefilename.Rapp.history, example savehistory(file = history.Rapp.history) /nkschmidt You replied to a message almost two years old, which to my mind is pretty useless. Not only that but the information is at best incomplete, and to some extent misleading. The saving of history sessions with the name .Rhistory in the working directory after normally exiting R.app is automatic unless specifically refused or disabled. Maria should have offered what evidence she has for them not being saved under the name .Rhistory. They are, of course, invisible to the Mac Finder due to their having a leadingdot in their name. That's my guess for why she might have erroneously concluded that they are not being saved. (I run my Finder with settings that show these dot-files but one does need to know that these dotfiles often contain system critical stuff so deleting them is unwise.) If she wanted to check the accuracy of this information she could have opened a Terminal session , navigate to the working directory and use the unix command: ls ... this is an example of such usage: david-winsemiuss-mac-pro:~ davidwinsemius$ ls .Rhistory .Rhistory The Preferences panel from the File menu allows one to disable loading of history files when the next session is started, but under normal operating conditions she should also be able to see the history by clicking on the green-and-yellow striped icon at the top of her R Console window: The Show/Hide R command History icon. -- David. Original message is here: https://stat.ethz.ch/pipermail/r-help/2009-December/221490.html Nabble does not host the R-help archive. Berend Maria Gouskova wrote Dear R users, I am having a minor but annoying issue with R.app. It doesn't retain the history information from the previous sessions. By history, I mean a record of commands/functions entered into R rather than the list of objects--that is properly recorded in the .Rdata file as well as in a workspace file I save separately. (...) So if there is some kind of a fix that doesn't involve upgrading R, I'd love to hear about it. Maria Gouskova -- View this message in context: http://r.789695.n4.nabble.com/Rhistory-in-R-app-tp956293p4540340.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. 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] filling the matrix row by row in the order from lower to larger elements
Sorry, I didn't have time to check the speed, indeed. However - isn't apply the same as a loop, just hidden? D. On Fri, Apr 6, 2012 at 6:59 PM, ilai ke...@math.montana.edu wrote: On Fri, Apr 6, 2012 at 4:02 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: This works great: Really ? surprising given it is the EXACT same for-loop as in your original problem with counter i replaced by k and reorder to matrix[!100]- 0 instead of matrix(0)[i]- 100 You didn't even attempt to implement Carl's suggestion to use apply family for looping (which I still think is completely unnecessary). The only logical conclusion is N=nrow(input) was not large enough to pose a problem in the first place. In the future please use some brain power before waisting ours. Cheers input-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8))) result-input N-nrow(input) for (k in 1:N){ foo - which (input == k,arr.ind=T) result[k,foo[2]] -100 } result[result !=100]-0 Dimitri On Fri, Apr 6, 2012 at 5:14 PM, Carl Witthoft c...@witthoft.com wrote: I think the OP wants to fill values in an arbitrarily large matrix. Now, first of all, I'd like to know what his real problem is, since this seems like a very tedious and unproductive matrix to produce. But in the meantime, since he also left out important information, let's assume the input matrix is N rows by M columns, and that he wants therefore to end up with N instances of 100, not counting the original value of 100 that is one of his ranking values (a bad BAD move IMHO). Then either loop or lapply over an equation like (I've expanded things more than necessary for clarity result-inmatrix for (k in 1:N){ foo - which (inmatrix == k,arr.ind=T) result[k,foo[2]] -100 } I maybe missing something but this seems like an indexing problem which doesn't require a loop at all. Something like this maybe? (input-matrix(c(5,1,3,7,2,6,4,8),nc=2)) output - matrix(0,max(input),2) output[input[,1],1] - 100 output[input[,2],2] - 100 output Cheers On Fri, Apr 6, 2012 at 1:49 PM, Dimitri Liakhovitski dimitri.liakhovitski at gmail.com wrote: Hello, everybody! I have a matrix input (see example below) - with all unique entries that are actually unique ranks (i.e., start with 1, no ties). I want to assign a value of 100 to the first row of the column that contains the minimum (i.e., value of 1). Then, I want to assign a value of 100 to the second row of the column that contains the value of 2, etc. The results I am looking for are in desired.results. My code (below) does what I need. But it's using a loop through all the rows of my matrix and searches for a matrix element every time. My actual matrix is very large. Is there a way to do it more efficiently? Thank you very much for the tips! Dimitri input-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8))) (input) desired.result-as.matrix(data.frame(a=c(100,0,100,0),b=c(0,100,0,100))) (desired.result) result-as.matrix(data.frame(a=c(0,0,0,0),b=c(0,0,0,0))) for(i in 1:nrow(input)){ # i-1 mymin-i mycoords-which(input==mymin,arr.ind=TRUE) result[i,mycoords[2]]-100 input[mycoords]-max(input) } (result) -- Sent from my Cray XK6 Quidvis recte factum, quamvis humile, praeclarum. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitri Liakhovitski marketfusionanalytics.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. -- Dimitri Liakhovitski marketfusionanalytics.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] filling the matrix row by row in the order from lower to larger elements
Thank you very much, Rui. This definitely produces the result needed. Again, I have not checked the speed yet. input-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8))) f - function(x){ nr - nrow(x) result - matrix(0, nrow=nr, ncol=ncol(x)) colnames(result) - colnames(x) inp.ord - order(x)[1:nr] - 1 # Keep only one per row, must be zero based inx - cbind(1:nr, inp.ord %/% nr + 1) # Index matrix result[inx] - 100 result } f(input) Dimitri On Fri, Apr 6, 2012 at 7:02 PM, Rui Barradas rui1...@sapo.pt wrote: Hello, Oops! What happened to the function 'f'? Forgot to copy and pasted only the rest, now complete. f - function(x){ nr - nrow(x) result - matrix(0, nrow=nr, ncol=ncol(x)) colnames(result) - colnames(x) inp.ord - order(x)[1:nr] - 1 # Keep only one per row, must be zero based inx - cbind(1:nr, inp.ord %/% nr + 1) # Index matrix result[inx] - 100 result } # Original example input - as.matrix(data.frame(a=c(5,1,3,7), b=c(2,6,4,8))) (input) desired.result - as.matrix(data.frame(a=c(100,0,100,0), b=c(0,100,0,100))) (desired.result) all.equal(f(input), desired.result) # Two other examples set.seed(123) (x - matrix(sample(10, 10), ncol=2)) f(x) (y - matrix(sample(40, 40), ncol=5)) f(y) Note that there's no loops (or apply, which is also a loop.) Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/filling-the-matrix-row-by-row-in-the-order-from-lower-to-larger-elements-tp4538171p4538486.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. -- Dimitri Liakhovitski marketfusionanalytics.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] newbie question: strategy
thanks for the heads up, I am checking all my providers EULAs to see which one I can share online... I imagine that as long as it is delayed 24 hours, there might be no issues... we will see... either way, worst case, I lost $9 for a registration... best case... I can share most ETF's with the community. On Sun, Apr 8, 2012 at 3:02 AM, R. Michael Weylandt michael.weyla...@gmail.com wrote: Just a heads up: I'm pretty sure Josh and the other QS developers have access to intra-day data, but they can't provide an example using it in the package because the EULAs of most data providers won't allow direct redistribution of their data. The examples included all go online and download data from a free source, but they don't provide it directly because even the free providers like Yahoo don't allow that. [There's a whole beer vs speech thing at play here] If you do put truly free intraday numbers online, you'll be doing a big service to the community, but make sure it's legal before you start. You'll also note that the older packages in the quant(mod|strat) universe like TTR don't use real data for their examples: rather they use simulated data to avoid all such issues. I imagine full quanstrat documentation will appear in time, but it's still under (very) active development so the mailing list archive examples are the best currently available. Once the system and the API are finalized, then it will make sense to document them. Hope this helps, Michael On Sat, Apr 7, 2012 at 10:15 PM, sysot1t syso...@gmail.com wrote: yes, I would have expected documented samples for something simple.. as I said, I am not asking for anything complex but something rather simple that I can use to learn from and build upon.. not a highly complex example that provides me with little explanation of what is going on... quanstrat is great, and it simplifies things, but hard to use if it is not clearly and extensively documented.. the demos are good, but again... one line describing what a block of 5-10 lines do.. that drives one to look into what the functions are actually doing and it can drive one nuts... just my 2 cents given I believe you are one of the experts on qstrat... with regard to intraday... I didn't realize that most people dont have access to intraday sources for data... I figure if you are using R for quant work, then you have access to RT data... btw, I am not a quant, I am an IT architect who trades his own retirement account... in any event, I will create a website and publish csv's for any universe of instruments and markets... for free ... in the same spirit of opensource that R was written on ... I just registered quantstrat-rt.com... both minute and tick data will be posted.. for all to use for analysis.. with the obvious disclaimers about the data of course. lastly, I dont mind putting in the time and effort to learn something, as long as proper and adequate learning resources are available... a few hours ago I ordered more books about R from springer this time... all those books are great to learn R itself, but useless to learn all the custom modules that are out there... quantmod has good docs, so does timesac and performanceanalytics... and one can go line by line (as I have done today) to see what all the samples do and how they are altering the information... but nothing formalized for learning to leverage them, just trial and error (which can be frustrating) I didnt ask for anyone to do my work for me, but rather I expected anyone that had done something similar to share what they had done so that I could learn from it... simple and straight forward... anyhow, feel free to send me a pm with your email contact information and I will reach out ... your reply is much appreciated. -- View this message in context: http://r.789695.n4.nabble.com/newbie-question-strategy-tp4538818p4540381.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] How to produce serveral plots with pairs of vectors
Please do your homework first: Read at least the beginning of An Introduction to R or other R tutorial -- there are many. I say this because in your post below you do not seem to realize that R is case sensitive, and you do not seem to know the difference between a data frame and a column thereof and/or how to index them . Saying you are a newbie is not an excuse to avoid making a minimal effort to learn what you need to know. R is not a point and click social application and has a fairly steep (or more properly shallow, as Sarah Goslee, I believe, has noted) learning curve associated with it. If you prefer to avoid this, you may wish to try R Commander, Deducer, RStudio or other R GUI package to avoid this -- check the RGUI page on CRAN for what's there. Obviously, you get only limited functionality in GUI, but it may be sufficient for you. That said, something like for(i in 1:5) boxplot( dimensionen[,i] ~ gruppe[,i] ) should work, but you will probably be unhappy with the captioning and axis labels. Proper main titles and axis labels can be programatically built, but that requires you to learn a good deal more R than you appear to presently know. -- Bert On Sun, Apr 8, 2012 at 5:51 AM, slyrs66 andreas.f...@gmx.de wrote: Dear R-Users, I have a newbie-question about producing several plots with five variable pairs within in one code (loop). Problem: I define two objects, erveryone has five vectors (columns /variables): dimensionen - data.frame(meinspss$attr_diff_gesamt, meinspss$finanz_diff_gesamt, meinspss$leist_diff_gesamt, meinspss$soz_diff_gesamt, meinspss$wert_diff_gesamt) gruppe - data.frame(meinspss$R1_02, meinspss$R2_02, meinspss$R3_02,meinspss$R4_02,meinspss$R5_02) Now I would like to plot five similar graphs (beanplots, boxplots) for every pair of vectors (dimension by gruppe) . This works: box plot (dimensioned) - I receive a plot with 5 boxes. This does not work: boxplot (Dimensionen ~ Gruppe) - I would like to receive 5 plots I get the error message: Fehler in model.frame.default(formula = dimensionen ~ gruppe) : ungültiger Typ (list) für die Variable 'Dimensionen' Any help is very much appreciated! Happy Easter slyrs66 -- View this message in context: http://r.789695.n4.nabble.com/How-to-produce-serveral-plots-with-pairs-of-vectors-tp4540968p4540968.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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] filling the matrix row by row in the order from lower to larger elements
Preoccupation with speed of execution is typically (certainly not always) misplaced. Provided you have used sensible basic vectorization, loops in whatever form work adequately. First get working code. Then, if necessary, parallelization, byte compilation, or complex vectorization strategies can be employed. And, of course, there's always C code for those who know it. -- Bert On Sun, Apr 8, 2012 at 7:31 AM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Thank you very much, Rui. This definitely produces the result needed. Again, I have not checked the speed yet. input-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8))) f - function(x){ nr - nrow(x) result - matrix(0, nrow=nr, ncol=ncol(x)) colnames(result) - colnames(x) inp.ord - order(x)[1:nr] - 1 # Keep only one per row, must be zero based inx - cbind(1:nr, inp.ord %/% nr + 1) # Index matrix result[inx] - 100 result } f(input) Dimitri On Fri, Apr 6, 2012 at 7:02 PM, Rui Barradas rui1...@sapo.pt wrote: Hello, Oops! What happened to the function 'f'? Forgot to copy and pasted only the rest, now complete. f - function(x){ nr - nrow(x) result - matrix(0, nrow=nr, ncol=ncol(x)) colnames(result) - colnames(x) inp.ord - order(x)[1:nr] - 1 # Keep only one per row, must be zero based inx - cbind(1:nr, inp.ord %/% nr + 1) # Index matrix result[inx] - 100 result } # Original example input - as.matrix(data.frame(a=c(5,1,3,7), b=c(2,6,4,8))) (input) desired.result - as.matrix(data.frame(a=c(100,0,100,0), b=c(0,100,0,100))) (desired.result) all.equal(f(input), desired.result) # Two other examples set.seed(123) (x - matrix(sample(10, 10), ncol=2)) f(x) (y - matrix(sample(40, 40), ncol=5)) f(y) Note that there's no loops (or apply, which is also a loop.) Rui Barradas -- View this message in context: http://r.789695.n4.nabble.com/filling-the-matrix-row-by-row-in-the-order-from-lower-to-larger-elements-tp4538171p4538486.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. -- Dimitri Liakhovitski marketfusionanalytics.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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Drawing a line in xyplot
On Sat, Apr 7, 2012 at 8:29 PM, wcheckle wchec...@jhsph.edu wrote: Thank you David, the bwplot option does what I need: snip However, I am interested in also learning how to do it in xyplot as well. I wasn’t able to follow the last two set of instructions That was me. Sorry for any confusion. wcheckle, these were not instructions but ramblings on an earlier code which used the original data.frame inside the lattice panel function, which in my view is an added complication in the case of only 2-3 conditioning variables. You were not meant to try and follow (the alternative was given in the form of bwplot). Your original post had two plots - in base graphics you had one conditional variable (type) and median lines, and a second was lattice with 2 variables (attend|type) without median lines. You were offered 2 solutions - David's to reproduce the first plot in lattice, and the bwplot to add medians to the second. You could work through the examples in lattice and on-line to find there is a multitude of ways to add features to grid/lattice plots. An example with panel.segments might look (untested) something like: panel=function(x,y,...) { panel.xyplot(x,y,...) yy- tapply(y,x,median) panel.segments(x0, x1, y0= yy , y1= yy , col=red,lwd=4) } Hope that clarifies things, and again sorry everyone for any confusion that may have resulted. Best, Elai __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Parallel writes in R
On 02.04.2012 21:35, Jonathan Greenberg wrote: R-helpers: I'm curious what support R has for parallel writes to a binary file? If I want to use snow to have each node write different rows of a flat binary file (possibly out of sequence), are there any tricks/issues I should be aware of? This is a very hard task, since you have to synchonice the nodes. Typically it is more advisable to collect the rows by the master and write the whole file from there. Uwe Ligges --j __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 produce serveral plots with pairs of vectors
On Apr 8, 2012, at 8:51 AM, slyrs66 wrote: Dear R-Users, I have a newbie-question about producing several plots with five variable pairs within in one code (loop). Problem: I define two objects, erveryone has five vectors (columns /variables): dimensionen - data.frame(meinspss$attr_diff_gesamt, meinspss$finanz_diff_gesamt, meinspss$leist_diff_gesamt, meinspss$soz_diff_gesamt, meinspss$wert_diff_gesamt) This would probably be more readable: dimensionen - with( meinspss , # creates an environment where the # column names can be used data.frame( attr_diff_gesamt, finanz_diff_gesamt, leist_diff_gesamt, soz_diff_gesamt, wert_diff_gesamt) ) (Spaces help the human brain separate elements.) gruppe - data.frame(meinspss$R1_02, meinspss$R2_02, meinspss$R3_02,meinspss$R4_02,meinspss$R5_02) At this point providing the output of str(dimensionen) # and str(gruppe) would be very helpful. Now I would like to plot five similar graphs (beanplots, boxplots) for every pair of vectors (dimension by gruppe) . This works: box plot (dimensioned) - I receive a plot with 5 boxes. Not with that spelling it shouldn't, but perhaps with boxplot(dimensionen) This does not work: boxplot (Dimensionen ~ Gruppe) - I would like to receive 5 plots I get the error message: Fehler in model.frame.default(formula = dimensionen ~ gruppe) : ungültiger Typ (list) für die Variable 'Dimensionen' There are no objects named 'Dimensionen' or 'Gruppe', only ones named 'dimensionen' and 'gruppe'. And why are you putting entire dataframes on each side of a boxplot formula call? That seemed doomed to failure (even before the error message told you so) since the RHS of the formula is generally formed from vectors. You created 'gruppe' with 5 column vectors. Please explain: what sort of association exists between the various column vectors in 'dimensionen' and 'gruppe'? In other words: What are those Rn_02 variables and how do you expect to use 5 different _gruppe-ing variables with 5 _diff_erent variables in 'dimensionen' ? -- 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] Error in xy.coords(x, NULL, log = log) : (list) object cannot be coerced to type 'double'
On 01.04.2012 20:15, Bazman76 wrote: Hi there, When I run the code below I get the error Error in xy.coords(x, NULL, log = log) :(list) object cannot be coerced to type 'double' Any tips how I can resolve this? The mra output is a list, hence plot.ts cannot handle it. You probably want to plot the original data in the first place given you are following the example from ?mra Uwe Ligges library(waveslim) vols=read.csv(file=C:/Users/ocuk/My Documents/Abs Vol.csv, header=TRUE, sep=,) x-c(vols[,1]) #x #data(ibm) av.la8- mra(x, la8, 4, modwt) #names(av.la8)- c(d1, d2, d3, d4,d5,d6, d7, d8,s8) names(av.la8)- c(d1, d2, d3, d4,s4) #par(mfcol=c(10,1), pty=m, mar=c(5-2,4,4-2,2)) par(mfcol=c(6,1), pty=m, mar=c(5-2,4,4-2,2)) plot.ts(av.la8, axes=F, ylab=, main=abs vol) *Error in xy.coords(x, NULL, log = log) : (list) object cannot be coerced to type 'double'* #for(i in 1:9) for(i in 1:5) + plot.ts(av.la8[[i]], axes=F, ylab=names(av.la8)[i]) axis(side=1, at=seq(0,1541,by=100), + labels=c(0,,200,,400,,600,,800,,1000,,1200,,1400,)) -- View this message in context: http://r.789695.n4.nabble.com/Error-in-xy-coords-x-NULL-log-log-list-object-cannot-be-coerced-to-type-double-tp4524046p4524046.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 package out of own function
Export the default method (and otehr methods) from your NAMESPACE? See Writing R Extensions about the S3method directive. Note that print.f is the print method for a class f, while f is a generic function, both fs are unrelated. Uwe Ligges On 02.04.2012 12:02, Johannes Radinger wrote: Hello, I already posted that on stackoverflow[1], but although it's crossposting, I think this question can probably easier to be answered by other R-users on this list, which maintain packages etc. I would like to make a package out of a function. The function is working in a script, but when I install and load it as library() I get an error. The example-function is: #Make generic function f- function(x,...) UseMethod(f) #Default method f.default- function(a,b=5,c=3,...){ out- a+b+c class(out)- f out } # Print method print.f- function(x,...){ cat(Result for f: ) print(unclass(x)) } In the NAMESPACE for export I set f. When I try to run the function from the package I get: Error in UseMethod(f) : no applicable method for 'f' applied to an object of class c('double', 'numeric') here some additional info: sessionInfo() R version 2.14.2 (2012-02-29) Platform: i386-apple-darwin9.8.0/i386 (32-bit) locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] fishmove_0.0-1 plyr_1.7.1 ggplot2_0.9.0 loaded via a namespace (and not attached): [1] colorspace_1.1-1 dichromat_1.2-4digest_0.5.1 grid_2.14.2 MASS_7.3-17 [6] memoise_0.1munsell_0.3proto_0.3-9.2 RColorBrewer_1.0-5 reshape2_1.2.1 [11] scales_0.2.0 stringr_0.6 Can anyone explain me how to solve that resp. how to make my own function into a package? Best regards, Johannes [1]: http://stackoverflow.com/questions/8430178/arguments-and-classes-for-writing-generic-functions-in-r __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] How do Sweave users collaborate with Word users?
This sounds neat, and I wish you the best of luck with it. While I'm sure it'll be great for folks who are already curious enough to dive into Sweave or knitr, my guess is that coaxing collaborators into using markdown with SVN or GIT instead of passing around a Word file with Track Changes is going to be a tough sell, to put it lightly. I'll keep my eyes out for emerging sweave/knitr - word solutions (note the double arrow), but sounds like manual change-synchronization is the only game in town right now, alas. Thanks, Allie On 4/7/2012 4:29 PM, Yihui Xie wrote: I cannot reply in detail at the moment, but we have a proposal to the Google Summer of Code this year which will address the collaboration issue. The basic idea is to write everything in plain text with markdown (including R code), and compile the file with the knitr package, then convert it to Word or whatever other formats with pandoc, which is an extremely powerful document converter. You can see a simple example here for how knitr works with markdown: http://yihui.name/knitr/demo/upload/ Since everything is in plain text, it is easy to collaborate through a version control system like SVN or GIT. Markdown is easy to write and cleaner compared to Word. Regards, Yihui -- Yihui Xie xieyi...@gmail.com Phone: 515-294-2465 Web: http://yihui.name Department of Statistics, Iowa State University 2215 Snedecor Hall, Ames, IA On Sat, Apr 7, 2012 at 3:54 PM, Alexander Shenkin ashen...@ufl.edu wrote: Hello All, I'm getting my workflow switched over to Sweave, which is very cool. However, I collaborate with folks (as many of you must as well) who use Word to Track Changes amongst a group while crafting a paper. In the simplest case, there will just be two people (one Sweave user and one Word user) editing a paper. I'm wondering, how do Sweave users go about this? I could convert a sweave file to a .docx easily enough via an intermediary pdf, rtf, html or otherwise. However, once the file has been marked up with changes, the challenge is to migrate those (accepted) changes back to the sweave document. Perhaps the most straightforward way is to manually back-propagate changes, but I imagine that could be a painstaking process. Ideally, I imagine a tool that puts invisible tags in the word document when it is originally produced from Sweave, and is then able to propagate changes back to that sweave file after markup. I'd be pleasantly surprised if such a tool existed. Perhaps there are other ways of making this work. Any thoughts are kindly appreciated! Thanks, Allie __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] xyplot() does not plot legends with relation=free scales
On Sun, Apr 8, 2012 at 3:42 AM, Kaveh Vakili kaveh.vak...@ulb.ac.be wrote: Hi all, I have this problem with lattice that xyplot() won't draw some of my axis labels if the type (i.e. the relation argument) of scales is set as free. For example, in the plot below, I would want it to also show: 1. the labels E1,...E6 below the 10th panel (i.e. 3rd row, 2 col)just as it is now done below the 12th panel You are setting your scales manually, so you need to make sure you don't have typos. Change the line lbl[[9]] - lbl[[12]]-c(E1,E2,E3,E4,E5,E6) to lbl[[10]] - lbl[[12]]-c(E1,E2,E3,E4,E5,E6) 2. as well as the labels (2,4,6,8) on the top of panels 1 and 3 (by on top, i mean above the strips, as xyplot normally does by default but can't seem to be willing to do in the example below). Same thing, I see the y axis labels for 1,3 but nothing for the at or labels for x-axis for [[1,3]]. Note also you need the appropriate tck argument for placing 'top-right' PS: i had originally posted this question on stackoverlow but since i didn't get an answer there i've deleted it there and posting it here. My guess is you didn't get an answer before because this is a reproducible example (thank you) but very involved. In the future try to reduce your code to the minimum which produces the problem behavior, you will often find that in the process of doing so you answer your own question... Hope this helped Elai Happy Easter, B-structure(list(yval = c(0.7, 0.61, 0.65, 0.63, 6.08, 0.64, 5.68, 6.77, 1.48, 7.71, 0.82, 1.15, 0.54, 1.01, 0.59, 4.84, 0.69, 0.71, 8.7, 0.48, 0.69, 4.81, 1.42, 1.19, 0.84, 4.89, 0.85, 0.67, 7.07, 0.66, 7.93, 0.69, 5.94, 0.47, 0.7, 0.73, 0.5, 3.62, 9.55, 4.48, 9.44, 1.06, 0.36, 0.73, 0.67, 1.4, 0.56, 7.07, 0.69, 0.42, 3.72, 0.8, 0.94, 0.66, 0.48, 6.94, 3.19, 0.84, 1.27, 1.85, 5.23, 0.75, 0.55, 4.69, 8.51, 3.98, 0.65, 4.72, 0.94, 0.86, 6.27, 3.42, 1.03, 1.83, 0.86, 8.59, 0.72, 7.92, 0.84, 0.49, 0.78, 7.31, 5.15, 0.88, 0.57, 0.95, 0.69, 8.77, 0.86, 0.82, 2.02, 6.99, 5.01, 0.84, 1.09, 1.02, 0.66, 9.23, 0.74, 2.21), xval = c(0.7, 0.61, 0.65, 0.63, 6.08, 0.64, 5.68, 6.77, 1.48, 7.71, 0.82, 1.15, 0.54, 1.01, 0.59, 4.84, 0.69, 0.71, 8.7, 0.48, 0.69, 4.81, 1.42, 1.19, 0.84, 4.89, 0.85, 0.67, 7.07, 0.66, 7.93, 0.69, 5.94, 0.47, 0.7, 0.73, 0.5, 3.62, 9.55, 4.48, 9.44, 1.06, 0.36, 0.73, 0.67, 1.4, 0.56, 7.07, 0.69, 0.42, 3.72, 0.8, 0.94, 0.66, 0.48, 6.94, 3.19, 0.84, 1.27, 1.85, 5.23, 0.75, 0.55, 4.69, 8.51, 3.98, 0.65, 4.72, 0.94, 0.86, 6.27, 3.42, ! 1.03, 1.83, 0.86, 8.59, 0.72, 7.92, 0.84, 0.49, 0.78, 7.31, 5.15, 0.88, 0.57, 0.95, 0.69, 8.77, 0.86, 0.82, 2.02, 6.99, 5.01, 0.84, 1.09, 1.02, 0.66, 9.23, 0.74, 2.21), gval = c(1, 3, 4, 4, 1, 5, 5, 4, 6, 4, 2, 6, 4, 3, 4, 4, 3, 5, 1, 5, 1, 5, 6, 6, 6, 1, 1, 1, 1, 5, 1, 3, 4, 5, 4, 3, 5, 1, 5, 4, 5, 6, 3, 4, 3, 6, 3, 1, 2, 1, 3, 2, 1, 3, 4, 5, 4, 6, 6, 6, 5, 2, 1, 4, 5, 5, 4, 1, 1, 1, 3, 2, 2, 6, 2, 3, 3, 4, 1, 3, 2, 1, 3, 6, 5, 2, 6, 4, 2, 2, 1, 1, 5, 2, 6, 6, 3, 1, 4, 3), type = structure(c(2L, 3L, 3L, 3L, 2L, 3L, 3L, 2L, 2L, 2L, 2L, 1L, 3L, 2L, 1L, 3L, 3L, 2L, 1L, 1L, 3L, 2L, 1L, 2L, 3L, 2L, 3L, 3L, 2L, 1L, 2L, 1L, 2L, 3L, 1L, 2L, 3L, 2L, 1L, 3L, 1L, 2L, 3L, 2L, 1L, 1L, 1L, 2L, 3L, 2L, 3L, 3L, 1L, 3L, 2L, 2L, 2L, 3L, 1L, 2L, 2L, 3L, 1L, 2L, 1L, 3L, 3L, 2L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 1L, 3L, 1L, 3L, 1L, 2L, 2L, 2L, 3L, 3L, 2L, 3L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 3L, 1L, 3L, 2L), .Label = c(0, 1, 5), class = factor), cr = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L! , 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = c(0.2, 0.3, 0.4), class = factor), p = structure(c(1L, 2L, 1L, 1L, 2L, 1L, 4L, 4L, 2L, 4L, 3L, 1L, 2L, 2L, 1L, 4L, 1L, 1L, 3L, 1L, 1L, 3L, 3L, 4L, 3L, 2L, 4L, 1L, 4L, 1L, 4L, 1L, 4L, 3L, 1L, 1L, 3L, 3L, 4L, 4L, 4L, 4L, 2L, 1L, 2L, 1L, 1L, 3L, 1L, 1L, 3L, 2L, 3L, 1L, 1L, 3L, 2L, 3L, 3L, 1L, 2L, 1L, 1L, 3L, 3L, 4L, 3L, 2L, 4L, 4L, 4L, 3L, 3L, 1L, 4L, 4L, 2L, 3L, 3L, 1L, 2L, 4L, 2L, 3L, 1L, 2L, 4L, 4L, 3L, 3L, 4L, 3L, 2L, 3L, 4L, 4L, 1L, 3L, 2L, 4L), .Label = c(4, 8, 12, 20), class = factor), grp = c(4, 2, 2, 2, 4, 2, 2, 4, 4, 4, 4, 5, 2, 4, 5, 2, 2, 4, 5, 5, 2, 4, 5, 4, 2, 4, 2, 2, 4, 5, 4, 5, 4, 2, 5, 4, 2, 4, 5, 2, 5, 4, 2, 4, 5, 5, 5, 4, 2, 4, 2, 2! , 5, 2, 4, 4, 4, 2, 5, 4, 4, 2, 5, 4, 5, 2, 2, 4, 2, 2, 4, 4, 4, 4, 4, 5, 2, 5, 2, 5, 4, 4, 4, 2, 2, 4, 2, 5, 4, 4, 4, 4, 4, 4, 4, 5, 2, 5, 2, 4)), .Names = c(yval, xval, gval, type, cr, p, grp), row.names = c(NA, -100L), class = data.frame) And the code: library(lattice) library(robustbase) library(latticeExtra) typis - c(A,B,C)
[R] axis labels not showing
Hello - I want to generate stacked plots with par(mfrow)) function. However, my axis labels aren't showing. My script is here: http://pastebin.com/yXXeMQgb The plot is here: http://www.crypticlineage.net/rdisc/strplot.pdf Thank you for your time. Vikram __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] independent set function from graph package
Dear all, I have been using the graph package until last week, especially the functions independence.number and largest.independent.vertex.sets. This weekend I formatted my hard disk and when trying to install packages I noticied that graph package is no longer on R repository although can be accessed from the BioConductor website. However, neither graph or RBGL packages have the above mentioned functions. Moreover the graph packages in archive are source files and I am experimenting some troubles installing it. Anyone knows where I can access functions to find the largest independent set in graphs? Greetings, Diogo __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] axis labels not showing
On Sun, Apr 8, 2012 at 11:40 AM, Vikram Chhatre crypticline...@gmail.com wrote: Hello - I want to generate stacked plots with par(mfrow)) function. However, my axis labels aren't showing. Your mar (2) are too narrow. You could increase back to the default or use the lines option in mtext to write labels closer to the plot or, well, a host of other things... Hope this helps My script is here: http://pastebin.com/yXXeMQgb The plot is here: http://www.crypticlineage.net/rdisc/strplot.pdf Thank you for your time. Vikram __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] axis labels not showing
Indeed. Changing margins brought back the axis labels. Thank you. What I would really like to do is stack these plots atop each other so they share the common x-axis. Is there a way to do it with ggplot2? Vikram On Sun, Apr 8, 2012 at 1:33 PM, ilai ke...@math.montana.edu wrote: On Sun, Apr 8, 2012 at 11:40 AM, Vikram Chhatre crypticline...@gmail.com wrote: Hello - I want to generate stacked plots with par(mfrow)) function. However, my axis labels aren't showing. Your mar (2) are too narrow. You could increase back to the default or use the lines option in mtext to write labels closer to the plot or, well, a host of other things... Hope this helps My script is here: http://pastebin.com/yXXeMQgb The plot is here: http://www.crypticlineage.net/rdisc/strplot.pdf Thank you for your time. Vikram __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Problems with CRAN package Ryacas
First: sessionInfo() R version 2.15.0 (2012-03-30) Platform: x86_64-pc-linux-gnu (64-bit) locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C [3] LC_TIME=en_US.UTF-8LC_COLLATE=en_US.UTF-8 [5] LC_MONETARY=en_US.UTF-8LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C 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 other attached packages: [1] Ryacas_0.2-11 XML_3.9-4 pnmath_0.0-3 MASS_7.3-17 loaded via a namespace (and not attached): [1] compiler_2.15.0 fortunes_1.5-0 tools_2.15.0 Operating system is debian (wheezy+some sid) I have installed yacas version 1.3.1 via synaptic. Then: library(Ryacas) yacas(expression(Factor(x^2-1))) # copied from yacas help page [1] Starting Yacas! Accepting requests from port 9734 Error in socketConnection(host = 127.0.0.1, port = 9734, server = FALSE, : cannot open the connection In addition: Warning message: In socketConnection(host = 127.0.0.1, port = 9734, server = FALSE, : 127.0.0.1:9734 cannot be opened ¿Any ideas? Kjetil __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] filling the matrix row by row in the order from lower to larger elements
On Sun, Apr 8, 2012 at 8:26 AM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Sorry, I didn't have time to check the speed, indeed. However - isn't apply the same as a loop, just hidden? D. Yes ?apply is a loop but not the same as ?for, see Intro to R. As Bert Gunter pointed out the issue here was not speed but that your problem could have been vectorized to avoid loops all together (which would have the added benefit of speed). This was given to you in my first response which assumed a small number of columns in the matrix, but Rui gave an elegant expansion to use on any ncol(matrix). Using apply was suggested at some point by others, my comment was simply that you failed to meet even that adjustment. Cheers On Fri, Apr 6, 2012 at 6:59 PM, ilai ke...@math.montana.edu wrote: On Fri, Apr 6, 2012 at 4:02 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: This works great: Really ? surprising given it is the EXACT same for-loop as in your original problem with counter i replaced by k and reorder to matrix[!100]- 0 instead of matrix(0)[i]- 100 You didn't even attempt to implement Carl's suggestion to use apply family for looping (which I still think is completely unnecessary). The only logical conclusion is N=nrow(input) was not large enough to pose a problem in the first place. In the future please use some brain power before waisting ours. Cheers input-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8))) result-input N-nrow(input) for (k in 1:N){ foo - which (input == k,arr.ind=T) result[k,foo[2]] -100 } result[result !=100]-0 Dimitri On Fri, Apr 6, 2012 at 5:14 PM, Carl Witthoft c...@witthoft.com wrote: I think the OP wants to fill values in an arbitrarily large matrix. Now, first of all, I'd like to know what his real problem is, since this seems like a very tedious and unproductive matrix to produce. But in the meantime, since he also left out important information, let's assume the input matrix is N rows by M columns, and that he wants therefore to end up with N instances of 100, not counting the original value of 100 that is one of his ranking values (a bad BAD move IMHO). Then either loop or lapply over an equation like (I've expanded things more than necessary for clarity result-inmatrix for (k in 1:N){ foo - which (inmatrix == k,arr.ind=T) result[k,foo[2]] -100 } I maybe missing something but this seems like an indexing problem which doesn't require a loop at all. Something like this maybe? (input-matrix(c(5,1,3,7,2,6,4,8),nc=2)) output - matrix(0,max(input),2) output[input[,1],1] - 100 output[input[,2],2] - 100 output Cheers On Fri, Apr 6, 2012 at 1:49 PM, Dimitri Liakhovitski dimitri.liakhovitski at gmail.com wrote: Hello, everybody! I have a matrix input (see example below) - with all unique entries that are actually unique ranks (i.e., start with 1, no ties). I want to assign a value of 100 to the first row of the column that contains the minimum (i.e., value of 1). Then, I want to assign a value of 100 to the second row of the column that contains the value of 2, etc. The results I am looking for are in desired.results. My code (below) does what I need. But it's using a loop through all the rows of my matrix and searches for a matrix element every time. My actual matrix is very large. Is there a way to do it more efficiently? Thank you very much for the tips! Dimitri input-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8))) (input) desired.result-as.matrix(data.frame(a=c(100,0,100,0),b=c(0,100,0,100))) (desired.result) result-as.matrix(data.frame(a=c(0,0,0,0),b=c(0,0,0,0))) for(i in 1:nrow(input)){ # i-1 mymin-i mycoords-which(input==mymin,arr.ind=TRUE) result[i,mycoords[2]]-100 input[mycoords]-max(input) } (result) -- Sent from my Cray XK6 Quidvis recte factum, quamvis humile, praeclarum. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitri Liakhovitski marketfusionanalytics.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. -- Dimitri Liakhovitski marketfusionanalytics.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] Problems with CRAN package Ryacas
On Sun, Apr 8, 2012 at 2:56 PM, Kjetil Halvorsen kjetilbrinchmannhalvor...@gmail.com wrote: First: sessionInfo() R version 2.15.0 (2012-03-30) Platform: x86_64-pc-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=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 [7] LC_PAPER=C 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 other attached packages: [1] Ryacas_0.2-11 XML_3.9-4 pnmath_0.0-3 MASS_7.3-17 loaded via a namespace (and not attached): [1] compiler_2.15.0 fortunes_1.5-0 tools_2.15.0 Operating system is debian (wheezy+some sid) I have installed yacas version 1.3.1 via synaptic. Then: library(Ryacas) yacas(expression(Factor(x^2-1))) # copied from yacas help page [1] Starting Yacas! Accepting requests from port 9734 Error in socketConnection(host = 127.0.0.1, port = 9734, server = FALSE, : cannot open the connection In addition: Warning message: In socketConnection(host = 127.0.0.1, port = 9734, server = FALSE, : 127.0.0.1:9734 cannot be opened ¿Any ideas? See the troubleshooting section on the home page: http://ryacas.googlecode.com -- Statistics Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] filling the matrix row by row in the order from lower to larger elements
Agreed, Rui provided a very elegant vectorized solution - and I am very thankful to him. Unfortunately (for myself), I am not as proficient in vectorization - otherwise, I would not have asked the question. Why I did not follow on the original hint to use apply? For this reason (quote): However - isn't apply the same as a loop, just hidden? with slight caveats, yes. Bert Dimitri On Sun, Apr 8, 2012 at 3:16 PM, ilai ke...@math.montana.edu wrote: On Sun, Apr 8, 2012 at 8:26 AM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: Sorry, I didn't have time to check the speed, indeed. However - isn't apply the same as a loop, just hidden? D. Yes ?apply is a loop but not the same as ?for, see Intro to R. As Bert Gunter pointed out the issue here was not speed but that your problem could have been vectorized to avoid loops all together (which would have the added benefit of speed). This was given to you in my first response which assumed a small number of columns in the matrix, but Rui gave an elegant expansion to use on any ncol(matrix). Using apply was suggested at some point by others, my comment was simply that you failed to meet even that adjustment. Cheers On Fri, Apr 6, 2012 at 6:59 PM, ilai ke...@math.montana.edu wrote: On Fri, Apr 6, 2012 at 4:02 PM, Dimitri Liakhovitski dimitri.liakhovit...@gmail.com wrote: This works great: Really ? surprising given it is the EXACT same for-loop as in your original problem with counter i replaced by k and reorder to matrix[!100]- 0 instead of matrix(0)[i]- 100 You didn't even attempt to implement Carl's suggestion to use apply family for looping (which I still think is completely unnecessary). The only logical conclusion is N=nrow(input) was not large enough to pose a problem in the first place. In the future please use some brain power before waisting ours. Cheers input-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8))) result-input N-nrow(input) for (k in 1:N){ foo - which (input == k,arr.ind=T) result[k,foo[2]] -100 } result[result !=100]-0 Dimitri On Fri, Apr 6, 2012 at 5:14 PM, Carl Witthoft c...@witthoft.com wrote: I think the OP wants to fill values in an arbitrarily large matrix. Now, first of all, I'd like to know what his real problem is, since this seems like a very tedious and unproductive matrix to produce. But in the meantime, since he also left out important information, let's assume the input matrix is N rows by M columns, and that he wants therefore to end up with N instances of 100, not counting the original value of 100 that is one of his ranking values (a bad BAD move IMHO). Then either loop or lapply over an equation like (I've expanded things more than necessary for clarity result-inmatrix for (k in 1:N){ foo - which (inmatrix == k,arr.ind=T) result[k,foo[2]] -100 } I maybe missing something but this seems like an indexing problem which doesn't require a loop at all. Something like this maybe? (input-matrix(c(5,1,3,7,2,6,4,8),nc=2)) output - matrix(0,max(input),2) output[input[,1],1] - 100 output[input[,2],2] - 100 output Cheers On Fri, Apr 6, 2012 at 1:49 PM, Dimitri Liakhovitski dimitri.liakhovitski at gmail.com wrote: Hello, everybody! I have a matrix input (see example below) - with all unique entries that are actually unique ranks (i.e., start with 1, no ties). I want to assign a value of 100 to the first row of the column that contains the minimum (i.e., value of 1). Then, I want to assign a value of 100 to the second row of the column that contains the value of 2, etc. The results I am looking for are in desired.results. My code (below) does what I need. But it's using a loop through all the rows of my matrix and searches for a matrix element every time. My actual matrix is very large. Is there a way to do it more efficiently? Thank you very much for the tips! Dimitri input-as.matrix(data.frame(a=c(5,1,3,7),b=c(2,6,4,8))) (input) desired.result-as.matrix(data.frame(a=c(100,0,100,0),b=c(0,100,0,100))) (desired.result) result-as.matrix(data.frame(a=c(0,0,0,0),b=c(0,0,0,0))) for(i in 1:nrow(input)){ # i-1 mymin-i mycoords-which(input==mymin,arr.ind=TRUE) result[i,mycoords[2]]-100 input[mycoords]-max(input) } (result) -- Sent from my Cray XK6 Quidvis recte factum, quamvis humile, praeclarum. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Dimitri Liakhovitski marketfusionanalytics.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. -- Dimitri
Re: [R] Error in xy.coords(x, NULL, log = log) : (list) object cannot be coerced to type 'double'
that's it! Thank you. -- View this message in context: http://r.789695.n4.nabble.com/Error-in-xy-coords-x-NULL-log-log-list-object-cannot-be-coerced-to-type-double-tp4524046p4541340.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] axis labels not showing
It's very simple my boy!! Do you already to play with mar? So..Try to change the values this object. For example, par(..., mar=c(*5*,2,2,2)). Bye! -- View this message in context: http://r.789695.n4.nabble.com/axis-labels-not-showing-tp4541268p4541354.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] Difference between spec.pgram spec.ar
Hi there, Can someone explain what the difference between spec.pgram and spec.ar is? I understand that they attempt to do the same thing one using an AR estimation of the underlying series to estimate teh sensity the other using the FFT. However when applied to teh same data set they seem to be giving quite different results? http://r.789695.n4.nabble.com/file/n4541358/R_example.jpg Clearly the spec.ar() result seems to be smoothed but the results are also generally very different only really sharing the peak as the frequencies go towards zero. Can someone please explain why these two functions produce such different results on the same data set? code shown below: library(waveslim) vols=read.csv(file=C:/Users/ocuk/My Documents/Abs Vol.csv, header=TRUE, sep=,) x-ts(vols[,1]) #x ## LA(8) vol.la8 - mra(x, la8, 4, modwt) names(vol.la8) - c(d1, d2, d3, d4, s4) ## plot multiresolution analysis of IBM data #par(mfcol=c(6,1), pty=m, mar=c(5-2,4,4-2,2)) par(mfcol=c(3,1), pty=m, mar=c(5-2,4,4-2,2)) plot.ts(x, axes=F, ylab=, main=(abs rtns)) #for(i in 1:5) # plot.ts(vol.la8[[i]], axes=F, ylab=names(vol.la8)[i]) #axis(side=1, at=seq(0,1600,by=100), # labels=c(0,,200,,400,,600,,800,,1000,,1200,,1400,,1600)) spectrum(vol.la8[[1]]) specx - spec.ar(x) -- View this message in context: http://r.789695.n4.nabble.com/Difference-between-spec-pgram-spec-ar-tp4541358p4541358.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] How to produce serveral plots with pairs of vectors
Thank you, David. What I actually would like to do in an more elegant way is the following boxplot (meinspss$attr_diff_gesamt ~ meinspss$R1_02) boxplot (meinspss$finanz_diff_gesamt ~ meinspss$R2_02) boxplot (meinspss$leist_diff_gesamt ~ meinspss$R3_02) boxplot (meinspss$soz_diff_gesamt ~ meinspss$R4_02) boxplot (meinspss$wert_diff_gesamt ~ meinspss$R5_02) As the final code is much more complicated (see below) I was looking for a loop oder lapply() way to do it Thanks gain for you help. Andrew + with (meinspss, { beanplot(dimension ~ gruppe, ll=0.04, what=c(1,1,1,1), jitter = 1.2, main = titel, ylab=Differenzwert, names = c(Aufwärts, Lateral, Abwärts ), overalline = mean, beanlines = median, col=c(orange,yellow,bisque, white)) ## Run boxplot to find statistics, but don't draw the boxplots S - boxplot(dimension ~ gruppe, names = c(Aufwärts, Lateral, Abwärts), plot=FALSE) ## Define locations for additional chart elements at - c(1:length(S$names)) means - by(dimension, gruppe, mean, na.rm=TRUE) points(at,means, pch = 23, cex = 1.2, bg = blue) ## Draw Mean values to the left edge of each violinplot text(at - 0.3, means, labels = formatC(means, format = f, digits = 1), pos = 2, cex = 1, col = blue) ## Draw Median values to the right edge of each violinplot text(at + 0.3, S$stats[3, ], labels = formatC(S$stats[3, ], format = f, digits = 1), pos = 4, cex = 1, col = darkgreen) ##- Get CIs -## ## create standard error function-- se - function(x) { y - x[!is.na(x)] sqrt(var(as.vector(y))/length(y)) } ## create length function for non-missing values lngth - function(x){ y - x[!is.na(x)] length(y) } ## Compute vectors of standard error and n Hse - by(dimension, gruppe,se) Hn - by(dimension, gruppe,lngth) ## compute 95% CIs and store in vectors civ.u - means + qt(.975, df=Hn-1) * Hse # Upper bound CI civ.l - means + qt(.025, df=Hn-1) * Hse # Lower bound CI ## Draw CI, first vertical line, then upper and lower horizontal segments(at, civ.u, at, civ.l, lty = solid, lwd = 2, col = red) segments(at - 0.1, civ.u, at + 0.1, civ.u, lty = solid, lwd =2,col = red) segments(at - 0.1, civ.l, at + 0.1, civ.l, lty = solid, lwd =2,col = red) ## Print n under the name of measure mtext(S$n, side = 1, at = at, cex=.75, line = 2.5) mtext(S$names, side = 1, at = at, cex=1, line = 1) }) -- View this message in context: http://r.789695.n4.nabble.com/How-to-produce-serveral-plots-with-pairs-of-vectors-tp4540968p4541164.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] Error in integrate(int.fn, lower = 0, upper = Inf) : evaluation of function gave a result of wrong length
Hi, i am writing a function to plot a pdf functions of a Generalized normal laplace distribution. The code is this { y = x-rho*mu cf.fn = function(s){ cplex = complex(1,0,1) temp1 = alpha*beta*exp(-sigma*s^2/2) temp2 = (alpha-cplex*s)*(beta+cplex*s) out = (temp1/temp2)^rho out } temp.fn = function(s){ (Mod(cf.fn(s)))*cos(Arg(cf.fn(s))-s*y) } int.fn = function(t){sapply(t,FUN=temp.fn)} te = integrate(int.fn,lower=0,upper=Inf,rel.tol=1e-10,subdivisions=100) temp3 = ifelse(te$message == OK,te$value/pi,NA) temp3 } for example if i call the function like this : GNL.pdf.fn(x[100],mu,sigma,alpha,beta,rho) there is no problem and as expected a number is returned but if i try to call it with a sequence of number ex: x = seq(-4,4,0.1) this error keeps show in up Error in integrate(int.fn, lower = 0, upper = Inf) : evaluation of function gave a result of wrong length Anyone call help me please ? Thanks in advance -- View this message in context: http://r.789695.n4.nabble.com/Error-in-integrate-int-fn-lower-0-upper-Inf-evaluation-of-function-gave-a-result-of-wrong-length-tp4541250p4541250.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] multithreaded low level functions
Hi all, I wanted to make sure that I am getting the most from my 8 core computer running R. I have a distance function like this: distance - function(pointX, pointY, vecX, vecY) { #convert everything to radians pointX = pointX * pi/180 pointY = pointY * pi/180 vecX = vecX * pi/180 vecY = vecY * pi/180 #data@coords[,2] = lat #data@coords[,1] = lon delta_lon = pointX - vecX #print(sprintf(Len Pt X: %d Len Pt Y: %d, length(pointX),length(pointY))) #print(sprintf(Len Vec X: %d Len Vec Y: %d, length(vecX),length(vecY))) #print(sprintf(Len delta_lon: %d, length(delta_lon))) R = 6372.8 #Radius of the earth (km) #spherical law of cosines: #acos(sin(lat)*sin(lat) + cos(lat)*cos(lat)*cos(delta lon)) delta_rad = acos(sin(pointY)*sin(vecY) + cos(pointY)*cos(vecY)*cos(delta_lon)) delta_km = R*delta_rad return(delta_km) } vecX and vecY are very large, about 500k elements or more. I want to know the most efficient way to write this function. I don't even need to do lapply or an apply function for this because I assume that cos(vector) and sign(vector) will handle all of the multi-threading that I could ask for. I know that R is a functional language and, as such, I assume that each of these will be run in parallel with the optimal settings. Am I mistaken in this and if I am, how can I can default multithreading base operations applied to vectors etc? Currently I also have MPI set up for some work I am doing. Should I use this heavily and assume that it is doing what I want it to? What free BLAS should I be using on ubuntu 11.10? Thank you, ~Ben [[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] assigment operator question
On Sun, Apr 8, 2012 at 11:57 AM, Duncan Murdoch murdoch.dun...@gmail.com wrote: On 12-04-07 4:51 PM, Henrik Bengtsson wrote: On Sat, Apr 7, 2012 at 1:30 PM, Mark Heckmannmark.heckm...@gmx.de wrote: Hello, using the- assignment operator I do not understand why the following does not work. l- list() l list() l$arg1- test error in l$arg1- test : Objekt 'l' not found ?- says: The operators- and - cause a search to made through the environment for an existing definition of the variable being assigned. If such a variable is found (and its binding is not locked) then its value is redefined, otherwise assignment takes place in the global environment. Still I do noch understand why the above does not work. The object l is in the global environment. Can someone explain it to me? Yes, the object 'l' is in the global environment, but 'l$arg1' is not, cf. exists(l$arg1) and exists(l). Instead, this works: I don't think that is the problem: - normally works with complex assignments. I think the problems are - Mark was working at top level in the console - The documentation isn't clear about what happens in that case. - R is inconsistent between simple and complex assignments with -. The - operator is designed to be used in a function, and it makes an assignment in the environment of the function, not in the local evaluation frame. If it can't find a variable there, it assigns into the global environment. So if the l$arg1 - test was a line in a function, everything would have worked as expected. When you use it at the top level, it tries looking in the parent of the global environment, its parent, and so on, back to the empty environment at the root of all the namespaces. If you happened to use a name like mean which exists, it will try to assign to that object (and fail, because that binding is locked). If you pick a name that doesn't exist, then R is inconsistent. If you're doing a simple assignment like l - 5 it will be done in the global environment, creating a new variable if necessary. If you're doing a complex assignment like l$arg1 - test it will just fail, there's no global environment fallback. I don't think this inconsistency is really worth fixing, since - is designed for use in functions. There really isn't any use for it at the top level. But maybe all of this should be documented. There's quite a bit of detail in section 3.4 of the R Language Definition, though it's focused on subscripting superassignments. It even covers pathological cases such as x[is.na(x)] - 0 -thomas -- Thomas Lumley Professor of Biostatistics University of Auckland __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] CRAN (and crantastic) updates this week
CRAN (and crantastic) updates this week New packages * bigdata (0.1) Maintainer: Han Liu Author(s): Han Liu, Tuo Zhao License: GPL-2 http://crantastic.org/packages/bigdata The big data package is a collection of scalable methods for large-scale data analysis. * boss (1.0) Maintainer: Arend Voorman Author(s): Arend Voorman License: GPL (= 2) http://crantastic.org/packages/boss BOSS uses parameter estimates obtained without genotype to boost standard one-step approximations, and precomputes as much as possible without genotype (using boss.set) to minimize effort required. * Distance (0.6) Maintainer: David L Miller Author(s): David L. Miller License: GPL (= 2) http://crantastic.org/packages/Distance A library that provides a simple way of fitting detection functions to distance sampling data for both line and point transects. Adjustment term selection, left and right truncation as well as monotonicity constraints and binning are supported. Abundance and density estimates can also be calculated if survey area information is provided. * FinAsym (1.0) Maintainer: Paolo Zagaglia Author(s): Paolo Zagaglia License: GPL-3 http://crantastic.org/packages/FinAsym This package accomplishes two tasks: a) it classifies implicit trading activity from quotes in OTC markets using the algorithm of Lee and Ready (1991); b) based on information for trade initiation, the package computes the probability of informed trading of Easley and O'Hara (1987). * gammSlice (1.2-5) Maintainer: Tung Pham Author(s): Tung Pham and Matt Wand License: GPL (= 2) http://crantastic.org/packages/gammSlice Uses a slice sampling-based Markov chain Monte Carlo to conduct Bayesian fitting and inference for generalized additive mixed models (GAMM). Generalized linear mixed models and generalized additive models are also handled as special cases of GAMM. * GenOrd (1.0.1) Maintainer: Alessandro Barbiero Author(s): Alessandro Barbiero, Pier Alda Ferrari License: GPL http://crantastic.org/packages/GenOrd The package implements a procedure for generating samples from ordinal/discrete random variables with pre-specified correlation matrix and marginal distributions. * Lambda4 (1.0) Maintainer: Unknown Author(s): Tyler Hunt License: GPL (= 2) http://crantastic.org/packages/Lambda4 This code provides 4 different estimates of maximized lambda4 (A split half reliability estimate) * leapp (1.0) Maintainer: Yunting Sun Author(s): Yunting Sun yunti...@stanford.edu , Nancy R.Zhang nzh...@stanford.edu, Art B.Owen o...@stanford.edu License: GPL (= 2) http://crantastic.org/packages/leapp These functions take a gene expression value matrix, a primary covariate vector, an additional known covariates matrix. A two stage analysis is applied to counter the effects of latent variables on the rankings of hypotheses. The estimation and adjustment of latent effects are proposed by Sun, Zhang and Owen (2011). quot;leappquot; is developed in the context of microarray experiments, but may be used as a general tool for high throughput data sets where dependence may be involved. * lxb (1.1) Maintainer: Björn Winckler Author(s): Björn Winckler bjorn.winck...@gmail.com License: BSD http://crantastic.org/packages/lxb Functions to quickly read LXB parameter data. * markdown (0.3) Maintainer: JJ Allaire Author(s): JJ Allaire, Jeffrey Horner, Vicent Marti, and Natacha Porte License: GPL-3 http://crantastic.org/packages/markdown Markdown is a plain-text formatting syntax that can be converted to XHTML or other formats. This package provides R bindings to the Sundown markdown rendering library. * phenology (3.28) Maintainer: Marc Girondot Author(s): Marc Girondot License: GPL-2 http://crantastic.org/packages/phenology Functions to fit and test the phenology of species based on counts. * RAFM (1.0) Maintainer: Unknown Author(s): Markku Karhunen, Uni. Helsinki License: GPL-2 http://crantastic.org/packages/RAFM Fits AFM by Metropolis-Hastings, calculates theta and FST out of AFM parameters * SCMA (0.0) Maintainer: Isis Bulte Author(s): Isis Bulte and Patrick Onghena License: GPL (= 2) http://crantastic.org/packages/SCMA A package for probability combining (additive and multiplicative method) and for calculating some effect size measures on single-case data (SMD, PND and PEM). * skewtools (0.1.0) Maintainer: Javier E. Contreras-Reyes Author(s): Javier E. Contreras-Reyes License: GPL (= 2) http://crantastic.org/packages/skewtools This package include functions related to following topics: 1. Information Theory: Entropy and Mutual Informacion Index for Multivariate Skew-t and Skew-Normal distributions. 2. Estimation of Growth models parameters (Von Bertalanffy, Gompertz, Logistic and Richards) using the robust ECME method via
Re: [R] quantmod getOptionChain Not Work
Michael, I have not had time to look at this for a while but still wanted to say thanks for looking into it and sending this solution. By the way, Jeff mentioned that the version of quantmod on the SVN (0.3.18) works for this. I tried to figure out how to download that version, but found the documentation on SVN's quite confusing. Is there anyway that you could make that version available? Much appreciated. --John Sparks On Fri, March 23, 2012 5:55 pm, R. Michael Weylandt wrote: Sorry about that: two small mistakes and I imagine there are a few more I've missed. This should actually work: ### library(XML) readYahooOptions - function(Symbols, Exp, ...){ parse.expiry - function(x) { if(is.null(x)) return(NULL) if(inherits(x, Date) || inherits(x, POSIXt)) return(format(x, %Y-%m)) if (nchar(x) == 5L) { x - sprintf(substring(x, 4, 5), match(substring(x, 1, 3), month.abb), fmt = 20%s-%02i) } else if (nchar(x) == 6L) { x - paste(substring(x, 1, 4), substring(x, 5, 6), sep = -) } return(x) } clean.opt.table - function(tableIn){ tableOut - sapply(tableIn[,-2], function(x) as.numeric(gsub(,,,x))) rownames(tableOut) - tableIn[,2] tableOut } if(missing(Exp)) optURL - paste(paste(http://finance.yahoo.com/q/op?s,Symbols,sep==;),Options,sep=+) else optURL - paste(paste(http://finance.yahoo.com/q/op?s=,Symbols,m=,parse.expiry(Exp),sep=),Options,sep=+) if(!missing(Exp) is.null(Exp)) { optPage - readLines(optURL) optPage - optPage[grep(View By Expiration, optPage)] allExp - gregexpr(m=, optPage)[[1]][-1] + 2 allExp - substring(optPage, allExp, allExp + 6) allExp - allExp[seq_len(length(allExp)-1)] # Last one seems useless ? return(structure(lapply(allExp, readYahooOptions, Symbols=Symbols), .Names=format(as.yearmon(allExp } stopifnot(require(XML)) optURL - readHTMLTable(optURL) # Not smart to hard code these but it's a 'good-enough' hack for now # Also, what is table 9 on this page? list(calls = clean.opt.table(optURL[[10]]), puts = clean.opt.table(optURL[[14]]), symbol = Symbols) } On Fri, Mar 23, 2012 at 6:44 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: I just got around to taking a look at this, but below is a fix. It seems like yahoo finance redesigned the page and rather than reparsing all their HTML, I'll use Duncan TL's XML package to make life happier. (I loathe HTML parsing) This isn't thoroughly tested and it'll break if yahoo redesigns things again (I hardcode the table numbers for now) but it seems to work well enough. Let me know if you have any errors with it. If Jeff likes it, it should be a drop-in replacement for the getOptionChain.yahoo for quantmod with a name change. Feedback welcome, Michael # library(XML) readYahooOptions - function(Symbols, Exp, ...){ parse.expiry - function(x) { if(is.null(x)) return(NULL) if(inherits(x, Date) || inherits(x, POSIXt)) return(format(x, %Y-%m)) if (nchar(x) == 5L) { x - sprintf(substring(x, 4, 5), match(substring(x, 1, 3), month.abb), fmt = 20%s-%02i) } else if (nchar(x) == 6L) { x - paste(substring(x, 1, 4), substring(x, 5, 6), sep = -) } return(x) } clean.opt.table - function(tableIn){ tableOut - lapply(tableIn[,-2], function(x) as.numeric(gsub(,,,x))) rownames(tableOut) - tableIn[,2] } if(missing(Exp)) optURL - paste(paste(http://finance.yahoo.com/q/op?s,Symbols,sep==;),Options,sep=+) else optURL - paste(paste(http://finance.yahoo.com/q/op?s=,Symbols,m=,parse.expiry(Exp),sep=),Options,sep=+) if(!missing(Exp) is.null(Exp)) { optPage - readLines(optURL) optPage - optPage[grep(View By Expiration, optPage)] allExp - gregexpr(m=, optPage)[[1]][-1] + 2 allExp - substring(optPage, allExp, allExp + 6) allExp - allExp[seq_len(length(allExp)-1)] # Last one seems useless ? Always true? return(structure(lapply(allExp, readYahooOptions, Symbols=Symbols), .Names=format(as.yearmon(allExp } stopifnot(require(XML)) optURL - readHTMLTable(optURL) # Not smart to hard code these but it's a 'good-enough' hack for now # Also, what is table 9 on this page? CALLS - optURL[[10]] PUTS - optURL[[14]] list(calls = CALLS, puts = PUTS, symbol = Symbols) } ### On Sun, Mar 4, 2012 at 2:18 PM, Sparks, John James jspa...@uic.edu wrote: Dear R Helpers, I am still having trouble with the getOptionChain command in quantmod. I have the latest version of quantmod, etc. so I was under the impression that the problem was
Re: [R] Drawing a line in xyplot
This can be simplified by using the layering abilities that Felix Andrews made available in latticeExtra. These are too little known. These pretty much make it unnecessary to resort to trellis.focus(), at least in such cases as this. These layering abilities are too little known: library(latticeExtra) x11(height=8,width=11) xdat = data.frame(mortality =c(5, 8,7,5,8,10,11,6,4,5,20,25,27,30,35,32,28,21,20,34,11,15,18,12,15,12,10,15,19,20), type= c(1, 1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3), attend = c(1, 0,1,1,1,1,0,0,0,1,0,1,0,0,0,0,1,0,0,0,1,1,1,0,1,0,1,0,0,0)) gph - xyplot ( mortality ~ attend|type, panel=function(x,y) { panel.grid(lty=5) panel.xyplot(x,y,pch=16,jitter.x=TRUE,col=1) for(i in 1:3) { panel.segments(x0=c(0.7, 1.7), x1=c(1.3, 2.3), y0=with(xdat, c(tapply(mortality[type==i], attend[type==i], median))), y1=with(xdat, c(tapply(mortality[type==i], attend[type==i], median))),col=red,lwd=4) } }, data = xdat, aspect=2:1,layout=c(3,1)) ## Now create a layer object that will add the further segments. addlayer - layer(panel.segments(x0=1,y0=20,x1=1.2, y1=20), panel.segments(x0=2,y0=30,x1=2.2, y1=30)) gph+addlayer The code that produces the object gph would also be simpler and easier to follow if some relevant part was separated out into a separate layer. See also my notices on layering of lattice objects at: http://www.maths.anu.edu.au/%7Ejohnm/r-book/add-graphics.html John Maindonald email: john.maindon...@anu.edu.au phone : +61 2 (6125)3473fax : +61 2(6125)5549 Centre for Mathematics Its Applications, Room 1194, John Dedman Mathematical Sciences Building (Building 27) Australian National University, Canberra ACT 0200. http://www.maths.anu.edu.au/~johnm On 08/04/2012, at 8:00 PM, r-help-requ...@r-project.org wrote: From: David Winsemius dwinsem...@comcast.net Subject: Re: [R] Drawing a line in xyplot Date: 8 April 2012 2:17:22 PM AEST To: wcheckle wchec...@jhsph.edu Cc: r-help@r-project.org On Apr 7, 2012, at 10:29 PM, wcheckle wrote: Thank you David, the bwplot option does what I need: x11(height=8,width=11) bwplot ( mortality~ attend|type, pch=95,cex=5,col=2, par.settings=list( box.rectangle = list(col = transparent), box.umbrella = list(col = transparent), plot.symbol = list(col = transparent) ), panel=function(x,y,...){ panel.grid(lty=5) panel.xyplot(x,y,pch=16,jitter.x=TRUE,col=1) panel.bwplot(x,y,...) }, data = x,aspect=2:1,layout=c(3,1)) However, I am interested in also learning how to do it in xyplot as well. I wasnt able to follow the last two set of instructions (condition on packet.number and loop over segments), wondering if I can ask for your help for the correct code (my attempt resulted in all three mean lines within each panel): x11(height=8,width=11) xyplot ( mortality ~ attend|type, panel=function(x,y) { panel.grid(lty=5) panel.xyplot(x,y,pch=16,jitter.x=TRUE,col=1) for(i in 1:3) { panel.segments(x0=c(0.7, 1.7), x1=c(1.3, 2.3), y0=c(tapply(x$mortality[x$type==i], x$attend[x$type==i], median)), y1=c(tapply(x$mortality[x$type==i], x$attend[x$type==i], median)),col=red,lwd=4) } }, data = x,aspect=2:1,layout=c(3,1)) thank you again. I also found your info on data.frame useful. I haven't figured out how to do it with the interaction of 'attend' and ''type' from inside xyplot. I'm thinking I might be able to succeed using trellis.focus() to address separate columns within a particular panel. This will draw segments at (1,20) and (2,30) without resorting to low level grid/viewport stuff. trellis.unfocus(); trellis.focus(panel, 1, 1) do.call(panel.segments, list(x0=1,y0=20,x1=1.2, y1=20)) trellis.unfocus() trellis.unfocus(); trellis.focus(panel, 1, 1) do.call(panel.segments, list(x0=2,y0=30,x1=2.2, y1=30)) trellis.unfocus() -- David David Winsemius, MD West Hartford, CT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Avoid loop with the integrate function
Hi, I am not sure I follow the scalar part of the suggestion. Could you please elaborate it a bit more? Each row has a different value of score for each subject at each time point. Also I simplified the example but there are other terms that change over each row for each subject. Does this mean that loops is the only way to go ? Thanks again for your help and time. Navin Goyal On Sun, Apr 8, 2012 at 4:03 AM, Berend Hasselman b...@xs4all.nl wrote: On 08-04-2012, at 08:28, Navin Goyal wrote: Dear R users, I am running a loop with the integrate function. I have pasted the code below. I am integrating a function from time=0 to the time value in every row. I have to perform this integration over thousands of rows with different parameters in each row. Could someone please suggest if there is an efficient/faster/easier way to do this by avoiding the loops ? Thank you so much for your help and time. -- Navin Goyal # dose-10 time-0:5 id-1:5 data1-expand.grid(id,time,dose) names(data1)-c(ID,TIME, DOSE) data1-data1[order(data1$ID,data1$TIME),] ed-data1[!duplicated(data1$ID) , c(ID,DOSE)] set.seed(5324123) for (k in 1:length(ed$ID)) { ed$base[k]-100*exp(rnorm(1,0,0.05)) ed$drop[k]-0.2*exp(rnorm(1,0,0.01)) ed$frac[k]-0.5*exp(rnorm(1,0,0.1)) } Why not ed$base - 100*exp(rnorm(length(ed$ID), 0, 0.05)) etc. comb1-merge(data1[, c(ID,TIME)], ed) comb2-comb1 comb2$score-comb2$base*exp(-comb2$drop*comb2$TIME) func1-function(t,cov1,beta1, change,other) { ifelse(t==0,cov1, cov1*exp(beta1*change+other)) } AFAICS, cov1, beta1, change and other are scalars. So when an item of t is == 0 then the function value is cov1 and in all other cases it is the same scalar and does not depend on t. So func1 is a step function. You could calculate the integral directly. Berend -- Navin Goyal [[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] Drawing a line in xyplot
On Apr 8, 2012, at 7:24 PM, John Maindonald wrote: This can be simplified by using the layering abilities that Felix Andrews made available in latticeExtra. These are too little known. These pretty much make it unnecessary to resort to trellis.focus(), at least in such cases as this. These layering abilities are too little known: library(latticeExtra) x11(height=8,width=11) xdat = data.frame(mortality =c(5, 8,7,5,8,10,11,6,4,5,20,25,27,30,35,32,28,21,20,34,11,15,18,12,15,12,10,15,19,20 ), type= c(1, 1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3), attend = c(1, 0,1,1,1,1,0,0,0,1,0,1,0,0,0,0,1,0,0,0,1,1,1,0,1,0,1,0,0,0)) gph - xyplot ( mortality ~ attend|type, panel=function(x,y) { panel.grid(lty=5) panel.xyplot(x,y,pch=16,jitter.x=TRUE,col=1) for(i in 1:3) { panel.segments(x0=c(0.7, 1.7), x1=c(1.3, 2.3), y0=with(xdat, c(tapply(mortality[type==i], attend[type==i], median))), y1=with(xdat, c(tapply(mortality[type==i], attend[type==i], median))),col=red,lwd=4) } }, data = xdat, aspect=2:1,layout=c(3,1)) ## Now create a layer object that will add the further segments. addlayer - layer(panel.segments(x0=1,y0=20,x1=1.2, y1=20), panel.segments(x0=2,y0=30,x1=2.2, y1=30)) Thanks for that John, but I think you missed my point. The lines I was adding were supposed to only be an example of how to put in single median value. The task with which I felt I had failed was to plot six separate medians, two different ones in each panel. I was basically throwing up my hands in dealing with the formula interface and suggesting going to a hand-crafted approach. I assumed that wcheckle would drop the panel.segments call and individually stick in the median values, perhaps using a for-loop. -- David gph+addlayer The code that produces the object gph would also be simpler and easier to follow if some relevant part was separated out into a separate layer. See also my notices on layering of lattice objects at: http://www.maths.anu.edu.au/%7Ejohnm/r-book/add-graphics.html John Maindonald email: john.maindon...@anu.edu.au phone : +61 2 (6125)3473fax : +61 2(6125)5549 Centre for Mathematics Its Applications, Room 1194, John Dedman Mathematical Sciences Building (Building 27) Australian National University, Canberra ACT 0200. http://www.maths.anu.edu.au/~johnm On 08/04/2012, at 8:00 PM, r-help-requ...@r-project.org wrote: From: David Winsemius dwinsem...@comcast.net Subject: Re: [R] Drawing a line in xyplot Date: 8 April 2012 2:17:22 PM AEST To: wcheckle wchec...@jhsph.edu Cc: r-help@r-project.org On Apr 7, 2012, at 10:29 PM, wcheckle wrote: Thank you David, the bwplot option does what I need: x11(height=8,width=11) bwplot ( mortality~ attend|type, pch=95,cex=5,col=2, par.settings=list( box.rectangle = list(col = transparent), box.umbrella = list(col = transparent), plot.symbol = list(col = transparent) ), panel=function(x,y,...){ panel.grid(lty=5) panel.xyplot(x,y,pch=16,jitter.x=TRUE,col=1) panel.bwplot(x,y,...) }, data = x,aspect=2:1,layout=c(3,1)) However, I am interested in also learning how to do it in xyplot as well. I wasnt able to follow the last two set of instructions (condition on packet.number and loop over segments), wondering if I can ask for your help for the correct code (my attempt resulted in all three mean lines within each panel): x11(height=8,width=11) xyplot ( mortality ~ attend|type, panel=function(x,y) { panel.grid(lty=5) panel.xyplot(x,y,pch=16,jitter.x=TRUE,col=1) for(i in 1:3) { panel.segments(x0=c(0.7, 1.7), x1=c(1.3, 2.3), y0=c(tapply(x$mortality[x$type==i], x$attend[x$type==i], median)), y1=c(tapply(x$mortality[x$type==i], x$attend[x$type==i], median)),col=red,lwd=4) } }, data = x,aspect=2:1,layout=c(3,1)) thank you again. I also found your info on data.frame useful. I haven't figured out how to do it with the interaction of 'attend' and ''type' from inside xyplot. I'm thinking I might be able to succeed using trellis.focus() to address separate columns within a particular panel. This will draw segments at (1,20) and (2,30) without resorting to low level grid/viewport stuff. trellis.unfocus(); trellis.focus(panel, 1, 1) do.call(panel.segments, list(x0=1,y0=20,x1=1.2, y1=20)) trellis.unfocus() trellis.unfocus(); trellis.focus(panel, 1, 1) do.call(panel.segments, list(x0=2,y0=30,x1=2.2, y1=30)) trellis.unfocus() -- David David Winsemius, MD West Hartford, CT David Winsemius, MD West Hartford, CT [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Drawing a line in xyplot
i appreciate all the interest in my question, and thank you Elai for both of your suggestions, which work very well. Elai, your last code was particularly simple and helpful to generate the figure i was looking for. x11(height=8,width=11) par(lend=2) xdat = data.frame(mortality =c(5, 8,7,5,8,10,11,6,4,5,20,25,27,30,35,32,28,21,20,34,11,15,18,12,15,12,10,15,19,20), type= c(1, 1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3), attend = c(1, 0,1,1,1,1,0,0,0,1,0,1,0,0,0,0,1,0,0,0,1,1,1,0,1,0,1,0,0,0)) xyplot ( mortality ~ factor(attend)|type, panel=function(x,y) { panel.grid(lty=5) panel.xyplot(x,y,pch=16,jitter.x=TRUE,col=1) yy- tapply(y,x,median) panel.segments(x0=c(0.7,1.7), x1=c(1.3,2.3), y0= yy , y1= yy , col=red,lwd=5) }, data = xdat, aspect=2:1,layout=c(3,1)) http://r.789695.n4.nabble.com/file/n4541912/trial.jpg as a side note, the par(lend=2) function did not square the ends of the lines for panel.segments in xyplot (i was trying to get square ends instead of round ends). John: thank you for your information regarding latticeExtra and the layer function, which will be helpful for future figures. -- View this message in context: http://r.789695.n4.nabble.com/Drawing-a-line-in-xyplot-tp4538689p4541912.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] Changing grid defaults
First I'd like to thank Ilaik and Paul for their responses. I seem to be getting what I need by using LaTeX's tikz package and including tikz=true in the options for the figure chunks using vcd, e.g., fig=true,tikz=true,width=5,height=5,echo=FALSE,results=hide= ... R commands ... @ I have actually used this before in other documents, but not for this purpose, so it didn't occurred to me to try it until Ilaik mentioned tikz in his message. FTR, I never could get successfully change the color defaults for grid, at least not for vcd graphics (again, this is easy to do for traditional R graphics in Sweave). In particular, when I took Paul's suggestion and added the line pushViewport(viewport(gp=gpar(col=yellow))) before the graphics command, I got no output, which didn't surprise me too much. Adding a popViewport() command produced an error message: Cannot pop the top-level viewport (grid and graphics output mixed?) I wasn't able to see how to get what I needed using the font commands in the article that Paul pointed to either, and I don't have time to pursue it any further right now. So I'm going to cut and run, and hope that the tikz approach will work out. Still, it would be nice (for me at least) if there was a full example somewhere showing how to change the grid defaults (foreground and background colors in particular) in an Sweave document in such a way that they stay changed throughout the document, particularly in a document that also uses traditional R graphics. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] How To Setup hunspell in R
Hello, I am doing some text mining and text analysis in R. However, I have NO idea how to install hunspell into R and use the aspell() function correctly, I keep running into this error: Error in aspell(f, Rd) : No suitable spell check program found. Come someone give me a detailed step by step process on how to install hunspell onto your windows and use it from R? Thank you. Sincerely, Yi Xiang -- View this message in context: http://r.789695.n4.nabble.com/How-To-Setup-hunspell-in-R-tp4541801p4541801.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] Summary Statistics Help
Hi, I would really appreciate all the help I can get. Unfortunately, I am really new to statistics! I hope you guys don't mind this. I am trying to find significance levels, beta, R, R squared, adjusted R squared, standard error and t test. FILE http://r.789695.n4.nabble.com/file/n4541923/datpat.csv datpat.csv Variables (written exactly as in the Excel file) I am trying to examine are : a) Patents and FHouse b) Patents and FHouse controlled for extra, interstate, internationalized c)Patents and FHouse controlled for internal threat (internal, DISAP, KILL, TORT, POLPRIS, frac_eth, frac_rel) d)Patents and EconGlob, SocGlob, PolGlob, Econflows, e)Patents and GDP_Constant f)Patents and durable, democ, autoc, My code so far, I got stuck at section SUMMARY STATS: datpat - read.csv(file=datpat.csv, header=TRUE, rownames = FALSE) datpat - datpat[,-1] datpat[,c(1:3,718)] colnames(datpat) # --- # PRELIMINARY ANALYSES # # Overall summary(datpat$Patents) # By Nation (using the Index No.) sumbynation - by(datpat$Patents, datpat$Nation, summary) mode(sumbynation) sumbynation - data.frame(cbind(levels(datpat[,3]),t(matrix(unlist(sumbynation),6, length(unique(datpat[,1])) dim(sumbynation) # Adding column names colnames(sumbynation) - c(ID, Min, 1st Qu, Median, Mean, 3rd Qu, Max) # Export table to LaTex install.packages(xtable) library(xtable) ?xtable xtable(sumbynation) # By Year (using the second column Year variable) sumbyyear - by(datpat$Patents, datpat$Year, summary) sumbyyear - cbind(unique(datpat[,2]),t(matrix(unlist(sumbyyear),6, length(unique(datpat[,2]) # Adding column names colnames(sumbyyear) - c(ID, Min, 1st Qu, Median, Mean, 3rd Qu, Max) # Export table to LaTex xtable(sumbyyear) # # New Analyses: Patents and FHouse # # Global correlation of Pattens with FHouse values cor(datpat$Patents, datpat$FHouse) # Conditional frequency count of data/time points by nation by(datpat$Patents, datpat$Nation, length) # Conditional correlations by nation corbynation - by(cbind(Patents = datpat$Patents, FHouse = datpat$FHouse), datpat$Nation, cor) length(corbynation) natcor - c() for(i in 1:length(corbynation)){ natcor - c(natcor,unlist(corbynation[i])[2]) } par(mar=c(4.5,4.5,5.5,1)) plot(natcor, type=p, pch=20, cex=2, axes=FALSE, main=Correlation of Patents and Freedom House Index by Nation, xlab=Nation, ylab=Correlation) box() axis(2) axis(1, at=c(1:46), labels=c(levels(datpat[,3]))) abline(h=0.00, lty=2, col=red3) # Global Patents by Freedom House Index plot(datpat$Patents, datpat$FHouse) --- # SUMMARY STATS --- mod.1-lm(Patents~FHouse, file=datpat.csv, header=TRUE) summary(mod.1) xtable(mod.1) -- View this message in context: http://r.789695.n4.nabble.com/Summary-Statistics-Help-tp4541923p4541923.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] Error using PGMM function in the PLM package
Good day fellow R users: I have routinely received the following message when attempting to estimate a GMM model for a somewhat square panel (N = 20, T = 9-27, Obs = 338) using the pgmm function in the plm package: Error in function (..., deparse.level = 1) : number of rows of matrices must match (see arg 2) So far, I am not wedded to a particular GMM model but what I have used thus far is similar to the Anderson - Hsaio estimator such that Y(t) = Y(t-2) + X(t-1) + u(i) + e(it) where Y(t-2) is the dependent variable lagged twice; X(t-1) is a series of lagged (more or less) exogenous regressors; u(i) is the individual (country) error component; and e(it) is the idiosyncratic error. The within estimator in plm works just fine for what it's worth (see script file). Basically, I was hoping to run the same basic model using pgmm. So far, I've tried to run different types of models using the pgmm function as well as have trimmed the data by adding more lagged versions of the dependent variable and subsequently trimming the dataset (in case there is sensitivity to NA observations) to no avail. I'm pretty familiar with R and the plm package in particular but less so with GMM estimation so I don't know if the issue relates to the software, the code I have written, or with how my data relates to GMM estimation (i.e. the theoretical/mathematical underpinnings of such a method). I have done a decent amount of work in trying to wrap my head around GMM and I don't see exactly what the problem could be so I'm reaching out to folks who know better. There was an earlier post on a similar topic (https://stat.ethz.ch/pipermail/r-help/2010-July/245807.html) but that issue appears to have been corrected with an amendment to the plm package. The links to my my (trimmed) dataset and R code are below. Thanks to all in advance for your help. Taylor White Research Assistant, UCLA taylorgentrywh...@gmail.com Link to dataset: https://docs.google.com/open?id=0B5VZMvsirgHCajdxWVI0aVVRQ2F0a3Q4V0NiaDlrdw Link to the script used to run the regressions: https://docs.google.com/open?id=0B5VZMvsirgHCamt3UG9yWlJUNEcwelp4UFVGNnhaQQ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 in integrate(int.fn, lower = 0, upper = Inf) : evaluation of function gave a result of wrong length
On Apr 8, 2012, at 1:28 PM, Guaramy wrote: Hi, i am writing a function to plot a pdf functions of a Generalized normal laplace distribution. The code is this { y = x-rho*mu cf.fn = function(s){ cplex = complex(1,0,1) temp1 = alpha*beta*exp(-sigma*s^2/2) temp2 = (alpha-cplex*s)*(beta+cplex*s) out = (temp1/temp2)^rho out } temp.fn = function(s){ (Mod(cf.fn(s)))*cos(Arg(cf.fn(s))-s*y) } int.fn = function(t){sapply(t,FUN=temp.fn)} te = integrate(int.fn,lower=0,upper=Inf,rel.tol=1e-10,subdivisions=100) temp3 = ifelse(te$message == OK,te$value/pi,NA) temp3 } for example if i call the function like this : GNL.pdf.fn(x[100],mu,sigma,alpha,beta,rho) there is no problem and as expected a number is returned but if i try to call it with a sequence of number ex: x = seq(-4,4,0.1) ?Vectorize this error keeps show in up Error in integrate(int.fn, lower = 0, upper = Inf) : evaluation of function gave a result of wrong length 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.
[R] rwmetrop
Hi, all: Can anybody check where is wrong with my code? I tried a lot of times, but did not find an error. The parameters' estimator is not accurate. It's a simple model about a multiple regression, with five covariates. rwmetrop is supposed to give a much more accurate estimand. Thanks a lot. rm(list=ls()) n=100; p=5; xTrue=matrix(rnorm(n*p),nrow=n, ncol=p) betaTrue=c(1,2,0,3,1) yTrue=xTrue%*%betaTrue+rnorm(n) d=list(y=yTrue, x=xTrue) datapost=function(theta,data){ x=data$x y=data$y mu=rep(0,times=100) for(j in 1:5){ mu=mu+x[,j]*theta[j] } logdensity=-(y-mu)^2/2-log(sqrt(2*pi)) sum(logdensity) } covariance=array(0,dim=c(p,p)) covariance[row(covariance)==col(covariance)]=1 proposal=list(var=covariance, scale=2) start=c(1,1,1,1,1) fit=rwmetrop(datapost, proposal, start, 10, d) colMeans(fit$par[50001:10,]) [[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] return one vector that is the sum of a list of vectors
Dear R Help, I am attempting to write a function that takes a list of variable groups and a vector of numbers (e.g., jtsv would indicate one group of variables, jtsv1, jtsv2, etc, each of which name a variable in a data frame), and returns a list of variable group sums. For example, given list(jtsv, ptsv) and c(1:10), where jtsv1, etc, are all numeric vectors of the same length, the function should return a list of jtsv and ptsv, where jtsv - jtsv1 + jtsv2 + jtsv3 + jtsv4 + jtsv5 + jtsv6 + jtsv7 + jtsv8 + jtsv9 + jtsv10 ptsv - ptsv1 + ptsv2 + ptsv3 + ptsv4 + ptsv5 + ptsv6 + ptsv7 + ptsv8 + ptsv9 + ptsv10 So far I've used a for loop to paste together the names of the variables as character vectors, so that I can at least name the variables that I want to get, but I'm stuck on how to add together the numeric vectors that those character vectors are ultimately supposed to name. It seems like I should be able to map the primitive + operator onto a list or vector that contains the variable names. If that's a good way to go, what would that look like? Or if that's not a good way to go, would someone please point me in a good direction? Sincerely, Frank Tamborello [[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] return one vector that is the sum of a list of vectors
?get ?rowSums ?rowsum a group is not a defined data structure in R, btw. You have a much better chance of getting precise answers if you ask precise questions. See the Posting Guide. -- Bert On Sun, Apr 8, 2012 at 9:01 PM, Frank Tamborello frank.ta...@gmail.com wrote: Dear R Help, I am attempting to write a function that takes a list of variable groups and a vector of numbers (e.g., jtsv would indicate one group of variables, jtsv1, jtsv2, etc, each of which name a variable in a data frame), and returns a list of variable group sums. For example, given list(jtsv, ptsv) and c(1:10), where jtsv1, etc, are all numeric vectors of the same length, the function should return a list of jtsv and ptsv, where jtsv - jtsv1 + jtsv2 + jtsv3 + jtsv4 + jtsv5 + jtsv6 + jtsv7 + jtsv8 + jtsv9 + jtsv10 ptsv - ptsv1 + ptsv2 + ptsv3 + ptsv4 + ptsv5 + ptsv6 + ptsv7 + ptsv8 + ptsv9 + ptsv10 So far I've used a for loop to paste together the names of the variables as character vectors, so that I can at least name the variables that I want to get, but I'm stuck on how to add together the numeric vectors that those character vectors are ultimately supposed to name. It seems like I should be able to map the primitive + operator onto a list or vector that contains the variable names. If that's a good way to go, what would that look like? Or if that's not a good way to go, would someone please point me in a good direction? Sincerely, Frank Tamborello [[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. -- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Avoid loop with the integrate function
On 09-04-2012, at 01:26, Navin Goyal wrote: Hi, I am not sure I follow the scalar part of the suggestion. Could you please elaborate it a bit more? Each row has a different value of score for each subject at each time point. That last remark has nothing to do with it. The point is that in your function func1 the returned value doesn't depend on the argument t. So func1 is returning a vector of length==length(t) of identical values except for the first entry which is zero. Do this after the loop for comb3 # No integral since expression in func1 doesn't depend on t comb4-comb2 comb4$cmhz=0 comb4-comb4[order(comb4$ID, comb4$TIME), ] for (q in 1:length(comb4$ID)) { comb4$cmhz[q]-comb4$TIME[q]*func1(comb4$TIME[q], cov1=0.001,beta1=0.02, change=comb4$score[q], other=comb4$frac[q]) } head(comb4) all.equal(comb3$cmhz, comb4$cmhz) You don't need integrate to get what you seem to be wanting. Berend Also I simplified the example but there are other terms that change over each row for each subject. Does this mean that loops is the only way to go ? Thanks again for your help and time. Navin Goyal On Sun, Apr 8, 2012 at 4:03 AM, Berend Hasselman b...@xs4all.nl wrote: On 08-04-2012, at 08:28, Navin Goyal wrote: Dear R users, I am running a loop with the integrate function. I have pasted the code below. I am integrating a function from time=0 to the time value in every row. I have to perform this integration over thousands of rows with different parameters in each row. Could someone please suggest if there is an efficient/faster/easier way to do this by avoiding the loops ? Thank you so much for your help and time. -- Navin Goyal # dose-10 time-0:5 id-1:5 data1-expand.grid(id,time,dose) names(data1)-c(ID,TIME, DOSE) data1-data1[order(data1$ID,data1$TIME),] ed-data1[!duplicated(data1$ID) , c(ID,DOSE)] set.seed(5324123) for (k in 1:length(ed$ID)) { ed$base[k]-100*exp(rnorm(1,0,0.05)) ed$drop[k]-0.2*exp(rnorm(1,0,0.01)) ed$frac[k]-0.5*exp(rnorm(1,0,0.1)) } Why not ed$base - 100*exp(rnorm(length(ed$ID), 0, 0.05)) etc. comb1-merge(data1[, c(ID,TIME)], ed) comb2-comb1 comb2$score-comb2$base*exp(-comb2$drop*comb2$TIME) func1-function(t,cov1,beta1, change,other) { ifelse(t==0,cov1, cov1*exp(beta1*change+other)) } AFAICS, cov1, beta1, change and other are scalars. So when an item of t is == 0 then the function value is cov1 and in all other cases it is the same scalar and does not depend on t. So func1 is a step function. You could calculate the integral directly. Berend -- Navin Goyal __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.