rescaleTable: Rescales the numeric part of the table

View source: R/hyperDirichlet.R

rescaleTableR Documentation

Rescales the numeric part of the table

Description

Takes a table representing a conditional probability distribution or a set of hyper-Dirichlet parameters and rescales the numeric part of the table. The function rescaleTable() scales the table by scaleFactor, the function normalizeTable() scales the function by the sum of the rows, making the result a conditional probability table.

Usage

rescaleTable(table, scaleFactor)
normalizeTable(table)

Arguments

table

A data frame describing a conditional probability table. Assumes that the conditions are expressed as factor variables, and all numeric columns represent states of the child variable.

scaleFactor

A scalar or vector of length equal to the number of rows of table.

Details

For rescaleTable(), every numeric column of table is multiplied by scaleFactor. This can be used to create a set of hyper-Dirichlet parameters by multiplying a conditional probability table by the effective sample size.

For normalizeTable(), the scaleFactor is set to be 1/rowSums(table) (excluding the factor variables) so that the resulting table is a proper conditional probability table.

Value

A data frame of the same shape as table with the numeric entries suitably scaled.

Note

The function scaleTable does a similar rescaling, only it works with a separate ‘Sum’ and ‘Scale’ columns in the table.

Author(s)

Russell Almond

See Also

getTableStates, scaleTable

Examples


#conditional table
X2.ptf <- data.frame(Theta=c("Expert","Novice"),
                     correct=c(4,2),
                     incorrect=c(2,4))

X2.t99 <- rescaleTable(X2.ptf,99/6)  #Reweight to effective samples size of 99
X2.t31 <- rescaleTable(X2.ptf,c(3,1))  #Weight expert prior 3 times more than
                             #novice prior.
X2.dtf <- normalizeTable(X2.ptf)


#Unconditional table
Theta.ptf <- data.frame(Expert=3,Novice=3)
Theta.t100 <- rescaleTable(Theta.ptf,100/6)  #Reweight to effective
                                             #sample size of 100
Theta.dtf <- normalizeTable(Theta.ptf)


ralmond/CPTtools documentation built on Dec. 27, 2024, 7:15 a.m.