{{ message }}

Instantly share code, notes, and snippets.

# Jonas Moss JonasMoss

Created Nov 29, 2017
Using tmvtnorm and parametric bootstrap to calculate the correlation coefficient in extreme group design.
View tmvtnorm_correlation_EGD.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
 ## 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)
Last active Dec 4, 2017
Selection for significance.
View selection_for_significance.ipynb
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Created Dec 4, 2017
A demonstration that skewness in both the dependent and independent variables is possible in linear regression.
View skewness.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
 ## 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!
Created Jan 2, 2018
Attempt to simulate trust data.
View trust_simulation.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
 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)
Created Jan 4, 2018
View SSC_posting_and_politics.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
 ## 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.
Created Jan 4, 2018
View SSC_posting_and_politics_beta.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
 ## 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.
Last active Feb 13, 2018
Sampling from a Gaussian kernel density estimate in R.
View kde_sampling_gaussian_kernel.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
 ## Make a function rkde that samples from a kernel density #' Sample from a kernel density. #' #' @param n Number of observations to sample. #' @param x The data from which the estimate is to be computed. #' @param bw Desired bandwidth. #' @return A numeric vector with n sampled data points from the kernel #' density estimator.
Created Feb 13, 2018
Sampling from an Epanechnikov kernel density estimate in R.
View kde_sampling_epanechnikov_kernel.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
 #' Sample from a kernel density with the Epanechnikov kernel. #' #' @param n Number of observations to sample. #' @param x The data from which the estimate is to be computed. #' @param bw Desired bandwidth. #' @return A numeric vector with n sampled data points from the kernel #' density estimator. #' @details The factor sqrt(5) in is needed since the standard deviation of #' the kernel is 1/sqrt(5). This makes the normal kernel and the Epanchnikov #' kernel comparable.
Last active Feb 19, 2018
C++-style functors in R.
View functors_in_R.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
 ## A simple example of a functor in R. ## A simple function of one argument. Since y is neither defined inside the function body or ## given as an argument, R will search the enclosing environment for y. Since R is lazy, it ## won't do this when the function is defined, but only when the function is called (and y ## is needed.) f = function(x) x^2 + y^2 ## This changes the enclosing environment of f to a new environment. It was the global ## environment before, and we don't want that.
Created Feb 18, 2018
Using functors to memoize a function in R.
View functor_memoization.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
 ## Functor example 1: Memoization. ## We memoize a function g with up to N values. ## The function to memoize: It is slow to calculate, so we'll gain from ## storing its values. g = function(x) { Sys.sleep(0.1) print("Processesing ...") x^2