Skip to content

Instantly share code, notes, and snippets.

@cheuerde
cheuerde / rforge_through_guit.sh
Last active August 29, 2015 14:26
Update R-Forge repository with Github-version
# Claas Heuer, July 2015
# first get svn
sudo apt-get install subversion
# get the r-forge project:
mkdir project
cd project
svn checkout svn+ssh://cheuer@r-forge.r-project.org/svnroot/cgen/
@cheuerde
cheuerde / ped_ancestors.r
Last active August 29, 2015 14:24
Pedigree - important ancestors based on cholesky of A
# Claas Heuer, July 2015
# adopted from: http://www.r-bloggers.com/setup-up-the-inverse-of-additive-relationship-matrix-in-r/
ped <- data.frame( id=c( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10),
fid=c( NA, NA, 2, 2, 4, 2, 5, 5, NA, 8),
mid=c( NA, NA, 1, NA, 3, 3, 6, 6, NA, 9))
@cheuerde
cheuerde / pev_gibbs.r
Created July 14, 2015 16:19
PEV and reliabilities from GBLUP using Gibbs Sampling
# Claas Heuer, 2015
library(cpgen)
library(pedigreemm)
library(MCMCglmm)
setwd("/home/claas/kaki/Analysedaten")
X<-cscanx("Xa")
@cheuerde
cheuerde / update_binom.r
Created July 14, 2015 16:17
Updating binomial mean - prior
# Claas Heuer, 2015
library(rjags)
# some data
n = 1296
p_success <- 0.94
x <- as.integer(p_success*n)
y <- c(rep(1,x),rep(0,n-x))
@cheuerde
cheuerde / plot_dist.r
Last active August 29, 2015 14:24
Plotting distributions in R
# Claas Heuer, 2015
# plotting distributions (or any function)
# is straightforward using the 'curve' function
# lets plot the pdf of a normal distribution with mean=0 and sd=1
curve(dnorm(x,0,1),from = -10, to = 10, n = 100)
# 'curve' evaluates the function given as first argument with one unknown over
@cheuerde
cheuerde / cor_random.r
Last active August 29, 2015 14:24
Generate correlated random variables
# Claas Heuer, 2015
#
# Generating 2 random vectors
# that have some given correlation
#
# actually, this is a covariance
cor = 0.98
# sample size
@cheuerde
cheuerde / multivariate_mcmcglmm.r
Last active August 29, 2015 14:23
Multivariate gaussian model in MCMCglmm #R #MCMCglmm
library(MCMCglmm)
n = 10000
x <- rnorm(n)
y <- rnorm(n)
dat <- data.frame(x=x,y=y)
model <- MCMCglmm(cbind(y,x)~ -1 + trait,rcov= ~us(trait):units, data=dat, family=c("gaussian","gaussian"))
@cheuerde
cheuerde / blup.r
Last active August 29, 2015 14:21
BLUP
# modified from Marvin Gertz, 2015
#
# Custom BLUP ############
blupLHS <- function (formula, ped, data, alpha, trim = FALSE)
{
colnames(ped)[1:3] <- c("ID", "SIRE", "DAM")
if (any(!all.vars(formula) %in% colnames(ped)))
stop("Formula has variables which are not present in the data.")
ww <- match(all.vars(formula)[-1], colnames(ped))
ped$b <- apply(ped, 1, function(x) !any(is.na(x[ww])))
@cheuerde
cheuerde / R_centos.sh
Last active August 29, 2015 14:21
Compile R on Centos
# get dependencies
# X11 stuff
sudo yum install libXt-devel
sudo yum install libX11-devel
# readline
sudo yum install readline-devel
# get R
@cheuerde
cheuerde / openblas_centos6.5.sh
Last active August 27, 2019 03:47
OpenBLAS for Centos 6.5
# Centos 6.5 comes with very old packages
# first we need to get git
sudo yum install git
# then update binutils to build OpenBLAS
# this is also needed
sudo yum install texinfo