{{ message }}

Instantly share code, notes, and snippets.

Jonas Moss JonasMoss

Created Nov 4, 2021
Default values in Python for EBA3500.
View defaults.py
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
 ### 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)
Created Nov 2, 2021
Exercise function!
View exercise.py
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
 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
Created Sep 23, 2021
Bullshit
View bullshit.csv
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
 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
Created Sep 22, 2021
Talent data set.
View talent.csv
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
 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
Last active Aug 28, 2019
View causality_first_meeting.md

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:

Created Jul 12, 2019
Define functions inside enclosing environment.
View H.R
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
 #' 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())
Last active Dec 19, 2018
An example of strange R squared values.
View strange_rsq.R
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
 # 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.
Last active Apr 30, 2018
Illustration of negative binomial.
View negative_binomial.R
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
 #' 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"))
Created Apr 28, 2018
Reproducible simulations for 'optional_stopping_streaks'.
View optional_stopping_streaks.R
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
 #' 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)
Last active Apr 25, 2018
A function that evaluates a call as if it was defined in a specified environment.
View S.R
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
 #' 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