1 optimBeta <- function(N, n, p, beta, b, link, ncores)
5 list(n=n, p=p, beta=beta, b=b, link=link),
11 M <- computeMoments(fargs$X, fargs$Y)
12 mu <- computeMu(fargs$X, fargs$Y, list(K=K, M=M))
13 op <- optimParams(fargs$X, fargs$Y, K, fargs$link, M)
14 x_init <- list(p=rep(1/K,K-1), beta=mu, b=rep(0,K))
17 res2 <- do.call(rbind, op$run(x_init))
18 }, error = function(e) {})
25 source("../patch_Bettina/FLXMRglm.R")
27 dat <- as.data.frame( cbind(fargs$Y,fargs$X) )
30 fm <- flexmix( cbind(V1, 1-V1) ~ .-V1, data=dat, k=K,
31 model = FLXMRglm(family = binomial(link = link)) )
32 pf <- mean(fm@posterior[["scaled"]][,1])
34 beta_b <- sapply( seq_len(K), function(i) {
35 as.double( out@components[[1]][[i]][,1] )
37 res2 <- rbind(pf, beta_b[2:nrow(beta_b),], beta_b[1,])
38 }, error = function(e) {
44 prepareArgs = function(fargs, index) {
46 io = generateSampleIO(fargs$n, fargs$p, fargs$beta, fargs$b, fargs$link)
50 }, N=N, ncores=ncores, verbose=TRUE)
52 for (i in 1:length(res)) {
54 if (is.null(res[[i]][[j]]) || is.na(res[[i]][[j]]))
57 print(paste("Count valid runs for ",i," = ",length(res[[i]]),sep=""))
58 res[[i]] <- alignMatrices(res[[i]], ref=rbind(p,beta,b), ls_mode="exact")
70 cmd_args <- commandArgs()
73 if (substr(arg,1,1)!='-') {
74 spl <- strsplit(arg,'=')[[1]]
76 ncores <- as.integer(spl[2])
77 } else if (spl[1] == "N") {
78 N <- as.integer(spl[2])
79 } else if (spl[1] == "n") {
80 n <- as.integer(spl[2])
81 } else if (spl[1] == "d") {
82 d <- as.integer(spl[2])
83 } else if (spl[1] == "link") {
92 beta <- matrix( c(1,-2, 3,1), ncol=2 )
96 beta <- matrix( c(1,2,-1,0,3, 2,-3,0,1,0), ncol=2 )
100 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=3 )
103 mr <- optimBeta(N, n, p, beta, b, link, ncores)
104 mr_params <- list("N"=N, "nc"=ncores, "n"=n, "link"=link,
105 "p"=c(p,1-sum(p)), "beta"=beta, "b"=b)
107 save("mr", "mr_params", file=paste("res_",n,"_",d,"_",link,".RData",sep=""))