pprobability | R Documentation |
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 each x
value once.
If sample
is an integer, then it is interpreted as the sample size and a sample is generated by rmultinom(1, sample, ddiscrete(runif(length(x))))
.
If sample
is a vector, it is interpreted in such a way that the corresponding x[i]
value occurs i
times in the sample. Thus, sum(sample)
is the sample size.
If coeff
is a polylist
of length(x)
, then these polynomials are taken.
If coeff
is a matrix
with length(x)
, columns and power+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 via ddiscrete(runif(length(x)), zero=zero)
.
If coeff
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 contain NA
or the estimated probabilities are outside the interval [0;1]
.
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
)
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: |
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 input x
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 of LS$pi
LS$df
: the derivative of LS$pf
LS$pest
: the estimated parameter, minimum of LS$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 of ML$pi
ML$df
: the derivative of ML$pf
ML$pest
: the estimated parameter, maximum of ML$pf
ML$p
: the estimated probabilities
# 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)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.