if (FALSE) {
## example 1: Bayesian analysis using data generated under the model
## define number of objects
J<-10
## define number of attributes
K<-10
## define number of features
F<-2
## generate true parameters
set.seed(43565)
objectparameters<-matrix(runif(J*F),nrow=J)
attributeparameters<-matrix(runif(K*F),nrow=K)
## generate data for conjunctive model using N=100 replications
gdat<-gendat(maprule="conj",N=100,
objpar=objectparameters,attpar=attributeparameters)
## Use stepplfm to compute posterior mode(s) for 1 up to 3 features
conj.lst<-stepplfm(minF=1,maxF=3,maprule="conj",freq1=gdat$freq1,freqtot=100,M=5)
## Compute a sample of the posterior distribution
## for the conjunctive model with two features
## use the posterior mode obtained with stepplfm as starting point
conjbayes2<-bayesplfm(maprule="conj",freq1=gdat$freq1,freqtot=100,F=2,
maxNiter=3000,Nburnin=0,Nstep=1000,Nchains=2,
start.bayes="fitted.plfm",fitted.plfm=conj.lst[[2]])
}
if (FALSE) {
## example 2: Bayesian analysis of situational determinants of anger-related behavior
## load data
data(anger)
## Compute one chain of 500 iterations (including 250 burn-in iterations)
## for the disjunctive model with two features
## use a random starting point
bayesangerdisj2a<-bayesplfm(maprule="disj",freq1=anger$freq1,freqtot=anger$freqtot,F=2,
maxNiter=500,Nstep=500,Nburnin=250,Nchains=1,start.bayes="random")
##print a summary of the output
summary(bayesangerdisj2a)
## Compute a sample of the posterior distribution
## for the disjunctive model with two features
## compute starting points with plfm
## run 2 chains with a maximum length of 10000 iterations
## compute convergence after each 1000 iterations
bayesangerdisj2b<-bayesplfm(maprule="disj",freq1=anger$freq1,freqtot=anger$freqtot,F=2,
maxNiter=10000,Nburnin=0,Nstep=1000,Nchains=2,start.bayes="best")
## print the output of the disjunctive 2-feature model for the anger data
print(bayesangerdisj2b)
## print a summary of the output of the disjunctive 2-feature model
##for the anger data
summary(bayesangerdisj2b)
}
Run the code above in your browser using DataLab