{"word_count": 499, "character_count": 3937}
Yesterday, Christopher asked me how to store an R object, in order to save some time, when working on the project.First, download the csv file for searches related to some keyword, via http://www.google.com/trends/, for instance "sunglasses". Recall that csv files store tabular data (numbers and text) in plain-text form, with comma-separated values (where csv term comes from). Even if it is not a single and well-defined format, it is a text file, not an excel file!Recherche sur le Web : intérêt pour sunglassesDans tous les pays; De 2004 à ce jourIntérêt dans le tempsSemaine,sunglasses2004-01-04 - 2004-01-10,482004-01-11 - 2004-01-17,472004-01-18 - 2004-01-24,512004-01-25 - 2004-01-31,502004-02-01 - 2004-02-07,52(etc) The file can be downloaded from the blog,&#62; report=read.table(+ "http://freakonometrics.blog.free.fr/public/data/glasses.csv",+ skip=4,header=TRUE,sep=",",nrows=464)Then, we have run a function on this data frame, to transform it. It can be found from a source file&#62; source("http://freakonometrics.blog.free.fr/public/code/H2M.R")In this source file, there is function that transforms a weekly series into a monthly one. The output is either a time series, or a numeric vector,&#62; sunglasses=H2M(report,lang="FR",type="ts")Here, we asked for a time series,&#62; sunglasses          Jan      Feb      Mar      Apr2004 49.00000 54.27586 66.38710 80.100002005 48.45161 58.25000 69.93548 80.066672006 49.70968 57.21429 67.41935 82.100002007 47.32258 55.92857 70.87097 84.366672008 47.19355 54.20690 64.03226 79.366672009 45.16129 50.75000 63.58065 76.900002010 32.67742 44.35714 58.19355 70.000002011 44.38710 49.75000 59.16129 71.600002012 43.64516 48.75862 64.06452 70.13333          May      Jun      Jul      Aug2004 83.77419 89.10000 84.67742 73.516132005 83.06452 91.36667 89.16129 76.322582006 86.00000 92.90000 93.00000 72.290322007 86.83871 88.63333 84.61290 72.935482008 80.70968 80.30000 78.29032 64.580652009 77.93548 70.40000 62.22581 51.580652010 71.06452 73.66667 76.90323 61.774192011 74.00000 79.66667 79.12903 66.290322012 79.74194 82.90000 79.96774 69.80645          Sep      Oct      Nov      Dec2004 56.20000 46.25806 44.63333 53.967742005 56.53333 47.54839 47.60000 54.387102006 51.23333 46.70968 45.23333 54.225812007 56.33333 46.38710 44.40000 51.129032008 51.50000 44.61290 40.93333 47.741942009 37.90000 30.38710 28.43333 31.677422010 50.16667 46.54839 42.36667 45.903232011 52.23333 45.32258 42.60000 47.354842012 54.03333 46.09677 43.45833that we can plot using&#62; plot(sunglasses)Now we would like to store this time series. This is done easily using&#62; save(sunglasses,file="sunglasses.RData")Next time we open R, we just have to use&#62; load("/Users/UQAM/sunglasses.RData")to load the time series in R memory. So saving objects is not difficult.Last be not least, for the part on seasonal models, we will be using some functions from an old package. Unfortunately, on the CRAN website, we see thatbut nicely, files can still be found on some archive page. On Linux, one can easily install the package using (in R)&#62; install.packages(+ "/Users/UQAM/uroot_1.4-1.tar.gz",+ type="source")With a Mac, it is slightly more complicated (see e.g. Jon's blog): one has to open a Terminal and to typeR CMD INSTALL /Users/UQAM/uroot_1.4-1.tar.gzOn Windows, it is possible to install a package from a zipped file: one has to download the file from archive page, and then to spot it from R.The package is now installed, we just have to load it to play with it, and use functions it contains to tests for cycles and seasonal behavior,&#62; library(uroot)&#62; CH.testfunction (wts, frec = NULL, f0 = 1, DetTr = FALSE, ltrunc = NULL){s &#60;- frequency(wts)t0 &#60;- start(wts)N &#60;- length(wts)if (class(frec) == "NULL")frec &#60;- rep(1, s/2)if (class(ltrunc) == "NULL")ltrunc &#60;- round(s * (N/100)^0.25)R1 &#60;- SeasDummy(wts, "trg")VFEalg &#60;- SeasDummy(wts, "alg")(etc)