Skip to content

Commit

Permalink
correct row selection in code
Browse files Browse the repository at this point in the history
  • Loading branch information
rempsyc committed Jul 2, 2024
1 parent 9b498ab commit 7b0dd27
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 14 deletions.
9 changes: 5 additions & 4 deletions papers/preprint/paper.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,15 @@ _Removing_ outliers that do not belong to the distribution of interest can in th
The _easystats_ ecosystem makes it easy to incorporate this step into your workflow through the `winsorize()` function of *{datawizard}*, a lightweight R package to facilitate data wrangling and statistical transformations [@patil2022datawizard]. This procedure will bring back univariate outliers within the limits of 'acceptable' values, based either on the percentile, the _z_ score, or its robust alternative based on the MAD. For example, let's say we want to winsorize the univariate outlier identified before:

```{r winsorization}
data[1501:1502, ] # See outliers rows
data[33:34, 2:3] # See outliers rows
# Winsorizing using the MAD
library(datawizard)
winsorized_data <- winsorize(data, method = "zscore", robust = TRUE, threshold = 3)
winsorized_data <- winsorize(data, method = "zscore",
robust = TRUE, threshold = 3)
# Values > +/- MAD have been winsorized
winsorized_data[1501:1502, ]
# Outlier values > +/- MAD have been winsorized
winsorized_data[33:34, 2:3]
```

## The Importance of Transparency
Expand Down
Binary file modified papers/preprint/paper.pdf
Binary file not shown.
21 changes: 11 additions & 10 deletions papers/preprint/paper.tex
Original file line number Diff line number Diff line change
Expand Up @@ -875,31 +875,32 @@ \subsection{Winsorization}\label{winsorization}
\begin{Shaded}
\begin{Highlighting}[]
\NormalTok{data[}\DecValTok{1501}\SpecialCharTok{:}\DecValTok{1502}\NormalTok{, ] }\CommentTok{\# See outliers rows}
\NormalTok{data[}\DecValTok{33}\SpecialCharTok{:}\DecValTok{34}\NormalTok{, }\DecValTok{2}\SpecialCharTok{:}\DecValTok{3}\NormalTok{] }\CommentTok{\# See outliers rows}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
#> car mpg cyl disp hp
#> NA <NA> NA NA NA NA
#> NA.1 <NA> NA NA NA NA
#> mpg cyl
#> 33 12 12
#> 34 55 55
\end{verbatim}
\begin{Shaded}
\begin{Highlighting}[]
\CommentTok{\# Winsorizing using the MAD}
\FunctionTok{library}\NormalTok{(datawizard)}
\NormalTok{winsorized\_data }\OtherTok{\textless{}{-}} \FunctionTok{winsorize}\NormalTok{(data, }\AttributeTok{method =} \StringTok{"zscore"}\NormalTok{, }\AttributeTok{robust =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{threshold =} \DecValTok{3}\NormalTok{)}
\NormalTok{winsorized\_data }\OtherTok{\textless{}{-}} \FunctionTok{winsorize}\NormalTok{(data, }\AttributeTok{method =} \StringTok{"zscore"}\NormalTok{, }
\AttributeTok{robust =} \ConstantTok{TRUE}\NormalTok{, }\AttributeTok{threshold =} \DecValTok{3}\NormalTok{)}
\CommentTok{\# Values \textgreater{} +/{-} MAD have been winsorized}
\NormalTok{winsorized\_data[}\DecValTok{1501}\SpecialCharTok{:}\DecValTok{1502}\NormalTok{, ]}
\CommentTok{\# Outlier values \textgreater{} +/{-} MAD have been winsorized}
\NormalTok{winsorized\_data[}\DecValTok{33}\SpecialCharTok{:}\DecValTok{34}\NormalTok{, }\DecValTok{2}\SpecialCharTok{:}\DecValTok{3}\NormalTok{]}
\end{Highlighting}
\end{Shaded}
\begin{verbatim}
#> car mpg cyl disp hp
#> NA <NA> NA NA NA NA
#> NA.1 <NA> NA NA NA NA
#> mpg cyl
#> 33 12.00000 12.0000
#> 34 36.32403 14.8956
\end{verbatim}
\subsection{The Importance of
Expand Down
Binary file modified papers/preprint/paper_files/figure-latex/fig1-1.pdf
Binary file not shown.
Binary file modified papers/preprint/paper_files/figure-latex/model_fig-1.pdf
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 7b0dd27

Please sign in to comment.