classprob: Determines the prevalence of each class

Description Usage Arguments Details Value Author(s) See Also Examples

Description

A function which determines the prevalence or probability for each class of a vector (treated as factor).

Usage

1

Arguments

x

a one dimensional vector

Details

This function treats the input vector as a factor and determines the probability for each level (class) of the factor. The order of the returned probabilities is the order of the levels command, which defaults to numeric or alphabetic order.

Value

A vector whose length is equal to the number of levels in the input. The order is numerically or alphabetically increasing. Note the factors may have levels which are not present in the vector, see examples for details.

Author(s)

Atina Dunlap Brooks

See Also

majority factor

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
#calculate probbilities
x <- sample( c("a","b","c","d","e"), 10, replace=TRUE )
classprob(x)
#label the probabilities
levels(as.factor(x))

#to see levels which aren't represnted in the vector
x<-as.factor(c('a','a','a','b','b','c'))
levels(x)
#now remove the 'c'
x<-x[1:5]
#but 'c' is still a level
levels(x)
#and the probability is calculated for it
classprob(x)

Dasonk/knnflex documentation built on May 6, 2019, 1:37 p.m.