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
Mode <- function(x, tie = c("missing", "error"), ignore_categories = NULL) { | |
if(!is.null(ignore_categories)){ | |
x <- x[!(x %in% ignore_categories)] | |
} | |
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
# produce balance statistics ------- | |
## version to pass unquoted | |
balance_stats_var <- function(data_, treatment_, variable_){ | |
treatment_ <- enquo(treatment_) | |
variable_ <- enquo(variable_) | |
temp_means <- group_by(data_, !!treatment_) %>% ## make it possible to change the 'treatment' var |
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
#include <Rcpp.h> | |
using namespace Rcpp; | |
// [[Rcpp::export]] | |
IntegerVector recode_outcomes(IntegerVector x) { | |
int n = x.size(); | |
IntegerVector y(n); | |
for(int i=0; i<n; i++){ |
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
#' Compute gini index. | |
#' | |
#' Compute the gini index with (optional) weights. | |
#' | |
#' @param x A numeric vector with the data. | |
#' @param weights A numeric vector with sample weights. | |
#' @return res An atomic vector with the gini index. | |
gini <- function(x, weights = NULL, na.rm = FALSE) { | |
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
# Prepare session | |
library(rlang) | |
library(glue) | |
library(fs) | |
library(dplyr) | |
library(magrittr) | |
library(purrr) | |
library(ggplot2) | |
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
library(readr) | |
library(dplyr) | |
library(magrittr) | |
library(purrr) | |
library(ggplot2) | |
all_lissyrtools_scripts <- fs::dir_ls("/media/user/lissyrtools/") | |
invisible(purrr::map(all_lissyrtools_scripts, ~ source(.x))) | |
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
import re | |
def backward_string_by_word(text: str) -> str: | |
spaces = re.findall(" +", text) | |
words = text.split() | |
if len(words) == 0: |
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
#' Weighted quantiles | |
#' | |
#' Wrap over Julia's 'StatsBase.quantile()' function. | |
#' | |
#' @param x A numeric vector for which the quantiles should be computed. | |
#' @param weights A numeric vector with the weights. | |
#' @param probs A numeric vector with the quantiles to compute. | |
#' @param na.rm a logical value indicating whether NA values should be stripped before the computation proceeds. | |
#' | |
#' @return A numeric vector with the weighted quantiles. |
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
##### Atkinson index ##### | |
""" | |
atkinson(v, w, ϵ) | |
Computes the weighted Atkinson index given an inequality adversion parameter ϵ. | |
""" | |
function wtd_atkinson(v::Array{<:Real,1}, w::Array{<:Real,1}, ϵ::Real) ::Float64 | |
v = v/Statistics.mean(v) | |
w = w/sum(w) | |
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
weighted_atkinson_jl <- function(x, weights, epsilon, na.rm = FALSE){ | |
JuliaCall::julia_call("weighted_atkinson", x, weights, epsilon, na.rm) | |
} | |
julia_weighted_atkinson_function <- JuliaCall::julia_eval("function weighted_atkinson(v, w, ϵ::Real, skipmissing::Bool) | |
if skipmissing | |
w = w[findall(!ismissing, v)] | |
v = v[findall(!ismissing, v)] |
OlderNewer