reweight.univariatetable: Reweighting a univariate table

Description Usage Arguments Details Value Examples

View source: R/reweight.univariatetable.R

Description

This function is used in the main function: rec.

Usage

1
reweight.univariatetable(observed.table, estimated.table)

Arguments

observed.table

A data.frame or matrix with two columns. See Details section for formatting.

estimated.table

A numeric vector with uncensored row names.

Details

Format for observed.table:
This 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.

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

Value

A censored univariate table (observed.table) of probabilities is reweighted to match probabilities in an uncensored numeric vector (estimated.table). If observed.table consist of frequencies, the reweight.contingencytable() function changes the frequencies to probabilities.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# use preloaded univariate table for observed table 
observed.table<-univariatetable.csv

# estimate parameters from observed table
pars=cnbinom.pars(observed.table)
mu=pars$Average
r = pars$Dispersion

# create estimated table 
# truncated negative binomial probabilities
# uncensored range is from 1:15 
library(truncdist)
estimated.table<-dtrunc(1:15, size = r, mu = mu, spec = "nbinom", a = 1-1, b = 15)
names(estimated.table)<-1:15

# reweight observed table to estimated table
results<-reweight.univariatetable(observed.table, estimated.table)

# check results for >=9 
reweightedresults<-sum(results[9:15])
# observed.table$V2[5] = 4.1
observedresults<-observed.table$V2[5]/sum(observed.table$V2)  
# matching probabilities
all.equal(reweightedresults, observedresults)

revengc documentation built on May 2, 2019, 3:43 a.m.