SignedRank

Struct SignedRank 

Source
pub struct SignedRank { /* private fields */ }
Expand description

§Distribution of the Wilcoxon Signed Rank Statistic

§Description

Density, distribution function, quantile function and random generation for the distribution of the Wilcoxon Signed Rank statistic obtained from a sample with size n.

§Arguments

  • n: number(s) of observations in the sample(s). A positive integer, or a vector of such integers.

§Details

This distribution is obtained as follows. Let x be a sample of size n from a continuous distribution symmetric about the origin. Then the Wilcoxon signed rank statistic is the sum of the ranks of the absolute values $ x[i] $ for which $ x[i] $ is positive. This statistic takes values between $ 0 $ and $ n(n+1)/2 $, and its mean and variance are $ n(n+1)/4 $ and $ n(n+1)(2n+1)/24 $, respectively.

If either of the first two arguments is a vector, the recycling rule is used to do the calculations for all combinations of the two up to the length of the longer vector.

§Value

dsignrank gives the density, psignrank gives the distribution function, qsignrank gives the quantile function, and rsignrank generates random deviates.

The length of the result is determined by nn for rsignrank, and is the maximum of the lengths of the numerical arguments for the other functions.

The numerical arguments other than nn are recycled to the length of the result. Only the first elements of the logical arguments are used.

§Density Plot

let sgnrank = SignedRankBuilder::new().build();
let x = <[f64]>::sequence_by(-1.0, 2.0, 0.001);
let y = x
    .iter()
    .map(|x| sgnrank.density(x).unwrap())
    .collect::<Vec<_>>();

let root = SVGBackend::new("density.svg", (1024, 768)).into_drawing_area();
Plot::new()
    .with_options(PlotOptions {
        x_axis_label: "x".to_string(),
        y_axis_label: "density".to_string(),
        ..Default::default()
    })
    .with_plottable(Line {
        x,
        y,
        color: BLACK,
        ..Default::default()
    })
    .plot(&root)
    .unwrap();

§Author(s)

Kurt Hornik; efficiency improvement by Ivo Ugrina.

§See Also

wilcox.test to calculate the statistic from data, find p values and so on.

Distributions for standard distributions, including dwilcox for the distribution of two-sample Wilcoxon rank sum statistic.

§Examples

let plot_coords = [
    [0.0, 0.5, 0.0, 0.5],
    [0.5, 1.0, 0.0, 0.5],
    [0.0, 0.5, 0.5, 1.0],
    [0.5, 1.0, 0.5, 1.0],
];
let ns = [4.0, 5.0, 10.0, 40.0];

let root = SVGBackend::new("densities.svg", (1024, 768)).into_drawing_area();
for i in 0..4 {
    let n = ns[i];
    let x = <[f64]>::sequence(0.0, n * (n + 1.0) / 2.0, 500);
    let sgnrank = SignedRankBuilder::new().with_sample_size(n).build();
    let y = x
        .iter()
        .map(|x| sgnrank.density(x).unwrap())
        .collect::<Vec<_>>();

    Plot::new()
        .with_options(PlotOptions {
            x_axis_label: "x".to_string(),
            y_axis_label: "density".to_string(),
            title: format!("n={n}"),
            plot_left: plot_coords[i][0],
            plot_right: plot_coords[i][1],
            plot_top: plot_coords[i][2],
            plot_bottom: plot_coords[i][3],
            ..Default::default()
        })
        .with_plottable(Line {
            x,
            y,
            color: BLACK,
            ..Default::default()
        })
        .plot(&root)
        .unwrap();
}

Trait Implementations§

Source§

impl Distribution for SignedRank

Source§

fn density<R: Into<Real64>>(&self, x: R) -> Real64

The density of the values at a given point
Source§

fn log_density<R: Into<Real64>>(&self, x: R) -> Real64

The logarithmic density of the values at a given point
Source§

fn probability<R: Into<Real64>>(&self, q: R, lower_tail: bool) -> Probability64

PDF; The probability that a value is found in a distribution (inverse of quantile)
Source§

fn log_probability<R: Into<Real64>>( &self, q: R, lower_tail: bool, ) -> LogProbability64

log(PDF); The logarithmic probability that a value is found in a distribution (inverse of quantile)
Source§

fn quantile<P: Into<Probability64>>(&self, p: P, lower_tail: bool) -> Real64

The value in the distribution that is associated with a probability (inverse of probability)
Source§

fn log_quantile<LP: Into<LogProbability64>>( &self, p: LP, lower_tail: bool, ) -> Real64

The logarithmic value in the distribution that is associated with a probability (inverse of probability)
Source§

fn random_sample<R: RNG>(&self, rng: &mut R) -> Real64

Generates a random sample from the distribution

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.