Learn R Programming

PlotNormTest (version 1.0.1)

Univariate_Score_function: Graphical plots to assess the univarite noramality assumption of data.

Description

Score function of a univariate normal distribution is a straight line. A non-linear graph of score function estimator shows evidence of non-normality.

Outliers are detected using the 2-sigma bands method.

Usage

cox(x, P = NULL, lambda = 0.5, x.dist = NULL)

score_plot1D(x, P = NULL, lambda = 0.5, x.dist = NULL, ori.index = NULL)

Value

cox returns the estimate of score function.

  • x: The updated univariate data if merging happens.

  • a: Score value estimated at x.

  • P: Updated weight (if merging happens).

  • slt: Index of merged data point (is NULL if x.dist = NULL).

score_plot1D returns score functions together with 2-sigma bands for outlier detection.

  • plot: plot of estimate score function and its band.

  • outlier: index of outliers.

Arguments

x

univariate data.

P

vector of weight.

lambda

smoothing parameter, default is \(0.5\).

x.dist

the minimum distance between two data points in vector x.

ori.index

original index of vector x, default is NULL when index is just the order.

Details

To avoid the singularity of coefficient matrices in spline method, points with distance less than x.dist are merged and weight of the representative points is updated by the summation of weight of discarded points.

Under null hypothesis, a unbiased estimator score function of a given data point \(x_k\) is $$ \hat{\psi}(x_k) = \dfrac{n - 4}{n - 2} \dfrac{x_k - \bar{X}_{-k}}{S_{-k}^2} $$ and if \(a_{k}\) is the estimate score from function cox at the point \(x_k\), then $$a_k\in \hat{\psi}(x_k) \pm 2 \sqrt{\hat{\text{Var}}(\hat{\psi}(x_k))}.$$ Hence points outside the 2-sigma bands are outliers.

References

ref:sp_estimatePlotNormTest

Examples

Run this code
set.seed(1)
x <- rnorm(100, 2, 4)
re <- cox(sort(x))
plot(re$x, re$a, xlab = "x", ylab = "Estimated Score",
 main = "Estimator of score function")
abline(0, 1)

set.seed(1)
x <- rnorm(100, 2, 4)
score_plot1D(sort(x))

Run the code above in your browser using DataLab