-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixing factor issue for alluvial_model_response
- Loading branch information
Showing
7 changed files
with
103 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: easyalluvial | ||
Title: Generate Alluvial Plots with a Single Line of Code | ||
Version: 0.2.0 | ||
Version: 0.2.0.900 | ||
Authors@R: person( "Bjoern", "Koneswarakantha", role = c("aut","cre"), email = "[email protected]", comment = c(ORCID = " 0000-0003-4585-7799") ) | ||
URL: https://github.com/erblast/easyalluvial | ||
Description: Alluvial plots are similar to sankey diagrams and visualise categorical data | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
data("titanic_train",package="titanic") | ||
library(tidyverse) | ||
str(titanic_train) | ||
|
||
d <- titanic_train %>% as_tibble %>% | ||
mutate(title=str_replace_all(string = Name, # extract title as general feature | ||
pattern = "^[[:alpha:][:space:]'-]+,\\s+(the\\s)?(\\w+)\\..+", | ||
replacement = "\\2")) %>% | ||
mutate(title=str_trim(title), | ||
title=case_when(title %in% c('Mlle','Ms')~'Miss', # normalize some titles | ||
title=='Mme'~ 'Mrs', | ||
title %in% c('Capt','Don','Major','Sir','Jonkheer', 'Col')~'Sir', | ||
title %in% c('Dona', 'Lady', 'Countess')~'Lady', | ||
TRUE~title)) %>% | ||
mutate(title=as_factor(title), | ||
Survived=factor(Survived,levels = c(0,1),labels=c("no","yes")), | ||
Sex=as_factor(Sex), | ||
Pclass=factor(Pclass,ordered = T)) %>% | ||
group_by(title) %>% # impute Age by median in current title | ||
mutate(Age=replace_na(Age,replace = median(Age,na.rm = T))) %>% ungroup | ||
table(d$title,d$Sex) # look on title distribution | ||
caret::nearZeroVar(x = d,saveMetrics = T) # search and drop some unusefull features (PassengerId,Name,Ticket) | ||
d <- d %>% select_at(vars(-c(PassengerId,Name,Ticket))) | ||
|
||
titanic_fac = d %>% | ||
mutate_if(is.character, as.factor) %>% | ||
select( - Cabin, - Fare, - Age, -SibSp, - Parch) | ||
|
||
usethis::use_data( titanic_fac, overwrite = TRUE ) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters