Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonas Moss JonasMoss

View GitHub Profile
@JonasMoss
JonasMoss / defaults.py
Created Nov 4, 2021
Default values in Python for EBA3500.
View defaults.py
### Here's some more info about default values!
### Especially when they are difficult to understand.
### An easy example of default values.
def f(x, a = True):
if a:
return (x + 1)
if not a:
return (x + 2)
@JonasMoss
JonasMoss / exercise.py
Created Nov 2, 2021
Exercise function!
View exercise.py
from collections import Counter
def f(i, s):
total = np.cumsum([0] + list(Counter(coding(s)).values()))
total = total / total[-1]
values = np.diff(total)
return values[i-1]
coding(data_student['apply'],f
View bullshit.csv
free_market_ideology bullshit_receptivity
1 40 3.1
2 30 2.66666666666667
3 70 3.3
4 10 1.9
5 50 3.56666666666667
6 35 3.93333333333333
7 50 2.03333333333333
8 50 2.53333333333333
9 25 1
@JonasMoss
JonasMoss / talent.csv
Created Sep 22, 2021
Talent data set.
View talent.csv
country points talent
1 Spain 1485 85
2 Germany 1300 76
3 Brazil 1242 48
4 Portugal 1189 16
5 Argentina 1175 35
6 Switzerland 1149 9
7 Uruguay 1147 9
8 Colombia 1137 3
9 Italy 1104 67
@JonasMoss
JonasMoss / causality_first_meeting.md
Last active Aug 28, 2019
Causality Reading Group: Proposed Reading Materials
View causality_first_meeting.md

First Reading

On the Consistency Rule in Causal Inference Axiom, Definition, Assumption, or Theorem? (Pearl, 2010, 4 page) One of the big problems with the causality literature is the terminology and the lack of foundationas for everyone to agree on.(Think about a vector space -- everyone agrees what it is. That's where we want to be.) The consistency rule appears to me to be the corner-stone of an axiomatic development of causality theory.

The following papers are mentioned in the Pearl paper and are a part of the assignment:

  1. The consistency statement in causal inference: a definition or an assumption

  2. Concerning the consistency assumption in causal inference

@JonasMoss
JonasMoss / H.R
Created Jul 12, 2019
Define functions inside enclosing environment.
View H.R
#' Hide non-function variables from function.
#'
#' @param ... Named functions and function definitions.
#' @return Nothing.
H = function(...) {
function_names = names(as.list(substitute((...)))[-1])
function_defs = list(...)
envir = parent.env(parent.frame())
@JonasMoss
JonasMoss / strange_rsq.R
Last active Dec 19, 2018
An example of strange R squared values.
View strange_rsq.R
# Create a covariance matrix for the covariates.
rho12 = -0.1
rho13 = 0.65
rho23 = -0.3
covariance = matrix(c(1, rho12, rho13,
rho12, 1, rho23,
rho13, rho23, 1), nrow = 3)
# Simulate a linear regression with all betas equal to 1.
@JonasMoss
JonasMoss / negative_binomial.R
Last active Apr 30, 2018
Illustration of negative binomial.
View negative_binomial.R
#' Graph of number of tries needed to obtain K successes.
#' @param K number of studies.
#' @return NULL.
plotter = function(K){
kk = 0:(K*70)
plot(kk + K, dnbinom(kk, K, 0.05), bty = "l", type = "b", pch = 20,
xlab = "Number of studies",
ylab = "Probability",
main = paste0("Number of studies before ", K, " successes"))
@JonasMoss
JonasMoss / optional_stopping_streaks.R
Created Apr 28, 2018
Reproducible simulations for 'optional_stopping_streaks'.
View optional_stopping_streaks.R
#' Find the cumulative maximal streak length in a vector of bools.
#'
#' @param bools Logical vector.
#' @return An integer vector. The \code{i}th element is the maximal streak
#' length in \code{x[1:i]}.
#' @example
#' bools1 = c(FALSE, TRUE, FALSE, TRUE, TRUE, TRUE, FALSE)
#' streaks(bools1) [1] 0 1 1 1 2 3 3
#'
#' bools2 = c(FALSE, FALSE, TRUE, TRUE, TRUE, TRUE, FALSE, TRUE)
@JonasMoss
JonasMoss / S.R
Last active Apr 25, 2018
A function that evaluates a call as if it was defined in a specified environment.
View S.R
#' Evaluates a call as if its function was defined in a specified environment
#'
#' When a name is encountered in the definition of a function, the search path
#' for that name is given by the defining environment of the function. This is
#' good behaviour, since it allows simple reasoning about how a function should
#' behave: If two calls to a function defined in a constant environment \code{e}
#' yield different results, this must be because they are given different
#' arguments.
#'
#' Sometimes, a function is defined to make messy code more readable, but is