wtorek, 5 stycznia 2016

R: xts and zoo package for missing data; two plots

Dealing with incomplete data:

Useful and basic entry into the topic:
http://nicercode.github.io/intro/missing-data.html and
http://thomasleeper.com/Rcourse/Tutorials/NAhandling.html
http://www.ats.ucla.edu/stat/r/faq/missing.htm

==Fill NA==
A very interesting reading on the use of zoo/xts package here (page 1 and the following): http://publish.illinois.edu/spencer-guerrero/2014/12/11/2-dealing-with-missing-data-in-r-omit-approx-or-spline-part-1/
 

My dirty notebook:

> is.na (
> mean(Data&Variable1, na.rm=TRUE)

Remove incomplete
> na.omit(Data$Variable1)
> complete.cases(Data)
> complete.data <- complete.cases(Data)

Fill continuous/time series data
> require (xts)
> prices <-na.locf(prices)
> prices <-na.fill(prices, fill="extend") are there other fills?
check out na.approx, na.spline!!!
na.contiguous (to find longest contiguous na's?) 

For plotting
na.fill etc functions turn data frame into atomic vectors...
It means that if we plot, we cannot refer to column names but to column numbers.

Plot several plots:
> par(mfrow=(c(2,1))
> plot(prices[,1], type='l')
> plot(prices[,2], type='l')




 ====
For correlation
cor ()... use the argument use='pairwise', then only the pairs with na will be ommited and not the whole observations.
 ====
Serious approach: imputation:
http://www.stat.columbia.edu/~gelman/arm/missing.pdf
e.g.: http://stackoverflow.com/questions/11990463/match-fitted-values-from-lm-with-a-data-frame-in-case-of-na-values
https://stat.ethz.ch/pipermail/r-help/2002-January/017756.html

Good article for a study: http://www.r-bloggers.com/imputing-missing-data-with-r-mice-package/
http://research.stowers-institute.org/efg/R/Statistics/loess.htm
http://www.biostat.jhsph.edu/~iruczins/teaching/jf/ch14.pdf
http://www.ats.ucla.edu/stat/r/faq/R_pmm_mi.htm
http://www.stefvanbuuren.nl/publications/MICE%20in%20R%20-%20Draft.pdf
http://stackoverflow.com/questions/2613420/handling-missing-incomplete-data-in-r-is-there-function-to-mask-but-not-remove

Brak komentarzy:

Prześlij komentarz