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(shiny) | |
library(shinythemes) | |
library(rhandsontable) | |
library(shinyalert) | |
library(PlackettLuce) | |
selopts <- list( | |
plugins = list("remove_button"), | |
create = TRUE, | |
persist = TRUE |
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 polars as pl | |
from metasynth import MetaFrame | |
# example dataframe from polars website | |
df = pl.DataFrame( | |
{ | |
"ID": [1, 2, 3, 4, 5], | |
"fruits": ["banana", "banana", "apple", "apple", "banana"], | |
"B": [5, 4, 3, 2, 1], | |
"cars": ["beetle", "audi", "beetle", "beetle", "beetle"], |
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
# Implementing synthetic control using glmnet | |
library(tidyverse) | |
library(tidysynth) | |
library(glmnet) | |
# we need a wide dataset, only cigsale | |
smoking_w <- | |
smoking |> | |
select(state, year, cigsale) |> | |
pivot_wider(names_from = state, values_from = cigsale) |
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(synthpop) | |
library(lightgbm) | |
library(tidyverse) | |
df <- SD2011 | |
syn_res <- syn(df[,1:7]) | |
sdf <- syn_res$syn | |
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
# t-mixture modeling with EM | |
priorp <- 0.6 | |
m1 <- 0 | |
m2 <- 3 | |
s1 <- 1 | |
s2 <- 0.707 | |
df1 <- 2 | |
df2 <- Inf | |
# generate some data with 2 classes |
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
# Low-dimensional visualisation and density ratio estimation | |
library(tidyverse) | |
library(patchwork) | |
library(umap) | |
library(lfda) | |
library(densratio) | |
# generate data | |
N <- 500 |
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
using Downloads | |
using CSV | |
using StatsKit | |
using Gadfly | |
# Apply macro from StatsBase to create new weights type | |
BayesianBootstrapWeights = StatsBase.@weights BayesianBoostrapWeights | |
function StatsBase.varcorrection(w::BayesianBootstrapWeights, corrected::Bool=false) | |
s = w.sum | |
if corrected |
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
# Showcase | |
env = Schelling([0.45, 0.45, 0.1], Ba = 0.5, dim = 200) | |
anim = @animate for i in 1:100 | |
plot(env; title = i) | |
step!(env) | |
end | |
gif(anim, "anim.gif", fps = 20) |
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
using Distributions | |
using Random | |
using DataFrames | |
struct MetaVariable | |
name::String | |
p_missing::Float64 | |
dist::UnivariateDistribution | |
end |
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
# exponential decay estimation with AR model | |
N <- 30 | |
y <- numeric(N) | |
first_obs <- 2 # where do we start? | |
asymptote <- .5 # where do we go? | |
ar1_param <- .6 # how slow do we go there? (between -1 and 1) | |
sigma <- 0 | |
y[1] <- first_obs | |
for (n in 2:N) { |