Type: | Package |
Title: | The Distribution of Distances Between Discrete Events in Fixed Time |
Version: | 1.0.1 |
Date: | 2021-12-28 |
Maintainer: | Kristian Hovde Liland <kristian.liland@nmbu.no> |
Description: | Distribution functions and test for over-representation of short distances in the Liland distribution. Simulation functions are included for comparison. |
License: | GPL-2 | GPL-3 [expanded from: GPL (≥ 2)] |
URL: | https://github.com/khliland/fixedTimeEvents/ |
BugReports: | https://github.com/khliland/fixedTimeEvents/issues/ |
Imports: | stats |
Suggests: | knitr, rmarkdown |
VignetteBuilder: | knitr |
RoxygenNote: | 7.1.1 |
NeedsCompilation: | no |
Packaged: | 2021-12-28 09:27:26 UTC; kristl |
Author: | Kristian Hovde Liland [aut, cre], Lars Snipen [ctb] |
Repository: | CRAN |
Date/Publication: | 2022-01-04 11:40:02 UTC |
Properties of the Liland distribution
Description
Calculates the mean and variance of the Liland distribution according to the number of trials and successes.
Usage
Liland(R, r)
Arguments
R |
number of trials. |
r |
number of successes. |
Value
Returns a named vector containing the mean and variance of the Liland distribution.
Author(s)
Kristian Hovde Liland
References
Liland, KH & Snipen, L, FixedTimeEvents: An R package for the distribution of distances between discrete events in fixed time, SoftwareX, in press.
See Also
dLiland
, Liland.test
, simLiland
Examples
Liland(R = 1949, r = 162)
A test for over represented short distances in the Liland distribution.
Description
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.
Usage
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)
Arguments
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). |
Value
Liland.test
returns a named vector of P-values with class Ltest
. The other methods only print.
References
Liland, KH & Snipen, L, FixedTimeEvents: An R package for the distribution of distances between discrete events in fixed time, SoftwareX 5 (2016).
See Also
Examples
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')
Translation of values from NA (not available) to NaN (not a number)
Description
Exchanges all occurrences of NA in a vector with NaN. A warning is issued when NAs or NaNs are found.
Usage
NA2NaN(k)
Arguments
k |
numerical vector possibly containig NAs. |
Value
Returns a vector where possible NAs have been changed to NaNs.
Author(s)
Kristian Hovde Liland
See Also
dLiland
, Liland
, Liland.test
, simLiland
Examples
NA2NaN( c(0, 1, NA, NaN))
NA2NaN( c(0, 1, 2, NaN))
NA2NaN( c(0, 1, NA, 100))
NA2NaN( c(0, 1, 2, 100))
The distribution of distances between discrete events in fixed time/space (the Liland distribution)
Description
Density, distribution function, quantile function and random generation
for the Liland distribution with R
trials and r
successes.
Usage
dLiland(x, R, r, warn = FALSE)
pLiland(q, R, r, lower.tail = TRUE, warn = FALSE)
qLiland(p, R, r)
rLiland(n, R, r)
Arguments
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. |
Details
The Liland distribution has probability mass
f(X=x;R,r) =
\frac{{R-x \choose r-1}}{{R \choose r}}
where x
is the distance between consecutive successes, R
is the number of trials and r
is the number of successes.
Value
dLiland
gives the probability mass, pLiland
gives the distribution
function, qLiland
gives the quantile function, and rLiland
generates
random Liland values.
Author(s)
Kristian Hovde Liland
References
Liland, KH & Snipen, L, FixedTimeEvents: An R package for the distribution of distances between discrete events in fixed time, SoftwareX 5 (2016).
See Also
Liland
, Liland.test
, simLiland
Examples
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)
Approximated logarithm of factorials
Description
Stirling's 2nd order approximation of the logarithm of a factorial.
Usage
facL(n)
Arguments
n |
vector of integers for which to compute the logarithmic factorial. |
Value
The logarithm of the factorial.
Author(s)
Kristian Hovde Liland
References
Liland, KH & Snipen, L, FixedTimeEvents: An R package for the distribution of distances between discrete events in fixed time, SoftwareX 5 (2016).
See Also
dLiland
, Liland
, Liland.test
, simLiland
Examples
# 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)
Random Bernoulli trials for Liland distributed mean numbers.
Description
r successes are drawn from R trials. This is repeated n times to produce a random vector of mean Liland distributed numbers.
Usage
rrLiland(n, R, r)
Arguments
n |
number of repeated samples. |
R |
number of Bernoulli trials. |
r |
number of successes per sample. |
Value
Vector of mean distance between successful events.
Author(s)
Kristian Hovde Liland
References
Liland, KH & Snipen, L, FixedTimeEvents: An R package for the distribution of distances between discrete events in fixed time, SoftwareX 5 (2016).
See Also
dLiland
, Liland
, Liland.test
, simLiland
Examples
mdist <- rrLiland(1000, 25, 7)
plot(density(mdist))
Simulations for the Liland distribution.
Description
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.
Usage
simLiland(S, R, r)
simLiland2(S, R, r)
simLilandMu(S, R, r)
Arguments
S |
number of samples. |
R |
number of trials or denominator of Bernoulli probability. |
r |
number of successes or numerator of Bernoulli probablity. |
Value
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.
Author(s)
Kristian Hovde Liland
References
Liland, KH & Snipen, L, FixedTimeEvents: An R package for the distribution of distances between discrete events in fixed time, SoftwareX 5 (2016).
See Also
Examples
simLiland(1000,20,10)
sl <- simLiland2(1000,20,10)
sl$counts[sl$ms]/1000
plot(density(simLilandMu(1000,20,10)))
Validation of Liland distribution parameters.
Description
Checks if parameters conform to R >= 2, r >= 2 and r <= R.
Usage
validate.Rr(R, r)
Arguments
R |
number of Bernoulli trials. |
r |
number of successes. |
Value
No return, only testing.
Author(s)
Kristian Hovde Liland
References
Liland, KH & Snipen, L, FixedTimeEvents: An R package for the distribution of distances between discrete events in fixed time, SoftwareX 5 (2016).
See Also
Examples
validate.Rr(20,10)
## Not run:
# r>R results in an error.
validate.Rr(20,30)
## End(Not run)