library(eqtl.lm)
help(package="eqtl.lm")
library(eqtl.lm)
help(package="eqtl.lm")
  v = c("AA", "AC", "AA", "CC")#
  code.genotype(v)
data(mData.y112)
is.matrix(mData.y112)
  mm = mData.y112
dim(mm)
dist.matrix
  data(mData.y112)#
  mm = mData.y112[1:10,]#
  mm = t(mm)#
  di = dist.matrix(mm)
  di = dist.matrix(mm, "r2")
di
mm
dim(mData.y112)
  data(mData.y112)#
  mm = mData.y112[c(1,101, 201),]#
  mm = t(mm)#
  di = dist.matrix(mm, "r2")
di
data(eData.y112)#
data(mData.y112)#
data(eInfo.y112)#
data(mInfo.y112)
dim(eData.y112)
dim(mData.y112)
dim(eData.y112)
library(qtl)
help(package="qtl")
?hyper
x1 = date()
x2 = date()
x1
x2
x2 - x1
?date
date()
?date
Sys.time()
d1 = Sys.time()
d2 = Sys.time()
d2 - d1
x = d2 - d1
x
x > 5
x < 5

#
n.burn = 1000
#
n.thin = 10
#
n.iter=100
#
delta=0.01
#
tau=1e-3
#
b.update.order=1
#
trace = 10
  n = length(y)
#
  if(nrow(X) !=n){
#
    stop("dimensions of y and X do not match!\n")
#
  }
#
  p = ncol(X)
#

#
  if(is.null(delta)){
#
    stop("delta cannot be NULL\n")
#
  }
#

#
  if(is.null(tau)){
#
    stop("tau cannot be NULL\n")
#
  }
#

#
  bSample = matrix(0, nrow=p, ncol=n.iter)
#

#
  Xj2 = apply(X, 2, function(v){sum(v*v)})
#
  b   = numeric(p)
#
  v   = rep(0.01, p)
#
  v0  = 0.01
#
  n.all = n.burn + n.thin*n.iter
#
  k = 0
#
  
#
  for(w in 1:n.all){
#
    if(trace > 0){
#
      trace = round(trace)
#
      if(w %% trace==0){
#
        cat(w, date(), "\n")
#
      }
#
    }
#
    
#
    res = as.numeric(y - X %*% b)
#
    b0.bar = mean(res)
#
    s0  = v0/n
#
    b0  = rnorm(1, b0.bar, sqrt(s0))
#
    
#
    res = res - b0
#
    
#
    for(j in 1:p){
#
      res = res + X[,j]*b[j]
#
    
#
      bj.bar = sum(X[,j]*res)
#
      bj.bar = bj.bar/Xj2[j]
#
      sj = v0/Xj2[j]
#
      bj = 0
#

#
      d1 = Sys.time()
#

#
      Z = .C("bj_sampler", as.integer(1), as.double(bj.bar),
#
       as.double(sj), as.double(v[j]), bj = bj, PACKAGE="mlm")
#

#
      d2 = Sys.time()
#
      
#
      if(d2 - d1 > 5){
#
        cat("w=", w, "j=", j, bj.bar, sj, v[j], d2-d1, "\n")
#
      }
#
      
#
      b[j] = Z$bj
#
      res = res - X[,j]*b[j]
#
    }
#

#
    v0 = sum(res*res)/rchisq(1,n)
#
    v  = 2*(abs(b) + tau)/rchisq(length(b),2+2*delta)
#
    
#
    if(w > n.burn){
#
      if((w - n.burn) %% n.thin == 0){
#
        k = k + 1
#
        bSample[,k] = b
#
      }
#
    }
#
    
#
  }
qnorm(0.95)
qnorm(0.7)
?dgamma
x = rgamma(10000, 0.01, 1e5)
plot(density(x)
)
x = rgamma(10000, 1, 1e2)
plot(density(x))
x = rgamma(10000, 2, 1e3)
plot(density(x))
x = rgamma(10000, 1, 1e2)
quartz()
plot(density(x))
x = rgamma(10000, 2, 1e2)
plot(density(x))
x = rgamma(10000, 1, 1e2)
quartz()
plot(density(x))
library(eqtl.lm)
rbinom(100,0.5)
library(qtl)
setwd("~/research/multiple_loci_mapping/bayesian/code")#
        #
md = read.table("genotype_data.txt")#
mi = read.table("genotype_info.txt")
dim(md)
dim(mi)
mm = matrix(t(md[1:60,])
)
mm = data.matrix(t(md[1:60,]))
dim(mm)
#
setwd("~/research/multiple_loci_mapping/bayesian/code")#
        #
md = read.table("genotype_data.txt")#
mi = read.table("genotype_info.txt")#
#
mm = data.matrix(t(md[,1:60]))
dim(mm)
setwd("~/research/multiple_loci_mapping/bayesian/code")#
        #
md = read.table("genotype_data.txt")#
mi = read.table("genotype_info.txt")#
#
mm = data.matrix(t(md[,1:60]))#
#
sex = runif(360)#
sex[sex >  0.5] = 1#
sex[sex <= 0.5] = 0
sex
mm[1:5,1:5]
setwd("~/research/multiple_loci_mapping/bayesian/code")#
        #
md = read.table("genotype_data.txt")#
mi = read.table("genotype_info.txt")#
#
mm = data.matrix(t(md[,1:60]))#
#
sex = runif(360)#
sex[sex >  0.5] = 1#
sex[sex <= 0.5] = 0#
#
me = matrix(0, nrow=10, ncol=360)#
x  = mm[1,]#
y  = x + x*sex + rnorm(100)
y  = x + x*sex + rnorm(360)
y
summary(y)
l  = lm(y~x + x:sex)#
summary(l)
y  = 0.5*x + 0.3x*sex + rnorm(360)#
l  = lm(y~x + x:sex)#
summary(l)
y  = 0.2*x + 0.1*x*sex + rnorm(360)#
l  = lm(y~x + x:sex)#
summary(l)
y  = 0.3*x + 0.2*x*sex + rnorm(360)#
l  = lm(y~x + x:sex)#
summary(l)
y  = 0.5*x + 0.2*x*sex + rnorm(360)#
l  = lm(y~x + x:sex)#
summary(l)
y  = 0.4*x + 0.2*x*sex + rnorm(360)#
l  = lm(y~x + x:sex)#
summary(l)
me = matrix(0, nrow=10, ncol=360)#
x  = mm[1,]#
y  = 0.5*x + 0.3*x*sex + rnorm(360)#
l  = lm(y~x + x:sex)#
summary(l)
me = matrix(0, nrow=10, ncol=360)#
x  = mm[1,]#
y  = 0.5*x + 0.3*x*sex + rnorm(360)#
l  = lm(y~x + x:sex)#
summary(l)
me = matrix(0, nrow=10, ncol=360)#
x  = mm[1,]#
y  = 0.5*x + 0.3*x*sex + rnorm(360)#
l  = lm(y~x + x:sex)#
summary(l)
me = matrix(0, nrow=10, ncol=360)#
x  = mm[1,]#
y  = 0.5*x + 0.5*x*sex + rnorm(360)#
l  = lm(y~x + x:sex)#
summary(l)
me = matrix(0, nrow=10, ncol=360)#
x  = mm[1,]#
y  = 0.4*x + 0.4*x*sex + 0.8*rnorm(360)#
l  = lm(y~x + x:sex)#
summary(l)#
#
me[1,] = y
var(y)
#
for(i in 2:9){#
  me[i,] = rnorm(360)#
}
dim(me)
simuD = list(expression=me, genotype=mm)
?save
mi[1:2,]
#
setwd("~/research/multiple_loci_mapping/bayesian/code")#
        #
md = read.table("genotype_data.txt")#
mi = read.table("genotype_info.txt", header=TRUE)#
#
mm = data.matrix(t(md[,1:60]))
dim(mi)
setwd("~/research/R/eqtl.lm/data/")#
#
simuD = list(expression=me, genotype=mm, gtpinfo=mi[1:60,])#
save(simuD, file = "simuD.rda")
?package.skeleton
simuD = list(expression=me, genotype=mm, gtpinfo=mi[1:60,])#
package.skeleton("tmp", simuD)
simuD = list(expression=me, genotype=mm, gtpinfo=mi[1:60,])#
package.skeleton("tmp", "simuD")
simuD = list(expression=me, genotype=mm, gtpinfo=mi[1:60,], sex=sex)#
package.skeleton("tmp", "simuD")
library(eqtl.TF)
help(package="eqtl.TF")
?eData.y112
