Skip to content

Instantly share code, notes, and snippets.

View even4void's full-sized avatar

chl even4void

View GitHub Profile
#lang racket
;; Euler problem 15
(define (reduce f xs)
(and (not (empty? xs)) (foldl f (first xs) (rest xs))))
(define (f n)
(reduce (lambda (x y) (* x y)) (range 1 (add1 n))))
## Time-stamp: <2016-05-27 13:18:56 chl>
##
## General purpose script to illustrate the estimation of path coefficients
## in a Partial Least Squares Path Model (PLS-PM) and multi-group comparison
## using resampling (permutation test).
##
library(plspm)
library(simsem)
@even4void
even4void / 1.c
Last active December 28, 2015 00:49
Computing some probability value from Student distribution
// Time-stamp: <2013-11-11 17:58:52 chl>
// gcc -Wall 1.c -lgsl -lgslcblas -lm
#include <stdio.h>
#include <gsl/gsl_cdf.h>
int main(void) {
double p;
@even4void
even4void / .emacs
Last active September 6, 2018 15:26
A basic previewer for R Markdown files edited with Emacs
(add-to-list 'auto-mode-alist '("\\.md\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.Rmd\\'" . markdown-mode))
(add-to-list 'auto-mode-alist '("\\.rmd\\'" . markdown-mode))
(add-hook 'markdown-mode-hook 'turn-on-outline-minor-mode)
(defun rmarkdown-new-chunk (name)
"Insert a new R chunk."
(interactive "sChunk name: ")
(insert "\n```{r " name "}\n")
(save-excursion
@even4void
even4void / .emacs
Last active August 21, 2021 08:47
Basic setup to use Gmail from Emacs using a combination of mu, mu4e and offlineimap
(require 'offlineimap)
(add-to-list 'load-path "~/.emacs.d/lib/mu4e")
(require 'mu4e)
(require 'mu4e-maildirs-extension)
(mu4e-maildirs-extension)
(setq mu4e-drafts-folder "/drafts"
mu4e-sent-folder "/sent"
mu4e-trash-folder "/trash")
(setq mu4e-maildir-shortcuts
@even4void
even4void / twins_power.r
Created May 28, 2013 02:43
Power and sample size for univariate ACE model.
## ESTIMATE SAMPLE SIZE NEEDED to achieve a given power in univariate twin studies.
##
## Input:
## pmz: sampling fraction MZ/DZ
## tmz: intraclass correlation for MZ twins
## tdz: intraclass correlation for DZ twins
## alpha: level I risk level
## beta: level II risk level (power = 1 - beta)
##
## Output:
@even4void
even4void / raneff.r
Last active June 1, 2017 04:30
Illustration of within-unit vs. random-effect model predictions.
library(lme4)
data(sleepstudy)
## Fit individual regression lines for each subject
dfrm <- coef(lmList(Reaction ~ Days | Subject, sleepstudy))
## Estimate parameters of a random intercept and random intercept and slope model
m1 <- lmer(Reaction ~ Days + (1 | Subject), data=sleepstudy)
m2 <- lmer(Reaction ~ Days + (Days | Subject), data=sleepstudy)
@even4void
even4void / Makefile
Created October 25, 2012 18:35
A sample demo of R Markdown with pandoc
RMDFILE=demo-rmd-pandoc
PANDOC=~/.cabal/bin/pandoc
all:
Rscript -e "require(knitr); require(markdown); knit('$(RMDFILE).rmd', '$(RMDFILE).md'); purl('$(RMDFILE).rmd')"
${PANDOC} --mathjax --toc -B header.html -A footer.html --bibliography refs.bib --css markdown.css -s $(RMDFILE).md -o $(RMDFILE).html
# Compute % agreement between any two columns in a data.frame
dfrm <- data.frame(replicate(18, sample(letters[1:3], 30, replace=TRUE)))
agree <- function(df, i, j) {
tab <- table(df[,c(i,j)])
sum(diag(tab))/sum(tab)
}
# Solution 1
vagree <- Vectorize(agree, vectorize.args=list("i","j"))
#! /usr/bin/env sh
# Post-process Stata do -> log file.
# We should ensure that we use the correct stata program
# (e.g., might be stata, stata-mp, etc.). I'll put this here
# for later update.
STATA="$(which stata)"
# Process command line options