View source: R/wald_wilks_score.R
wws | R Documentation |
A movie to illustrate the nature of the Wald, Wilks and score
likelihood-based test statistics, for a model with a scalar unknown
parameter \theta
. The user can change the value of the parameter
under a simple null hypothesis and observe the effect on the test
statistics and (approximate) p-values associated with the tests of
this hypothesis against the general alternative. The user can
specify their own log-likelihood or use one of two in-built examples.
wws(
model = c("norm", "binom"),
theta_range = NULL,
...,
mult = 3,
theta0 = if (!is.null(theta_range)) sum(c(0.25, 0.75) * theta_range) else NULL,
panel_plot = TRUE,
hscale = NA,
vscale = hscale,
delta_theta0 = if (!is.null(theta_range)) abs(diff(theta_range))/20 else NULL,
theta_mle = NULL,
loglik = NULL,
alg_score = NULL,
alg_obs_info = NULL,
digits = 3
)
model |
A character scalar. Name of the the distribution on which one of two in-built examples are based. If If The behaviour of these examples can be controlled using arguments
supplied via
|
theta_range |
A numeric vector of length 2. The range of values of
|
... |
Additional arguments to be passed to |
mult |
A positive numeric scalar. If |
theta0 |
A numeric scalar. The value of |
panel_plot |
A logical parameter that determines whether the plot
is placed inside the panel ( |
hscale , vscale |
Numeric scalars. Scaling parameters for the size
of the plot when |
delta_theta0 |
A numeric scalar. The amount by which the value of
|
theta_mle |
A numeric scalar. The user may use this to supply the
value of the maximum likelihood estimate (MLE) of |
loglik |
An R function, vectorised with respect to its first argument, that returns the value of the log-likelihood (up to an additive constant). The movie will not work if the observed information is not finite at the maximum likelihood estimate. |
alg_score |
A R function that returns the score function, that is,
the derivative of |
alg_obs_info |
A R function that returns the observed information
that is, the negated second derivative of |
digits |
An integer indicating the number of significant digits to
be used in the displayed values of the test statistics and
p-values. See |
The Wald,
Wilks
(or likelihood ratio)
and Score tests are
asymptotically equivalent tests of a simple hypothesis that a parameter
of interest \theta
is equal to a particular value \theta_0
.
The test statistics are all based on the log-likelihood l(\theta
for \theta
but they differ in the way that they measure the
distance between the maximum likelihood estimate (MLE) of \theta
and
\theta_0
. The Wilks statistic is the amount by which the
log-likelihood evaluated \theta_0
is smaller than the log-likelihood
evaluated at the MLE. The Walk statistics is based on the absolute
difference between the MLE and \theta_0
. The score test is
based on the gradient of the log-likelihood (the score function)
at \theta_0
.
For details see Azzalini (1996).
This movie illustrates the differences between the test
statistics for simple models with a single scalar parameter.
In the (default) normal example the three test statistics coincide.
This is not true in general, as shown by the other in-built example
(distn
= "binom").
A user-supplied log-likelihood can be provided via loglik
.
Nothing is returned, only the animation is produced.
Azzalini, A. (1996) Statistical Inference Based on the Likelihood, Chapman & Hall / CRC, London.
movies
: a user-friendly menu panel.
smovie
: general information about smovie.
# N(theta, 1) example, test statistics equivalent
wws(theta0 = 0.8)
# binomial(20, theta) example, test statistics similar
wws(theta0 = 0.5, model = "binom")
# binomial(20, theta) example, test statistic rather different
# for theta0 distant from theta_mle
wws(theta0 = 0.9, model = "binom", data = c(19, 1), theta_range = c(0.1, 0.99))
# binomial(2000, theta) example, test statistics very similar
wws(theta0 = 0.5, model = "binom", data = c(1000, 1000))
set.seed(47)
x <- rnorm(10)
wws(theta0 = 0.2, model = "norm", theta_range = c(-1, 1))
# Log-likelihood for a binomial experiment (up to an additive constant)
bin_loglik <- function(p, n_success, n_failure) {
return(n_success * log(p) + n_failure * log(1 - p))
}
wws(loglik = bin_loglik, theta0 = 0.5, theta_range = c(0.1, 0.7),
theta_mle = 7 / 20, n_success = 7, n_failure = 13)
bin_alg_score <- function(p, n_success, n_failure) {
return(n_success / p - n_failure / (1 - p))
}
bin_alg_obs_info <- function(p, n_success, n_failure) {
return(n_success / p ^ 2 + n_failure / (1 - p) ^ 2)
}
wws(loglik = bin_loglik, theta0 = 0.5, theta_range = c(0.1, 0.7),
theta_mle = 7 / 20, n_success = 7, n_failure = 13,
alg_score = bin_alg_score, alg_obs_info = bin_alg_obs_info)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.