ha-pu / supportr Goto Github PK
View Code? Open in Web Editor NEWCollection of R helper functions
License: MIT License
Collection of R helper functions
License: MIT License
When package tibble
available return as tibble
.
logit_to_prob <- function(logit){
odds <- exp(logit)
prob <- odds / (1 + odds)
return(prob)
}
Create data based on more realistic inputs - e.g. means and sd from Compustat
Cluster names are not correct
Create method for print_correlation to replace class test
Allow to run step-wise models without interaction terms.
When at
is set to an integer, use the variable name instead of the number for output.
show = FALSE
sg = FALSE
randfe = TRUE
-> no random fixed effect provided
Update gather
and spread
to pivot_longer
and pivot_wider
.
data_polcon <- expand_grid(year = years, geo = mapping_geo$geo_bvd) %>%
left_join(data_polcon, by = c("year", "geo")) %>%
group_by(geo) %>%
mutate(score_lag = lag(polconiii),
score_lead = lead(polconiii)) %>%
fill(score_lag, .direction = "down") %>%
fill(score_lead, .direction = "up") %>%
mutate(polcon_imp = case_when(
!is.na(polconiii) ~ polconiii,
!is.na(score_lag) & !is.na(score_lead) ~ mean(c(score_lag, score_lead)),
!is.na(score_lead) ~ score_lead,
!is.na(score_lag) ~ score_lag
)) %>%
select(-contains("score")) %>%
left_join(select(mapping_geo, geo = geo_bvd, geo_region)) %>%
group_by(geo_region, year) %>%
mutate(score_region = mean(polcon_imp, na.rm = TRUE)) %>%
mutate(polcon_imp = coalesce(polcon_imp, score_region)) %>%
ungroup() %>%
select(-contains("region"))
Enable function to add grouping variable to data_summary()
Suppress row numbers for grouped_df output
## define search patterns ----
pat_int <- c("abroad", "border(?!line)", "export", "foreign(?!e|i|n)", "geographic", "global", "internation", "mn[ce]s?$", "multination", "offshore", "transnation", "subsidiar[iy]")
pat_flx <- c("allocat", "deploy", "flexib", "^options?", "platform", "relocat", "switch", "shift")
pat_opr <- c("^capacity", "facilit[iy]", "(?<!col|e)labou?r(?!at|ing)", "logistics", "manufactur", "network", "(?<!co|peri)operat(?!ionaliz|ionalis)", "(?<!im|sup|trans)plant", "(?<!co|re)production", "(?<!crowd)sourcing", "suppl[iy]")
pat_rsk <- c("crisis", "(?<!con)currenc[iy]", "exchange$", "expos", "fluctuation", "(?<!aste)risk", "uncertain", "volatil", "^variance")
len_max <- max(map_int(list(pat_int, pat_flx, pat_opr, pat_rsk), length))
pattern_srch <- tibble(pat_int = c(pat_int, rep(NA, len_max - length(pat_int))),
pat_flx = c(pat_flx, rep(NA, len_max - length(pat_flx))),
pat_opr = c(pat_opr, rep(NA, len_max - length(pat_opr))),
pat_rsk = c(pat_rsk, rep(NA, len_max - length(pat_rsk))))
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.