Skip to content

Instantly share code, notes, and snippets.

View certifiedwaif's full-sized avatar

Mark Greenaway certifiedwaif

  • University of Sydney
  • Sydney, Australia
View GitHub Profile
@certifiedwaif
certifiedwaif / multinomial_regression.stan
Created July 6, 2021 23:14
Multinomial regression model
/*
This model is based on the multinomial model in Bayesian Data Analysis 3, p426.
I used the multinomial regression example from the Stan website
https://mc-stan.org/docs/2_27/stan-users-guide/multi-logit-section.html and
then modified it to match our model.
For this model to work, you need an up to date version of `rstan`, at least
2.26.2. Follow the instructions here: https://mc-stan.org/r-packages/ to
upgrade your `rstan` if you have an old version. You can check which version
#!/bin/sh
sudo apt install -y build-essential
sudo apt install -y git
sudo apt install -y zlib1g-dev
sudo apt install -y libxml2-dev
sudo apt install -y gfortran
sudo apt install -y libclang-dev
@certifiedwaif
certifiedwaif / gist:ed21b83af388a53558614b008c4a0363
Created January 24, 2019 22:32
Does anyone know how to resolve this error?
> library(devtools)
> test()
Loading blma
Error in processx::run(bin, args = real_cmdargs, stdout_line_callback = real_callback(stdout), :
System command error
@certifiedwaif
certifiedwaif / make_my_matrix_symmetric.py
Created August 12, 2018 11:21
What, you expect me to do this by hand?!?
matrix_str = """\\sigma^2_{\\text{intercept}} & & & & &
\\rho_{\\text{intercept} x} & \\sigma^2_x & \\ldots
\\rho_{\\text{intercept} x^2} & \\rho_{x x^2} & \\sigma^2_{x^2} & \\ldots
\\rho_{\\text{intercept} x^3} & \\rho_{x x^3} & \\rho_{x^2 x^3} & \\sigma^2_{x^3} & \\ldots
0 & \\rho_{x (x - \\kappa_1)^3_+} & \\rho_{x^2 (x-\\kappa_1)_+^3} & \\rho_{x^3 (x - \\kappa_1)_+^3} & \\sigma^2_{(x - \\kappa_1)_+^3} & \\ldots
0 & 0 & \\rho_{x^2 (x-\\kappa_2)_+^3} & \\rho_{x^3 (x-\\kappa_2)_+^3} & \\rho_{(x-\\kappa_1)_+^3 (x-\\kappa_2)_+^3} & \\sigma^2_{(x - \\kappa_2)_+^3}
0 & 0 & 0 & \\rho_{x^3 (x - \\kappa_3)_+^3} & \\rho_{(x - \\kappa_1)_+^3 (x - \\kappa_3)_+^3} & \\rho_{(x - \\kappa_2)_+^3 (x - \\kappa_3)_+^3} & \\sigma^2_{(x - \\kappa_3)_+^3} """
lines =
parameters_tbl <- parameters_tbl %>%
mutate(sampler_mGamma=map(sampler_result, "mGamma"),
sampler_vip=map(sampler_mGamma, ~apply(.x, 2, mean)),
blma_vip=map(blma_result, "vinclusion_prob"),
error=map2_dbl(sampler_vip, blma_vip, ~sum((.x - .y)^2)))
travis_fold:start:worker_info
Worker information
hostname: 6dc47c14-8e9d-4f9f-81c7-9b5fdf8db233@1.production-5-worker-org-a-1-gce
version: v3.6.0 https://github.com/travis-ci/worker/tree/170b2a0bb43234479fd1911ba9e4dbcc36dadfad
instance: travis-job-1af23089-3d0d-47c3-ac95-49d98f31b7d4 travis-ci-amethyst-trusty-1512508224-986baf0 (via amqp)
startup: 27.327058835s
travis_fold:end:worker_info
travis_fold:start:system_info
Build system information
Build language: r
@certifiedwaif
certifiedwaif / maps.R
Created September 22, 2016 01:37
What's a better way to loop over all combinations of vp, vn and vR2, producing p*n, p and R2 and ending up with an n by 3 data frame or matrix?
library(purrr)
vp <- c(10, 20, 50, 100, 500, 1000)
vn <- c(1.1, 1.25, 1.5, 2, 5, 10)
vR2 <- seq(from=0.00, to=1.00, by = 1e-2)
df <- map(vp, function(p) {
map(vn, function(n) {
map(vR2, function(R2) {c(p*n, p, R2)})
})
}) %>% as.data.frame %>% t
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Final//EN">
<html><head>
<title>HardInfo (0.5.1) System Report</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style>
body { background: #fff }
.title { font: bold 130% serif; color: #0066FF; padding: 30px 0 10px 0 }
.stitle { font: bold 100% sans-serif; color: #0044DD; padding: 30px 0 10px 0 }
.sstitle{ font: bold 80% serif; color: #000000; background: #efefef }
.field { font: 80% sans-serif; color: #000000; padding: 2px; padding-left: 50px }
@certifiedwaif
certifiedwaif / optimal_points.cpp
Last active April 23, 2016 08:29
optimal_points.cpp
#include <algorithm>
#include <iostream>
#include <climits>
#include <vector>
#include <algorithm>
#include <string>
// #include <boost/dynamic_bitset.hpp>
using namespace std;
// using namespace boost;
@certifiedwaif
certifiedwaif / greycode.R
Created February 16, 2016 05:10
I think the intent of this code is perfectly obvious</sarcasm>
greycode <- function(p)
{
A <- matrix(c(0,1),2,1)
if (p!=1) {
for (i in 2:p) {
P <- nrow(A)
inds <- rev(1:P)
A1 <- matrix(c(rep(0,P),rep(1,P)),2*P,1)
A2 <- rbind(A,matrix(A[inds,],nrow(A),ncol(A)))
A <- cbind(A1,A2)