pprobability {exams.forge} | R Documentation |
Polynomial Probability
Description
Creates for each value of a discrete random variable, a polynomial and estimates the least squares and the maximum likelihood solution. The following conditions stand:
If
sample
is not given then the sample contains eachx
value once.If
sample
is an integer, then it is interpreted as the sample size and a sample is generated byrmultinom(1, sample, ddiscrete(runif(length(x))))
.If
sample
is a vector, it is interpreted in such a way that the correspondingx[i]
value occursi
times in the sample. Thus,sum(sample)
is the sample size.If
coeff
is apolylist
oflength(x)
, then these polynomials are taken.If
coeff
is amatrix
withlength(x)
, columns andpower+1
rows, then the columns are interpreted as the coefficients of a polynomial.Otherwise
coeff
is interpreted as a vector from which the coefficient is sampled. The intercepts are sampled viaddiscrete(runif(length(x)), zero=zero)
. Ifcoeff
is not given then it is ensured that the least squares and the maximum likelihood solution exists and the estimated probabilities are between zero and one. Otherwise, the results may containNA
or the estimated probabilities are outside the interval[0;1]
.
Usage
pprobability(
x,
power = 1,
zero = FALSE,
coef = round(seq(-1, 1, by = 0.1), 1),
sample = rep(1, length(x)),
pl = NULL,
tol = 1e-09
)
polynomial_probability(
x,
power = 1,
zero = FALSE,
coef = round(seq(-1, 1, by = 0.1), 1),
sample = rep(1, length(x)),
pl = NULL,
tol = 1e-09
)
Arguments
x |
numeric: values of a discrete random variable |
power |
integer: the degree for the polynomials (default: |
zero |
logical: are zero coefficients and zero samples allowed? (default: |
coef |
matrix: for each degree coefficients to sample from (default: |
sample |
integer: number of |
pl |
polylist: a list of polynomials which describes the probability for |
tol |
numeric: tolerance to detect zero values (default: |
Value
A list with the components:
-
p
: the polynomials for the probabilities -
ep
: the expected value as polynomial -
x
: the values for the discrete random variable, the same as the inputx
-
sample
: the sample given or generated -
LS$pi
: the summands for the least squares problem -
LS$pl
: the summands for the least squares problem in LaTeX -
LS$pf
: the sum ofLS$pi
-
LS$df
: the derivative ofLS$pf
-
LS$pest
: the estimated parameter, minimum ofLS$pf
-
LS$p
: the estimated probabilities -
ML$pi
: the factors for the maximum likelihood problem -
ML$pl
: the summands for the maximum likelihood problem in LaTeX -
ML$pf
: the product ofML$pi
-
ML$df
: the derivative ofML$pf
-
ML$pest
: the estimated parameter, maximum ofML$pf
-
ML$p
: the estimated probabilities
Examples
# linear polynomials
pprobability(0:2)
pprobability(0:2, power=1)
# constant polynomials, some NAs are generated
pprobability(0:3, power=0)
# polynomials generated from a different set
pprobability(0:2, coef=seq(-2, 2, by=0.1))
pprobability(0:2, 0, coef=seq(-2, 2, by=0.1))
# polynomials (x, x, 1-2*x) are used
pprobability(0:2, 0, coef=matrix(c(0.4, 0.4, 0.3), ncol=3))
pprobability(0:2, 1, coef=polylist(c(0,1), c(0,1), c(1, -2)))