-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJags-Model-4-Example.R
More file actions
64 lines (48 loc) · 2.33 KB
/
Jags-Model-4-Example.R
File metadata and controls
64 lines (48 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#Title: Jags-Model-2
#Author: Jack Crum
#Date: 4/13/2018
#-------------------------------------------------------------------------------
# Optional generic preliminaries:
graphics.off() # This closes all of R's graphics windows.
library(dplyr)
#-------------------------------------------------------------------------------
# # Two predictors:
setwd("C:/Users/sjcrum/Documents/Bayesian Statistics/DataSets/Visas")
#Reading in whole dataset
Data <- read.csv( file="training.csv" )
#Set for reproducibility
set.seed(29)
# Sample out 20000 observations to make model runable
myData <- sample(Data[sample(nrow(Data), 20000), ])
#y = predicted variable, x = predictor variables
yName = "case_status" ; xName = c("pw_amount_9089","employer_num_employees")
fileNameRoot = "training-robust-met"
numSavedSteps=5000 ; thinSteps=2
# #.............................................................................
graphFileType = "jpg"
#-------------------------------------------------------------------------------
# Load the relevant model into R's working memory
setwd("C:/Users/sjcrum/Documents/Bayesian Statistics/DataSets/Visas/Bayesian")
source("Jags-Model-4.R")
#-------------------------------------------------------------------------------
# Generate the MCMC chain:
mcmcCoda = genMCMC( data=myData , xName=xName , yName=yName ,
numSavedSteps=numSavedSteps , thinSteps=thinSteps ,
saveName=fileNameRoot )
#-------------------------------------------------------------------------------
# Display diagnostics of chain, for specified parameters:
parameterNames = varnames(mcmcCoda) # get all parameter names
for ( parName in parameterNames ) {
diagMCMC( codaObject=mcmcCoda , parName=parName ,
saveName=fileNameRoot , saveType=graphFileType )
}
#-------------------------------------------------------------------------------
# Get summary statistics of chain:
summaryInfo = smryMCMC( mcmcCoda ,
saveName=fileNameRoot )
show(summaryInfo)
# Display posterior information:
plotMCMC( mcmcCoda , data=myData , xName=xName , yName=yName ,
pairsPlot=TRUE , showCurve=FALSE ,
saveName=fileNameRoot , saveType=graphFileType )
#-------------------------------------------------------------------------------