maxPostClass: Determines class with maximum posterior class probability for...

View source: R/maxPostClass.R

maxPostClassR Documentation

Determines class with maximum posterior class probability for each observation

Description

For each observation the posterior class probability is determined for each class, and then the class with the maximum posterior class probability is returned.

Usage

maxPostClass(object)

Arguments

object

randomLCA object

Details

Returns the class with the maximum posterior class probability for each observation.

Value

A data frame. The first columns of the data frame correspond to the patterns, followed by the frequency of each pattern, and then the class with the maximum posterior class probability. The returned result is for the summarised data. If raw data is used, that is no frequencies, and it is required to calculated the posterior class probability for each observation then it is simply required to merge the maximum class with the raw data, possibly removing any variable "Freq" in the raw data.

Author(s)

Ken Beath

Examples


pap.lca2 <- randomLCA(pap[, 1:10], freq = pap$Freq, nclass = 2, cores = 1)
maxClass.lca2 <- maxPostClass(pap.lca2)
names(maxClass.lca2)[length(names(maxClass.lca2))] <- "maxProb.lca2"

pap.lca3 <- randomLCA(pap[, 1:10], freq = pap$Freq, nclass = 3, cores = 1)
maxClass.lca3 <- maxPostClass(pap.lca3)
names(maxClass.lca3)[length(names(maxClass.lca3))] <- "maxProb.lca3"

maxClass <- merge(maxClass.lca2, maxClass.lca3)
# aggregate because there is more than one record for each combination
# shows the relationship between the 2 and 3 class models
print(aggregate(maxClass$Freq, list(maxProb2 = maxClass$maxProb.lca2, 
    maxProb3 = maxClass$maxProb.lca3), sum))


randomLCA documentation built on July 9, 2023, 6:09 p.m.