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
#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)))) |
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
## 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) |
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
// 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; |
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
(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 |
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
(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 |
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
## 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: |
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
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) |
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
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 | |
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
# 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")) |
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
#! /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 |