DFA_Field=DFA(data = data_DFA_Field,
groups = 'Group',
variables = c('Actions','Thoughts'),
predictive = TRUE, priorprob = 'SIZES',
covmat_type='separate', # altho better to used 'separate' for these data
verbose = TRUE)
# \donttest{
# plots of posterior probabilities by group
# hoping to see correct separations between cases from different groups
# first, display the posterior probabilities
print(cbind(round(DFA_Field$posteriors[1:3],3), DFA_Field$posteriors[4]))
# group NT vs CBT
plot(DFA_Field$posteriors$posterior_NT, DFA_Field$posteriors$posterior_CBT,
pch = 16, col = c('red', 'blue', 'green')[DFA_Field$posteriors$Group],
xlim=c(0,1), ylim=c(0,1),
main = 'DFA Posterior Probabilities by Original Group Memberships',
xlab='Posterior Probability of Being in Group NT',
ylab='Posterior Probability of Being in Group CBT' )
legend(x=.8, y=.99, c('CBT','BT','NT'), cex=1.2, col=c('red', 'blue', 'green'), pch=16, bty='n')
# group NT vs BT
plot(DFA_Field$posteriors$posterior_NT, DFA_Field$posteriors$posterior_BT,
pch = 16, col = c('red', 'blue', 'green')[DFA_Field$posteriors$Group],
xlim=c(0,1), ylim=c(0,1),
main = 'DFA Posterior Probabilities by Group Membership',
xlab='Posterior Probability of Being in Group NT',
ylab='Posterior Probability of Being in Group BT' )
legend(x=.8, y=.99, c('CBT','BT','NT'), cex=1.2,col=c('red', 'blue', 'green'), pch=16, bty='n')
# group CBT vs BT
plot(DFA_Field$posteriors$posterior_CBT, DFA_Field$posteriors$posterior_BT,
pch = 16, col = c('red', 'blue', 'green')[DFA_Field$posteriors$Group],
xlim=c(0,1), ylim=c(0,1),
main = 'DFA Posterior Probabilities by Group Membership',
xlab='Posterior Probability of Being in Group CBT',
ylab='Posterior Probability of Being in Group BT' )
legend(x=.8, y=.99, c('CBT','BT','NT'), cex=1.2, col=c('red', 'blue', 'green'), pch=16, bty='n')
DFA_Sherry <- DFA(data = data_DFA_Sherry,
groups = 'Group',
variables = c('Neuroticism','Extroversion','Openness',
'Agreeableness','Conscientiousness'),
predictive = TRUE, priorprob = 'SIZES',
covmat_type='separate',
verbose = TRUE)
# plots of posterior probabilities by group
# hoping to see correct separations between cases from different groups
# first, display the posterior probabilities
print(cbind(round(DFA_Sherry$posteriors[1:3],3), DFA_Sherry$posteriors[4]))
# group 1 vs 2
plot(DFA_Sherry$posteriors$posterior_1, DFA_Sherry$posteriors$posterior_2,
pch = 16, cex = 1, col = c('red', 'blue', 'green')[DFA_Sherry$posteriors$Group],
xlim=c(0,1), ylim=c(0,1),
main = 'DFA Posterior Probabilities by Original Group Memberships',
xlab='Posterior Probability of Being in Group 1',
ylab='Posterior Probability of Being in Group 2' )
legend(x=.8, y=.99, c('1','2','3'), cex=1.2, col=c('red', 'blue', 'green'), pch=16, bty='n')
# group 1 vs 3
plot(DFA_Sherry$posteriors$posterior_1, DFA_Sherry$posteriors$posterior_3,
pch = 16, col = c('red', 'blue', 'green')[DFA_Sherry$posteriors$Group],
xlim=c(0,1), ylim=c(0,1),
main = 'DFA Posterior Probabilities by Group Membership',
xlab='Posterior Probability of Being in Group 1',
ylab='Posterior Probability of Being in Group 3' )
legend(x=.8, y=.99, c('1','2','3'), cex=1.2,col=c('red', 'blue', 'green'), pch=16, bty='n')
# group 2 vs 3
plot(DFA_Sherry$posteriors$posterior_2, DFA_Sherry$posteriors$posterior_3,
pch = 16, col = c('red', 'blue', 'green')[DFA_Sherry$posteriors$Group],
xlim=c(0,1), ylim=c(0,1),
main = 'DFA Posterior Probabilities by Group Membership',
xlab='Posterior Probability of Being in Group 2',
ylab='Posterior Probability of Being in Group 3' )
legend(x=.8, y=.99, c('1','2','3'), cex=1.2, col=c('red', 'blue', 'green'), pch=16, bty='n')
# data from Tabachnik & Fiddel (2019, p 307)
table9.1 <- '
1 87 5 31 6.4
1 97 7 36 8.3
1 112 9 42 7.2
2 102 16 45 7.0
2 85 10 38 7.6
2 76 9 32 6.2
3 120 12 30 8.4
3 85 8 28 6.3
3 99 9 27 8.2'
table9.1 <- data.frame(read.table(text=table9.1,
col.names=c('group','perf','info','verbexp','age')))
DFA(data = table9.1,
groups = 'group',
variables = c('perf','info','verbexp','age'),
predictive = TRUE, priorprob = 'SIZES', covmat_type='within',
verbose = TRUE)
# }
Run the code above in your browser using DataLab