-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmissing_value_imputation.Rmd
99 lines (74 loc) · 2.31 KB
/
missing_value_imputation.Rmd
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
---
title: "Missing value imputation"
author:
- name: Xiaotao Shen (https://www.shenxt.info/)
date: "Created on 2020-04-01 and updated on `r Sys.Date()`"
output:
html_document:
df_print: paged
toc: no
pdf_document:
toc: no
vignette: >
%\VignetteIndexEntry{missing_value_imputation}
%\VignettePackage{masscleaner}
% \VignetteEngine{knitr::rmarkdown}
% \usepackage[utf8]{inputenc}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE, echo=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
warning = FALSE,
message = TRUE,
out.width = "100%"
)
```
# **Introduction**
We can use `masscleaner` for missing value (MV) imputation.
First, we need to prepare samples for `masscleaner`.
```{r,eval=TRUE,warning=FALSE, R.options="", message=TRUE, cache=TRUE}
library(masscleaner)
library(massdataset)
library(tidyverse)
```
# **Data preparation**
Load the data in [previous step](https://tidymass.github.io/masscleaner/articles/filter_variable_outlier.html).
```{r,eval=TRUE,warning=FALSE, R.options="", message=TRUE, cache=TRUE}
load("peak_tables/POS/object")
```
```{r,eval=TRUE,warning=FALSE, R.options="", message=TRUE, cache=TRUE}
get_mv_number(object)
head(massdataset::get_mv_number(object, by = "sample"))
head(massdataset::get_mv_number(object, by = "variable"))
head(massdataset::get_mv_number(object, by = "sample", show_by = "percentage"))
head(massdataset::get_mv_number(object, by = "variable"), show_by = "percentage")
```
# **Impute missing values**
## zero
```{r,eval=TRUE,warning=FALSE, R.options="", message=TRUE, cache=TRUE}
object_zero =
impute_mv(object = object, method = "zero")
get_mv_number(object_zero)
```
## KNN
```{r,eval=TRUE,warning=FALSE, R.options="", message=TRUE, cache=TRUE}
object =
impute_mv(object = object, method = "knn")
get_mv_number(object)
```
More methods can be found `?impute_mv()`.
# **Note**
If there are blank samples in dataset, we use different method to impute missing
values.
For Blank samples, just use the zero.
For non-Blank samples, just use the knn or other method
Save data for next analysis.
```{r,eval=TRUE,warning=FALSE, R.options="", message=TRUE, cache=TRUE}
save(object, file = "peak_tables/POS/object")
```
# **Session information**
```{r,eval=TRUE,warning=FALSE, R.options="", message=TRUE, cache=TRUE}
sessionInfo()
```