basicr_on_data.luftkval.oslo10.Rmd 2.92 KB
Newer Older
jml's avatar
jml committed
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
44
45
46
47
48
---
title: "basicr on data.luftkval.oslo10"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{luft}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
library(basicr)
knitr::opts_chunk$set(collapse = T, comment = "#>")
```

## Basic analysis on 'data.luftkval.oslo10' df.

### install
```R
library("devtools")
devtools::install_git("https://git.nilu.no/rdiagnosis/basicr.git")
devtools::install_git("https://git.nilu.no/rfriendlyr/friendlyr.git")
devtools::install_git("https://git.nilu.no/rfriendlyr/d.luft.oslyr.git")

```

### Get the 'data.luftkval.oslo10' dataset with friendlyr.

The dataset represents real observations, meaning that it contains errors.
It is possible to know the quality of the value by requesting the qa flags with 'friendlyr::qa()', cf this [vignette](https://git.nilu.no/rfriendlyr/friendlyr/blob/master/vignettes/data.luftkval.oslo10.Rmd)

```R

fromDate <- "2004/01/01 00:00:00"
toDate <- "2018/12/31 23:00:00"
timeResolution <- "hourly"
precision <- "hourly"

element_id <- c("NO2")

# station ids
station_id <- c("7","848","464","827","665","9","11","163","504","809")


# luft
luft <- friendlyr::ts(service="d.luft.oslyr",
                 fromDate=fromDate,toDate=toDate,precision=timeResolution,timeResolution=timeResolution,
                 element_id=element_id,station_id=station_id)

49
# filter negatives values, used as NA
jml's avatar
jml committed
50
51
varnames <- setdiff(names(luft), friendlyts::get_name_date_col(precision))

52
53
library(dplyr)
library(tidyr)
jml's avatar
jml committed
54
tmp <- luft %>% select(names(luft)) %>%
55
56
57
                gather(variable, value, -c(friendlyts::get_name_date_col(precision))) %>%
                mutate(value = replace(value, value < 0, NA)) %>%
                spread(variable, value) %>% friendlyts::as_tbl_friendlyts(precision=precision,date_type="friendlyts")
jml's avatar
jml committed
58
59
60

```

61
### basics characteristics
jml's avatar
jml committed
62
63
64

```R

65
66
67
68
69
70
71
basicr::basic_info(df=tmp,target="NO2_7",group="none")
basicr::basic_info(df=tmp,target="NO2_7",group="YEAR")
basicr::basic_info(df=tmp,target="NO2_7",group="MONTH")
basicr::basic_info(df=tmp,target="NO2_7",group="WDAY")
basicr::basic_info(df=tmp,target="NO2_7",group="HOUR")
basicr::basic_info(df=tmp,target="NO2_7",group=c("YEAR","MONTH"))
res <- basicr::basic_info(df=tmp,target="NO2_7",group=c("MONTH","WDAY","HOUR"))
jml's avatar
jml committed
72

73
74
75
basicr::plot_tbl_basic(tmp,target="NO2_7",group="HOUR",y_name="[ug/m3]")
basicr::plot_tbl_basic(tmp,target="NO2_7",group="WDAY",y_name="[ug/m3]")
basicr::plot_tbl_basic(tmp,target="NO2_7",group="MONTH",y_name="[ug/m3]")
jml's avatar
jml committed
76

77
78
79
80
81
82
83
84
85
86
87
88
89
90
```

### Timeseries of basic characteristics and box-whisker timeseries plot with observation timeseries

```R

res <- basicr::basic_ts(df=tmp,target="NO2_7",group=c("WDAY","HOUR"),precision="hourly")
basicr::plot_boxwhisk_ts(x=res,fromDate="2004/01/05 00:00:00",toDate="2004/01/06 00:00:00",timeResolution="hourly",DESKTOP=TRUE)

```

### L-moment

```R
jml's avatar
jml committed
91

92
lmom_ <- basicr::samlmu2(df=tmp,target=varnames)
jml's avatar
jml committed
93

94
basicr::plot_lmrd(x=lmom_,DESKTOP=TRUE)
jml's avatar
jml committed
95
96
97


```