Hello, I apologize for this question that may has been asked a lot of times but I could not go through it. I create a multivariate time series containing NA values. I want to compute a linear regression and obtain a time serie for both residuals and fitted values. I have tried the trick ts.intersect, without success. Could you help me out of this? #### Example: y<-ts(1:10+rnorm(10)) x<-ts(1:10) datats<-cbind(y,lagx=lag(x)) Notice the datats could come directly from an imported file, that is why I did not use ts.intersect(y,lagx=lag(x)) fit<-lm(y~lagx,data=datats,na.action=na.omit) but how do I get a time serie of residuals instead of a vector residuals(fit)? ###### Matthieu Cornec
Matthieu Cornec <matthieu.cornec <at> gmail.com> writes:> I create a multivariate time series containing NA values. > I want to compute a linear regression and obtain a time serie for both > residuals and fitted values. I have tried the trick ts.intersect, > without success. > > Could you help me out of this? > #### > Example: > > y<-ts(1:10+rnorm(10)) > x<-ts(1:10) > datats<-cbind(y,lagx=lag(x))Are you sure that you want lag(x) here? lag(x) moves the time scale one unit earlier so this will predict a past y based on a future x. I think you probably meant lag(x, -1). (I have continued to use lag(x) below for consitency with your post.)> > Notice the datats could come directly from an imported file, that is > why I did not use ts.intersect(y,lagx=lag(x)) > > fit<-lm(y~lagx,data=datats,na.action=na.omit) > > but how do I get a time serie of residuals instead of a vector residuals(fit)? # Define this function: plain2ts <- function(x, ts.) ts(x, start = start(ts.), freq = frequency(ts.)) # It can be used like this: datats.na <- na.omit(datats) datats.fit <- lm(y ~ lagx, datats.na) datats.resid <- plain2ts(resid(datats.fit), datats.na) # Also note that using the zoo package one can directly perform # lm on ts objects and it will automatically align them provided # you surround the formula with I(...): library(zoo) fit2 <- lm(I(y ~ lag(x))) # y and x are the ts objects in your post however, you would still have to use the previous method to convert the residuals back to ts class as that is not currently handled. For more on zoo: library(zoo) vignette("zoo")
Hello, I apologize for this question that may has been asked a lot of times but I could not go through it. I create a multivariate time series containing NA values. (This dataset of time series can come directly from an imported file). I want to compute a linear regression and obtain a time serie for both residuals and fitted values. I have tried the trick ts.intersect, without success. Could you help me out of this? #### Example: y<-ts(1:10+rnorm(10)) x<-ts(1:10) datats<-cbind(y,lagx=lag(x)) Notice the datats could come directly from an imported file, that is why I did not use ts.intersect(y,lagx=lag(x)) fit<-lm(y~lagx,data=datats,na.action=na.omit) but how do I get a time serie of residuals instead of a vector residuals(fit)? ######
Hello, I would like to convert c("a","b","c") into "abc". Anyone could help? Thanks, Matthieu Cornec
Matthieu Cornec wrote:> Hello, > > I would like to convert c("a","b","c") into "abc". > Anyone could help??paste paste(c("a","b","c"), collapse="") -- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 452-1424 (M, W, F) fax: (917) 438-0894
Matthieu Cornec wrote:> Hello, > > I would like to convert c("a","b","c") into "abc". > Anyone could help?See ?paste Uwe Ligges> Thanks, > > Matthieu Cornec > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Use the collapse argument in paste. paste( c("a", "b", "c"), collapse="" ) [1] "abc" On Fri, 2005-03-04 at 03:32 -0800, Matthieu Cornec wrote:> Hello, > > I would like to convert c("a","b","c") into "abc". > Anyone could help? > Thanks, > > Matthieu Cornec > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >
Hi all, ted <- letters[1:3] ted paste(ted, collapse = "") cheers, P.BADY At 03:32 04/03/2005 -0800, Matthieu Cornec wrote:>Hello, > >I would like to convert c("a","b","c") into "abc". >Anyone could help? >Thanks, > >Matthieu Cornec > >______________________________________________ >R-help@stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.htmlPierre BADY <°)))))>< Université Claude Bernard Lyon 1 UMR CNRS 5023, LEHF bat Alphonse Forel 43 boulevard du 11 novembre 1918 F-69622 VILLEURBANNE CEDEX FRANCE TEL : +33 (0)4 72 44 62 34 FAX : +33 (0)4 72 43 28 92 MEL : pierre.bady@univ-lyon1.fr http://limnologie.univ-lyon1.fr http://pierre.bady.free.fr (in construction) [[alternative HTML version deleted]]
How about: > paste( c("a","b","c"), collapse="") [1] "abc" > hope this helps. spencer graves Matthieu Cornec wrote:>Hello, > >I would like to convert c("a","b","c") into "abc". >Anyone could help? >Thanks, > >Matthieu Cornec > >______________________________________________ >R-help at stat.math.ethz.ch mailing list >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html > >
On 4 Mar 2005, at 11:32 am, Matthieu Cornec wrote:> Hello, > > I would like to convert c("a","b","c") into "abc". > Anyone could help?paste(c("a", "b", "c"), sep="") Tim -- Dr Tim Cutts Informatics Systems Group, Wellcome Trust Sanger Institute GPG: 1024D/E3134233 FE3D 6C73 BBD6 726A A3F5 860B 3CDD 3F56 E313 4233