#rm(list=ls(all=TRUE))
# ==================================================================================
if ( FALSE ) {
# ==================================================================================
# set working directory
oldDir <- getwd()
curDir <- tempdir()
setwd(curDir)
if ( !file.exists("bayesMCClust-wd") ) dir.create("bayesMCClust-wd")
setwd("bayesMCClust-wd")
myOutfilesDir <- "MNLAuxMix-Example-Outfiles"
data(MCCExtExampleData)
if (!is.element("MCCExtExampleData$covariates", search())) {
attach(MCCExtExampleData$covariates)
}
# ==================================================================================
response <- MCCExtExampleData[[ sample(5:7, 1) ]] # MCCExtExampleData$MNLresponse2gr
# MCCExtExampleData$MNLresponse3gr # MCCExtExampleData$MNLresponse4gr #
groupNr <- max(response) # 3
# ==================================================================================
# ==================================================================================
require(nnet, quietly = TRUE)
H <- groupNr
X = cbind( intercept=1, alrateBezNew, unskilled, skilled, angStart )
N <- dim(X)[1]
mX <- data.frame( cbind(group=as.factor( response ), X[,-1],
matrix(sample(1:H,H*N,replace=TRUE),N,H)) )
colnames(mX)[6:(6+groupNr-1)] <- c( "as.1", "as.2", "as.3", "as.4" )[1:groupNr]
tempMNom <- multinom(group ~ alrateBezNew+ unskilled+ skilled+ angStart,
data=as.data.frame(mX))
toStartBeta <- t(rbind(0,coef( tempMNom )))
# ==================================================================================
system.time(
outList <- MNLAuxMix(
Data = list( storeDir = myOutfilesDir,
# will be created if not existing (in current working directory!)
X = cbind( intercept=1, alrateBezNew, unskilled, skilled, angStart ) ),
Prior = list( H = groupNr, # number of alternatives 1,...,H
betaPrior = "informative",
# 'uninformative' (improper) prior pars for beta (betaPriorVar = infty)
betaPriorMean = 0,
betaPriorVar = 1), # 'informative' prior pars for beta -> N(0,1)
Initial = list( S.i.start = response, # vector of multinomial outcomes / choice made
Beta.start = toStartBeta ),
Mcmc = list( M = 100,
M0 = 50,
mOut = 10,
mSave = 50,
seed = sample(1:100000, 1) # 6984684
)
)
)
str(outList)
#outFileName <- outList$workspaceFile
#outFileName
#results <- load(outFileName)
#results
allocList <- calcAllocationsMNL(outList, thin=1, maxi=50)
str(allocList)
myRegCoeffs <- calcRegCoeffs(outList, hBase=2, thin=1)
#, M0=Mcmc$M0, grLabels=paste("Group", 1:Prior$H),
# printHPD=TRUE, plotPaths=TRUE, plotACFs=TRUE
str(myRegCoeffs)
mySegPower <- calcSegmentationPower(outList, classProbs=allocList$classProbs,
class=allocList$class, printXtable=TRUE, calcSharp=TRUE, printSharpXtable=TRUE )
# , grLabels=paste("Group", 1:Prior$H)
str(mySegPower)
myEntropy <- calcEntropy(outList, classProbs=allocList$classProbs,
class=allocList$class, printXtable=TRUE )
# , grLabels=paste("Group", 1:Prior$H)
myEntropy
plotLikeliPaths(outList, from=10, by=1 )
myNumEffTables <- calcNumEff( outList, thin=1, printXi=TRUE, printE=TRUE,
printBeta=TRUE, grLabels=paste("Group", 1:outList$Prior$H) )
str(myNumEffTables)
setwd(oldDir)
# ==================================================================================
if ( is.element("MCCExtExampleData$covariates", search())) {
detach(MCCExtExampleData$covariates)
}
# ==================================================================================
} # end if
# ==================================================================================
# ==================================================================================Run the code above in your browser using DataLab