dpeak {skedastic}R Documentation

Probability mass function of number of peaks in an i.i.d. random sequence

Description

This function computes P(n,k)P(n,k) as defined by Goldfeld and Quandt (1965), i.e. the probability that a sequence of nn independent and identically distributed random variables contains exactly kk peaks, with peaks also as defined by Goldfeld and Quandt (1965). The function is used in ppeak to compute pp-values for the Goldfeld-Quandt nonparametric test for heteroskedasticity in a linear model.

Usage

dpeak(k, n, usedata = FALSE)

Arguments

k

An integer or a sequence of integers strictly incrementing by 1, with all values between 0 and n - 1 inclusive. Represents the number of peaks in the sequence.

n

A positive integer representing the number of observations in the sequence.

usedata

A logical. Should probability mass function values be read from dpeakdat rather than computing them? This option will save significantly on computation time if n<170n < 170 but is currently only available for n1000n \leq 1000.

Value

A double between 0 and 1 representing the probability of exactly k peaks occurring in a sequence of nn independent and identically distributed continuous random variables. The double has a names attribute with the values corresponding to the probabilities. Computation time is very slow for n>170n > 170 (if usedata is FALSE) and for n>1000n > 1000 regardless of usedata value.

References

Goldfeld SM, Quandt RE (1965). “Some Tests for Homoscedasticity.” Journal of the American Statistical Association, 60(310), 539–547.

See Also

ppeak, goldfeld_quandt

Examples

dpeak(0:9, 10)
plot(0:9, dpeak(0:9, 10), type = "p", pch = 20, xlab = "Number of Peaks",
         ylab = "Probability")

# This would be extremely slow if usedata were set to FALSE:
prob <- dpeak(0:199, 200, usedata = TRUE)
plot(0:199, prob, type = "l", xlab = "Number of Peaks", ylab = "Probability")

# `dpeakdat` is a dataset containing probabilities generated from `dpeak`
utils::data(dpeakdat)
expval <- unlist(lapply(dpeakdat,
                 function(p) sum(p * 0:(length(p) - 1))))
plot(1:1000, expval[1:1000], type = "l", xlab = parse(text = "n"),
     ylab = "Expected Number of Peaks")

[Package skedastic version 2.0.2 Index]