Description Usage Arguments Details Value Examples
A univariate censored frequency table is fit to a negative binomial distribution using a likelihood function customized to handle left, right, and interval censored data. The output is a list containing the average and dispersion parameter that maximizes the custom function.
1 | cnbinom.pars(censoredtable)
|
censoredtable |
A frequency table. A data.frame and matrix are acceptable classes. See Details section for formatting. |
The censored table for the cnbinom.pars function has restrictions. The univariate frequency table, which can be a data.frame or matrix class, must have two columns and n number of rows. The categories must be in the first column with frequencies or probabilities in the second column. Row names should never be placed in this table (the default row names should always be 1:n). Column names can be any character string. The only symbols accepted for censored data are listed below. Note, less than or equal to (<= and LE) is not equivalent to less than (< and L) and greater than or equal to (>=, +, and GE) is not equivalent to greater than (> and G). Also, calculations use closed intervals.
left censoring: <, L, <=, LE
interval censoring: - or I (symbol has to be placed in the middle of the two category values)
right censoring: >, >=, +, G, GE
uncensored: no symbol (only provide category value)
Below are three correctly formatted tables.
Category | Frequency |
<=6 | 11800 |
7-12 | 57100 |
13-19 | 14800 |
20+ | 3900 |
Category | Frequency |
LE6 | 11800 |
7I12 | 57100 |
13I19 | 14800 |
GE20 | 3900 |
Category | Frequency |
<7 | 11800 |
7I12 | 57100 |
13-19 | 14800 |
>=20 | 3900 |
The cnbinom.pars function outputs a list consisting of the estimated average (mu) and dispersion (r) parameter.
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 | # create frequency table that follows a Poisson distribution
set.seed(123)
testdata1<-data.frame(table(rpois(100000,lambda = 10)))
# negative binomial converges in distribution to the Poisson
## when dispersion->infinity
cnbinom.pars(testdata1)
# censor table of testdata1 (lambda = 10)
testdata2<-cbind(as.character(c("<=5", "6-10", "11-15", "16-20", ">20")),
c(6718,51329,37041,4732, 180))
cnbinom.pars(testdata2)
# create frequency table that follows a negative binomial distribution
# different ways to parameterize the negative binomial distribution
mu = 10
r = 2
p = r/(r+mu)
set.seed(123)
testdata3<-data.frame(table(rnbinom(100000, size = r, mu = mu)))
cnbinom.pars(testdata3)
set.seed(123)
testdata4<-data.frame(table(rnbinom(100000, size = r, p = p)))
cnbinom.pars(testdata4)
# censor table with mu = 10 and r = 2
testdata5<-cbind(as.character(c("<5", "5-15", "16I26", "27-37", "38I48", ">48")),
c(26130,53979,15899,3267, 593, 132))
cnbinom.pars(testdata5)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.