Skip to content

Instantly share code, notes, and snippets.

View JonasMoss's full-sized avatar

Jonas Moss JonasMoss

View GitHub Profile
## Checks for associations between politics and posting at SSC, using Beta-Bayes!
## Data from: http://slatestarcodex.com/Stuff/ssc2018public.xlsx
library("tidyverse")
SSC = read_excel("ssc2018public.xlsx") # Downloaded from SSC.
Politics = as.factor(SSC$PoliticalAffiliation)
Comments = as.factor(SSC$Comment)
## Not everyone will agree with my classification.
## Makes a plot checking for clear associations between politics and postign in SSC.
## Data from: http://slatestarcodex.com/Stuff/ssc2018public.xlsx
library("tidyverse")
SSC = read_excel("ssc2018public.xlsx") # Downloaded from SSC.
Politics = as.factor(SSC$PoliticalAffiliation)
Comments = as.factor(SSC$Comment)
## Not everyone will agree with my classification.
@JonasMoss
JonasMoss / trust_simulation.R
Created January 2, 2018 20:37
Attempt to simulate trust data.
N = 1000
K = 1
res = MCMCpack::rdirichlet(N, K*c(0.1, 0.15, 0.7, 0.05))
score = rowSums(res^2)
trust = res%*%c(-1,-1,1,0) + rnorm(N, 0, 0.1)
covs = data.frame(afro = res[1,], latios = res[2,], whites = res[3,], asians = res[4,], score = score)
lm(trust ~ ., data = covs)
@JonasMoss
JonasMoss / selection_for_significance.ipynb
Last active December 4, 2017 16:06
Selection for significance.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@JonasMoss
JonasMoss / skewness.R
Created December 4, 2017 13:42
A demonstration that skewness in both the dependent and independent variables is possible in linear regression.
## Needed to calculate moments.
library("moments")
set.seed(313)
## An illustration with both variables skewed.
n = 200
x = rbeta(n, 1, 15)
y = 3 + x + rnorm(n, 0, 0.01)
## Plotting!
@JonasMoss
JonasMoss / tmvtnorm_correlation_EGD.R
Created November 29, 2017 09:59
Using tmvtnorm and parametric bootstrap to calculate the correlation coefficient in extreme group design.
## This script uses the tmvtnorm package, check it out.
if(!("tmvtnorm" %in% rownames(installed.packages()))) {
install.packages("tmvtnorm")
}
library("tmvtnorm")
## Seed for reproducibility.
set.seed(313)