ddiscrete2: ddiscrete2

View source: R/ddiscrete2.R

ddiscrete2R Documentation

ddiscrete2

Description

Creates a bivariate discrete probability function based on the marginal probability fuctions row and col. If unit is not given then unit will be the product of the units used in row and col otherwise the least common multiple of unit product of the units used in row and col. If target is NA then the common distribution of two independent random variables is returned otherwise an iterative algorithm is run to approach a target association or correlation measure, see also assoc_data() called internally. zero allows for zero entries in the common distribution. FUN computes the association or correlation measure based on a frequency table. tol gives the maximal deviation of the association or correlation measure and the target value. maxit limits the number of steps. Note that a solution is not guaranteed, especially for extreme values for target, for example for +1 or -1 or values nearby. If attr(joint, "iterations")==maxit then you need either to increase maxit, to decrease tol or to check if you have choosen an appropriate target value (for a nominal measure in 0 <= target <= 1, for ordinal measure in -1 <= target <= +1).

Usage

ddiscrete2(
  row,
  col,
  unit = NULL,
  zero = FALSE,
  FUN = nom.cc,
  target = NA,
  tol = 0.001,
  maxit = 500,
  ...
)

Arguments

row

numeric: marginal row distribution

col

numeric: marginal col distribution

unit

integer: reciprocal of smallest non-zero probability (default: NULL)

zero

logical: zeros in the final probabilities allowed (default: FALSE)

FUN

function: association or correlation function (default: nom.cc)

target

numeric: target association or correlation (default: NA)

tol

numeric: tolerance for target association or correlation (default: 0.001)

maxit

integer: maximal number of iterations (default: 100)

...

further parameter for FUN

Value

a discrete probability function

Examples

row <- ddiscrete(runif(5))
col <- ddiscrete(runif(3))
joint <- ddiscrete2(row, col)
joint
joint <- ddiscrete2(row, col, target=0.5)
joint
nom.cc(joint*attr(joint, "unit"))

sigbertklinke/exams2moodle documentation built on July 6, 2023, 3:26 p.m.