Skip to content
Snippets Groups Projects
Commit 1e611282 authored by sanchezi's avatar sanchezi
Browse files

Improve HowTo vignette + add ref

parent 19fc691c
No related branches found
No related tags found
No related merge requests found
Pipeline #69268 passed
...@@ -55,3 +55,8 @@ See also citation() for citing R itself. ...@@ -55,3 +55,8 @@ See also citation() for citing R itself.
The **kfino** logo was created using the **hexSticker** package: The **kfino** logo was created using the **hexSticker** package:
* Guangchuang Yu (2020). hexSticker: Create Hexagon Sticker in R. R package version 0.4.9. https://CRAN.R-project.org/package=hexSticker * Guangchuang Yu (2020). hexSticker: Create Hexagon Sticker in R. R package version 0.4.9. https://CRAN.R-project.org/package=hexSticker
Walk-over-weighing system:
* E.González-García *et. al.* (2018) A mobile and automated walk-over-weighing system for a close and remote monitoring of liveweight in sheep. vol 153: 226-238. https://doi.org/10.1016/j.compag.2018.08.022
* González García, Eliel, 2021, Individual liveweight of Mérinos d'Arles ewelambs, measured with a Walk-over-Weighing (WoW) system under Mediterranean grazing conditions, https://doi.org/10.15454/IXSHF7, Recherche Data Gouv, V5, UNF:6:q4HEDt0n8nzxYRxc+9KK8g==[fileUNF]
...@@ -74,6 +74,7 @@ resu1<-kfino_fit(datain=spring1, ...@@ -74,6 +74,7 @@ resu1<-kfino_fit(datain=spring1,
Tvar="dateNum",Yvar="Poids", Tvar="dateNum",Yvar="Poids",
param=param1, param=param1,
doOptim=TRUE, doOptim=TRUE,
method="ML",
verbose=TRUE) verbose=TRUE)
# flags are qualitative # flags are qualitative
...@@ -89,6 +90,24 @@ kfino_plot(resuin=resu1,typeG="prediction", ...@@ -89,6 +90,24 @@ kfino_plot(resuin=resu1,typeG="prediction",
Tvar="Day",Yvar="Poids",Ident="IDE") Tvar="Day",Yvar="Poids",Ident="IDE")
## ----error=TRUE---------------------------------------------------------------
resu1b<-kfino_fit(datain=spring1,
Tvar="dateNum",Yvar="Poids",
doOptim=TRUE,method="EM",param=param1,
verbose=TRUE)
# flags are qualitative
kfino_plot(resuin=resu1b,typeG="quali",
Tvar="Day",Yvar="Poids",Ident="IDE")
# flags are quantitative
kfino_plot(resuin=resu1b,typeG="quanti",
Tvar="Day",Yvar="Poids",Ident="IDE")
kfino_plot(resuin=resu1b,typeG="prediction",
Tvar="Day",Yvar="Poids",Ident="IDE")
## ----------------------------------------------------------------------------- ## -----------------------------------------------------------------------------
data(merinos1) data(merinos1)
......
...@@ -26,10 +26,11 @@ library(dplyr) ...@@ -26,10 +26,11 @@ library(dplyr)
library(ggplot2) library(ggplot2)
``` ```
# Objectives
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. 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.
**Kalman filter with impulse noised outliers** (kfino) is a robust sequential algorithm allowing to filter data with a large number of outliers. This algorithm is based on simple latent linear Gaussian processes as in the Kalman Filter method and is devoted to detect impulse-noised outliers. These are data points that differ significantly from other observations. **Kalman filter with impulse noised outliers** (kfino) is a robust sequential algorithm allowing to filter data with a large number of outliers. This algorithm is based on simple latent linear Gaussian processes as in the Kalman Filter method and is devoted to detect impulse-noised outliers. These are data points that differ significantly from other observations. `ML` (Maximization Likelihood) and `EM` (Expectation-Maximization algorithm) algorithms were implemented in `kfino`.
The method is described in full details in the following arxiv preprint: https://arxiv.org/abs/2208.00961. The method is described in full details in the following arxiv preprint: https://arxiv.org/abs/2208.00961.
...@@ -37,9 +38,9 @@ To test the **kfino** algorithm, we enclosed real data sets into the **kfino** p ...@@ -37,9 +38,9 @@ To test the **kfino** algorithm, we enclosed real data sets into the **kfino** p
https://doi.org/10.1016/j.compag.2018.08.022 https://doi.org/10.1016/j.compag.2018.08.022
To test the feasibility of using an automated weighing prototype suitable for a range of contrasting sheep farming systems, the authors automatically record the weight of 15 sheep grazing outdoor in spring. To test the feasibility of using an automated weighing prototype suitable for a range of contrasting sheep farming systems, the authors automatically recorded the weight of 15 sheep grazing outdoor in spring.
the **kfino** package has 3 data set available of automated weighing: The **kfino** package has 4 data sets available of automated weighing:
* `spring1`: contains the weighing data of one animal grazing outdoor in spring (203 data points recorded) * `spring1`: contains the weighing data of one animal grazing outdoor in spring (203 data points recorded)
* `merinos1`: contains the weighing data of one merinos lamb (397 data points recorded) * `merinos1`: contains the weighing data of one merinos lamb (397 data points recorded)
...@@ -49,6 +50,7 @@ the **kfino** package has 3 data set available of automated weighing: ...@@ -49,6 +50,7 @@ the **kfino** package has 3 data set available of automated weighing:
# Description of the `spring1` dataset # Description of the `spring1` dataset
We start by using the `spring1` data set: We start by using the `spring1` data set:
```{r} ```{r}
data(spring1) data(spring1)
...@@ -142,6 +144,9 @@ kfino_plot(resuin=resu2,typeG="quanti", ...@@ -142,6 +144,9 @@ kfino_plot(resuin=resu2,typeG="quanti",
## Parameters (m0, mm and pp) optimized ## Parameters (m0, mm and pp) optimized
The user can use either (Maximization Likelihood) `ML` or (Expectation-Maximization algorithm) `EM` method.
### Maximized Likelihood (ML) method
If the user chooses to optimize the initial parameters, m0, mm and pp must be set to NULL. If the user chooses to optimize the initial parameters, m0, mm and pp must be set to NULL.
```{r,error=TRUE} ```{r,error=TRUE}
...@@ -162,6 +167,7 @@ resu1<-kfino_fit(datain=spring1, ...@@ -162,6 +167,7 @@ resu1<-kfino_fit(datain=spring1,
Tvar="dateNum",Yvar="Poids", Tvar="dateNum",Yvar="Poids",
param=param1, param=param1,
doOptim=TRUE, doOptim=TRUE,
method="ML",
verbose=TRUE) verbose=TRUE)
# flags are qualitative # flags are qualitative
...@@ -173,7 +179,7 @@ kfino_plot(resuin=resu1,typeG="quanti", ...@@ -173,7 +179,7 @@ kfino_plot(resuin=resu1,typeG="quanti",
Tvar="Day",Yvar="Poids",Ident="IDE") Tvar="Day",Yvar="Poids",Ident="IDE")
``` ```
### Prediction of the weight on the cleaned dataset Prediction of the weight on the cleaned dataset:
```{r,error=TRUE} ```{r,error=TRUE}
kfino_plot(resuin=resu1,typeG="prediction", kfino_plot(resuin=resu1,typeG="prediction",
...@@ -181,6 +187,27 @@ kfino_plot(resuin=resu1,typeG="prediction", ...@@ -181,6 +187,27 @@ kfino_plot(resuin=resu1,typeG="prediction",
``` ```
### Expectation-Maximization (EM) method
```{r,error=TRUE}
resu1b<-kfino_fit(datain=spring1,
Tvar="dateNum",Yvar="Poids",
doOptim=TRUE,method="EM",param=param1,
verbose=TRUE)
# flags are qualitative
kfino_plot(resuin=resu1b,typeG="quali",
Tvar="Day",Yvar="Poids",Ident="IDE")
# flags are quantitative
kfino_plot(resuin=resu1b,typeG="quanti",
Tvar="Day",Yvar="Poids",Ident="IDE")
kfino_plot(resuin=resu1b,typeG="prediction",
Tvar="Day",Yvar="Poids",Ident="IDE")
```
# Description of the `merinos1` dataset # Description of the `merinos1` dataset
The user can test the **kfino** method using another data set given in the package. Here, we test with the `merinos1`data set on a ewe lamb. For this animal,the range weight is between 10 and 45 kg and must be given in the initial parameters of the `kfino_fit()`function. The user can test the **kfino** method using another data set given in the package. Here, we test with the `merinos1`data set on a ewe lamb. For this animal,the range weight is between 10 and 45 kg and must be given in the initial parameters of the `kfino_fit()`function.
...@@ -225,7 +252,7 @@ kfino_plot(resuin=resu3,typeG="quanti", ...@@ -225,7 +252,7 @@ kfino_plot(resuin=resu3,typeG="quanti",
Tvar="Day",Yvar="Poids",Ident="IDE") Tvar="Day",Yvar="Poids",Ident="IDE")
``` ```
### Prediction of the weight on the cleaned dataset Prediction of the weight on the cleaned dataset:
```{r,error=TRUE} ```{r,error=TRUE}
kfino_plot(resuin=resu3,typeG="prediction", kfino_plot(resuin=resu3,typeG="prediction",
...@@ -236,6 +263,7 @@ kfino_plot(resuin=resu3,typeG="prediction", ...@@ -236,6 +263,7 @@ kfino_plot(resuin=resu3,typeG="prediction",
# References # References
1. E.González-García *et. al.* (2018) A mobile and automated walk-over-weighing system for a close and remote monitoring of liveweight in sheep. vol 153: 226-238. https://doi.org/10.1016/j.compag.2018.08.022 1. E.González-García *et. al.* (2018) A mobile and automated walk-over-weighing system for a close and remote monitoring of liveweight in sheep. vol 153: 226-238. https://doi.org/10.1016/j.compag.2018.08.022
2. González García, Eliel, 2021, Individual liveweight of Mérinos d'Arles ewelambs, measured with a Walk-over-Weighing (WoW) system under Mediterranean grazing conditions, https://doi.org/10.15454/IXSHF7, Recherche Data Gouv, V5, UNF:6:q4HEDt0n8nzxYRxc+9KK8g==[fileUNF]
# Session informations # Session informations
```{r session,echo=FALSE,message=FALSE, warning=FALSE} ```{r session,echo=FALSE,message=FALSE, warning=FALSE}
......
This diff is collapsed.
## ---- include = FALSE---------------------------------------------------------
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
## ----setup--------------------------------------------------------------------
library(kfino)
library(dplyr)
library(ggplot2)
## -----------------------------------------------------------------------------
data(spring1)
# Dimension of this dataset
dim(spring1)
head(spring1)
## -----------------------------------------------------------------------------
# --- 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))
## ----error=TRUE---------------------------------------------------------------
resu1<-kfino_fit(datain=spring1,
Tvar="dateNum",Yvar="Poids",
doOptim=TRUE,method="ML",param=param1,
verbose=TRUE)
# 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")
## ----error=TRUE---------------------------------------------------------------
resu2<-kfino_fit(datain=spring1,
Tvar="dateNum",Yvar="Poids",
doOptim=TRUE,method="EM",param=param1,
verbose=TRUE)
# 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")
kfino_plot(resuin=resu2,typeG="prediction",
Tvar="Day",Yvar="Poids",Ident="IDE")
## -----------------------------------------------------------------------------
sessionInfo()
---
title: "How to perform a kfino outlier detection using the EM or ML method"
author: "B. Cloez & I. Sanchez"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
html_document:
toc: yes
toc_float: true
number_sections: true
vignette: >
%\VignetteIndexEntry{How to perform a kfino outlier detection using the EM or ML method}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
```{r setup}
library(kfino)
library(dplyr)
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, optimizing the initial parameter to better automize the process. The user can use either (Maximization Likelihood) `ML` or (Expectation-Maximization algorithm) `EM` method.
The method is described in full details in the following arxiv preprint: https://arxiv.org/abs/2208.00961.
# Description of the `spring1` dataset
We start by loading the `spring1` data set:
```{r}
data(spring1)
# Dimension of this dataset
dim(spring1)
head(spring1)
```
The range weight of this animal is between 30 and 75 kg and must be given in the initial parameters of the `kfino_fit()`function and we use the same initial parameters settings. The user can specify in the call of the `kfino_fit()` function which optimisation method to use.
# Kfino algorithm with optimized initial parameters
```{r}
# --- 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))
```
## Maximized Likelihood (ML) method
```{r,error=TRUE}
resu1<-kfino_fit(datain=spring1,
Tvar="dateNum",Yvar="Poids",
doOptim=TRUE,method="ML",param=param1,
verbose=TRUE)
# 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")
```
## Expectation-Maximization (EM) method
```{r,error=TRUE}
resu2<-kfino_fit(datain=spring1,
Tvar="dateNum",Yvar="Poids",
doOptim=TRUE,method="EM",param=param1,
verbose=TRUE)
# 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")
kfino_plot(resuin=resu2,typeG="prediction",
Tvar="Day",Yvar="Poids",Ident="IDE")
```
# References
1. E.González-García *et. al.* (2018) A mobile and automated walk-over-weighing system for a close and remote monitoring of liveweight in sheep. vol 153: 226-238. https://doi.org/10.1016/j.compag.2018.08.022
# session info
```{r}
sessionInfo()
```
This diff is collapsed.
...@@ -1512,7 +1512,7 @@ div.tocify { ...@@ -1512,7 +1512,7 @@ div.tocify {
<h1 class="title toc-ignore">How to perform a kfino outlier detection on <h1 class="title toc-ignore">How to perform a kfino outlier detection on
multiple individuals</h1> multiple individuals</h1>
<h4 class="author">B. Cloez &amp; I. Sanchez</h4> <h4 class="author">B. Cloez &amp; I. Sanchez</h4>
<h4 class="date">septembre 06, 2022</h4> <h4 class="date">septembre 13, 2022</h4>
   
</div> </div>
   
...@@ -1571,7 +1571,7 @@ for (i in seq_along(myIDE)){ ...@@ -1571,7 +1571,7 @@ for (i in seq_along(myIDE)){
#&gt; [1] &quot;250017033503096&quot; #&gt; [1] &quot;250017033503096&quot;
#&gt; [1] 566 5 #&gt; [1] 566 5
Sys.time() - t0 Sys.time() - t0
#&gt; Time difference of 18.59745 secs #&gt; Time difference of 18.85249 secs
   
print(length(resu1)) print(length(resu1))
#&gt; [1] 4</code></pre> #&gt; [1] 4</code></pre>
...@@ -1620,7 +1620,7 @@ resu2&lt;-foreach(i=seq_along(myIDE), .packages=&quot;kfino&quot;) %dopar% ...@@ -1620,7 +1620,7 @@ resu2&lt;-foreach(i=seq_along(myIDE), .packages=&quot;kfino&quot;) %dopar%
   
parallel::stopCluster(myCluster) parallel::stopCluster(myCluster)
Sys.time() - t0 Sys.time() - t0
#&gt; Time difference of 9.28879 secs #&gt; Time difference of 9.442032 secs
   
print(length(resu2)) print(length(resu2))
#&gt; [1] 4</code></pre> #&gt; [1] 4</code></pre>
......
...@@ -26,10 +26,11 @@ library(dplyr) ...@@ -26,10 +26,11 @@ library(dplyr)
library(ggplot2) library(ggplot2)
``` ```
# Objectives
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. 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.
**Kalman filter with impulse noised outliers** (kfino) is a robust sequential algorithm allowing to filter data with a large number of outliers. This algorithm is based on simple latent linear Gaussian processes as in the Kalman Filter method and is devoted to detect impulse-noised outliers. These are data points that differ significantly from other observations. **Kalman filter with impulse noised outliers** (kfino) is a robust sequential algorithm allowing to filter data with a large number of outliers. This algorithm is based on simple latent linear Gaussian processes as in the Kalman Filter method and is devoted to detect impulse-noised outliers. These are data points that differ significantly from other observations. `ML` (Maximization Likelihood) and `EM` (Expectation-Maximization algorithm) algorithms were implemented in `kfino`.
The method is described in full details in the following arxiv preprint: https://arxiv.org/abs/2208.00961. The method is described in full details in the following arxiv preprint: https://arxiv.org/abs/2208.00961.
...@@ -37,9 +38,9 @@ To test the **kfino** algorithm, we enclosed real data sets into the **kfino** p ...@@ -37,9 +38,9 @@ To test the **kfino** algorithm, we enclosed real data sets into the **kfino** p
https://doi.org/10.1016/j.compag.2018.08.022 https://doi.org/10.1016/j.compag.2018.08.022
To test the feasibility of using an automated weighing prototype suitable for a range of contrasting sheep farming systems, the authors automatically record the weight of 15 sheep grazing outdoor in spring. To test the feasibility of using an automated weighing prototype suitable for a range of contrasting sheep farming systems, the authors automatically recorded the weight of 15 sheep grazing outdoor in spring.
the **kfino** package has 3 data set available of automated weighing: The **kfino** package has 4 data sets available of automated weighing:
* `spring1`: contains the weighing data of one animal grazing outdoor in spring (203 data points recorded) * `spring1`: contains the weighing data of one animal grazing outdoor in spring (203 data points recorded)
* `merinos1`: contains the weighing data of one merinos lamb (397 data points recorded) * `merinos1`: contains the weighing data of one merinos lamb (397 data points recorded)
...@@ -49,6 +50,7 @@ the **kfino** package has 3 data set available of automated weighing: ...@@ -49,6 +50,7 @@ the **kfino** package has 3 data set available of automated weighing:
# Description of the `spring1` dataset # Description of the `spring1` dataset
We start by using the `spring1` data set: We start by using the `spring1` data set:
```{r} ```{r}
data(spring1) data(spring1)
...@@ -142,6 +144,9 @@ kfino_plot(resuin=resu2,typeG="quanti", ...@@ -142,6 +144,9 @@ kfino_plot(resuin=resu2,typeG="quanti",
## Parameters (m0, mm and pp) optimized ## Parameters (m0, mm and pp) optimized
The user can use either (Maximization Likelihood) `ML` or (Expectation-Maximization algorithm) `EM` method.
### Maximized Likelihood (ML) method
If the user chooses to optimize the initial parameters, m0, mm and pp must be set to NULL. If the user chooses to optimize the initial parameters, m0, mm and pp must be set to NULL.
```{r,error=TRUE} ```{r,error=TRUE}
...@@ -162,6 +167,7 @@ resu1<-kfino_fit(datain=spring1, ...@@ -162,6 +167,7 @@ resu1<-kfino_fit(datain=spring1,
Tvar="dateNum",Yvar="Poids", Tvar="dateNum",Yvar="Poids",
param=param1, param=param1,
doOptim=TRUE, doOptim=TRUE,
method="ML",
verbose=TRUE) verbose=TRUE)
# flags are qualitative # flags are qualitative
...@@ -173,7 +179,7 @@ kfino_plot(resuin=resu1,typeG="quanti", ...@@ -173,7 +179,7 @@ kfino_plot(resuin=resu1,typeG="quanti",
Tvar="Day",Yvar="Poids",Ident="IDE") Tvar="Day",Yvar="Poids",Ident="IDE")
``` ```
### Prediction of the weight on the cleaned dataset Prediction of the weight on the cleaned dataset:
```{r,error=TRUE} ```{r,error=TRUE}
kfino_plot(resuin=resu1,typeG="prediction", kfino_plot(resuin=resu1,typeG="prediction",
...@@ -181,6 +187,27 @@ kfino_plot(resuin=resu1,typeG="prediction", ...@@ -181,6 +187,27 @@ kfino_plot(resuin=resu1,typeG="prediction",
``` ```
### Expectation-Maximization (EM) method
```{r,error=TRUE}
resu1b<-kfino_fit(datain=spring1,
Tvar="dateNum",Yvar="Poids",
doOptim=TRUE,method="EM",param=param1,
verbose=TRUE)
# flags are qualitative
kfino_plot(resuin=resu1b,typeG="quali",
Tvar="Day",Yvar="Poids",Ident="IDE")
# flags are quantitative
kfino_plot(resuin=resu1b,typeG="quanti",
Tvar="Day",Yvar="Poids",Ident="IDE")
kfino_plot(resuin=resu1b,typeG="prediction",
Tvar="Day",Yvar="Poids",Ident="IDE")
```
# Description of the `merinos1` dataset # Description of the `merinos1` dataset
The user can test the **kfino** method using another data set given in the package. Here, we test with the `merinos1`data set on a ewe lamb. For this animal,the range weight is between 10 and 45 kg and must be given in the initial parameters of the `kfino_fit()`function. The user can test the **kfino** method using another data set given in the package. Here, we test with the `merinos1`data set on a ewe lamb. For this animal,the range weight is between 10 and 45 kg and must be given in the initial parameters of the `kfino_fit()`function.
...@@ -225,7 +252,7 @@ kfino_plot(resuin=resu3,typeG="quanti", ...@@ -225,7 +252,7 @@ kfino_plot(resuin=resu3,typeG="quanti",
Tvar="Day",Yvar="Poids",Ident="IDE") Tvar="Day",Yvar="Poids",Ident="IDE")
``` ```
### Prediction of the weight on the cleaned dataset Prediction of the weight on the cleaned dataset:
```{r,error=TRUE} ```{r,error=TRUE}
kfino_plot(resuin=resu3,typeG="prediction", kfino_plot(resuin=resu3,typeG="prediction",
...@@ -236,6 +263,7 @@ kfino_plot(resuin=resu3,typeG="prediction", ...@@ -236,6 +263,7 @@ kfino_plot(resuin=resu3,typeG="prediction",
# References # References
1. E.González-García *et. al.* (2018) A mobile and automated walk-over-weighing system for a close and remote monitoring of liveweight in sheep. vol 153: 226-238. https://doi.org/10.1016/j.compag.2018.08.022 1. E.González-García *et. al.* (2018) A mobile and automated walk-over-weighing system for a close and remote monitoring of liveweight in sheep. vol 153: 226-238. https://doi.org/10.1016/j.compag.2018.08.022
2. González García, Eliel, 2021, Individual liveweight of Mérinos d'Arles ewelambs, measured with a Walk-over-Weighing (WoW) system under Mediterranean grazing conditions, https://doi.org/10.15454/IXSHF7, Recherche Data Gouv, V5, UNF:6:q4HEDt0n8nzxYRxc+9KK8g==[fileUNF]
# Session informations # Session informations
```{r session,echo=FALSE,message=FALSE, warning=FALSE} ```{r session,echo=FALSE,message=FALSE, warning=FALSE}
......
---
title: "How to perform a kfino outlier detection using the EM or ML method"
author: "B. Cloez & I. Sanchez"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
html_document:
toc: yes
toc_float: true
number_sections: true
vignette: >
%\VignetteIndexEntry{How to perform a kfino outlier detection using the EM or ML method}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
```{r setup}
library(kfino)
library(dplyr)
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, optimizing the initial parameter to better automize the process. The user can use either (Maximization Likelihood) `ML` or (Expectation-Maximization algorithm) `EM` method.
The method is described in full details in the following arxiv preprint: https://arxiv.org/abs/2208.00961.
# Description of the `spring1` dataset
We start by loading the `spring1` data set:
```{r}
data(spring1)
# Dimension of this dataset
dim(spring1)
head(spring1)
```
The range weight of this animal is between 30 and 75 kg and must be given in the initial parameters of the `kfino_fit()`function and we use the same initial parameters settings. The user can specify in the call of the `kfino_fit()` function which optimisation method to use.
# Kfino algorithm with optimized initial parameters
```{r}
# --- 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))
```
## Maximized Likelihood (ML) method
```{r,error=TRUE}
resu1<-kfino_fit(datain=spring1,
Tvar="dateNum",Yvar="Poids",
doOptim=TRUE,method="ML",param=param1,
verbose=TRUE)
# 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")
```
## Expectation-Maximization (EM) method
```{r,error=TRUE}
resu2<-kfino_fit(datain=spring1,
Tvar="dateNum",Yvar="Poids",
doOptim=TRUE,method="EM",param=param1,
verbose=TRUE)
# 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")
kfino_plot(resuin=resu2,typeG="prediction",
Tvar="Day",Yvar="Poids",Ident="IDE")
```
# References
1. E.González-García *et. al.* (2018) A mobile and automated walk-over-weighing system for a close and remote monitoring of liveweight in sheep. vol 153: 226-238. https://doi.org/10.1016/j.compag.2018.08.022
# session info
```{r}
sessionInfo()
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment