1 optimBeta <- function(N, n, K, p, beta, b, link, ncores)
5 list(n=n,p=p,beta=beta,b=b,optargs=list(K=K,link=link)),
11 M <- computeMoments(fargs$X, fargs$Y)
13 mu <- computeMu(fargs$X, fargs$Y, fargs$optargs)
14 op <- optimParams(K,link,fargs$optargs)
15 x_init <- list(p=rep(1/K,K-1), beta=mu, b=rep(0,K))
16 do.call(rbind, op$run(x_init))
21 source("../patch_Bettina/FLXMRglm.R")
23 dat <- as.data.frame( cbind(fargs$Y,fargs$X) )
24 fm <- flexmix( cbind(V1, 1-V1) ~ .-V1, data=dat, k=K,
25 model = FLXMRglm(family = binomial(link = link)) )
26 p <- mean(fm@posterior[["scaled"]][,1])
28 beta_b <- sapply( seq_len(K), function(i) {
29 as.double( out@components[[1]][[i]][,1] )
31 rbind(p, beta_b[2:nrow(beta_b),], beta_b[1,])
33 prepareArgs = function(fargs, index) {
35 io = generateSampleIO(fargs$n, fargs$p, fargs$beta, fargs$b, fargs$optargs$link)
38 fargs$optargs$K = ncol(fargs$beta)
39 fargs$optargs$M = computeMoments(io$X,io$Y)
41 }, N=N, ncores=ncores, verbose=TRUE)
44 res[[i]] <- alignMatrices(res[[i]], ref=rbind(p,beta,b), ls_mode="exact")
48 #model = binomial; default values:
55 cmd_args <- commandArgs()
58 if (substr(arg,1,1)!='-') {
59 spl <- strsplit(arg,'=')[[1]]
61 ncores <- as.integer(spl[2])
62 } else if (spl[1] == "N") {
63 N <- as.integer(spl[2])
64 } else if (spl[1] == "n") {
65 n <- as.integer(spl[2])
66 } else if (spl[1] == "d") {
67 d <- as.integer(spl[2])
68 } else if (spl[1] == "link") {
78 beta <- matrix( c(1,-2, 3,1), ncol=K )
83 beta <- matrix( c(1,2,-1,0,3, 2,-3,0,1,0), ncol=K )
88 beta <- matrix( c(1,2,-1,0,3,4,-1,-3,0,2, 2,-3,0,1,0,-1,-4,3,2,0, -1,1,3,-1,0,0,2,0,1,-2), ncol=K )
93 beta <- matrix( c(1,2,-1,0,3,4,-1,-3,0,2,2,-3,0,1,0,-1,-4,3,2,0, -1,1,3,-1,0,0,2,0,1,-2,1,2,-1,0,3,4,-1,-3,0,2, 2,-3,0,1,0,-1,-4,3,2,0,1,1,2,2,-2,-2,3,1,0,0), ncol=K )
96 mr <- optimBeta(N, n, K, p, beta, b, link, ncores)
97 mr_params <- list("N"=N, "n"=n, "K"=K, "d"=d, "link"=link,
98 "p"=c(p,1-sum(p)), "beta"=beta, "b"=b)
100 save("mr", "mr_params", file=paste("multirun_",d,"_",link,".RData",sep=""))