Thank you David. The plot() you sugested worked nicely. You and Weyland both think ts class objects are difficult to use. I had not considered doing differently, but I have just gotten many tutorials on package zoo and how to use it in econometrics. Looks promising, will read everything now. But let me ask first, I am going to do some exercises using vars package, and I wanted to replicate on my own database the following script (below) that I have managed to put together using the data Canada (available in R): So I compared the structure of "Canada" and I concluded it was a "ts" object, and that's why I decided to create my own data the same way. Is this necessary or am I taking an irrelevant precaution? > str(Canada) mts [1:84, 1:4] 930 930 930 931 933 ... - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr [1:4] "e" "prod" "rw" "U" - attr(*, "tsp")= num [1:3] 1980 2001 4 - attr(*, "class")= chr [1:2] "mts" "ts"
> str(dados2) #my database on public dept mts [1:210, 1:44] 83 65 136 13 154 118 100 30 205 188 ... - attr(*, "dimnames")=List of 2 ..$ : NULL ..$ : chr [1:44] "data" "igpm" "ipca" "iigpdi" ... - attr(*, "tsp")= num [1:3] 1994 2011 12 - attr(*, "class")= chr [1:2] "mts" "ts" > data("Canada") > plot(Canada,nc=2,xlab="") > VARselect(Canada,lag.max=8,type="both") > Canada<-Canada[,c("prod","e","U","rw")] > pict<-VAR(Canada,p=1,type="both") > summary(pict,equation="e") > varcov[1:4,1:4]=summary(pict)$covres[1:4,1:4] #getting the covar . I had > problem with this comand, so i used instead as below: >getVarCov=summary(pict)$covres[1:4,1:4] > c=chol(varcov) #Choleski > u=rnorm(4) #vetcor with 4 random variables N(0,1) > P=c%*%u #matricial multiplication choleski%*%rnorm > xteste=matrix(1:6,nrow=6,ncol=1) # generates a test vector for X ### Start - coefficients of each equation ### > coef_e=pict$varresult$e$coefficients > coef_rw=pict$varresult$rw$coefficients > coef_U=pict$varresult$U$coefficients > coef_prod=pict$varresult$prod$coefficients > coef=rbind(coef_prod,coef_e,coef_U,coef_rw) ### End - generates coef matrix with the coefficients of each equation > coef%*%xx+P #simulates vector Yt+1, conditioned to shocks in vector X and > shocks already ajusted between the variables by the covar ________________________________ De: David Winsemius <dwinsem...@comcast.net> Cc: "r-help@r-project.org" <r-help@r-project.org> Enviadas: Segunda-feira, 17 de Outubro de 2011 22:09 Assunto: Re: [R] Beginner's question about plotting variables in a time series object with the date on the x axis On Oct 17, 2011, at 5:23 PM, Iara Faria wrote: > Dear R helpers, > > I am a beginner at R so please be gentle :) > I have already read manuals and FAQs, with no help. > I have a monthly time series data on public debt with 40 variables, it starts > on January 1994 and ends on June 2011. I agree with Weyland. Figuring out how to use class `ts` objects in R is difficult. If it were easy I don't think Zeileis would have invented `zoo`. > I am loading the data into R using read.csv and the data looks ok when I do > edit(dados): >> dados<-read.csv("dadosR3.csv", header=T) > then I tried making it into a time series object, using: >> dados2<-ts(dados, start = c(1994,1), frequency=12) (See below for what that did.) > > Now when I try plotting any of the variables, for example divliq.pib (net > debt), the date doesn't appear on the x axis. How can I do this? > I use >> plot.ts(divliq.pib) Try: plot(time(dados2), dados[, "divliq.pib"] , xy.labels=FALSE)) > > also the function names() doesn't work, which would be important since I have > so many variables. >> names(dados2) Read the help page again(?). "A data frame will be coerced to a numeric matrix via data.matrix." The names function only works for lists and name vectors. Try colnames() > NULL > > I am using R.2.13.1 > > Thank you very much. > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. David Winsemius, MD West Hartford, CT [[alternative HTML version deleted]]
______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.