Skip to content

Instantly share code, notes, and snippets.

View ljcolling's full-sized avatar
💭
Currently going through my “I ❤️Rust” phase

Lincoln Colling ljcolling

💭
Currently going through my “I ❤️Rust” phase
View GitHub Profile
@ljcolling
ljcolling / bayes_q.r
Created September 11, 2023 18:42
Bayes quartet
install.packages("bayesplay")
install.packages("tidyverse")
install.packages("patchwork")
require(bayesplay)
require(tidyverse)
require(patchwork)
# version 1
l <- bayesplay::likelihood("normal", 0, 1)
p1 <- bayesplay::prior("normal", 10, 1)
const d3 = Object.assign({},
require("d3-selection"),
require("d3-scale"),
require("d3-array"),
require("d3-shape"),
require("d3-transition"),
require("d3-ease"),
require("d3-timer"),
require("d3-format"));
@ljcolling
ljcolling / instructions.md
Last active January 28, 2020 14:16
Description of how to install `adata` package on university lab machines

Source the sussex.fix() function using

source("http://tinyurl.com/sussexfix")

and then run it using

sussex.fix()
@ljcolling
ljcolling / setup.r
Last active October 30, 2019 12:52
setup<-function(){
user_renviron = path.expand(file.path("~", ".Renviron"))
if(!file.exists(user_renviron)){ # check to see if the file already exists
file.create(user_renviron)
conn = file(user_renviron)
writeLines("R_LIBS_USER=\"N:/Documents/R/win-library/3.6\"\nR_USER=\"N:/Documents\"\nHOME=\"N:/Documents\"",
con = conn)
close(conn)}
}
@ljcolling
ljcolling / gist:9e7483de3ab64cea7c7759735de7107d
Created May 16, 2019 12:45
R gist for calculating Bayes factors with arbitrary location parameter
BayesFactor::ttest.tstat(t = sqrt(N) * mean(x - 1) / sd(x), n1 = 10, simple = T)
#rnorm(10, mean = 1, sd = .5) -> x
N=10
BayesFactor::ttestBF(x = x, mu = 1)
my.es=mean(x) / sd(x)
nullvalue = 0
############################
@ljcolling
ljcolling / FormatPValue.r
Created January 4, 2018 13:01
Simple one-liner for formatting p-values in r
# This example takes the p value for a aov structure, but it can be modified for work with anything
unname(ifelse(aov[[1]][row.index,][[p.index]] > 0.001,
paste("*p* =",str_trunc(sprintf("%.3f",unname(aov[[1]][row.index,p.index])),4,"left",ellipsis = "")),
paste("*p* < 0.001")))
@ljcolling
ljcolling / MutlivariateNormalModel.txt
Created August 23, 2017 12:35
rjags model string for a multivariate normal distribution with moral
## Takes the standarded data matrix as it's input
## model available from:
## http://doingbayesiandataanalysis.blogspot.co.uk/2017/06/bayesian-estimation-of-correlations-and.html
model {
for ( i in 1:Ntotal ) {
zy[i,1:Nvar] ~ dmnorm( zMu[1:Nvar] , zInvCovMat[1:Nvar,1:Nvar] )
}
for ( varIdx in 1:Nvar ) { zMu[varIdx] ~ dnorm( 0 , 1/2^2 ) }
zInvCovMat ~ dwish( zRmat[1:Nvar,1:Nvar] , zRscal )