Skip to content

Instantly share code, notes, and snippets.

View JonasMoss's full-sized avatar

Jonas Moss JonasMoss

View GitHub Profile
@JonasMoss
JonasMoss / alphabetical_order.py
Last active February 17, 2025 09:45
Longest words in alphabetical and reverse alphabetical order.
#!/usr/bin/env python3
# Prompt to o3-mini-high: The file url = "https://raw.githubusercontent.com/dwyl/english-words/master/words.txt" contains "all" english words. I want a Python script that prints out the longest word with letters in alphabetical order (e.g., "abc") AND reverse alphabetical order (e.g., "cba"). Convert all words to lowercase and replace hyphens with nothing before doing this. The script should be executable immediately, so you need to provide code for downloading the file.
import urllib.request
def is_alphabetical(word):
return list(word) == sorted(word)
@JonasMoss
JonasMoss / defaults.py
Created November 4, 2021 09:59
Default values in Python for EBA3500.
### 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 / bullshit.csv
Created September 23, 2021 14:31
Bullshit
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 September 22, 2021 10:45
Talent data set.
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 August 28, 2019 09:24
Causality Reading Group: Proposed Reading Materials

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 July 12, 2019 13:54
Define functions inside enclosing environment.
#' 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 December 19, 2018 19:48
An example of strange R squared values.
# 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 April 30, 2018 13:53
Illustration of negative binomial.
#' 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 April 28, 2018 08:41
Reproducible simulations for 'optional_stopping_streaks'.
#' 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)