library(kfino)
library(dplyr)
#>
#> Attachement du package : 'dplyr'
#> Les objets suivants sont masqués depuis 'package:stats':
#>
#> filter, lag
#> Les objets suivants sont masqués depuis 'package:base':
#>
#> intersect, setdiff, setequal, union
library(ggplot2)
This vignette describes how to use the kfino algorithm on time courses in order to detect impulse noised outliers and predict the parameter of interest.
RAJOUTER DU TEXTE
spring1
datasetblablabla
data(spring1)
# Dimension of this dataset
dim(spring1)
#> [1] 203 5
head(spring1)
#> # A tibble: 6 x 5
#> # Groups: IDE [1]
#> Poids Date IDE Day dateNum
#> <dbl> <dttm> <chr> <dttm> <dbl>
#> 1 28.6 2017-05-24 00:00:00 250016286863027 2017-05-24 16:34:00 0.469
#> 2 45 2017-05-24 00:00:00 250016286863027 2017-05-24 19:24:00 0.587
#> 3 25 2017-05-25 00:00:00 250016286863027 2017-05-25 05:25:00 1.00
#> 4 43 2017-05-25 00:00:00 250016286863027 2017-05-25 05:45:00 1.02
#> 5 23.4 2017-05-25 00:00:00 250016286863027 2017-05-25 05:58:00 1.03
#> 6 0 2017-05-25 00:00:00 250016286863027 2017-05-25 09:30:00 1.17
spring1
dataset# --- Without Optimisation on initial parameters
param2<-list(m0=41,
mm=45,
pp=0.5,
aa=0.001,
expertMin=30,
expertMax=75,
sigma2_m0=1,
sigma2_mm=0.05,
sigma2_pp=5,
K=2,
seqp=seq(0.5,0.7,0.1))
resu2<-kfino_fit(datain=spring1,
Tvar="dateNum",Yvar="Poids",
param=param2,
doOptim=FALSE)
#> [1] "-------:"
#> [1] "No optimisation of initial parameters:"
#> [1] "Used parameters: "
#> [1] 41.0 0.5 45.0
# flags are qualitative
kfino_plot(resuin=resu2,typeG="quali",
Tvar="Day",Yvar="Poids",Ident="IDE")
# flags are quantitative
kfino_plot(resuin=resu2,typeG="quanti",
Tvar="Day",Yvar="Poids",Ident="IDE")
# --- With Optimisation on initial parameters
param1<-list(m0=NULL,
mm=NULL,
pp=NULL,
aa=0.001,
expertMin=30,
expertMax=75,
sigma2_m0=1,
sigma2_mm=0.05,
sigma2_pp=5,
K=2,
seqp=seq(0.5,0.7,0.1))
resu1<-kfino_fit(datain=spring1,
Tvar="dateNum",Yvar="Poids",
doOptim=TRUE,param=param1)
#> [1] "-------:"
#> [1] "Optimisation of initial parameters with ML method - result:"
#> [1] "no sub-sampling performed:"
#> range m0: 40.1 43
#> initial m0opt: 41.3
#> initial mmopt: 46.3
#> [1] "Optimised parameters: "
#> Optimized m0: 42.1
#> Optimized mm: 61.1
#> Optimized pp: 0.7
#> [1] "-------:"
# flags are qualitative
kfino_plot(resuin=resu1,typeG="quali",
Tvar="Day",Yvar="Poids",Ident="IDE")
# flags are quantitative
kfino_plot(resuin=resu1,typeG="quanti",
Tvar="Day",Yvar="Poids",Ident="IDE")
kfino_plot(resuin=resu1,typeG="prediction",
Tvar="Day",Yvar="Poids",Ident="IDE")
merinos1
datasetewelambs, expected weights between 10 and 45 kg.
data(merinos1)
# Dimension of this dataset
dim(merinos1)
#> [1] 397 5
head(merinos1)
#> # A tibble: 6 x 5
#> # Groups: IDE [1]
#> Poids Date IDE Day dateNum
#> <dbl> <dttm> <chr> <dttm> <dbl>
#> 1 0 2021-01-27 00:00:00 250017033503004 2021-01-27 08:31:00 0.353
#> 2 0 2021-01-27 00:00:00 250017033503004 2021-01-27 08:31:00 0.353
#> 3 0 2021-01-27 00:00:00 250017033503004 2021-01-27 08:31:00 0.353
#> 4 0 2021-01-27 00:00:00 250017033503004 2021-01-27 08:31:00 0.353
#> 5 0 2021-01-27 00:00:00 250017033503004 2021-01-27 08:31:00 0.353
#> 6 40.2 2021-01-27 00:00:00 250017033503004 2021-01-27 12:37:00 0.524
merinos1
dataset# --- With Optimisation on initial parameters
param3<-list(m0=NULL,
mm=NULL,
pp=NULL,
aa=0.001,
expertMin=10,
expertMax=45,
sigma2_m0=1,
sigma2_mm=0.05,
sigma2_pp=5,
K=2,
seqp=seq(0.5,0.7,0.1))
resu3<-kfino_fit(datain=merinos2,
Tvar="dateNum",Yvar="Poids",
doOptim=TRUE,param=param3)
#> [1] "-------:"
#> [1] "Optimisation of initial parameters with ML method - result:"
#> [1] "no sub-sampling performed:"
#> range m0: 29 41.8
#> initial m0opt: 36.8
#> initial mmopt: 37.6
#> [1] "Optimised parameters: "
#> Optimized m0: 29
#> Optimized mm: 48
#> Optimized pp: 0.7
#> [1] "-------:"
# flags are qualitative
kfino_plot(resuin=resu3,typeG="quali",
Tvar="Day",Yvar="Poids",Ident="IDE")
# flags are quantitative
kfino_plot(resuin=resu3,typeG="quanti",
Tvar="Day",Yvar="Poids",Ident="IDE")
kfino_plot(resuin=resu3,typeG="prediction",
Tvar="Day",Yvar="Poids",Ident="IDE")
#> R version 4.1.3 (2022-03-10)
#> Platform: x86_64-w64-mingw32/x64 (64-bit)
#> Running under: Windows 10 x64 (build 19044)
#>
#> Matrix products: default
#>
#> locale:
#> [1] LC_COLLATE=French_France.1252 LC_CTYPE=French_France.1252
#> [3] LC_MONETARY=French_France.1252 LC_NUMERIC=C
#> [5] LC_TIME=French_France.1252
#>
#> attached base packages:
#> [1] stats graphics grDevices utils datasets methods base
#>
#> other attached packages:
#> [1] ggplot2_3.3.6 dplyr_1.0.8 kfino_1.0.0
#>
#> loaded via a namespace (and not attached):
#> [1] tidyselect_1.1.2 xfun_0.30 bslib_0.3.1 remotes_2.4.2
#> [5] purrr_0.3.4 colorspace_2.0-3 vctrs_0.4.0 generics_0.1.2
#> [9] testthat_3.1.3 usethis_2.1.5 htmltools_0.5.2 yaml_2.3.5
#> [13] utf8_1.2.2 rlang_1.0.2 pkgbuild_1.3.1 pillar_1.7.0
#> [17] jquerylib_0.1.4 glue_1.6.2 withr_2.5.0 DBI_1.1.2
#> [21] sessioninfo_1.2.2 lifecycle_1.0.1 stringr_1.4.0 munsell_0.5.0
#> [25] gtable_0.3.0 devtools_2.4.3 evaluate_0.15 memoise_2.0.1
#> [29] labeling_0.4.2 knitr_1.39 callr_3.7.0 fastmap_1.1.0
#> [33] ps_1.6.0 fansi_1.0.3 highr_0.9 scales_1.2.0
#> [37] cachem_1.0.6 desc_1.4.1 pkgload_1.2.4 jsonlite_1.8.0
#> [41] farver_2.1.0 fs_1.5.2 brio_1.1.3 digest_0.6.29
#> [45] stringi_1.7.6 processx_3.5.3 rprojroot_2.0.3 grid_4.1.3
#> [49] cli_3.2.0 tools_4.1.3 magrittr_2.0.3 sass_0.4.1
#> [53] tibble_3.1.6 crayon_1.5.1 pkgconfig_2.0.3 ellipsis_0.3.2
#> [57] prettyunits_1.1.1 assertthat_0.2.1 rmarkdown_2.14 rstudioapi_0.13
#> [61] R6_2.5.1 compiler_4.1.3