[R] singular matrix in composition package
Dear R user how to solve the error of singular matrix in composition package thanks in advance ros [[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] invalid command name tk::MenuDup
It seems that tcl/tk doesn't work fine on R-2.11 version. Anyone can run this code to confirm ? [CODE]require(tcltk) tt - tktoplevel() topMenu - tkmenu(tt) tkconfigure(tt,menu=topMenu) fileMenu - tkmenu(topMenu,tearoff=FALSE) tkadd(fileMenu,command,label=Quit,command=function() tkdestroy(tt)) tkadd(topMenu,cascade,label=File,menu=fileMenu) tkfocus(tt)[/CODE] Thanks, -- View this message in context: http://r.789695.n4.nabble.com/invalid-command-name-tk-MenuDup-tp4091092p4094860.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] Unexpected result with lag() et diff() in plm package.
I didn't see you got an answer posted to this question: You can't modify a pdata.frame object. Your transforms turn it back to a normal data frame and diff and lag won't work as expected. Try: Grunfeld.p - pdata.frame(Grunfeld,c(firm,year)) tmp - transform(Grunfeld.p, d.value = diff(Grunfeld.p$value,1)) tmp - cbind(tmp, l.value = lag(Grunfeld.p$value,1)) ... When everything is in shape, convert it back to a pdata.frame for further analysis: Grunfeld.p - pdata.frame(tmp,c(firm,year)) [[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] Capping outliers
Hi Experts, I am new to R, using following sample code for capping outliers using percentile information. Working on large data (3 observations and 150 variables), loop I am using in the below mentioned code for detecting outliers and capping to upper /lower percentile value is taking much time for the execution. Is there anything wrong with code, can anyone suggest improvement in the script to enhance performance! min_pctle_cut - 0.01 max_pctle_cut - 0.99 library(outliers) n - 100 x1 - runif(n) x2 - runif(n) x3 - x1 + x2 + runif(n)/10 x4 - x1 + x2 + x3 + runif(n)/10 x5 - factor(sample(c('a','b','c'),n,replace=TRUE)) x6 - factor(1*(x5=='a' | x5=='c')) data1 - cbind(x1,x2,x3,x4,x5,x6) x - data.frame(data1) z - x[,sapply(x,is.numeric)] qs - sapply(z, function(z) quantile(z, c(min_pctle_cut, max_pctle_cut), na.rm = TRUE)) #Loop below taking time for execution system.time(for (i in 1:ncol(z)) { for (j in 1:nrow(z)) { if (z[j,i] qs[1,i]) z[j,i]=qs[1,i] if (z[j,i] qs[2,i]) z[j,i]=qs[2,i] } }) -- View this message in context: http://r.789695.n4.nabble.com/Capping-outliers-tp4094647p4094647.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] problem in creating a dataframe
Hi I have a character class and i need to convert into dataframe data=(0,0,0,0) I want a dataframe with each one should under a separate column Please help me -- View this message in context: http://r.789695.n4.nabble.com/problem-in-creating-a-dataframe-tp4094676p4094676.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 gls function in loop structure
Hi, r-users I got a problem when I try to call a *gls* function in loop structure. The gls function seems not able to recognize the parameters that I pass into the loop function! (But, if I use lm function, it works.) The code looks like this: = gls.lm - function(Data, iv1, dv1) { gls.model - gls(Data[ , dv1] ~ Data[ , iv1], correlation = corARMA(p=1), method='ML',na.action=na.omit, data = Data) print(summary(gls.model)) } regResultMatrix - gls.lm(DR, 'Period', 'Aircraft') regResultMatrix - gls.lm(DR, 'Period', 'Total.Employees') == The DR is the data in excel file which includes three columns: Period, Aircraft and Total.Employees. And, I got the error message like this: *Error in eval(expr, envir, enclos) : object 'dv1' not found* Could any one tell me what is going on there? Thanks in advance. Miles -- ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ Miles Yang Mobileï¼+61-411-985-538 E-mailï¼miles2y...@gmail.com ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] errors with lme4
Dear Alessio, A few remarks. - R-sig-mixed models is a better list for this kind of questions - use the glmer() function if you want logistic or poisson regression - the error you are getting is an indication that the model is too complex for the data - watch for colinearity in the covariates Best regards, Thierry -Oorspronkelijk bericht- Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Namens Alessio Unisi Verzonden: maandag 21 november 2011 18:20 Aan: r-help@r-project.org Onderwerp: [R] errors with lme4 Urgentie: Hoog Dear list, i'm a new R user, so I apologize if the topic is already being addressed by some other user. I'm trying to determine if the reproductive success of a species of bird is related to a list of covariates. These are the covariates: §elev: elevation of nest (meters) §seadist: distance from the sea (meters) §meanterranova: records of temperature §minpengS1: records of temperature §wchillpengS1: records of temperature §minpengS2: records of temperature §wchillpengS2: records of temperature §nnd: nearest neighbour distance §npd: nearest penguin distance §eggs: numbers of eggs §lay: laying date (julian calendar) §hatch: hatching date (julian calendar) I have some NAs in the data. I want to test the model with all the variable then i want to remove some, but the ideal model: GLM.1 -lmer(fledgesucc ~ +lay +hatch +elev +seadist +nnd +npd +meanterranova +minpengS1 +minpengS2 +wchillpengS1 +wchillpengS2 +(1|territory), family=binomial(logit), data=fledge) doesn't work because of these errors: 'Warning message: In mer_finalize(ans) : gr cannot be computed at initial par (65)'. matrix is not symmetric [1,2] If i delete one or more of the T records (i.e. minpengS2 +wchillpengS2) the model works...below and example: GLM.16 -lmer(fledgesucc ~ lay +hatch +elev +seadist +nnd +npd +meanterranova +minpengS1 +(1|territory), family=binomial(logit), data=fledge) summary(GLM.16) Generalized linear mixed model fit by the Laplace approximation Formula: fledgesucc ~ lay + hatch + elev + seadist + nnd + npd + meanterranova + minpengS1 + (1 | territory) Data: fledge AIC BIC logLik deviance 174 204.2-77 154 Random effects: GroupsNameVariance Std.Dev. territory (Intercept) 0.54308 0.73694 Number of obs: 152, groups: territory, 96 Fixed effects: Estimate Std. Error z value Pr(|z|) (Intercept) 14.136846 14.510089 0.9740.330 lay -0.007642 0.267913 -0.0280.977 hatch -0.025947 0.267318 -0.0970.923 elev 0.007481 0.027765 0.2700.788 seadist -0.004277 0.004550 -0.9400.347 nnd -0.035535 0.026504 -1.3410.180 npd0.003788 0.005521 0.6860.493 meanterranova 1.242570 1.426158 0.8710.384 minpengS1 -0.399852 0.418722 -0.9550.340 Correlation of Fixed Effects: (Intr) layhatch elev seadst nndnpdmntrrn lay 0.411 hatch -0.515 -0.993 elev-0.015 0.141 -0.135 seadist -0.003 -0.023 0.019 -0.440 nnd -0.061 0.066 -0.059 -0.020 0.231 npd 0.033 -0.108 0.100 0.298 -0.498 -0.338 meanterranv 0.459 -0.118 0.075 -0.061 0.014 -0.048 0.130 minpengS1 -0.540 0.015 0.035 0.032 0.000 0.039 -0.086 -0.970 I've attached an example of my dataset only 15 rows just to see the dataset. Let me know if you need more informations. Thanks in advance for your help and advices! regards -- Alessio Franceschi Phd student Dipartimento di Scienze Ambientali G. Sarfatti Università di Siena Via P.A. Mattioli, 8 - 53100 Siena (Italy) Cell. +393384431806 email: francesc...@unisi.it; alfrances...@alice.it __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [OT] 1 vs 2-way anova technical question
On Mon, Nov 21, 2011 at 1:28 PM, Giovanni Azua brave...@gmail.com wrote: On Nov 21, 2011, at 8:31 PM, Bert Gunter wrote: we disagree is that I think data analysts with limited statistical backgrounds should consult with local statisticians instead of trying to muddle through on their own thru lists like this. This is not meant I think that people lacking reading skills should not be subscribed in lists like this one, bullying and creating confusion around. I agree with you that emails lists are not the place for those who cannot read. I will asks as many times as I want/need and the way I use lists if none of your f. b. It is true the way you use general lists is not our business, but the R-help list is a community and there are community rules. One of those is not to ask questions that are primarily about a lack of statistical understanding (although they are not strictly prohibited). Your original post suggests that you knew this, I know there is plenty of people in this group who can give me a good answer :) but chose to ignore it. Despite this, Bert was generous enough to give you some suggestions, perhaps not what you wanted but useful tips nonetheless. You may ask many times, but failing to follow guidelines and thinly veiled profanity are unlikely to endear you to the people here who can offer useful suggestions. Further, to me, your comment below falls under the, Ad hominem comments are absolutely out of place. Note that no loop hole or pass is given for the behavior of other parties. That is, ad hominem comments do not become in place if someone else is rude enough or makes them first. Regarding your suggestion that the list be split into a beginner and advanced list, while that is one option, your original question was appropriate for neither. It was, however, very appropriate for a statistics list (e.g., http://stats.stackexchange.com/). to be arrogance on my part -- though it may seem to come across that way -- but rather a plea for good science. I believe that bad statistics -- bad science, a problem that I see as pervasive and inimical to scientific progress, especially in today's data saturated world. But enough of my off topic B.S. Please reply privately to not waste yet more space here (positively or negatively -- stone throwers need to catch them, too). You are actually full of your off topic prime matter, you arrogant prick. To me, this is extremely offensive. Disagreements are inevitable, but we can strive to keep them civil. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. I agree with Rolf Turner's idea that it would be nice if there was a mechanism to limit these sorts of posts. Sincerely, Josh -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.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] attach 'name' argument ignored with a file?
Dear useRs experRts, I have the feeling that the 'name' argument to the attach function is ignored when 'what' is a file name. Here is an example: save(letters, file=letters.RData) letters.env - attach(letters.RData, name=letters) search() letters.env The name on the search path is file:letters.RData. I would expect it to be letters... Is it by design? From the doc I read: name name to use for the attached database. ... The name given for the attached environment will be used by search and can be used as the argument to as.environment. I don't see why that would be restricted when 'what' is a file name. What do you think about it? Should I fill a bug about it or did I mis-read the doc? Regards, Xavier __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] invalid command name tk::MenuDup
On Tue, 22 Nov 2011, habasque wrote: It seems that tcl/tk doesn't work fine on R-2.11 version. As the posting guide says, there is no such version, and this list is only for current versions of R: you were asked to upgrade *before* posting. But it does work correctly in R 2.11.0 on my Linux box. This is all about the version of Tcl/Tk, as someone told you yesterday. Tcl/Tk is not part of R, even if on the binary platforms we provide a build (which on Windows has not changed since R 2.7.0). But we don't know what your platform is, as you ignored the posting guide. Anyone can run this code to confirm ? [CODE]require(tcltk) tt - tktoplevel() topMenu - tkmenu(tt) tkconfigure(tt,menu=topMenu) fileMenu - tkmenu(topMenu,tearoff=FALSE) tkadd(fileMenu,command,label=Quit,command=function() tkdestroy(tt)) tkadd(topMenu,cascade,label=File,menu=fileMenu) tkfocus(tt)[/CODE] Thanks, -- View this message in context: http://r.789695.n4.nabble.com/invalid-command-name-tk-MenuDup-tp4091092p4094860.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. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Rotation Forest in R
http://weka.sourceforge.net/doc.packages/rotationForest/weka/classifiers/meta/RotationForest.html -- View this message in context: http://r.789695.n4.nabble.com/Rotation-Forest-in-R-tp3434951p4095006.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] Sensitivity and Specificity Forest Plots
Essentially, this is a side-by-side forest plot, where the plot on the left is for sensitivity and the plot on the right is for specificity. For 2x2 table data from diagnostic studies, it is easy to calculate the sensitivity and specificity values (and corresponding sampling variances) by hand. In fact, since sensitivity and specificity values are actually simply proportions, you can use the escalc() function in the metafor package to do this for you (just pass the appropriate cell counts to escalc() and use one of the outcome measures listed under Proportions and Transformations Thereof -- see help(escalc). Then, you could set up a plotting device with layout() and put the forest plot for sensitivity on the left and the plot for specificity on the right. So, everything is already there to do this. Best, Wolfgang -- Wolfgang Viechtbauer, Ph.D., Statistician Department of Psychiatry and Psychology School for Mental Health and Neuroscience Faculty of Health, Medicine, and Life Sciences Maastricht University, P.O. Box 616 6200 MD Maastricht, The Netherlands +31 (43) 368-5248 | http://www.wvbauer.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jonathan Minton Sent: Monday, November 21, 2011 17:34 To: r-help@r-project.org Subject: [R] Sensitivity and Specificity Forest Plots Dear R Users, Do you know of an existing function that allows the production of sensitivity and specificity forest plots? See the following for an example: http://www.google.co.uk/imgres?q=forest+plots+of+sensitivity+and+specifici tyum=1hl=enauthuser=0biw=1920bih=989tbm=ischtbnid=JLxXNU7iQ2N_CM:i mgrefurl=http://www.medscape.com/viewarticle/717751_3docid=NnthE8_KgNQZdM imgurl=http://img.medscape.com/article/717/751/717751- fig3.jpgw=857h=734ei=UnzKTvfTGIWC8gPnq4R7zoom=1iact=hcvpx=1300vpy=2 82dur=19hovh=208hovw=243tx=140ty=108sig=112892243842455187632page=1 tbnh=123tbnw=144start=0ndsp=69ved=1t:429,r:20,s:0 The standard meta-analysis packages (metafor etc) do not seem to have this type of forest plot. If I were to construct a bespoke function within R, would you recommend using the forest function within metafor, or the dotplot function within lattice, or something else entirely as a starting point for constructing the function? Many thanks, -- Dr Jon Minton Decision Support Unit Health Economics Decision Science School of Health and Related Research University of Sheffield Tel: 0114 222 0836 [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting- guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problem in creating a dataframe
I believe the command you are looking for is as.data.frame(), though you are probably going to need as.double() rather soon as well. Do note that data frames can, and often do, have character elements. Best, Michael On Nov 22, 2011, at 1:21 AM, arunkumar akpbond...@gmail.com wrote: Hi I have a character class and i need to convert into dataframe data=(0,0,0,0) I want a dataframe with each one should under a separate column Please help me -- View this message in context: http://r.789695.n4.nabble.com/problem-in-creating-a-dataframe-tp4094676p4094676.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] Capping outliers
You can easily vectorize this code using pmin/pmax. Sent from my iPad On Nov 22, 2011, at 1:06, Aher ajit.a...@cedar-consulting.com wrote: Hi Experts, I am new to R, using following sample code for capping outliers using percentile information. Working on large data (3 observations and 150 variables), loop I am using in the below mentioned code for detecting outliers and capping to upper /lower percentile value is taking much time for the execution. Is there anything wrong with code, can anyone suggest improvement in the script to enhance performance! min_pctle_cut - 0.01 max_pctle_cut - 0.99 library(outliers) n - 100 x1 - runif(n) x2 - runif(n) x3 - x1 + x2 + runif(n)/10 x4 - x1 + x2 + x3 + runif(n)/10 x5 - factor(sample(c('a','b','c'),n,replace=TRUE)) x6 - factor(1*(x5=='a' | x5=='c')) data1 - cbind(x1,x2,x3,x4,x5,x6) x - data.frame(data1) z - x[,sapply(x,is.numeric)] qs - sapply(z, function(z) quantile(z, c(min_pctle_cut, max_pctle_cut), na.rm = TRUE)) #Loop below taking time for execution system.time(for (i in 1:ncol(z)) { for (j in 1:nrow(z)) { if (z[j,i] qs[1,i]) z[j,i]=qs[1,i] if (z[j,i] qs[2,i]) z[j,i]=qs[2,i] } }) -- View this message in context: http://r.789695.n4.nabble.com/Capping-outliers-tp4094647p4094647.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Goodness of fit test in fitdistrplus
I am using the fitdistrplus package in R and would like to do a goodness of fit test. But there does not seem to be any option to do that. Any ideas on how I can do that? Thanks Regards, Indrajit [[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] Problems using log() in a plm() regression.
Hello Manuel. Yes please, would you send me the data to reproduce the example? Else I cannot tell, although this error is typical of undefined logs (zero or negative argument). Two general observations, for now: - inserting special characters like '*' in variable names is looking for trouble - a good first step in diagnosing 'plm' errors is always to check the same specification (formula+data) on lm() Please remember to exclude the r-help list from the reply containing the dataset. I will treat it with confidentiality. Let me know Giovanni Giovanni Millo, PhD Research Dept., Assicurazioni Generali SpA Via Machiavelli 4, 34132 Trieste (Italy) tel. +39 040 671184 fax +39 040 671160 -- original message Message: 17 Date: Mon, 21 Nov 2011 04:33:13 -0800 (PST) From: ManuelS steiner-man...@web.de To: r-help@r-project.org Subject: [R] Problems using log() in a plm() regression. Message-ID: 1321878793485-4091377.p...@n4.nabble.com Content-Type: text/plain; charset=us-ascii hey guys I have a panel data set that i want to perform some regressions on. I am using the /plm/ package. I defined a model in the following way: PWBw.pool - plm(*PWB* ~ log(*I_EQON*) + log(*RD*) + ... + *PAGRI*, data = pfem, na.action=na.exclude, model=pooling) When i run this it gives the following error (the error remains when i use other model = specifications like within or random): /Fehler in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : NA/NaN/Inf in externem Funktionsaufruf (arg 1) / The translation would be something like: /Error in lm.fit(x,y, offset = offset, singular.ok = singular.ok, ...) : NA/NaN/Inf in external fuction call (arg 1)/ This error disappears and the regression work perfectly when i remove the log() from *RD*. The log of *I_EQON* on the other hand poses no problem. I dont quite get that cause there is no difference in the variables *I_EQON* and *RD*: They have: 1.) the same number of variables 2.) both NA's so that cant be it 3.) class: numeric When performing /log() /on the variable *RD* simply like this (not within the plm command): log(pfem$*RD*) everything works out fine which in my opinion indicates that the problem is related to the/ plm()/ function. Anyone any advise? If u need the data to run the regression please let me know so i can send them to you personally. Thank you in advance. Manu -- View this message in context: http://r.789695.n4.nabble.com/Problems-using-log-in-a-plm-regression-tp4 091377p4091377.html Sent from the R help mailing list archive at Nabble.com. end original message -- Ai sensi del D.Lgs. 196/2003 si precisa che le informazi...{{dropped:12}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] problem in creating a dataframe
Being new to R myself, I always get trapped by factors. Taking the data you have provided, this worked for my understanding of your intention: x - rep( 0, 4 ) x [1] 0 0 0 0 df - data.frame( matrix( x, 1 ), stringsAsFactors = FALSE ) df X1 X2 X3 X4 1 0 0 0 0 is.character( df[1,1] ) [1] TRUE Rgds, Rainer On Monday 21 November 2011 22:21:54 arunkumar wrote: Hi I have a character class and i need to convert into dataframe data=(0,0,0,0) I want a dataframe with each one should under a separate column Please help me -- View this message in context: http://r.789695.n4.nabble.com/problem-in-creating-a-dataframe-tp4094676p 4094676.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] Capping outliers
Here is the solution using pmin/pmax for 10,000 rows. min_pctle_cut - 0.01 max_pctle_cut - 0.99 library(outliers) n - 1 x1 - runif(n) x2 - runif(n) x3 - x1 + x2 + runif(n)/10 x4 - x1 + x2 + x3 + runif(n)/10 x5 - factor(sample(c('a','b','c'),n,replace=TRUE)) x6 - factor(1*(x5=='a' | x5=='c')) data1 - cbind(x1,x2,x3,x4,x5,x6) x - data.frame(data1) z - x[,sapply(x,is.numeric)] zNew - z # save for 2nd test qs - sapply(z, function(z) quantile(z, +c(min_pctle_cut, max_pctle_cut), na.rm = TRUE)) #Loop below taking time for execution system.time(for (i in 1:ncol(z)) + { +for (j in 1:nrow(z)) + { + if (z[j,i] qs[1,i]) z[j,i]=qs[1,i] + if (z[j,i] qs[2,i]) z[j,i]=qs[2,i] + } + }) user system elapsed 6.640.007.76 system.time({ + for (i in 1:ncol(z)) zNew[[i]] - pmax(qs[1,i], pmin(qs[2,i], z[[i]])) + }) user system elapsed 0.020.000.00 all(z == zNew) # are they the same? [1] TRUE On Tue, Nov 22, 2011 at 6:24 AM, Jim Holtman jholt...@gmail.com wrote: You can easily vectorize this code using pmin/pmax. Sent from my iPad On Nov 22, 2011, at 1:06, Aher ajit.a...@cedar-consulting.com wrote: Hi Experts, I am new to R, using following sample code for capping outliers using percentile information. Working on large data (3 observations and 150 variables), loop I am using in the below mentioned code for detecting outliers and capping to upper /lower percentile value is taking much time for the execution. Is there anything wrong with code, can anyone suggest improvement in the script to enhance performance! min_pctle_cut - 0.01 max_pctle_cut - 0.99 library(outliers) n - 100 x1 - runif(n) x2 - runif(n) x3 - x1 + x2 + runif(n)/10 x4 - x1 + x2 + x3 + runif(n)/10 x5 - factor(sample(c('a','b','c'),n,replace=TRUE)) x6 - factor(1*(x5=='a' | x5=='c')) data1 - cbind(x1,x2,x3,x4,x5,x6) x - data.frame(data1) z - x[,sapply(x,is.numeric)] qs - sapply(z, function(z) quantile(z, c(min_pctle_cut, max_pctle_cut), na.rm = TRUE)) #Loop below taking time for execution system.time(for (i in 1:ncol(z)) { for (j in 1:nrow(z)) { if (z[j,i] qs[1,i]) z[j,i]=qs[1,i] if (z[j,i] qs[2,i]) z[j,i]=qs[2,i] } }) -- View this message in context: http://r.789695.n4.nabble.com/Capping-outliers-tp4094647p4094647.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [OT] 1 vs 2-way anova technical question
On Nov 22, 2011, at 10:35 AM, Joshua Wiley wrote: It is true the way you use general lists is not our business, but the R-help list is a community and there are community rules. One of I meant that my use of the lists is not of __his__ business I wasn't referring to you nor other people in this list. Ok the reading skills remark starts to get recursive ... and btw the OP even though marked in the subject as OT was not entirely so i.e. use of R formula etc. those is not to ask questions that are primarily about a lack of statistical understanding (although they are not strictly prohibited). The lack of statistical understanding was his own judgmental conclusion which he should have kept for himself, if he starts throwing stones around he should not expect to get flowers back. Previous to this I also received some totally out of place private emails from him and I am not the kind of person that takes B.S. from anyone, he got the wrong guy. And in fact his great fallacious conclusions originated from his lack of reading skills, besides I don't really think he read it at all but just try to run me down with his attacks and unwelcome remarks. Your original post suggests that you knew this, I know there is plenty of people in this group who can give me a good answer :) but chose to ignore it. Despite this, Bert was generous enough to give you some suggestions, perhaps not what you wanted but useful tips nonetheless. My original post only suggested that I know there is people with knowledge about this practical applied statistics problems, nothing else. Before addressing the list I talked to two TA's and one professor. Their help was generic but helpful nevertheless. I preferred to address the question to people with practical working knowledge of ANOVA (I don't think there is a huge population in this area) and the best place I can think of is the R list, the place where I would be subscribed if I worked on these problems every day. Statistics lists will be full of college students who will have equivalent knowledge to what I already have and there they will probably only agree to say yes your QQ looks non-normal and heavy tailed which is what I already knew ... this is a similar answer I got from a TA and couple of student friends doing the MSc in Statistics track. Mr. Gunter did not read/understand my problem, and there were no useful tips but only ad hominem attacks. By your side-taking I suspect you are in the same party club if you want to defend him maybe you should start by tying better your dog so to speak. Regarding your suggestion that the list be split into a beginner and advanced list, while that is one option, your original question was appropriate for neither. It was, however, very appropriate for a statistics list (e.g., http://stats.stackexchange.com/). Thank you for the link, it looks very promising. Best regards, Giovanni __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Similar function for Redun() from Hmisc ?
Hi List, Working on the large data frame (number of records=35000 and number of variables=160). Using redun() for dropping variables before using into model. V - redun(~., data = data.frame, r2 = 0.8) It takes enormously high time for execution, is there anything wrong in the script? Suggest any other similar function available for dropping redundant variables. Thanks in advance! ~A -- View this message in context: http://r.789695.n4.nabble.com/Similar-function-for-Redun-from-Hmisc-tp4095455p4095455.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] Similar function for Redun() from Hmisc ?
Specifying nk=0 to force all effects to be linear will speed things up. Frank aajit75 wrote Hi List, Working on the large data frame (number of records=35000 and number of variables=160). Using redun() for dropping variables before using into model. V - redun(~., data = data.frame, r2 = 0.8) It takes enormously high time for execution, is there anything wrong in the script? Suggest any other similar function available for dropping redundant variables. Thanks in advance! ~A - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/Similar-function-for-Redun-from-Hmisc-tp4095455p4095771.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 with step and glmmML
Hi everybody, I'm trying to select a model with the function step. It is a mixed generalized linear model fitted by the function glmmML. I have one random variable (id), one response variable (var) and many independent variables (x1, x2, x3..). I obtain the following error: Error in if (all(is.finite(c(n0, nnew))) nnew != n0) stop(number of rows in use has changed: remove missing values?) : missing value where TRUE/FALSE needed But I swear that I do NOT have any NA in my database (data1). I have checked it many times even with is.na() My script is the following: model-step(glmmML(var~1,cluster = id, family = poisson,data = data1),direction=c(both),data=data1,scope=~x1+x2+x3+x4+x5+x6+x7+x8+x9+x10) Does anybody know where the problem could be? Thank you in advance, Alba -- View this message in context: http://r.789695.n4.nabble.com/Error-with-step-and-glmmML-tp4095404p4095404.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] logarithmically scaled y-axis in vioplot
Dear all I am trying to make a graphic with the vioplot package. I use the following code: library(vioplot) x1 - GSMrxDL x2 - WIFI x3 - UMT vioplot(x1, x2, x3, ylim=c(0, 10), names=c(GSMrxDL, WIFI, UMT), col=gold) title(NIS Strahlung, xlab=Sender, ylab=V/m) Now I want to scale the y-axis logarithmically, i.e. 0.01; 0.1; 1; 10. How can I do this? Thank you very much Alex -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Scatter plot - using colour to group points?
Thanks all for suggestions. I now have a nice plot showing the temperature of 6 different sites, each site distinguished by different coloured points, using nested ifelse. My apologies I thought I could change the type to l and the same arguments would be applied to line graph, with 6 different lines for each site...? I wanted to try lines as I think they might show the trends more clearly. I have just found the plottrix package manual and will try that to achieve this, and look at ggplot too. -- View this message in context: http://r.789695.n4.nabble.com/Scatter-plot-using-colour-to-group-points-tp4092794p4095079.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] snow package, socketConnection error, SSH, in Windows 7 x64
Hi. I have some problems trying to make cluster via snow package and haven't found a solution for my problem in archives and relative topics. I installed ssh server using cygwin and set a password-less SSH Login. In R session after starting ssh service: system(ssh 10.10.5.15 date) Tue Nov 22 16:22:36 AST 2011 But when I make connection: con - makeSOCKcluster(rep('10.10.5.15',2), port = 22, master = '10.10.5.15') Error in socketConnection(port = port, server = TRUE, blocking = TRUE, : cannot open the connection In addition: Warning message: In socketConnection(port = port, server = TRUE, blocking = TRUE, : port 22 cannot be opened Firewall is turned off. My R sesioninfo: R version 2.14.0 Patched (2006-00-00 r0) Platform: x86_64-pc-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=English_United States.1252 [2] LC_CTYPE=English_United States.1252 [3] LC_MONETARY=English_United States.1252 [4] LC_NUMERIC=C [5] LC_TIME=English_United States.1252 attached base packages: [1] stats graphics grDevices utils datasets methods base other attached packages: [1] snow_0.3-7 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] SE for parameters estimated by optim() - problem with constraints
Dear all, I have a problem with calculation of SE of parameters with a fisher matrix. the fisher matrix is calculated from the hessian matrix which is an output from optim(). However, can I calculate it this way if the optimisation criterion was to minimise RMSE? Maybe it works only with a log-likelihood optimisation? The more important problem is that I need to put constarints on my parameters, that: all parameters are between 0 and 1 and their sum = 1. I use following transformation: nSpec = length(pars) pars = exp(pars) / (1 + sum(exp(pars[1:nSspec]))) pars[nSspec] = 1 - sum(pars[1:(nSspec-1)]) where, pars is a vector of parameters supplied by optim() In this case I am calculating SE for untransformed parameters which is obviously not what I need. What sould I do to calculate SE for transformed parameters? My full optimization function: opt = function(pars) { pars=exp(pars)/(1+sum(exp(pars[1:nSspec]))) pars[nSspec]=1-sum(pars[1:(nSspec-1)]) for(i in 1:nSspec) est = est + pars[i] * selSpec[,i] sum(abs(est-spec)) } where: nSspec is a number of parameters spec is the vector to which I want to fit the vector est selSpec is a constant matrix with nSspec columns and length(spec) rows I hope you can help me. Best regards, Tomasz __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] readDGE: Error in colnames/length of dimnames not equal to array extent
On 11/21/2011 12:43 PM, jazevedo wrote: Hello, all, I'm a new R user (new to any programming language in general, really), so I apologize if this is easy/has already been answered (I've attempted searching online but did not understand the pages I found). My data is stored in text files with the headers LANE, RNA_NAME, SEQ, and SEQCNT. I've been using x = filename.txt y = aggregate(x$SEQCNT, list(x$RNA_NAME), sum) write.table(y, C:/path/filename.txt, sep=\t) to generate an output that I've analyzed using readDGE in the edgeR package: RNA Targets = read.delim(Targets.txt, stringsAsFactors = FALSE) Targets Files Groups A.txt 1 B.txt 2 v = readDGE(Targets, skip = 5, comment.char = !) I've done this several times; until yesterday, it worked fine. Today, however, an error message started cropping up after attempting readDGE: Error in `colnames-`(`*tmp*`, value = c(1, 2)) : length of 'dimnames' [2] not equal to array extent Hi -- looking at Targets, e.g., summary(Targets), str(Targets), might point to input problems. traceback() after the error occurs might point to problems in readDGE. Posting to the Bioconductor mailing list http://bioconductor.org/help/mailing-list/ is appropriate for Bioconductor packages. Martin I've tried to figure this out with no luck, so absolutely any help would be appreciated. Thank you all! -- View this message in context: http://r.789695.n4.nabble.com/readDGE-Error-in-colnames-length-of-dimnames-not-equal-to-array-extent-tp4093251p4093251.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. -- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] logarithmically scaled y-axis in vioplot
On 22.11.2011 12:37, french-connect...@gmx.net wrote: Dear all I am trying to make a graphic with the vioplot package. I use the following code: library(vioplot) x1- GSMrxDL x2- WIFI x3- UMT vioplot(x1, x2, x3, ylim=c(0, 10), names=c(GSMrxDL, WIFI, UMT), col=gold) title(NIS Strahlung, xlab=Sender, ylab=V/m) Now I want to scale the y-axis logarithmically, i.e. 0.01; 0.1; 1; 10. How can I do this? I think you will have to tweak the underlying code. A feature request to the authors may help, a patch that adds the requested feature may help even more. Best, Uwe Ligges Thank you very much Alex -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] logarithmically scaled y-axis in vioplot
On 22.11.2011 12:37, french-connect...@gmx.net wrote: Dear all I am trying to make a graphic with the vioplot package. I use the following code: library(vioplot) x1- GSMrxDL x2- WIFI x3- UMT vioplot(x1, x2, x3, ylim=c(0, 10), names=c(GSMrxDL, WIFI, UMT), col=gold) title(NIS Strahlung, xlab=Sender, ylab=V/m) Now I want to scale the y-axis logarithmically, i.e. 0.01; 0.1; 1; 10. How can I do this? [resending this since my mailtool forgot to add the address of the OP] I think you will have to tweak the underlying code. A feature request to the authors may help, a patch that adds the requested feature may help even more. Best, Uwe Ligges Thank you very much Alex -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] singular matrix in composition package
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code! On 22.11.2011 05:13, nur mohd wrote: Dear R user There are thousands on this list, none of them able to help you. how to solve the error of singular matrix in composition package I guess the matrix is not provided by the package but caused by the data *you* provided. So try to find out why the matrix is singular and the it is much easier to tackle it. Uwe Ligges thanks in advance ros [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Read from HTML file, print if see a specific string
On 21.11.2011 21:51, yesitsjess wrote: So basically I have made a HTML file with a table in it. Column 3 contains a GenBank number and is always proceeded by =GenBank. I want to read the file and return the number which comes directly after this (the contents of column 3). Ideally I would like to save this number as a string for use later in the script, but any help is good help. Been at this for HOURS and HOURS and HOURS. This is what I have so far: #Open html file $filename1 = 'Result1.html'; open (FILE1, $filename1) or die Can't open $filename1 $!; #Create array of results file data @html1 =FILE1; close (FILE1); #What to look for $genbank='^=GenBank\$'; foreach $html1(@html1) { if (index($html1,$genbank) ge 0) { print Number here!\n; } } This is not R code. Please note you wrote to the *R*-help list! Uwe Ligges -- View this message in context: http://r.789695.n4.nabble.com/Read-from-HTML-file-print-if-see-a-specific-string-tp4093273p4093273.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] [OT] 1 vs 2-way anova technical question
On Tue, Nov 22, 2011 at 2:09 PM, Giovanni Azua brave...@gmail.com wrote: Mr. Gunter did not read/understand my problem, and there were no useful tips but only ad hominem attacks. By your side-taking I suspect you are in the same party club if you want to defend him maybe you should start by tying better your dog so to speak. I believe that most of the readers of this thread got put off by your offending and misplaced remarks. To echo other posters, it would be nice to get your e-mail address banned from the list. Regards Liviu __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Cp -Inf
Hello All: I am using the leaps package on scale and centered data for an exhaustive search. There are Cp values of -Inf being returned for all models. I was going to look at the source before contacting the list, but it has been a while since I have looked under the hood. There are .rdb and .rdx files where I expected the source files to be. I am sure that I have over looked something. I can provide data and code if it is needed. Stephen __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] [OT] 1 vs 2-way anova technical question
On Nov 22, 2011, at 3:52 PM, Liviu Andronic wrote: On Tue, Nov 22, 2011 at 2:09 PM, Giovanni Azua brave...@gmail.com wrote: Mr. Gunter did not read/understand my problem, and there were no useful tips but only ad hominem attacks. By your side-taking I suspect you are in the same party club if you want to defend him maybe you should start by tying better your dog so to speak. I believe that most of the readers of this thread got put off by your offending and misplaced remarks. To echo other posters, it would be nice to get your e-mail address banned from the list. If needed go ahead and do so, your blockade won't stop my learning efforts. I don't see any concrete reason why I should be taking bullets from random people who fancy themselves with superiority and arrogance. And as usual these bullies always seem to win. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help 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 ticks in the 3rd and 4th row of a lattice
On Fri, Nov 18, 2011 at 11:22 AM, Ashim Kapoor ashimkap...@gmail.com wrote: Dear all, I want to draw ticks on the 3rd and 4th row of a lattice. How do I do this ? In my search of the help, I discovered a parameter alternating,which kind of says where the ticks will be but does not suffice for me. You need to explain more clearly what you want. Your plot does already have ticks in the 3rd and 4th row. If you need the x-axes labeled in each row, you need to have something like scales=list(x = list(relation = free, rot = 45, ... -Deepayan I am running this command : - barchart(X03/1000~time|Company, data=df1[which(df1$time!=1),], horiz=F, scales=list(x=list(rot=45,labels=paste(Mar,c(07,08,09,10,11 ,par.strip.text=list(lineheight=1,lines=2,cex=.75), ylab = In Rs. Million,xlab=,layout=c(3,4),as.table=T,between=list(y=1)) where my data is : - dput(df1) structure(list(Company = structure(c(9L, 7L, 1L, 6L, 8L, 4L, 2L, 5L, 11L, 10L, 9L, 7L, 1L, 6L, 8L, 4L, 2L, 5L, 11L, 10L, 9L, 7L, 1L, 6L, 8L, 4L, 2L, 5L, 11L, 10L, 9L, 7L, 1L, 6L, 8L, 4L, 2L, 5L, 11L, 10L, 9L, 7L, 1L, 6L, 8L, 4L, 2L, 5L, 11L, 10L, 9L, 7L, 1L, 6L, 8L, 4L, 2L, 5L, 11L, 10L), .Label = c(Bharat Petroleum Corpn. Ltd., Chennai Petroleum Corpn. Ltd., Company Name, Essar Oil Ltd., Hindalco Industries Ltd., Hindustan Petroleum Corpn. Ltd., Indian Oil Corpn. Ltd., Mangalore Refinery Petrochemicals Ltd., Reliance Industries Ltd., Steel Authority Of India Ltd., Sterlite Industries (India) Ltd.), class = factor), time = c(7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1), X03 = c(722931.1, 751620.5, 304456.3, 294868.9, 192712.6, 36695.4, 188313.4, 98954.9, 100088.7, 72379.9, 848517.5, 864562.2, 347310.9, 301022.1, 253514.5, 165661.6, 206377.7, 108897, 109336.3, 71207.6, 1003504.6, 1145993.8, 392261.5, 341086, 289737.4, 359837.2, 252964.3, 90036.2, 90474.8, 127623.2, 1411082.1, 907480.4, 364637.5, 290915.7, 255397.4, 328557.2, 202855.3, 118725.4, 116647.6, 106254.9, 1772254.7, 1204856.9, 469935.6, 313527.6, 320131.1, 384323.5, 260813.9, 137403.3, 137238.5, 136888.4, 1151658, 974902.76, 375720.36, 308284.06, 262298.6, 255014.98, 64.92, 110803.36, 110757.18, 102870.8)), row.names = c(Reliance Industries Ltd..7, Indian Oil Corpn. Ltd..7, Bharat Petroleum Corpn. Ltd..7, Hindustan Petroleum Corpn. Ltd..7, Mangalore Refinery Petrochemicals Ltd..7, Essar Oil Ltd..7, Chennai Petroleum Corpn. Ltd..7, Hindalco Industries Ltd..7, Sterlite Industries (India) Ltd..7, Steel Authority Of India Ltd..7, Reliance Industries Ltd..8, Indian Oil Corpn. Ltd..8, Bharat Petroleum Corpn. Ltd..8, Hindustan Petroleum Corpn. Ltd..8, Mangalore Refinery Petrochemicals Ltd..8, Essar Oil Ltd..8, Chennai Petroleum Corpn. Ltd..8, Hindalco Industries Ltd..8, Sterlite Industries (India) Ltd..8, Steel Authority Of India Ltd..8, Reliance Industries Ltd..9, Indian Oil Corpn. Ltd..9, Bharat Petroleum Corpn. Ltd..9, Hindustan Petroleum Corpn. Ltd..9, Mangalore Refinery Petrochemicals Ltd..9, Essar Oil Ltd..9, Chennai Petroleum Corpn. Ltd..9, Hindalco Industries Ltd..9, Sterlite Industries (India) Ltd..9, Steel Authority Of India Ltd..9, Reliance Industries Ltd..10, Indian Oil Corpn. Ltd..10, Bharat Petroleum Corpn. Ltd..10, Hindustan Petroleum Corpn. Ltd..10, Mangalore Refinery Petrochemicals Ltd..10, Essar Oil Ltd..10, Chennai Petroleum Corpn. Ltd..10, Hindalco Industries Ltd..10, Sterlite Industries (India) Ltd..10, Steel Authority Of India Ltd..10, Reliance Industries Ltd..11, Indian Oil Corpn. Ltd..11, Bharat Petroleum Corpn. Ltd..11, Hindustan Petroleum Corpn. Ltd..11, Mangalore Refinery Petrochemicals Ltd..11, Essar Oil Ltd..11, Chennai Petroleum Corpn. Ltd..11, Hindalco Industries Ltd..11, Sterlite Industries (India) Ltd..11, Steel Authority Of India Ltd..11, Reliance Industries Ltd..1, Indian Oil Corpn. Ltd..1, Bharat Petroleum Corpn. Ltd..1, Hindustan Petroleum Corpn. Ltd..1, Mangalore Refinery Petrochemicals Ltd..1, Essar Oil Ltd..1, Chennai Petroleum Corpn. Ltd..1, Hindalco Industries Ltd..1, Sterlite Industries (India) Ltd..1, Steel Authority Of India Ltd..1 ), .Names = c(Company, time, X03), reshapeLong = structure(list( varying = structure(list(X03 = c(X03.07, X03.08, X03.09, X03.10, X03.11, X03.1)), .Names = X03, v.names = X03, times = c(7, 8, 9, 10, 11, 1)), v.names = X03, idvar = Company, timevar = time), .Names = c(varying, v.names, idvar, timevar)), class = data.frame) [[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,
[R] (no subject)
http://jennys.cz/modules/mod_wdbanners/yes.php?html143 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Scatter plot - using colour to group points?
There's also the lines() command which takes a col argument if you want to do multiple lines (I usually wind up wrapping it in a for loop though there might be something smarter) ggplot2 is great, though the learning curve is a little rough: you can get good help here but if you go down that path, there's also a dedicated ggplot2 list that's worth checking out. Glad to have you as a new useR! Michael On Nov 22, 2011, at 5:13 AM, SarahH sarah@hotmail.co.uk wrote: Thanks all for suggestions. I now have a nice plot showing the temperature of 6 different sites, each site distinguished by different coloured points, using nested ifelse. My apologies I thought I could change the type to l and the same arguments would be applied to line graph, with 6 different lines for each site...? I wanted to try lines as I think they might show the trends more clearly. I have just found the plottrix package manual and will try that to achieve this, and look at ggplot too. -- View this message in context: http://r.789695.n4.nabble.com/Scatter-plot-using-colour-to-group-points-tp4092794p4095079.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] help to setting a multiple (linear) regression model with a 5% significance level (threshold) for the inclusion of the model variables.
Dear Researchers, someone know the right syntax to chose a 5% signiï¬cance level (threshold) for the inclusion of the model variables in a multiple (linear) regression in backward way? I set the formula in this way, but I don't know to choose the 5% significance? lmodelV - step(lm(formula=MyFormula[[1]],data=LR.train),direction=backward) thanks in advance gianni [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] help to setting a multiple (linear) regression model with a 5% significance level (threshold) for the inclusion of the model variables.
On 22/11/2011 16:30, gianni lavaredo wrote: Dear Researchers, someone know the right syntax to chose a 5% signiï¬cance level (threshold) for the inclusion of the model variables in a multiple (linear) regression in backward way? I set the formula in this way, but I don't know to choose the 5% significance? lmodelV- step(lm(formula=MyFormula[[1]],data=LR.train),direction=backward) That is not what step() does. Please do read the help page! Description: Select a formula-based model by AIC. Note, 'by AIC'. Now, as Frank Harrell says here often, stepwise methods are inadmissible for prediction, and in addition stepwise F-test methods are always invalid as they ignore multiple testing. So you won't find such methods prominently available in R (and all the stepwise methods I am aware of in R packages use AIC or similar). The author of step() thanks in advance gianni [[alternative HTML version deleted]] Please do not send HTML when expressly asked not to. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Brian D. Ripley, rip...@stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UKFax: +44 1865 272595 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Varma models in the dse package
Hi, I tried to run the VARMA model in the dse package. I specified a model: arma A(L) = 1+0.244L10+0.05L1 0-0.325L11-0.234L1 B(L) = 1-0.277L10+0.211L1 0-0.206L11+0.238L1 and have a TSdata object: dfdata output data: Series 1 Series 2 1 difex2 difem2 but I get this warning message: estMaxLik(arma, dfdata) Error in l.ARMA(setArrays(Shape, coefficients = coefficients), data, result = like, : NA/NaN/Inf in foreign function call (arg 14) In addition: Warning message: In l.ARMA(setArrays(Shape, coefficients = coefficients), data, result = like, : NAs introduced by coercion bots series are the same length (69). Is there something I am missing? Kind regards and thanks in advance, Tanja [[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] Removing rows in dataframe w'o duplicated values
Hi, Is there an easy way to remove dataframe rows without duplicated values of a specified column ('id')? e.g., dat - data.frame(id = c(1,1,1,2,3,3), value = c(5,6,7,4,5,4), value2 = c(1,4,3,3,4,3)) dat id value value2 1 1 5 1 2 1 6 4 3 1 7 3 4 2 4 3 5 3 5 4 6 3 4 3 This is sample data and the real data has hundreds of rows. In this case, only row 4 does not have a duplicated id and I would like to remove it without using: dat$id[4] - NULL Any help is appreciated! AC [[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] Compile R package under Windows
Hi. I need to compile an R package under Windows, to get a zip file. I can't used the web services, because it is avalaible only for the current version of R while I need of a package compiled with R 2.13.1. The package contain C code that requires the GSL C library. In your experience, what is the best way to compile an R library? I read the R manuals, now I need some tricks with experienced people. Thanks in advance. Nicola [[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] Removing rows in dataframe w'o duplicated values
This is ugly, but it gets what you want. dat[which(dat[,1] %in% unique((dat[duplicated(dat[,1], fromLast = T), 1]))),] AC Del Re wrote Hi, Is there an easy way to remove dataframe rows without duplicated values of a specified column ('id')? e.g., dat - data.frame(id = c(1,1,1,2,3,3), value = c(5,6,7,4,5,4), value2 = c(1,4,3,3,4,3)) dat id value value2 1 1 5 1 2 1 6 4 3 1 7 3 4 2 4 3 5 3 5 4 6 3 4 3 This is sample data and the real data has hundreds of rows. In this case, only row 4 does not have a duplicated id and I would like to remove it without using: dat$id[4] - NULL Any help is appreciated! AC [[alternative HTML version deleted]] __ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- View this message in context: http://r.789695.n4.nabble.com/Removing-rows-in-dataframe-w-o-duplicated-values-tp4096582p4096672.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] Compile R package under Windows
On 22.11.2011 18:57, Nicola Sturaro Sommacal wrote: Hi. I need to compile an R package under Windows, to get a zip file. I can't used the web services, because it is avalaible only for the current version of R while I need of a package compiled with R 2.13.1. The package contain C code that requires the GSL C library. In your experience, what is the best way to compile an R library? You mean a package. I read the R manuals, now I need some tricks with experienced people. Why? The R Installation an Administration manual tells you how to set up the environment so that you can do it yourself. We may be able to help if you get stuck, but you really have to tell us where that happened. Best, Uwe Ligges Thanks in advance. Nicola [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] evaluation question
Dear R People: Hope you're having a nice day. Here is a character vector: yz [1] pexp(3.2,rate=1) str(yz) chr pexp(3.2,rate=1) And I would like to evaluate that vector. I tried: eval(as.expression(yz)) [1] pexp(3.2,rate=1) But that doesn't work. Any suggestions would be most welcome. I have a feeling that it's quite simple and that I'm having a forest vs. trees issue. Thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] evaluation question
Good morning Erin, eval(parse(text = pexp(3.2,rate=1))) seems to work But the general rule applies: library(fortunes) fortune(parse()) Best, Michael On Tue, Nov 22, 2011 at 1:23 PM, Erin Hodgess erinm.hodg...@gmail.com wrote: Dear R People: Hope you're having a nice day. Here is a character vector: yz [1] pexp(3.2,rate=1) str(yz) chr pexp(3.2,rate=1) And I would like to evaluate that vector. I tried: eval(as.expression(yz)) [1] pexp(3.2,rate=1) But that doesn't work. Any suggestions would be most welcome. I have a feeling that it's quite simple and that I'm having a forest vs. trees issue. Thanks, Erin -- Erin Hodgess Associate Professor Department of Computer and Mathematical Sciences University of Houston - Downtown mailto: erinm.hodg...@gmail.com __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] arima.sim: innov querry
On 22/11/11 13:04, Andy Bunn wrote: Apologies for thickness - I'm sure that this operates as documented and with good reason. However... My understanding of arima.sim() is obviously imperfect. In the example below I assume that x1 and x2 are similar white noise processes with a mean of 5 and a standard deviation of 1. I thought x3 should be an AR1 process but still have a mean of 5 and a sd of 1. Why does x3 have a mean of ~7? Obviously I'm missing something fundamental about the burn in or the innovations. x1- rnorm(1e3,mean=5,sd=1) summary(x1) x2- arima.sim(list(order=c(0,0,0)),n=1e3,mean=5,sd=1) summary(x2) x3- arima.sim(list(order=c(1,0,0),ar=0.3),n=1e3,mean=5,sd=1) summary(x3) # why does x3 have a mean of ~7? X_t = 0.3 * X_{t-1} + E_t where E_t ~ N(5,1). So E(X_t) = 0.3*E(X_{t-1}) + E(E_t), i.e mu = 0.3*mu + 5, whence mu = 5/0.7 = 7.1429 approx. = 7 Of course, stupid of me. I should not send r-help requests out at the end of the day. But now I do have a more nuanced question. I'm trying to simulate an ARMA(1,1) process where the underlying distribution is log normal. At the end of the process, can I use arima.sim in conjunction with rlnorm with the parameters below? Thanks in advance for advice. -A mu - -0.935338 sigma - 0.4762476 # the dist'n I want but with white noise x1 - rlnorm(1e5,meanlog=mu,sdlog=sigma) # how can I add these arima coefs to a log-normal distn yet keep parameters mu and sigma? ar1 - 0.6621 ma1 - -0.1473 # This is not it: x2 - arima.sim(list(order=c(1,0,1),ar=ar1,ma=ma1), n = 1e3, rand.gen=rlnorm, meanlog=mu, sdlog=sigma) So all is in harmony. OMM! :-) cheers, Rolf Turner P. S. If you want the population mean of x3 to be 5, add 5 *after* generating x3 from innovations with mean 0. R. T. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] evaluation question
On 22.11.2011 19:23, Erin Hodgess wrote: Dear R People: Hope you're having a nice day. Here is a character vector: yz [1] pexp(3.2,rate=1) str(yz) chr pexp(3.2,rate=1) And I would like to evaluate that vector. I tried: eval(as.expression(yz)) [1] pexp(3.2,rate=1) But that doesn't work. Any suggestions would be most welcome. I have a feeling that it's quite simple and that I'm having a forest vs. trees issue. Erin, you need to parse() the text before eval()uating it. In most cases, the original problem is why you got the text and not already something that is a language object. Best, Uwe Thanks, Erin __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Removing rows in dataframe w'o duplicated values
Hi: Here's one way: do.call(rbind, lapply(L, function(d) if(nrow(d) 1) return(d))) id value value2 1.1 1 5 1 1.2 1 6 4 1.3 1 7 3 3.5 3 5 4 3.6 3 4 3 HTH, Dennis On Tue, Nov 22, 2011 at 9:43 AM, AC Del Re de...@wisc.edu wrote: Hi, Is there an easy way to remove dataframe rows without duplicated values of a specified column ('id')? e.g., dat - data.frame(id = c(1,1,1,2,3,3), value = c(5,6,7,4,5,4), value2 = c(1,4,3,3,4,3)) dat id value value2 1 1 5 1 2 1 6 4 3 1 7 3 4 2 4 3 5 3 5 4 6 3 4 3 This is sample data and the real data has hundreds of rows. In this case, only row 4 does not have a duplicated id and I would like to remove it without using: dat$id[4] - NULL Any help is appreciated! AC [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Removing rows in dataframe w'o duplicated values
Sorry, you need this first: L - split(dat, dat$id) do.call(rbind, lapply(L, function(d) if(nrow(d) 1) return(d))) D. On Tue, Nov 22, 2011 at 10:38 AM, Dennis Murphy djmu...@gmail.com wrote: Hi: Here's one way: do.call(rbind, lapply(L, function(d) if(nrow(d) 1) return(d))) id value value2 1.1 1 5 1 1.2 1 6 4 1.3 1 7 3 3.5 3 5 4 3.6 3 4 3 HTH, Dennis On Tue, Nov 22, 2011 at 9:43 AM, AC Del Re de...@wisc.edu wrote: Hi, Is there an easy way to remove dataframe rows without duplicated values of a specified column ('id')? e.g., dat - data.frame(id = c(1,1,1,2,3,3), value = c(5,6,7,4,5,4), value2 = c(1,4,3,3,4,3)) dat id value value2 1 1 5 1 2 1 6 4 3 1 7 3 4 2 4 3 5 3 5 4 6 3 4 3 This is sample data and the real data has hundreds of rows. In this case, only row 4 does not have a duplicated id and I would like to remove it without using: dat$id[4] - NULL Any help is appreciated! AC [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Removing rows in dataframe w'o duplicated values
one approach is the following: dat - data.frame(id = c(1,1,1,2,3,3), value = c(5,6,7,4,5,4), value2 = c(1,4,3,3,4,3)) ind - ave(dat$id, dat$id, FUN = length) 1 dat[ind, ] I hope it helps. Best, Dimitris On 11/22/2011 6:43 PM, AC Del Re wrote: Hi, Is there an easy way to remove dataframe rows without duplicated values of a specified column ('id')? e.g., dat- data.frame(id = c(1,1,1,2,3,3), value = c(5,6,7,4,5,4), value2 = c(1,4,3,3,4,3)) dat id value value2 1 1 5 1 2 1 6 4 3 1 7 3 4 2 4 3 5 3 5 4 6 3 4 3 This is sample data and the real data has hundreds of rows. In this case, only row 4 does not have a duplicated id and I would like to remove it without using: dat$id[4]- NULL Any help is appreciated! AC [[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. -- Dimitris Rizopoulos Assistant Professor Department of Biostatistics Erasmus University Medical Center Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands Tel: +31/(0)10/7043478 Fax: +31/(0)10/7043014 Web: http://www.erasmusmc.nl/biostatistiek/ __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Removing rows in dataframe w'o duplicated values
On Nov 22, 2011, at 12:43 PM, AC Del Re wrote: Hi, Is there an easy way to remove dataframe rows without duplicated values of a specified column ('id')? e.g., dat - data.frame(id = c(1,1,1,2,3,3), value = c(5,6,7,4,5,4), value2 = c(1,4,3,3,4,3)) dat id value value2 1 1 5 1 2 1 6 4 3 1 7 3 4 2 4 3 5 3 5 4 6 3 4 3 dat[ave(dat$id, dat$id, FUN=length) 1, ] id value value2 1 1 5 1 2 1 6 4 3 1 7 3 5 3 5 4 6 3 4 3 This is sample data and the real data has hundreds of rows. In this case, only row 4 does not have a duplicated id and I would like to remove it without using: dat$id[4] - NULL Any help is appreciated! AC [[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. 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] Cp -Inf
On Wed, Nov 23, 2011 at 3:55 AM, Stephen Sefick sas0...@auburn.edu wrote: Hello All: I am using the leaps package on scale and centered data for an exhaustive search. There are Cp values of -Inf being returned for all models. I was going to look at the source before contacting the list, but it has been a while since I have looked under the hood. There are .rdb and .rdx files where I expected the source files to be. I am sure that I have over looked something. I can provide data and code if it is needed. The best place to find the source is the source code package, also on CRAN (but you can also get it from inside R) The -Inf occurs when there are linear dependencies in your predictors, so that the 'full model' residual sum of squares is zero. Calculating Cp involves dividing the residual mean square for each model by the residual mean square for the full model, and this obviously will break down. The fact that it returns -Inf rather than +Inf is probably a bug, and there should be an explanation in the documentation of why you can't get Mallows' Cp for some data sets. You might think it would be possible to divide by the residual mean square for the best model rather than the full model, but 'best model' isn't well defined -- and the reason that the 'leaps' package exists is to provide large sets of best models, not a single one. -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] Looking for a C function
Dear all, I was looking for the C program found within approxfun() function. I already have a list of available C programs which are being used with R here, https://svn.r-project.org/R/trunk/src/main/. However this list does not contain above C function. Can somebody help me on where to find that? Thanks, __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] plotting output from LME with natural cubic spline
I have used LME to fit a mixed effects model on my data. The data has 274 subjects with 1 to 6 observations per subject. Time is not linearly associated with the outcome, so I used ns to fit a natural cubic spline with 3 auto knots. Subject and the natural cubic time of spline are both treated as random effects. This model has run without any problem, but now I would like to plot trajectories for subjects using their fitted random effects and incorporating the shape of the natural cubic spline. I am able to plot a point for each subject's fitted random effect score at the time the outcome was measured (fitLME$fitted[,2]). However, I cannot figure out how to connect the points to reflect the natural cubic spline. Does anyone know how to do this using output produced in the LME model object (e.g., fixed or random model coefficients) ? Code: fitLME-lme(Y~ns(time, df=4), random=list(id = pdDiag(form = ~ ns(time, df=4, data=data) Angie Mae Rodday, MS The Health Institute Tufts Medical Center 800 Washington St, #345 Boston, MA 02111 phone: 617-636-7193 fax: 617-636-8351 email: arod...@tuftsmedicalcenter.org The information in this e-mail is intended only for the ...{{dropped:7}} __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Header = T
Hi, I just start to use R today! I am reading the R Help on read.csv and the description for header says header is set to TRUE if and only if the first row contains one fewer field than the number of columns. Why is that? My data has the same number of fields in the first row as the number of columns. I mean I have no problem opening my csv file I am just curious why it should be one fewer. Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Header-T-tp4097045p4097045.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] Data Frame Search Slow
Hey All, So - I promise to write a blog post on this topic and post it somewhere on the internet once I get to the bottom of this. Basically, the set-up to the problem is like this: 1. I have a data frame with dim (2547290, 4) 2. I need to make SQL like lookups on the dataframe. I have been using the following sort of syntax: a.dataframe[a.dataframe[[column_index]] %in% some_value, ] 3. This process takes quite a lot of time (~2 seconds) on m1.small instances AMIs (AWS) So, I hope I can get that look-up/search logic quite a lot faster. I have heard that using matrices is the way to do it but I haven't found any resources on performing that sort of operation specifically that have yielded better results. Thought, feelings and advice are more than welcome. Best, TMD -- View this message in context: http://r.789695.n4.nabble.com/Data-Frame-Search-Slow-tp4096906p4096906.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] Lattice graph strips and axes
Hi all I was wondering if it is possible to get rid of the horizontal strips and produce each barchart with a left y axes and lower x axes only. Also can you specify an exact size of graph ie 88mm wide with a font size of 'x'. library(lattice) library(latticeExtra) n=as.factor(c(1:5,1:5)) Breed=as.factor(c(rep(Cow,3),rep(Sheep,3),rep(Goat,2),rep(Yak,2))) Test=as.factor(c(rep(Bovine viral diarrhoea,5),rep(Border Disease,5))) Titer=as.numeric(c(10,20,30,40, 50,15, 25, 35, 45, 55)) heif=data.frame(n,Breed, Test, Titer) x=barchart( Titer ~ n | Test+Breed, data=heif, layout = c(2,4),between = list(y = c(0.5),x = c(0.5)),scales = list(x = list(alternating = 1, tck = c(1,0)), y = list(alternating = 1, tck = c(1,0))), xlab = count (n), ylab = titer) useOuterStrips(x) Kind regards Andrew McFadden MVS BVSc | Veterinary Epidemiologist, Investigation and Diagnostic Centre | Biosecurity New Zealand Ministry of Agriculture and Forestry | 66 Ward St, Wallaceville | PO Box 40 742 | Upper Hutt | New Zealand Telephone: 64-4-894 5611 | Facsimile: 64-4-894 4973| Mobile: 027-733-1791 | Web: www.maf.govt.nz This email message and any attachment(s) is intended solely for the addressee(s) named above. The information it contains is confidential and may be legally privileged. Unauthorised use of the message, or the information it contains, may be unlawful. If you have received this message by mistake please call the sender immediately on 64 4 8940100 or notify us by return email and erase the original message and attachments. Thank you. The Ministry of Agriculture and Forestry accepts no responsibility for changes made to this email or to any attachments after transmission from the office. [[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] On-demand importing of a package
Dear All, in some functions of my package, I use the Matrix S4 class, as defined in the Matrix package. I don't want to depend on Matrix, however, because my package is perfectly fine without Matrix, most of the functionality does not need Matrix. Matrix is so included in the 'Suggests' line. I load Matrix via require(), from the functions that really need it. This mostly works fine, but I have an issue now that I cannot sort out. If I define a function like this in my package: f - function() { require(Matrix) res - sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5) y - rowSums(res) res / y } then calling it from the R prompt I get Error in rowSums(res) : 'x' must be an array of at least two dimensions which basically means that the rowSums() in the base package is called, not the S4 generic in the Matrix package. Why is that? Is there any way to work around this problem, without depending on Matrix? I am doing this on R 2.14.0, x86_64-apple-darwin9.8.0. Thank You, Best Regards, Gabor -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] On-demand importing of a package
How about calling Matrix's namespace directly? Matrix:::rowSums() Michael On Tue, Nov 22, 2011 at 3:16 PM, Gábor Csárdi csa...@rmki.kfki.hu wrote: Dear All, in some functions of my package, I use the Matrix S4 class, as defined in the Matrix package. I don't want to depend on Matrix, however, because my package is perfectly fine without Matrix, most of the functionality does not need Matrix. Matrix is so included in the 'Suggests' line. I load Matrix via require(), from the functions that really need it. This mostly works fine, but I have an issue now that I cannot sort out. If I define a function like this in my package: f - function() { require(Matrix) res - sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5) y - rowSums(res) res / y } then calling it from the R prompt I get Error in rowSums(res) : 'x' must be an array of at least two dimensions which basically means that the rowSums() in the base package is called, not the S4 generic in the Matrix package. Why is that? Is there any way to work around this problem, without depending on Matrix? I am doing this on R 2.14.0, x86_64-apple-darwin9.8.0. Thank You, Best Regards, Gabor -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] On-demand importing of a package
Hi Gábor, You could import rowSums. This will not fully attach Matrix. I am not sure there is a really good solution for what you want to do. To fully use and validate your package, Matrix appears to be required. This is different from simply, for example, enhancing the Matrix package. You could just write the functions assuming matrix is there, make sure the examples are marked don't run, and tell users if they want to use them, they need to load Matrix first. I do this with OpenMx in my package. Cheers, Josh On Tue, Nov 22, 2011 at 12:16 PM, Gábor Csárdi csa...@rmki.kfki.hu wrote: Dear All, in some functions of my package, I use the Matrix S4 class, as defined in the Matrix package. I don't want to depend on Matrix, however, because my package is perfectly fine without Matrix, most of the functionality does not need Matrix. Matrix is so included in the 'Suggests' line. I load Matrix via require(), from the functions that really need it. This mostly works fine, but I have an issue now that I cannot sort out. If I define a function like this in my package: f - function() { require(Matrix) res - sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5) y - rowSums(res) res / y } then calling it from the R prompt I get Error in rowSums(res) : 'x' must be an array of at least two dimensions which basically means that the rowSums() in the base package is called, not the S4 generic in the Matrix package. Why is that? Is there any way to work around this problem, without depending on Matrix? I am doing this on R 2.14.0, x86_64-apple-darwin9.8.0. Thank You, Best Regards, Gabor -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.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] Data Frame Search Slow
take a look at using the 'data.table' package. Here are some times to do the lookup using dataframes, matrices and data.tables: data.tables give the answer is less than 0.1 seconds. str(x.df) 'data.frame': 250 obs. of 4 variables: $ x : Factor w/ 455063 levels ,AAAB,..: 200683 388992 241029 305994 209907 112469 105656 233058 247529 416273 ... $ x.1: Factor w/ 455063 levels ,AAAB,..: 200683 388992 241029 305994 209907 112469 105656 233058 247529 416273 ... $ x.2: Factor w/ 455063 levels ,AAAB,..: 200683 388992 241029 305994 209907 112469 105656 233058 247529 416273 ... $ x.3: Factor w/ 455063 levels ,AAAB,..: 200683 388992 241029 305994 209907 112469 105656 233058 247529 416273 ... system.time(a - x.df[[1]] %in% ) user system elapsed 0.330.000.39 x.m - as.matrix(x.df) str(x.m) chr [1:250, 1:4] LMDC WFXC NUBQ RMOK LZVR GLCE GAZE NIFT ... - attr(*, dimnames)=List of 2 ..$ : NULL ..$ : chr [1:4] x x.1 x.2 x.3 system.time(a - x.m[,1] %in% ) user system elapsed 0.500.000.51 require(data.table) x.df - data.table(x.df) setkey(x.df, x) system.time(a - x.df[]) user system elapsed 0.050.030.13 str(a) Classes ‘data.table’ and 'data.frame': 7 obs. of 4 variables: $ x : Factor w/ 1 level : 1 1 1 1 1 1 1 $ x.1: Factor w/ 455063 levels ,AAAB,..: 1 1 1 1 1 1 1 $ x.2: Factor w/ 455063 levels ,AAAB,..: 1 1 1 1 1 1 1 $ x.3: Factor w/ 455063 levels ,AAAB,..: 1 1 1 1 1 1 1 - attr(*, sorted)= chr x system.time(x.df[ABCD]) user system elapsed 0.080.020.16 On Tue, Nov 22, 2011 at 2:01 PM, TimothyDalbey tmdal...@gmail.com wrote: Hey All, So - I promise to write a blog post on this topic and post it somewhere on the internet once I get to the bottom of this. Basically, the set-up to the problem is like this: 1. I have a data frame with dim (2547290, 4) 2. I need to make SQL like lookups on the dataframe. I have been using the following sort of syntax: a.dataframe[a.dataframe[[column_index]] %in% some_value, ] 3. This process takes quite a lot of time (~2 seconds) on m1.small instances AMIs (AWS) So, I hope I can get that look-up/search logic quite a lot faster. I have heard that using matrices is the way to do it but I haven't found any resources on performing that sort of operation specifically that have yielded better results. Thought, feelings and advice are more than welcome. Best, TMD -- View this message in context: http://r.789695.n4.nabble.com/Data-Frame-Search-Slow-tp4096906p4096906.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Adding two or more columns of a data frame for each row when NAs are present.
I think, here is the solution. If NA is included in read.table list the row becomes a factor: $ Q21: Factor w/ 3 levels 1, 2, NA: 1 2 3 2 2. This will not work with rowSums. If I put the missing value as a blank, then it is still read as NA but the whole row is considered as an integer and OK for rowSums etc. A missing value in col Q00 will be interpreted as a row with one less value at the end, I think. Ian + yy - read.table( header = T, sep=,, text = + Q00, Q20, Q21, Q22, Q23, Q24 + 0, 0, 1, 2, 3, 4 + 0, 1, 2, 3, 4, 5 + 0, 0, NA, 3, 4, 5 + 0, 1, 2, 3, 4, 5 + 0, 1, 2, 3, 4, 5) + yy Q00 Q20 Q21 Q22 Q23 Q24 1 0 0 1 2 3 4 2 0 1 2 3 4 5 3 0 0 NA 3 4 5 4 0 1 2 3 4 5 5 0 1 2 3 4 5 + str(yy) 'data.frame': 5 obs. of 6 variables: $ Q00: int 0 0 0 0 0 $ Q20: int 0 1 0 1 1 $ Q21: Factor w/ 3 levels 1, 2, NA: 1 2 3 2 2 $ Q22: int 2 3 3 3 3 $ Q23: int 3 4 4 4 4 $ Q24: int 4 5 5 5 5 + yy - read.table( header = T, sep=,, text = + Q00, Q20, Q21, Q22, Q23, Q24 + 0, 0, 1, 2, 3, 4 + 0, 0, , 3, 4, 5 + 0, 1, 2, 3, 4, 5) + yy Q00 Q20 Q21 Q22 Q23 Q24 1 0 0 1 2 3 4 2 0 0 NA 3 4 5 3 0 1 2 3 4 5 + str(yy) 'data.frame': 3 obs. of 6 variables: $ Q00: int 0 0 0 $ Q20: int 0 0 1 $ Q21: int 1 NA 2 $ Q22: int 2 3 3 $ Q23: int 3 4 4 $ Q24: int 4 5 5 + x - transform( yy, Example 6 +mySum = rowSums(yy[ ,c(Q00,Q20,Q21,Q23)], na.rm=T), +myCount = as.numeric(!is.na(Q20))+as.numeric(!is.na(Q21))+as.numeric(!is.na(Q24)), +myMean = rowMeans(yy[ ,c(Q00,Q20,Q21,Q23)], na.rm=T) + ) + x Q00 Q20 Q21 Q22 Q23 Q24 mySum myCount myMean 1 0 0 1 2 3 4 4 3 1.00 2 0 0 NA 3 4 5 4 2 1.33 3 0 1 2 3 4 5 7 3 1.75 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] x, y for point of intersection
Hi everyone, I am trying to get a point of intersection between a polyline and a straight line ….. and get the x and y coordinates of this point. For exemplification consider this: set.seed(123) k1 -rnorm(100, mean=1.77, sd=3.33) k1 - sort(k1) q1 - rnorm(100, mean=2.37, sd=0.74) q1 - sort(q1, decreasing = TRUE) plot(k1, q1, xlim - c((min(k1)-5), (max(k1)+5)), type=l) ya - 2 xa = -5 yb=4 xb=12 lines(c(xa, xb), c(ya, yb), col = 2) # I want to get the x and y coordinates of the intersection of the 2 lines …. m - (ya-yb)/(xa-xb) b - ya-m*xa ln - loess(q1~k1) lines(ln) It is clear that the x, y will satisfy both linear equations, y = m*x + b and the ln polyline ….. but while I can visualize the equation of the straight line – I have problems with the polyline. I will appreciate any ideas to solve this problem. I thought it a trivial solution but it seems I cannot see it. Thanks, Monica __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Bezier curve in R?
Hi dear all, I am wondering if there is a function existing in R that did the quadratic bezier curve interpolation? I hope to generate a bezier curve based on three sets of points: two end of the line and a control point. Thanks in advance. Tengfei -- Tengfei Yin MCDB PhD student 1620 Howe Hall, 2274, Iowa State University Ames, IA,50011-2274 [[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] x, y for point of intersection
If it's a one off, the identify() function might be of help -- if you need something algorithmic it's harder due to floating point stuff and sampling frequencies. Let me know if that's the case. Michael On Nov 22, 2011, at 3:40 PM, Monica Pisica pisican...@hotmail.com wrote: Hi everyone, I am trying to get a point of intersection between a polyline and a straight line ….. and get the x and y coordinates of this point. For exemplification consider this: set.seed(123) k1 -rnorm(100, mean=1.77, sd=3.33) k1 - sort(k1) q1 - rnorm(100, mean=2.37, sd=0.74) q1 - sort(q1, decreasing = TRUE) plot(k1, q1, xlim - c((min(k1)-5), (max(k1)+5)), type=l) ya - 2 xa = -5 yb=4 xb=12 lines(c(xa, xb), c(ya, yb), col = 2) # I want to get the x and y coordinates of the intersection of the 2 lines …. m - (ya-yb)/(xa-xb) b - ya-m*xa ln - loess(q1~k1) lines(ln) It is clear that the x, y will satisfy both linear equations, y = m*x + b and the ln polyline ….. but while I can visualize the equation of the straight line – I have problems with the polyline. I will appreciate any ideas to solve this problem. I thought it a trivial solution but it seems I cannot see it. Thanks, Monica __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Bezier curve in R?
require(Hmisc) ?bezier ?drawPlot Frank Tengfei Yin wrote Hi dear all, I am wondering if there is a function existing in R that did the quadratic bezier curve interpolation? I hope to generate a bezier curve based on three sets of points: two end of the line and a control point. Thanks in advance. Tengfei -- Tengfei Yin MCDB PhD student 1620 Howe Hall, 2274, Iowa State University Ames, IA,50011-2274 [[alternative HTML version deleted]] __ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/Bezier-curve-in-R-tp4097274p4097309.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] Missing data?
I was wondering what the best approach is for missing data in a time series. I give an example using xts but I would like to know what seems to be the best method. Say I have library(xts) xts.ts - xts(1:4,as.Date(c(1970-01-01, 1970-1-3, 1980-10-10, 2007-8-19)), frequency=52) I would like to turn this into a time series (still could be xts, or converted to ts) that has values for every week starting with the week that includes the start date and ending with the week that includes the end date. If there is data for the week then use it otherwise set it to NA or 0. Remember some years have 52, 53, or rarely 54 full or partial weeks. What to do with the partials at the beginning and ending of the year? This seems to be a fairly common problem and doing it myself is very cumbersome. Does a solution to this kind of problem exist? Once the approach to a weekly period is found I am sure that adjustment to daily, monthly, or quarterly would be relatively straightforward. Thank you. Kevin [[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] On-demand importing of a package
Thanks, I have tried that, it does not work, because rowSums() calls callGeneric(): Matrix:::rowSums(W) Error in callGeneric() : 'callGeneric' must be called from a generic function or method G. On Tue, Nov 22, 2011 at 3:20 PM, R. Michael Weylandt michael.weyla...@gmail.com wrote: How about calling Matrix's namespace directly? Matrix:::rowSums() Michael On Tue, Nov 22, 2011 at 3:16 PM, Gábor Csárdi csa...@rmki.kfki.hu wrote: Dear All, in some functions of my package, I use the Matrix S4 class, as defined in the Matrix package. I don't want to depend on Matrix, however, because my package is perfectly fine without Matrix, most of the functionality does not need Matrix. Matrix is so included in the 'Suggests' line. I load Matrix via require(), from the functions that really need it. This mostly works fine, but I have an issue now that I cannot sort out. If I define a function like this in my package: f - function() { require(Matrix) res - sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5) y - rowSums(res) res / y } then calling it from the R prompt I get Error in rowSums(res) : 'x' must be an array of at least two dimensions which basically means that the rowSums() in the base package is called, not the S4 generic in the Matrix package. Why is that? Is there any way to work around this problem, without depending on Matrix? I am doing this on R 2.14.0, x86_64-apple-darwin9.8.0. Thank You, Best Regards, Gabor -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Missing data?
Couldn't you use seq.Date() to set up the time index and then just fill as appropriate? Alternatively, to.weekly if you are starting with a daily series. Michael On Nov 22, 2011, at 4:00 PM, Kevin Burton rkevinbur...@charter.net wrote: I was wondering what the best approach is for missing data in a time series. I give an example using xts but I would like to know what seems to be the best method. Say I have library(xts) xts.ts - xts(1:4,as.Date(c(1970-01-01, 1970-1-3, 1980-10-10, 2007-8-19)), frequency=52) I would like to turn this into a time series (still could be xts, or converted to ts) that has values for every week starting with the week that includes the start date and ending with the week that includes the end date. If there is data for the week then use it otherwise set it to NA or 0. Remember some years have 52, 53, or rarely 54 full or partial weeks. What to do with the partials at the beginning and ending of the year? This seems to be a fairly common problem and doing it myself is very cumbersome. Does a solution to this kind of problem exist? Once the approach to a weekly period is found I am sure that adjustment to daily, monthly, or quarterly would be relatively straightforward. Thank you. Kevin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] On-demand importing of a package
Hi Josh, On Tue, Nov 22, 2011 at 3:31 PM, Joshua Wiley jwiley.ps...@gmail.com wrote: Hi Gábor, You could import rowSums. This will not fully attach Matrix. I am not sure there is a really good solution for what you want to do. To fully use and validate your package, Matrix appears to be required. This is different from simply, for example, enhancing the Matrix package. importing rowSums() from NAMESPACE requires having Matrix in the 'Depends:' line, I think. I would like to avoid that, if possible. Sure, to validate my package it is required. That is fine. For fully using it might be required, but most users don't fully use a package, they just use 1-20-50% of the functionality, depending on the size of the package. My package does not depend on Matrix, except in less than 1% of its (quite many) functions. You could just write the functions assuming matrix is there, make sure the examples are marked don't run, and tell users if they want to use them, they need to load Matrix first. I do this with OpenMx in my package. Hmmm, this is close to what I want to do. Actually my functions work, even if Matrix is not there, but they work better with Matrix. The problem is that if I do this, then I get the error I've shown in my initial email. I.e. Matrix is there, it is loaded, but the rowSums() generic is not called for some reasons. Thanks again, Gabor Cheers, Josh On Tue, Nov 22, 2011 at 12:16 PM, Gábor Csárdi csa...@rmki.kfki.hu wrote: Dear All, in some functions of my package, I use the Matrix S4 class, as defined in the Matrix package. I don't want to depend on Matrix, however, because my package is perfectly fine without Matrix, most of the functionality does not need Matrix. Matrix is so included in the 'Suggests' line. I load Matrix via require(), from the functions that really need it. This mostly works fine, but I have an issue now that I cannot sort out. If I define a function like this in my package: f - function() { require(Matrix) res - sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5) y - rowSums(res) res / y } then calling it from the R prompt I get Error in rowSums(res) : 'x' must be an array of at least two dimensions which basically means that the rowSums() in the base package is called, not the S4 generic in the Matrix package. Why is that? Is there any way to work around this problem, without depending on Matrix? I am doing this on R 2.14.0, x86_64-apple-darwin9.8.0. Thank You, Best Regards, Gabor -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/ -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Bezier curve in R?
Hi Prof. Frank Harrell, The bezier function in Hmisc package is exactly what I am looking for. Thanks a lot! Tengfei On Tue, Nov 22, 2011 at 2:55 PM, Frank Harrell f.harr...@vanderbilt.eduwrote: require(Hmisc) ?bezier ?drawPlot Frank Tengfei Yin wrote Hi dear all, I am wondering if there is a function existing in R that did the quadratic bezier curve interpolation? I hope to generate a bezier curve based on three sets of points: two end of the line and a control point. Thanks in advance. Tengfei -- Tengfei Yin MCDB PhD student 1620 Howe Hall, 2274, Iowa State University Ames, IA,50011-2274 [[alternative HTML version deleted]] __ R-help@ mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. - Frank Harrell Department of Biostatistics, Vanderbilt University -- View this message in context: http://r.789695.n4.nabble.com/Bezier-curve-in-R-tp4097274p4097309.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. -- Tengfei Yin MCDB PhD student 1620 Howe Hall, 2274, Iowa State University Ames, IA,50011-2274 Homepage: www.tengfei.name [[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] On-demand importing of a package
On 11/22/2011 01:16 PM, Gábor Csárdi wrote: Hi Josh, On Tue, Nov 22, 2011 at 3:31 PM, Joshua Wileyjwiley.ps...@gmail.com wrote: Hi Gábor, You could import rowSums. This will not fully attach Matrix. I am not sure there is a really good solution for what you want to do. To fully use and validate your package, Matrix appears to be required. This is different from simply, for example, enhancing the Matrix package. importing rowSums() from NAMESPACE requires having Matrix in the 'Depends:' line, I think. I would like to avoid that, if possible. No need to Depend:. Use Imports: Matrix plus in the NAMESPACE file importFrom(Matrix, rowSums) Why do you not want to do this? Matrix is available for everyone, Imports: doesn't influence the package search path. There is a cost associated with loading the library in the first place, but...? Sure, to validate my package it is required. That is fine. For fully using it might be required, but most users don't fully use a package, they just use 1-20-50% of the functionality, depending on the size of the package. My package does not depend on Matrix, except in less than 1% of its (quite many) functions. I'm more into black-and-white -- it either needs Matrix or not; apparently it does. You could just write the functions assuming matrix is there, make sure the examples are marked don't run, and tell users if they want to use them, they need to load Matrix first. I do this with OpenMx in my package. Hmmm, this is close to what I want to do. Actually my functions work, even if Matrix is not there, but they work better with Matrix. The problem is that if I do this, then I get the error I've shown in my initial email. I.e. Matrix is there, it is loaded, but the rowSums() generic is not called for some reasons. In another message you mention Matrix:::rowSums(W) Error in callGeneric() : 'callGeneric' must be called from a generic function or method but something else is going on -- you don't get to call methods directly; you're getting Matrix::rowSums (it's exported, so no need for a :::, see getNamespaceExports(Matrix)). Maybe traceback() after the error would be insightful? Martin Thanks again, Gabor Cheers, Josh On Tue, Nov 22, 2011 at 12:16 PM, Gábor Csárdicsa...@rmki.kfki.hu wrote: Dear All, in some functions of my package, I use the Matrix S4 class, as defined in the Matrix package. I don't want to depend on Matrix, however, because my package is perfectly fine without Matrix, most of the functionality does not need Matrix. Matrix is so included in the 'Suggests' line. I load Matrix via require(), from the functions that really need it. This mostly works fine, but I have an issue now that I cannot sort out. If I define a function like this in my package: f- function() { require(Matrix) res- sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5) y- rowSums(res) res / y } then calling it from the R prompt I get Error in rowSums(res) : 'x' must be an array of at least two dimensions which basically means that the rowSums() in the base package is called, not the S4 generic in the Matrix package. Why is that? Is there any way to work around this problem, without depending on Matrix? I am doing this on R 2.14.0, x86_64-apple-darwin9.8.0. Thank You, Best Regards, Gabor -- Gabor Csardicsa...@rmki.kfki.hu MTA KFKI RMKI __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/ -- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] x, y for point of intersection
Hi, No it is not one off, the situation is even more complicated i will have a series of straight lines like the red one parallel with each other that intersect the black polyline and i need to get all the points (x, y). Meanwhile i was thinking if it will not be easier if somehow i can rotate the coordinate axes so the red lines are horizontal (of course the polyline needs to be rotated as well) and maybe knowing the distance between the red parallel lines and the fact that now they are horizontal will help. I need to think a little bit more about that - and of course afterwards the results need to be translated back to the original coordinate system. Thanks, Monica CC: r-help@r-project.org From: michael.weyla...@gmail.com Subject: Re: [R] x, y for point of intersection Date: Tue, 22 Nov 2011 15:48:34 -0500 To: pisican...@hotmail.com If it's a one off, the identify() function might be of help -- if you need something algorithmic it's harder due to floating point stuff and sampling frequencies. Let me know if that's the case. Michael On Nov 22, 2011, at 3:40 PM, Monica Pisica pisican...@hotmail.com wrote: Hi everyone, I am trying to get a point of intersection between a polyline and a straight line ….. and get the x and y coordinates of this point. For exemplification consider this: set.seed(123) k1 -rnorm(100, mean=1.77, sd=3.33) k1 - sort(k1) q1 - rnorm(100, mean=2.37, sd=0.74) q1 - sort(q1, decreasing = TRUE) plot(k1, q1, xlim - c((min(k1)-5), (max(k1)+5)), type=l) ya - 2 xa = -5 yb=4 xb=12 lines(c(xa, xb), c(ya, yb), col = 2) # I want to get the x and y coordinates of the intersection of the 2 lines …. m - (ya-yb)/(xa-xb) b - ya-m*xa ln - loess(q1~k1) lines(ln) It is clear that the x, y will satisfy both linear equations, y = m*x + b and the ln polyline ….. but while I can visualize the equation of the straight line – I have problems with the polyline. I will appreciate any ideas to solve this problem. I thought it a trivial solution but it seems I cannot see it. Thanks, Monica __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] On-demand importing of a package
I also wondered why it is important to not mention Matrix in the DEPSCRIPTION file's Depends or Imports lines, even though some functions in the package require it. If this is a hard requirement you could split your package into two packages, pkgBasic and pkgEnhanced. pkgBasic would not not depend on Matrix and pkgEnhanced would depend on Matrix and pkgBasic. Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Martin Morgan Sent: Tuesday, November 22, 2011 1:27 PM To: Gábor Csárdi Cc: R mailing list Subject: Re: [R] On-demand importing of a package On 11/22/2011 01:16 PM, Gábor Csárdi wrote: Hi Josh, On Tue, Nov 22, 2011 at 3:31 PM, Joshua Wileyjwiley.ps...@gmail.com wrote: Hi Gábor, You could import rowSums. This will not fully attach Matrix. I am not sure there is a really good solution for what you want to do. To fully use and validate your package, Matrix appears to be required. This is different from simply, for example, enhancing the Matrix package. importing rowSums() from NAMESPACE requires having Matrix in the 'Depends:' line, I think. I would like to avoid that, if possible. No need to Depend:. Use Imports: Matrix plus in the NAMESPACE file importFrom(Matrix, rowSums) Why do you not want to do this? Matrix is available for everyone, Imports: doesn't influence the package search path. There is a cost associated with loading the library in the first place, but...? Sure, to validate my package it is required. That is fine. For fully using it might be required, but most users don't fully use a package, they just use 1-20-50% of the functionality, depending on the size of the package. My package does not depend on Matrix, except in less than 1% of its (quite many) functions. I'm more into black-and-white -- it either needs Matrix or not; apparently it does. You could just write the functions assuming matrix is there, make sure the examples are marked don't run, and tell users if they want to use them, they need to load Matrix first. I do this with OpenMx in my package. Hmmm, this is close to what I want to do. Actually my functions work, even if Matrix is not there, but they work better with Matrix. The problem is that if I do this, then I get the error I've shown in my initial email. I.e. Matrix is there, it is loaded, but the rowSums() generic is not called for some reasons. In another message you mention Matrix:::rowSums(W) Error in callGeneric() : 'callGeneric' must be called from a generic function or method but something else is going on -- you don't get to call methods directly; you're getting Matrix::rowSums (it's exported, so no need for a :::, see getNamespaceExports(Matrix)). Maybe traceback() after the error would be insightful? Martin Thanks again, Gabor Cheers, Josh On Tue, Nov 22, 2011 at 12:16 PM, Gábor Csárdicsa...@rmki.kfki.hu wrote: Dear All, in some functions of my package, I use the Matrix S4 class, as defined in the Matrix package. I don't want to depend on Matrix, however, because my package is perfectly fine without Matrix, most of the functionality does not need Matrix. Matrix is so included in the 'Suggests' line. I load Matrix via require(), from the functions that really need it. This mostly works fine, but I have an issue now that I cannot sort out. If I define a function like this in my package: f- function() { require(Matrix) res- sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5) y- rowSums(res) res / y } then calling it from the R prompt I get Error in rowSums(res) : 'x' must be an array of at least two dimensions which basically means that the rowSums() in the base package is called, not the S4 generic in the Matrix package. Why is that? Is there any way to work around this problem, without depending on Matrix? I am doing this on R 2.14.0, x86_64-apple-darwin9.8.0. Thank You, Best Regards, Gabor -- Gabor Csardicsa...@rmki.kfki.hu MTA KFKI RMKI __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/ -- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do
[R] Graphics in vector format
Hello, Is there a way to save plots in vector format like SVG or smth else? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Header = T
a b A 1 2 B 3 4 C 5 6 The assumption above is that the rownames don't have a header and the columns do. Therefore the default is header=TRUE. r a b A 1 2 B 3 4 C 5 6 In the second example, the first column is called r and it is not clear whether that is a column with a variable or a rowname. Therefore the default is header=FALSE. On Tue, Nov 22, 2011 at 2:47 PM, lucky7 wokeliandehotm...@gmail.com wrote: Hi, I just start to use R today! I am reading the R Help on read.csv and the description for header says header is set to TRUE if and only if the first row contains one fewer field than the number of columns. Why is that? My data has the same number of fields in the first row as the number of columns. I mean I have no problem opening my csv file I am just curious why it should be one fewer. Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Header-T-tp4097045p4097045.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[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] making scatterplot easier to read
Dear R users, do you know an easy way (other than star plot) of making several points laying one over another visible? Is it any simple way of increasing such multipoint symbols - or shifting their positions randomly to make several points in one place visible? Cheers, sz. -- Szymon Drobniak || Population Ecology Group *Institute of Environmental Sciences, Jagiellonian University ul. Gronostajowa 7, 30-387 Kraków, POLAND *tel.: +48 12 664 52 19 fax: +48 12 664 69 12 www.eko.uj.edu.pl/drobniak [[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] Graphics in vector format
I believe the Cairo package provides SVG faculties. Michael On Nov 22, 2011, at 4:48 PM, Antonio Rodriges antonio@gmail.com wrote: Hello, Is there a way to save plots in vector format like SVG or smth else? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] x, y for point of intersection
On Nov 22, 2011, at 3:40 PM, Monica Pisica wrote: (edited out excessive white space) I am trying to get a point of intersection between a polyline and a straight line ….. and get the x and y coordinates of this point. For exemplification consider this: set.seed(123) k1 -rnorm(100, mean=1.77, sd=3.33) k1 - sort(k1) q1 - rnorm(100, mean=2.37, sd=0.74) q1 - sort(q1, decreasing = TRUE) plot(k1, q1, xlim - c((min(k1)-5), (max(k1)+5)), type=l) ya - 2 xa = -5 yb=4 xb=12 lines(c(xa, xb), c(ya, yb), col = 2) # I want to get the x and y coordinates of the # intersection of the 2 lines …. m - (ya-yb)/(xa-xb) b - ya-m*xa ln - loess(q1~k1) lines(ln) You should look at: str(ln) # then plot lines(ln$x, ln$fitted, col=blue) plot(approxfun(c(xa, xb), c(ya, yb)), add=TRUE, col=green) plot(approxfun(ln$x, ln$fitted), col=orange, add=TRUE) And think about minimizing the difference in distances between two functions. It is clear that the x, y will satisfy both linear equations, y = m*x + b and the ln polyline ….. but while I can visualize the equation of the straight line – I have problems with the polyline. I will appreciate any ideas to solve this problem. I thought it a trivial solution but it seems I cannot see it. Thanks, Monica __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] making scatterplot easier to read
On Nov 22, 2011, at 4:58 PM, Szymek Drobniak wrote: Dear R users, do you know an easy way (other than star plot) of making several points laying one over another visible? Is it any simple way of increasing such multipoint symbols - or shifting their positions randomly to make several points in one place visible? You can make them with transparent colors ... or you can make them small and jitter the x and y values,... or you can use hexbin plots... or you can use 2d density plots or probably other ways. We don't really have a very good problem description yet, so it is difficult to be very helpful. Why not read the Posting Guide and see if cam be more complete along its guidelines. -- 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] Missing data?
Thank you for the suggestions. The only problems I see with 'to.weekly' is converting from the OHLC format and realizing that the date is the last day of the week rather than the first day of the week. Very minor compared to doing the whole thing myself. -Original Message- From: R. Michael Weylandt michael.weyla...@gmail.com [mailto:michael.weyla...@gmail.com] Sent: Tuesday, November 22, 2011 3:10 PM To: Kevin Burton Cc: r-help@r-project.org Subject: Re: [R] Missing data? Couldn't you use seq.Date() to set up the time index and then just fill as appropriate? Alternatively, to.weekly if you are starting with a daily series. Michael On Nov 22, 2011, at 4:00 PM, Kevin Burton rkevinbur...@charter.net wrote: I was wondering what the best approach is for missing data in a time series. I give an example using xts but I would like to know what seems to be the best method. Say I have library(xts) xts.ts - xts(1:4,as.Date(c(1970-01-01, 1970-1-3, 1980-10-10, 2007-8-19)), frequency=52) I would like to turn this into a time series (still could be xts, or converted to ts) that has values for every week starting with the week that includes the start date and ending with the week that includes the end date. If there is data for the week then use it otherwise set it to NA or 0. Remember some years have 52, 53, or rarely 54 full or partial weeks. What to do with the partials at the beginning and ending of the year? This seems to be a fairly common problem and doing it myself is very cumbersome. Does a solution to this kind of problem exist? Once the approach to a weekly period is found I am sure that adjustment to daily, monthly, or quarterly would be relatively straightforward. Thank you. Kevin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Fwd: xtable and sweave: caption placement problem
On 11/18/2011 1:22 AM, ren...@vannieuwkoop.ch wrote: \documentclass[11pt,a4paper]{article} \usepackage{Sweave} \begin{document} = x = runif(100, 1, 10) y = 2 + 3 * x + rnorm(100) @ echo=FALSE,results=tex= library(xtable) print(xtable(summary(lm(y~x)), align=r, caption=Summary statistics for the regression model, caption.placement=top, label=tab:summary, digits=2)) @ \end{document} caption.placement is an argument to print.xtable, not xtable. print(xtable(summary(lm(y~x)), align=r, caption=Summary statistics for the regression model, label=tab:summary, digits=2), caption.placement=top) -- Brian S. Diggs, PhD Senior Research Associate, Department of Surgery Oregon Health Science University __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Missing data?
Also with to.weekly there seems to be a problem with when the week starts. For example: xts.ts - xts(1:4, c(as.Date(2011-01-01), as.Date(2011-01-10), as.Date(2011-10-09), as.Date(2011-10-10)), frequency=52) to.weekly(xts.ts) xts.ts.Open xts.ts.High xts.ts.Low xts.ts.Close 2011-01-01 1 1 11 2011-01-10 2 2 22 2011-10-09 3 3 33 2011-10-10 4 4 44 xts.ts - xts(1:4, c(as.Date(2011-01-01), as.Date(2011-01-02), as.Date(2011-10-09), as.Date(2011-10-10)), frequency=52) to.weekly(xts.ts) xts.ts.Open xts.ts.High xts.ts.Low xts.ts.Close 2011-01-02 1 2 12 2011-10-09 3 3 33 2011-10-10 4 4 44 So in the first case the week ends on January 1st. But the second indicates that the end of the week is the 2nd but it includes the data from the first. I would expect that the first column should be consistent. Notice that 10-09 and 10-10 are properly considered different weeks because the 9th is a Sunday and the 10th is a Monday (the beginning of the week). -Original Message- From: R. Michael Weylandt michael.weyla...@gmail.com [mailto:michael.weyla...@gmail.com] Sent: Tuesday, November 22, 2011 3:10 PM To: Kevin Burton Cc: r-help@r-project.org Subject: Re: [R] Missing data? Couldn't you use seq.Date() to set up the time index and then just fill as appropriate? Alternatively, to.weekly if you are starting with a daily series. Michael On Nov 22, 2011, at 4:00 PM, Kevin Burton rkevinbur...@charter.net wrote: I was wondering what the best approach is for missing data in a time series. I give an example using xts but I would like to know what seems to be the best method. Say I have library(xts) xts.ts - xts(1:4,as.Date(c(1970-01-01, 1970-1-3, 1980-10-10, 2007-8-19)), frequency=52) I would like to turn this into a time series (still could be xts, or converted to ts) that has values for every week starting with the week that includes the start date and ending with the week that includes the end date. If there is data for the week then use it otherwise set it to NA or 0. Remember some years have 52, 53, or rarely 54 full or partial weeks. What to do with the partials at the beginning and ending of the year? This seems to be a fairly common problem and doing it myself is very cumbersome. Does a solution to this kind of problem exist? Once the approach to a weekly period is found I am sure that adjustment to daily, monthly, or quarterly would be relatively straightforward. Thank you. Kevin [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] x, y for point of intersection
On 22-Nov-11 21:25:56, Monica Pisica wrote: Hi everyone, I am trying to get a point of intersection between a polyline and a straight line .. and get the x and y coordinates of this point. For exemplification consider this: set.seed(123) k1 -rnorm(100, mean=1.77, sd=3.33) k1 - sort(k1) q1 - rnorm(100, mean=2.37, sd=0.74) q1 - sort(q1, decreasing = TRUE) plot(k1, q1, xlim - c((min(k1)-5), (max(k1)+5)), type=l) ya - 2 xa = -5 yb=4 xb=12 lines(c(xa, xb), c(ya, yb), col = 2) # I want to get the x and y coordinates of the # intersection of the 2 lines. m - (ya-yb)/(xa-xb) b - ya-m*xa ln - loess(q1~k1) lines(ln) It is clear that the x, y will satisfy both linear equations, y = m*x + b and the ln polyline - .. but while I can visualize the equation of the straight line - I have problems with the polyline. I will appreciate any ideas to solve this problem. I thought it a trivial solution but it seems I cannot see it. Thanks, Monica ya - 2 xa = -5 yb = 4 xb = 12 These define a line y = ya + (x - xa)*(yb - ya)/(xb - xa) so write this as y = A + B*x Then points above the line satisfy y A + B*X and points below the line satisfy Y A + B*X A - ya - xa*(yb - ya)/(xb - xa) B - (yb - ya)/(xb - xa) So now extract the points (x,y) fron the loess fit: x.ln - ln$x y.ln - ln$y and now find the points on 'ln' which are above, and the points on ln which are below, which will locate the segment which crosses the (X,Y) line: ix.upper - which(y.ln A + B*ln$y) ix.lower - which(y.ln =3D A + B*ln$y) ix.upper # 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15=20 So now you have the line segment from (x.ln[15],y.ln[15]) to (x.ln[16],y.ln[16]) and now all you need to do is to find the intersection of the line from (ln.x[15],ln.y[15]) to (ln.x[16],ln.y[16]) with the line from (xa,ya) to (xb,yb). (There could be complications if the y-values of ln do not continually decrease in value; but happily they do decrease in your example). Hoping this helps! Ted. E-Mail: (Ted Harding) ted.hard...@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 22-Nov-11 Time: 22:49:54 -- XFMail -- __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] filtering probesets with Bioconductor?
Hi, I am relatively new to R and Bioconductor and am trying to filter the topTable that I generated of differentially expressed genes from my normlized eset file comprised of ~ 40 HG-133A Affy microarrays . I would like to see if particular probesets are represented in this list. Alternatively I would like to generate a topTable of differentially expressed genes using only specified probesets within my eset file. Can anyone tell me how I would begin to approach this? I have looked into using the genefilter() function but can't figure out if it can take the right parameters (i.e. specific probe set id's). Thanks in advance, -M This is the code I used to generate my topTable fit - lmFit(eset, design) cont.matrix - makeContrasts(NormalvsTumor=Tumor-Normal, levels=design) fit2 - contrasts.fit(fit, cont.matrix) fit2 - eBayes(fit2) topTable(fit2, number=100, adjust=BH) -- View this message in context: http://r.789695.n4.nabble.com/filtering-probesets-with-Bioconductor-tp4097747p4097747.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] Data Frame Search Slow
Wow, these specs are fantastic: user system elapsed 0.330.000.39 I wonder how much of that is because of the capacity of the box that you are running R on. Can you post pertinent specs? This suggest to me that hardware upgrades (RAM specifically) may also be in order. Investigating data.table now. Thanks! -- View this message in context: http://r.789695.n4.nabble.com/Data-Frame-Search-Slow-tp4096906p4097278.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 to inputting a pre-defined correlation structure in a Mixed Model
I'm working in a Gen/Marker-Phenotype association study in wheat and I'm using a Mixed Model Approach to estimate the effect of the markers. My model has the atribute measured as y (response variable), the markers and the blocks (of a complete random block design) as fixed and the genotypes and the residuals as random. In one hand I'm assuming that there is no correlation between residuals and that they have a normal distribution with mean equals to zero and a common variance equals to (sigma e)^2. On the other hand I'm also asumming that the genotypes are normally distributed with mean equals to zero but with variance equals to a G matrix that considers the relatdness between individuals. This G matrix is expressed as 2 * (sigma g)^2 * K, where K is a matrix with the reladness coefficients (kinship) between all individuals in the study. The K matrix is calculated outside of R environment, and I'm using it as an input. I'm using the lme function of the nlme library in R, but I want to know how can I gap the structures that R offers me (as corrAR1, corrSumm, etc.) as default structures, because I already have this structure and I only have to estimate the (sigma g)^2 parameter, possibly using REML. I'm new in the use of mixed models and I will be very pleased if someone could help me with this particular question. Thanks a lot in advance. -- View this message in context: http://r.789695.n4.nabble.com/Help-to-inputting-a-pre-defined-correlation-structure-in-a-Mixed-Model-tp4097147p4097147.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] Data Frame Search Slow
So, here is the result time from using the datatable package: user system elapsed 0.800 0.012 1.847 Here are the methods that I am using: ush - data.table(read.csv(...)) setkey(ush, product_id) s1 - subset(ush, product_id == product.id) Seems like a minor improvement but not enough to get those subsets in less than ~2 seconds. Am I doing something wrong I wonder... -- View this message in context: http://r.789695.n4.nabble.com/Data-Frame-Search-Slow-tp4096906p4097441.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] Rcmdr numSummary: means of multiple variables without grouping
Hello there, when using the function numSummary in Rcmdr and selecting more than one variable (without grouping), the grand mean across all variables is returned for each variable instead of the mean of each single variable. However, this happens only for the mean, and not for sd, quantiles and na. This is the output: numSummary(dataset1 [,c(var1, var2)], + statistics=c(mean, sd, quantiles), quantiles=c(0,.25,.5,.75,1)) mean sd 0% 25% 50% 75% 100% n NA var1 15.58491 4.154637 10 14 15 19.5 28 54 0 var2 15.58491 5.904053 5 10 15 18.5 30 52 2 When using a grouping variable, everything is fine: numSummary(dataset1 [,c(var1, var2)], + groups= dataset1$gender, statistics=c(mean, sd, quantiles), + quantiles=c(0,.25,.5,.75,1)) Variable: var1 mean sd 0% 25% 50% 75% 100% n NA male 16.57895 4.634602 10 14 16 20 28 19 0 female 16.28571 3.937538 10 14 15 18 28 35 0 Variable: var2 mean sd 0% 25% 50% 75% 100% n NA male 14.7 5.442810 8 10 14 15.0 28 18 1 female 14.76471 6.213664 5 10 15 19.5 30 34 1 Any ideas how to get separate means for multiple variables in numSummary without grouping? I am using R 2.14.0 and Rcmdr 1.7.2 on Windows 7 Professional. Thanks in advance! Boris [[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] On-demand importing of a package
On Tue, Nov 22, 2011 at 4:27 PM, Martin Morgan mtmor...@fhcrc.org wrote: [...] No need to Depend:. Use Imports: Matrix plus in the NAMESPACE file importFrom(Matrix, rowSums) Why do you not want to do this? Matrix is available for everyone, Imports: doesn't influence the package search path. There is a cost associated with loading the library in the first place, but...? Not just loading, installing a package has a cost, too. Dependencies are bad, they might make my package fail, and I have no control over them. It's not just 'Matrix', I have this issue with other packages as well. Anyway, 'Imports: Matrix' is just a workaround I think. Or is the example in my initial mail expected to fail? Why is that? Why can I call some functions from 'Matrix' that way and why can't I call others? I'm more into black-and-white -- it either needs Matrix or not; apparently it does. It's a matter of opinion, I guess. I find it very annoying when I need to install a bunch of packages from which I don't use any code, just because some tiny bit of a package I need uses them. I would like to spare my users from this. [...] In another message you mention Matrix:::rowSums(W) Error in callGeneric() : 'callGeneric' must be called from a generic function or method but something else is going on -- you don't get to call methods directly; you're getting Matrix::rowSums (it's exported, so no need for a :::, see getNamespaceExports(Matrix)). Maybe traceback() after the error would be insightful? Another poster suggested this, that's why I tried. It is clear that I should not call it directly. All I want to do is having a function like this: f - function() { if (require(Matrix)) { res - sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5) } else { res - diag(1:5) } y - rowSums(res) res / y } Setting the subjective bit, about depending or not, aside, is there really no solution for this? The code in the manual page examples work fine without importing the package and just loading it if needed and available. Why doesn't the code within the package? Thanks for the patience, Gabor Martin [...] -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Data Frame Search Slow
Update from email outside of this thread: Justin Haynes writes: matrices will help, but two quick solutions: if you are looking for single items to go in the some_value space, use == instead of %in% and you'll notice speedups. The second more involved option is to take a look at the package data.table. it provides a wrapper for data.frame that has some impressive optimizations as well as allowing for SQL like indexing and syntax. hope that helps! Justin, thanks. Here's the before and after clock: Before: user system elapsed 0.976 0.164 2.607 After: user system elapsed 0.624 0.156 1.810 You are correct. I still need to get that elapsed down even more. Data.table sounds like a good option. I'll look into it more. Thank you. -- View this message in context: http://r.789695.n4.nabble.com/Data-Frame-Search-Slow-tp4096906p4097261.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] Data Frame Search Slow
Answer to my own question: ush - data.table(read.csv(...)) setkey(ush, product_id) s1 - ush[J[product.id]] user system elapsed 0.000 0.000 0.003 It seems like that's the method to use! Amazing. -- View this message in context: http://r.789695.n4.nabble.com/Data-Frame-Search-Slow-tp4096906p4097576.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] Scatter plot - using colour to group points?
Success with the lines command and col argument! I have some nice point and line plots. Thanks so much for you help. Ongoing project - I will probably be back! Sarah -- View this message in context: http://r.789695.n4.nabble.com/Scatter-plot-using-colour-to-group-points-tp4092794p4097625.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] Rcmdr numSummary: means of multiple variables without grouping
Dear Boris, This bug is traceable to a change in the mean() function in R and is fixed in the current version (1.7-3) of the Rcmdr package on CRAN. Best, John John Fox Sen. William McMaster Prof. of Social Statistics Department of Sociology McMaster University Hamilton, Ontario, Canada http://socserv.mcmaster.ca/jfox/ On Tue, 22 Nov 2011 21:26:41 +0100 Boris Mayer bocab...@googlemail.com wrote: Hello there, when using the function numSummary in Rcmdr and selecting more than one variable (without grouping), the grand mean across all variables is returned for each variable instead of the mean of each single variable. However, this happens only for the mean, and not for sd, quantiles and na. This is the output: numSummary(dataset1 [,c(var1, var2)], + statistics=c(mean, sd, quantiles), quantiles=c(0,.25,.5,.75,1)) mean sd 0% 25% 50% 75% 100% n NA var1 15.58491 4.154637 10 14 15 19.5 28 54 0 var2 15.58491 5.904053 5 10 15 18.5 30 52 2 When using a grouping variable, everything is fine: numSummary(dataset1 [,c(var1, var2)], + groups= dataset1$gender, statistics=c(mean, sd, quantiles), + quantiles=c(0,.25,.5,.75,1)) Variable: var1 mean sd 0% 25% 50% 75% 100% n NA male 16.57895 4.634602 10 14 16 20 28 19 0 female 16.28571 3.937538 10 14 15 18 28 35 0 Variable: var2 mean sd 0% 25% 50% 75% 100% n NA male 14.7 5.442810 8 10 14 15.0 28 18 1 female 14.76471 6.213664 5 10 15 19.5 30 34 1 Any ideas how to get separate means for multiple variables in numSummary without grouping? I am using R 2.14.0 and Rcmdr 1.7.2 on Windows 7 Professional. Thanks in advance! Boris [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] evaluation question
On 23/11/11 07:31, R. Michael Weylandt wrote: Good morning Erin, eval(parse(text = pexp(3.2,rate=1))) seems to work But the general rule applies: library(fortunes) fortune(parse()) The fortune notwithstanding I find this *specific* use of parse() to be very, uh, useful! :-) cheers, Rolf Turner __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] glht for lme object with significant interaction term
Dear all, I'm working on some data from an experiment on the breeding behavior of birds. In short, I have been measuring how the time spent on performing a certain task (variable 'mean_on_active') differs over time (variable 'day', 2 levels) across three experimental categories (variable 'treat'; levels 'C', 'R', 'E'). The model shows a significant interaction between treatment and day. To have a closer look at this, I would like to do multiple comparisons for treatment levels within day (i.e. across treatments for each day in turn). I have browsed the forum for a way of doing this using the glht function, but haven't found a good solution to my problem. Any hints on how to proceed, or on other methods that might be (more) appropriate? Final model output below, data attached. http://r.789695.n4.nabble.com/file/n4097865/sub.data.txt sub.data.txt Kind regards, Andreas ##Final model m.final-lme(mean.on.active~treat+day+treat:day,random=1|id,na.action=na.omit) summary(m.final) Linear mixed-effects model fit by REML Data: NULL AIC BIClogLik 1051.779 1075.757 -517.8896 Random effects: Formula: ~1 | id (Intercept) Residual StdDev:6.276309 5.473167 Fixed effects: mean_on_active ~ treat * day Value Std.Error DF t-value p-value (Intercept) 24.987123 1.792599 75 13.939049 0. treatE15.661119 2.327329 73 6.729225 0. treatR 1.133678 2.228713 73 0.508670 0.6125 day6-7-1.068160 1.758899 73 -0.607289 0.5455 treatE:day6-7 -6.650690 2.335567 73 -2.847570 0.0057 treatR:day6-7 -1.495927 2.273071 73 -0.658108 0.5125 Correlation: (Intr) treatE treatR day6-7 tE:6-7 treatE-0.736 treatR-0.747 0.572 day6-7-0.482 0.372 0.389 treatE:day6-7 0.361 -0.522 -0.292 -0.753 treatR:day6-7 0.370 -0.281 -0.524 -0.774 0.582 Standardized Within-Group Residuals: Min Q1Med Q3Max -2.5774244 -0.4585991 -0.1360731 0.3902143 3.9752257 Number of Observations: 154 Number of Groups: 76 -- View this message in context: http://r.789695.n4.nabble.com/glht-for-lme-object-with-significant-interaction-term-tp4097865p4097865.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] On-demand importing of a package
If Suggests doesn't work for you, perhaps you need to put more effort into reinventing the wheel, and depend less on other packages. --- Jeff NewmillerThe . . Go Live... DCN:jdnew...@dcn.davis.ca.usBasics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. Gábor Csárdi csa...@rmki.kfki.hu wrote: On Tue, Nov 22, 2011 at 4:27 PM, Martin Morgan mtmor...@fhcrc.org wrote: [...] No need to Depend:. Use Imports: Matrix plus in the NAMESPACE file importFrom(Matrix, rowSums) Why do you not want to do this? Matrix is available for everyone, Imports: doesn't influence the package search path. There is a cost associated with loading the library in the first place, but...? Not just loading, installing a package has a cost, too. Dependencies are bad, they might make my package fail, and I have no control over them. It's not just 'Matrix', I have this issue with other packages as well. Anyway, 'Imports: Matrix' is just a workaround I think. Or is the example in my initial mail expected to fail? Why is that? Why can I call some functions from 'Matrix' that way and why can't I call others? I'm more into black-and-white -- it either needs Matrix or not; apparently it does. It's a matter of opinion, I guess. I find it very annoying when I need to install a bunch of packages from which I don't use any code, just because some tiny bit of a package I need uses them. I would like to spare my users from this. [...] In another message you mention Matrix:::rowSums(W) Error in callGeneric() : 'callGeneric' must be called from a generic function or method but something else is going on -- you don't get to call methods directly; you're getting Matrix::rowSums (it's exported, so no need for a :::, see getNamespaceExports(Matrix)). Maybe traceback() after the error would be insightful? Another poster suggested this, that's why I tried. It is clear that I should not call it directly. All I want to do is having a function like this: f - function() { if (require(Matrix)) { res - sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5) } else { res - diag(1:5) } y - rowSums(res) res / y } Setting the subjective bit, about depending or not, aside, is there really no solution for this? The code in the manual page examples work fine without importing the package and just loading it if needed and available. Why doesn't the code within the package? Thanks for the patience, Gabor Martin [...] -- Gabor Csardi csa...@rmki.kfki.hu MTA KFKI RMKI __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/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] Missing data?
Void of any other suggestions this approach makes sense but for my case I think I need to use zoo objects rather than xts. If I sequence the data generally I don't know if there will be 365 days in the year or 366. So I have to sequence the dates as: seq(from=as.Date(2011-01-01), to=as.Date(2011-12-31), by=day) If I use this sequence with xts I get: ds - xts(NA, seq(from=as.Date(2011-01-01), to=as.Date(2011-12-31), by=day)) Error in xts(NA, seq(from = as.Date(2011-01-01), to = as.Date(2011-12-31), : NROW(x) must match length(order.by) If I leave the 'data' empty I don't get the error but if I try to assign an individual item (fill as appropriate) ds - xts(, seq(from=as.Date(2011-01-01), to=as.Date(2011-12-31), by=day)) ds[2011-12-24] - 10 ds Error in structure(coredata(x), names = x.attr$dimnames[[1]]) : 'names' attribute [365] must be the same length as the vector [358] So now I need to remember that I have not filled in all of the data. Also simple dereferencing gives: ds[1] Error in `[.xts`(ds, 1) : subscript out of bounds With zoo I am able to create a time-series where all of the data is initially NA: ds - zoo(NA, seq(from=as.Date(2011-01-01), to=as.Date(2011-12-31), by=day)) So I can fill the data as appropriate and the remaining slots will have NA. I may be new with xts but I cannot see a way of creating a useable 'blank' time-series. Also with xts it seems like the frequency is ignored. ds - xts(1:365, seq(from=as.Date(2011-01-01), to=as.Date(2011-12-31), by=day), frequency=52) frequency(ds) [1] 1 Whereas zoo remembers the frequency setting ds - zoo(1:365, seq(from=as.Date(2011-01-01), to=as.Date(2011-12-31), by=day), frequency=52) frequency(ds) [1] 52 But since the ultimate goal is to get the time-series in a 'ts' format (as many functions require 'ts') it seems like even zoo has problems: as.ts(ds) Time Series: Start = c(14975, 1) End = c(15339, 1) Frequency = 52 [1] 1 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [42] NA NA NA NA NA NA NA NA NA NA NA 2 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [83] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 3 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [124] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA 4 NA NA NA NA NA NA NA [165] NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA [206] . . . . . . So the conversion from zoo to ts maintained the frequency but I am not sure where it decided on the start and end values. Also the conversion seemed to changed the data also. Notice that every period (52 entries) the original data is maintained. In other words if ds is the original zoo time series then ds[1] is 1 and ds[2] is 2 etc. The converted time-series keeps ds[1] but inserts 51 NA's then adds ds[2] etc till the end of the series. That is not what the initial data was. The conversion is inserting data of its own. The conversion to ts from xts seems better behaved: ds - xts(1:365, seq(from=as.Date(2011-01-01), to=as.Date(2011-12-31), by=day), frequency=52) as.ts(ds) Time Series: Start = 1 End = 365 Frequency = 1 [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 [43] 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 [85] 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 [127] 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 [169] 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 [211] 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 [253] 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 [295] 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 [337] 337 338 339 340 341 342 343 344 345 346 347 348 349 350
Re: [R] On-demand importing of a package
On 11/22/2011 03:06 PM, Gábor Csárdi wrote: On Tue, Nov 22, 2011 at 4:27 PM, Martin Morganmtmor...@fhcrc.org wrote: [...] No need to Depend:. Use Imports: Matrix plus in the NAMESPACE file importFrom(Matrix, rowSums) Why do you not want to do this? Matrix is available for everyone, Imports: doesn't influence the package search path. There is a cost associated with loading the library in the first place, but...? Not just loading, installing a package has a cost, too. Dependencies are bad, they might make my package fail, and I have no control over them. It's not just 'Matrix', I have this issue with other packages as well. Anyway, 'Imports: Matrix' is just a workaround I think. Or is the example in my initial mail expected to fail? Why is that? Why can I call some functions from 'Matrix' that way and why can't I call others? I'm more into black-and-white -- it either needs Matrix or not; apparently it does. It's a matter of opinion, I guess. I find it very annoying when I need to install a bunch of packages from which I don't use any code, just because some tiny bit of a package I need uses them. I would like to spare my users from this. [...] In another message you mention Matrix:::rowSums(W) Error in callGeneric() : 'callGeneric' must be called from a generic function or method but something else is going on -- you don't get to call methods directly; you're getting Matrix::rowSums (it's exported, so no need for a :::, see getNamespaceExports(Matrix)). Maybe traceback() after the error would be insightful? Another poster suggested this, that's why I tried. It is clear that I should not call it directly. All I want to do is having a function like this: f- function() { if (require(Matrix)) { res- sparseMatrix(dims=c(5, 5), i=1:5, j=1:5, x=1:5) } else { res- diag(1:5) } y- rowSums(res) res / y } Setting the subjective bit, about depending or not, aside, is there really no solution for this? The code in the manual page examples work fine without importing the package and just loading it if needed and available. Why doesn't the code within the package? If I create a package that does not Import: Matrix (btw, Matrix is distributed with all R), with only a function f, and with exports(f) in NAMESPACE, I get library(pkgA) f() Loading required package: Matrix Loading required package: lattice Attaching package: 'Matrix' The following object(s) are masked from 'package:base': det Error in rowSums(res) : 'x' must be an array of at least two dimensions This is because (a) Matrix is attached to the user search path but (b) because f is defined in the NAMESPACE of pkgA, rowSums is looked for first in the pkgA NAMESPACE, and in then in the search of the package (which includes base) and then in the user search path. It is found in base, and the search ends there. If I modify f to use y - Matrix::rowSums(res) I get f() Loading required package: Matrix Loading required package: lattice Attaching package: 'Matrix' The following object(s) are masked from 'package:base': det 5 x 5 sparse Matrix of class dgCMatrix [1,] 1 . . . . [2,] . 1 . . . [3,] . . 1 . . [4,] . . . 1 . [5,] . . . . 1 I start off with the correct rowSums, and continue from there. Martin Thanks for the patience, Gabor Martin [...] -- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793 __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.