Title: | The Distribution of Distances Between Discrete Events in Fixed Time |
---|---|
Description: | Distribution functions and test for over-representation of short distances in the Liland distribution. Simulation functions are included for comparison. |
Authors: | Kristian Hovde Liland [aut, cre], Lars Snipen [ctb] |
Maintainer: | Kristian Hovde Liland <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.0.1 |
Built: | 2025-01-12 05:35:54 UTC |
Source: | https://github.com/khliland/fixedtimeevents |
Density, distribution function, quantile function and random generation
for the Liland distribution with R
trials and r
successes.
dLiland(x, R, r, warn = FALSE) pLiland(q, R, r, lower.tail = TRUE, warn = FALSE) qLiland(p, R, r) rLiland(n, R, r)
dLiland(x, R, r, warn = FALSE) pLiland(q, R, r, lower.tail = TRUE, warn = FALSE) qLiland(p, R, r) rLiland(n, R, r)
x , q
|
vector of quantiles. |
p |
vector of probabilities. |
n |
number of observations. |
R |
number of trials. |
r |
number of successes. |
warn |
logical indicating if a warning should be issued if approximation is used. |
lower.tail |
logical indicating if the lower tail of the distribution should be summed. |
The Liland distribution has probability mass
where is the distance between consecutive successes,
is the number of trials and
is the number of successes.
dLiland
gives the probability mass, pLiland
gives the distribution
function, qLiland
gives the quantile function, and rLiland
generates
random Liland values.
Kristian Hovde Liland
Liland, KH & Snipen, L, FixedTimeEvents: An R package for the distribution of distances between discrete events in fixed time, SoftwareX 5 (2016).
Liland
, Liland.test
, simLiland
dLiland(19, R = 1949, r = 162) pLiland(19, R = 1949, r = 162) qLiland(0.5, R = 1949, r = 162) plot( pLiland(1:100, R = 1949, r = 162) ) ## QQ-plot of Liland distribution and random Liland values R <- 2000 r <- 120 n <- 1000 samp <- rLiland(n,R,r) theo <- qLiland(ppoints(n),R,r) qqplot(theo,samp, xlab='F(x;2000,120)', ylab='Sample (1000)', axes=FALSE) axis(1,at=c(0,40,80,120)) axis(2,at=c(0,40,80,120)) box() qqline(samp, distribution = function(p)qLiland(p,R=2000,r=120), col='gray',lty=2)
dLiland(19, R = 1949, r = 162) pLiland(19, R = 1949, r = 162) qLiland(0.5, R = 1949, r = 162) plot( pLiland(1:100, R = 1949, r = 162) ) ## QQ-plot of Liland distribution and random Liland values R <- 2000 r <- 120 n <- 1000 samp <- rLiland(n,R,r) theo <- qLiland(ppoints(n),R,r) qqplot(theo,samp, xlab='F(x;2000,120)', ylab='Sample (1000)', axes=FALSE) axis(1,at=c(0,40,80,120)) axis(2,at=c(0,40,80,120)) box() qqline(samp, distribution = function(p)qLiland(p,R=2000,r=120), col='gray',lty=2)
Stirling's 2nd order approximation of the logarithm of a factorial.
facL(n)
facL(n)
n |
vector of integers for which to compute the logarithmic factorial. |
The logarithm of the factorial.
Kristian Hovde Liland
Liland, KH & Snipen, L, FixedTimeEvents: An R package for the distribution of distances between discrete events in fixed time, SoftwareX 5 (2016).
dLiland
, Liland
, Liland.test
, simLiland
# Some values of the logarithm of factorials. facL( c(2,10,100,1000) ) log( factorial( c(2,10,100,1000) ) ) # Fraction of two factorials exp( facL(200)-facL(180) ) factorial(200)/factorial(180)
# Some values of the logarithm of factorials. facL( c(2,10,100,1000) ) log( factorial( c(2,10,100,1000) ) ) # Fraction of two factorials exp( facL(200)-facL(180) ) factorial(200)/factorial(180)
Calculates the mean and variance of the Liland distribution according to the number of trials and successes.
Liland(R, r)
Liland(R, r)
R |
number of trials. |
r |
number of successes. |
Returns a named vector containing the mean and variance of the Liland distribution.
Kristian Hovde Liland
Liland, KH & Snipen, L, FixedTimeEvents: An R package for the distribution of distances between discrete events in fixed time, SoftwareX, in press.
dLiland
, Liland.test
, simLiland
Liland(R = 1949, r = 162)
Liland(R = 1949, r = 162)
A binomial test is performed using probabilites from the Liland distribution to check
if the number of distances shorter to or equal to xlim
are significantly
higher than the expected value. Critical value and power are supplied as separate functions.
Liland.test(y, xlim, R, r) ## S3 method for class 'Ltest' print(x, ...) ## S3 method for class 'Ltest' summary(object, ...) Liland.crit(xlim, R, r, alpha = 0.05) Liland.pow(xlim, R, r, y = 1:(r-1), alpha = 0.05)
Liland.test(y, xlim, R, r) ## S3 method for class 'Ltest' print(x, ...) ## S3 method for class 'Ltest' summary(object, ...) Liland.crit(xlim, R, r, alpha = 0.05) Liland.pow(xlim, R, r, y = 1:(r-1), alpha = 0.05)
y |
The number of observed short distances. |
xlim |
The maximum distance that is seen as short. |
R |
The number of trials. |
r |
The number of successes. |
alpha |
Significance level. |
x |
The object to printed. |
object |
The object to be summarized. |
... |
Additional arguments for print and summary (not used). |
Liland.test
returns a named vector of P-values with class Ltest
. The other methods only print.
Liland, KH & Snipen, L, FixedTimeEvents: An R package for the distribution of distances between discrete events in fixed time, SoftwareX 5 (2016).
Lt <- Liland.test(12,1,1949,162) print(Lt) summary(Lt) # Critical value Liland.crit(1, 1949, 162) # Power plot(Liland.pow(1,1949,161, alpha = 0.05), type = 'l', xlab = '#(x<2)', ylab = 'power')
Lt <- Liland.test(12,1,1949,162) print(Lt) summary(Lt) # Critical value Liland.crit(1, 1949, 162) # Power plot(Liland.pow(1,1949,161, alpha = 0.05), type = 'l', xlab = '#(x<2)', ylab = 'power')
Exchanges all occurrences of NA in a vector with NaN. A warning is issued when NAs or NaNs are found.
NA2NaN(k)
NA2NaN(k)
k |
numerical vector possibly containig NAs. |
Returns a vector where possible NAs have been changed to NaNs.
Kristian Hovde Liland
dLiland
, Liland
, Liland.test
, simLiland
NA2NaN( c(0, 1, NA, NaN)) NA2NaN( c(0, 1, 2, NaN)) NA2NaN( c(0, 1, NA, 100)) NA2NaN( c(0, 1, 2, 100))
NA2NaN( c(0, 1, NA, NaN)) NA2NaN( c(0, 1, 2, NaN)) NA2NaN( c(0, 1, NA, 100)) NA2NaN( c(0, 1, 2, 100))
r successes are drawn from R trials. This is repeated n times to produce a random vector of mean Liland distributed numbers.
rrLiland(n, R, r)
rrLiland(n, R, r)
n |
number of repeated samples. |
R |
number of Bernoulli trials. |
r |
number of successes per sample. |
Vector of mean distance between successful events.
Kristian Hovde Liland
Liland, KH & Snipen, L, FixedTimeEvents: An R package for the distribution of distances between discrete events in fixed time, SoftwareX 5 (2016).
dLiland
, Liland
, Liland.test
, simLiland
mdist <- rrLiland(1000, 25, 7) plot(density(mdist))
mdist <- rrLiland(1000, 25, 7) plot(density(mdist))
Three different simulations are provided for the Liland distribution. These include sampling repeatedly from a given Liland distribution, sampling from the Bernoulli distribution and summarizing, and sampling random mean Liland numbers.
simLiland(S, R, r) simLiland2(S, R, r) simLilandMu(S, R, r)
simLiland(S, R, r) simLiland2(S, R, r) simLilandMu(S, R, r)
S |
number of samples. |
R |
number of trials or denominator of Bernoulli probability. |
r |
number of successes or numerator of Bernoulli probablity. |
simLiland
returns a vector of simulated Liland probabilities.
simLiland2
returns a list of sampled counts (res
),
summary of counts (counts
) and order of counts (ms
).
simLilandMu
returns a vector of simulated mean Liland numbers.
Kristian Hovde Liland
Liland, KH & Snipen, L, FixedTimeEvents: An R package for the distribution of distances between discrete events in fixed time, SoftwareX 5 (2016).
simLiland(1000,20,10) sl <- simLiland2(1000,20,10) sl$counts[sl$ms]/1000 plot(density(simLilandMu(1000,20,10)))
simLiland(1000,20,10) sl <- simLiland2(1000,20,10) sl$counts[sl$ms]/1000 plot(density(simLilandMu(1000,20,10)))
Checks if parameters conform to R >= 2, r >= 2 and r <= R.
validate.Rr(R, r)
validate.Rr(R, r)
R |
number of Bernoulli trials. |
r |
number of successes. |
No return, only testing.
Kristian Hovde Liland
Liland, KH & Snipen, L, FixedTimeEvents: An R package for the distribution of distances between discrete events in fixed time, SoftwareX 5 (2016).
validate.Rr(20,10) ## Not run: # r>R results in an error. validate.Rr(20,30) ## End(Not run)
validate.Rr(20,10) ## Not run: # r>R results in an error. validate.Rr(20,30) ## End(Not run)