Title: | Maximum Likelihood Analysis of Circular Data |
---|---|
Description: | A series of wrapper functions to implement the 10 maximum likelihood models of animal orientation described by Schnute and Groot (1992) <DOI:10.1016/S0003-3472(05)80068-5>. The functions also include the ability to use different optimizer methods and calculate various model selection metrics (i.e., AIC, AICc, BIC). The ability to perform variants of the Hermans-Rasson test and Pycke test is also included as described in Landler et al. (2019) <DOI:10.1186/s12898-019-0246-8>. The latest version also includes a new method to calculate circular-circular and circular-linear distance correlations. |
Authors: | Robert Fitak [aut, cre], Sönke Johnsen [aut] |
Maintainer: | Robert Fitak <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.3.0 |
Built: | 2025-02-12 03:09:58 UTC |
Source: | https://github.com/cran/CircMLE |
Make sure data is in the right format. Datasets are coerced into class 'circular' of type = angles, units = radians, and modulo = 2pi. It is recommended to set these atributes ahead of time.
check_data(data)
check_data(data)
data |
A vector, class 'circular' is recommended but not required |
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3, control.circular = list(units = "degrees")) check_data(testdata)
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3, control.circular = list(units = "degrees")) check_data(testdata)
Calculate the 95% confidence interval for estimated model parameters
ci_circmle(circmle, model)
ci_circmle(circmle, model)
circmle |
A list consisting of the output from function 'circ_mle' |
model |
character string indicating the model to be used to estimate parameter uncertainty. Must be one of c("M2A", "M2B", "M2C", "M3A", "M3B", "M4A", "M4B", "M5A", "M5B"). Default = the $bestmodel from the circmle object. |
A data frame with a column for the parameter name, the maximum likelihood estimate (MLE), standard error (SE), and 95% confidence interval (CI) for each estimated model parameter.
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) fit <- circ_mle(testdata) ci_circmle(fit)
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) fit <- circ_mle(testdata) ci_circmle(fit)
Run all 10 maximum likelihood models of circular orientation
circ_mle( data, criterion = "AIC", nchains = 5, BadStart = 10^9, niter = 5000, method = "BFGS", lambda.min = 0.25, q.diff, exclude = NULL )
circ_mle( data, criterion = "AIC", nchains = 5, BadStart = 10^9, niter = 5000, method = "BFGS", lambda.min = 0.25, q.diff, exclude = NULL )
data |
A vector of class 'circular' |
criterion |
chose from either "AIC", "AICc", or "BIC" for the model comparison information criterion. (default = "AIC") |
nchains |
A positive integer indicating the number of chains to run. Only the chain with the lowest log likelihood is returned (default = 5) |
BadStart |
An integer to replace the log likelihood when starting parameters of the optimizer fall outside the preset bounds. This is usually set to a large number. Can also be set to Inf, but will result in an error if a method other than "Nelder-Mead" is chosen. (default = 10^9) |
niter |
The maximum number of iterations for the optimizing algorithm. Equivalent to the 'maxit' control parameter of the optim() function. See ?optim for more details. (default = 5000) |
method |
A character string indicating the optimizing algorithm to use. Either "BFGS" or "Nelder-Mead" are recommended. See ?optim for more details. (default = "BFGS") |
lambda.min |
The minimum proportional size of the first distribution. Must be between 0 and 1. (default = 0.25) |
q.diff |
The minimum difference (in radians) in preferred direction for bimodal models. Must be set between 0 and pi. (default = pi/4) |
exclude |
A character vector of the models to be excluded from the calculations. (The default is to include all 10 models). For example, exclude = c("M1", "M3A", "M5B"). |
A list with 4 elements:
$results: A data frame consisting of a row for each model (rownames) with the columns: 1 = number of free parameters, 2 = mu1, 3 = kappa1, 4 = lamda, 5 = mu2, 6 = kappa2, 7 = negative log likelihood, 8 = Counts.function, 9 = Counts.Gradient, 10 = convergence, 11 = message, 12 = AIC, 13 = AICc, 14 = BIC, 15 = delta AIC, 16 = delta AICc, 17 = delta BIC, 18 = relative likelihoods of criterion chosen, 19 = model weights (probabilities) for criterion chosen, 20 = evidence ratios for the best model selected by the criterion. See ?optim for details on columns 8-11.
$bestmodel: The best model according to the criterion chosen
$rt: A two-element vector giving the test statistic and p-value for the Rayleigh Test
$hessians: A list with each element containing the hessian matrix for each model. Used for calculating connfidence intervals of parameters.
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) circ_mle(testdata)
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) circ_mle(testdata)
Perform a distance correlation between circular datasets or between circular and linear datasets.
dcor.circular(x, y, method = "chord", type = "c-c", ...)
dcor.circular(x, y, method = "chord", type = "c-c", ...)
x |
A vector of class 'circular', or numeric vector of angles measured in radians |
y |
A vector of class 'circular', numeric vector of angles measured in radians, or numeric vector |
method |
the distance measure to be used. This must be one of the following functions: ‘"angularseparation"’, ‘"chord"’, '"geodesic"’, or '"circ.range"' (default = "chord"). see ?dist.circular for additional details. |
type |
if ‘type == "c-c"’ then perform a circular-circular distance corellation, else if ‘type == "c-l"’ then perform a circular-linear distance corellation (default = "c-c"). |
... |
additional parameters passed to the dcor.test function |
Same as from the dcor.test
function:
a list with class ‘htest’containing
method: description of test
statistic: observed value of the test statistic
estimate: dCov(x,y) or dCor(x,y)
estimates: a vector: [dCov(x,y), dCor(x,y), dVar(x), dVar(y)]
replicates: replicates of the test statistic
p.value: approximate p-value of the test
n: sample size
data.name: description of data
dcor
dcov
DCOR
dcor.test
dist.circular
# Circular-circular distance corellation x <- circular::rvonmises(n = 50, mu = circular::circular(0), kappa = 3) y <- x + circular::rvonmises(n = 50, mu = circular::circular(pi), kappa = 10) dcor.circular(x, y) # Run permutation test with 9999 iterations dcor.circular(x, y, R = 9999) # Circular-linear distance corellation x <- circular::rvonmises(n = 50, mu = circular::circular(0), kappa = 3) y <- as.numeric(x) + rnorm(50, mean = 5, sd = 2) dcor.circular(x, y, type = "c-l", R = 9999)
# Circular-circular distance corellation x <- circular::rvonmises(n = 50, mu = circular::circular(0), kappa = 3) y <- x + circular::rvonmises(n = 50, mu = circular::circular(pi), kappa = 10) dcor.circular(x, y) # Run permutation test with 9999 iterations dcor.circular(x, y, R = 9999) # Circular-linear distance corellation x <- circular::rvonmises(n = 50, mu = circular::circular(0), kappa = 3) y <- as.numeric(x) + rnorm(50, mean = 5, sd = 2) dcor.circular(x, y, type = "c-l", R = 9999)
Perform variants of the Hermans-Rasson test.
HR_test(data, original = F, iter = 9999)
HR_test(data, original = F, iter = 9999)
data |
A vector of class 'circular', or numeric vector of angles measured in radians |
original |
A logical of whether or not to run the original version of the Hermans-Rasson test or the newer version described in Landler et al. (2019) doi: 10.1186/s12898-019-0246-8 (default = F) |
iter |
The number of bootstrap replicates to perform in order to estimate the p-value of the test. (default = 9999) |
A numeric vector of the test statistic (T) and associated p-value
testdata = circular::rvonmises(20, mu = circular::circular(pi), kappa = 3) HR_test(testdata, iter = 999)
testdata = circular::rvonmises(20, mu = circular::circular(pi), kappa = 3) HR_test(testdata, iter = 999)
Statistically test nested models for the rejection of the null model in favor of the alternative model.
lr_test(data, null_model, alt_model)
lr_test(data, null_model, alt_model)
data |
A vector of class 'circular' |
null_model |
character string indicating the null model to be used. Must be one of c("M1", "M2A", "M2B", "M2C", "M3A", "M3B", "M4A", "M4B", "M5A", "M5B"). |
alt_model |
character string indicating the alternative model to be used. Must be one of c("M1", "M2A", "M2B", "M2C", "M3A", "M3B", "M4A", "M4B", "M5A", "M5B"). |
A list with elements:
$null_model: Vector with the model name and number of free parameters
$alt_model: Vector with the model name and number of free parameters
$lr: likelihood ratio test statistic 2 * (-log(L1) - -log(L2))
$df: degrees of freedom (difference in number of parameters between models)
$p_val: probability of rejecting null model in favor of alternative model due to chance (e.g, if <0.05, data favors alternative model).
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) lr_test(testdata, "M1", "M2A")
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) lr_test(testdata, "M1", "M2A")
Run Maximum likelihood estimation for model M1.
M1(data)
M1(data)
data |
A vector of class 'circular' |
A list with the elements:
$lik: The negative log likelihood of data for model M1
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M1(testdata)
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M1(testdata)
Run Maximum likelihood estimation for model M2A.
M2A(data, BadStart, nchains, method, niter)
M2A(data, BadStart, nchains, method, niter)
data |
A vector of class 'circular' |
BadStart |
An integer to replace the log likelihood when starting parameters of the optimizer fall outside the preset bounds. This is usually set to a large number. Can also be set to Inf, but will result in an error if a method other than "Nelder-Mead" is chosen. (default = 10^9) |
nchains |
A positive integer indicating the number of chains to run. Only the chain with the lowest log likelihood is returned (default = 5) |
method |
A character string indicating the optimizing algorithm to use. Either "BFGS" or "Nelder-Mead" are recommended. See ?optim for more details. (default = "BFGS") |
niter |
The maximum number of iterations for the optimizing algorithm. Equivalent to the 'maxit' control parameter of the optim() function. See ?optim for more details. (default = 5000) |
A list with elements (same as for function optim()):
$par: Vector with the optimized mean angle (mu1) and concentration parameter (kappa1)
$lik: The negative log likelihood
$counts: A two-element integer vector giving the number of calls to ‘fn’ and ‘gr’ respectively. See ?optim() for details.
$convergence: An integer code. ‘0’ indicates successful completion (which is always the case for ‘"SANN"’ and ‘"Brent"’). Possible error codes are:
‘1’ indicates that the iteration limit ‘maxit’ had been reached.
‘10’ indicates degeneracy of the Nelder-Mead simplex.
‘51’ indicates a warning from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
‘52’ indicates an error from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
$message: A character string giving any additional information returned by the optimizer, or ‘NULL’.
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M2A(testdata)
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M2A(testdata)
Run Maximum likelihood estimation for model M2B.
M2B(data, BadStart, nchains, method, niter)
M2B(data, BadStart, nchains, method, niter)
data |
A vector of class 'circular' |
BadStart |
An integer to replace the log likelihood when starting parameters of the optimizer fall outside the preset bounds. This is usually set to a large number. Can also be set to Inf, but will result in an error if a method other than "Nelder-Mead" is chosen. (default = 10^9) |
nchains |
A positive integer indicating the number of chains to run. Only the chain with the lowest log likelihood is returned (default = 5) |
method |
A character string indicating the optimizing algorithm to use. Either "BFGS" or "Nelder-Mead" are recommended. See ?optim for more details. (default = "BFGS") |
niter |
The maximum number of iterations for the optimizing algorithm. Equivalent to the 'maxit' control parameter of the optim() function. See ?optim for more details. (default = 5000) |
A list with elements (same as for function optim()):
$par: Vector with the optimized mean angle (mu1) and concentration parameter (kappa1)
$lik: The negative log likelihood
$counts: A two-element integer vector giving the number of calls to ‘fn’ and ‘gr’ respectively. See ?optim() for details.
$convergence: An integer code. ‘0’ indicates successful completion (which is always the case for ‘"SANN"’ and ‘"Brent"’). Possible error codes are:
‘1’ indicates that the iteration limit ‘maxit’ had been reached.
‘10’ indicates degeneracy of the Nelder-Mead simplex.
‘51’ indicates a warning from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
‘52’ indicates an error from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
$message: A character string giving any additional information returned by the optimizer, or ‘NULL’.
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M2B(testdata)
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M2B(testdata)
Run Maximum likelihood estimation for model M2C.
M2C(data, BadStart, nchains, method, niter, lambda.min)
M2C(data, BadStart, nchains, method, niter, lambda.min)
data |
A vector of class 'circular' |
BadStart |
An integer to replace the log likelihood when starting parameters of the optimizer fall outside the preset bounds. This is usually set to a large number. Can also be set to Inf, but will result in an error if a method other than "Nelder-Mead" is chosen. (default = 10^9) |
nchains |
A positive integer indicating the number of chains to run. Only the chain with the lowest log likelihood is returned (default = 5) |
method |
A character string indicating the optimizing algorithm to use. Either "BFGS" or "Nelder-Mead" are recommended. See ?optim for more details. (default = "BFGS") |
niter |
The maximum number of iterations for the optimizing algorithm. Equivalent to the 'maxit' control parameter of the optim() function. See ?optim for more details. (default = 5000) |
lambda.min |
The minimum proportional size of the first distribution. Must be between 0 and 1. (default = 0.25) |
A list with elements (same as for function optim()):
$par: Vector with the optimized mean angle (mu1), concentration parameter (kappa1) and proportional size (lambda) of the first distribution (mu1 and kappa1).
$lik: The negative log likelihood
$counts: A two-element integer vector giving the number of calls to ‘fn’ and ‘gr’ respectively. See ?optim() for details.
$convergence: An integer code. ‘0’ indicates successful completion (which is always the case for ‘"SANN"’ and ‘"Brent"’). Possible error codes are:
‘1’ indicates that the iteration limit ‘maxit’ had been reached.
‘10’ indicates degeneracy of the Nelder-Mead simplex.
‘51’ indicates a warning from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
‘52’ indicates an error from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
$message: A character string giving any additional information returned by the optimizer, or ‘NULL’.
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M2C(testdata)
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M2C(testdata)
Run Maximum likelihood estimation for model M3A.
M3A(data, BadStart, nchains, method, niter)
M3A(data, BadStart, nchains, method, niter)
data |
A vector of class 'circular' |
BadStart |
An integer to replace the log likelihood when starting parameters of the optimizer fall outside the preset bounds. This is usually set to a large number. Can also be set to Inf, but will result in an error if a method other than "Nelder-Mead" is chosen. (default = 10^9) |
nchains |
A positive integer indicating the number of chains to run. Only the chain with the lowest log likelihood is returned (default = 5) |
method |
A character string indicating the optimizing algorithm to use. Either "BFGS" or "Nelder-Mead" are recommended. See ?optim for more details. (default = "BFGS") |
niter |
The maximum number of iterations for the optimizing algorithm. Equivalent to the 'maxit' control parameter of the optim() function. See ?optim for more details. (default = 5000) |
A list with elements (same as for function optim()):
$par: Vector with the optimized mean angle (mu1) and concentration parameter (kappa1).
$lik: The negative log likelihood
$counts: A two-element integer vector giving the number of calls to ‘fn’ and ‘gr’ respectively. See ?optim() for details.
$convergence: An integer code. ‘0’ indicates successful completion (which is always the case for ‘"SANN"’ and ‘"Brent"’). Possible error codes are:
‘1’ indicates that the iteration limit ‘maxit’ had been reached.
‘10’ indicates degeneracy of the Nelder-Mead simplex.
‘51’ indicates a warning from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
‘52’ indicates an error from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
$message: A character string giving any additional information returned by the optimizer, or ‘NULL’.
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M3A(testdata)
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M3A(testdata)
Run Maximum likelihood estimation for model M3B.
M3B(data, BadStart, nchains, method, niter)
M3B(data, BadStart, nchains, method, niter)
data |
A vector of class 'circular' |
BadStart |
An integer to replace the log likelihood when starting parameters of the optimizer fall outside the preset bounds. This is usually set to a large number. Can also be set to Inf, but will result in an error if a method other than "Nelder-Mead" is chosen. (default = 10^9) |
nchains |
A positive integer indicating the number of chains to run. Only the chain with the lowest log likelihood is returned (default = 5) |
method |
A character string indicating the optimizing algorithm to use. Either "BFGS" or "Nelder-Mead" are recommended. See ?optim for more details. (default = "BFGS") |
niter |
The maximum number of iterations for the optimizing algorithm. Equivalent to the 'maxit' control parameter of the optim() function. See ?optim for more details. (default = 5000) |
A list with elements (same as for function optim()):
$par: Vector with the optimized mean angle (mu1), concentration parameter (kappa1), and concentration parameter (kappa2).
$lik: The negative log likelihood
$counts: A two-element integer vector giving the number of calls to ‘fn’ and ‘gr’ respectively. See ?optim() for details.
$convergence: An integer code. ‘0’ indicates successful completion (which is always the case for ‘"SANN"’ and ‘"Brent"’). Possible error codes are:
‘1’ indicates that the iteration limit ‘maxit’ had been reached.
‘10’ indicates degeneracy of the Nelder-Mead simplex.
‘51’ indicates a warning from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
‘52’ indicates an error from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
$message: A character string giving any additional information returned by the optimizer, or ‘NULL’.
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M3B(testdata)
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M3B(testdata)
Run Maximum likelihood estimation for model M4A.
M4A(data, BadStart, nchains, method, niter, lambda.min)
M4A(data, BadStart, nchains, method, niter, lambda.min)
data |
A vector of class 'circular' |
BadStart |
An integer to replace the log likelihood when starting parameters of the optimizer fall outside the preset bounds. This is usually set to a large number. Can also be set to Inf, but will result in an error if a method other than "Nelder-Mead" is chosen. (default = 10^9) |
nchains |
A positive integer indicating the number of chains to run. Only the chain with the lowest log likelihood is returned (default = 5) |
method |
A character string indicating the optimizing algorithm to use. Either "BFGS" or "Nelder-Mead" are recommended. See ?optim for more details. (default = "BFGS") |
niter |
The maximum number of iterations for the optimizing algorithm. Equivalent to the 'maxit' control parameter of the optim() function. See ?optim for more details. (default = 5000) |
lambda.min |
The minimum proportional size of the first distribution. Must be between 0 and 1. (default = 0.25) |
A list with elements (same as for function optim()):
$par: Vector with the optimized mean angle (mu1), concentration parameter (kappa1), and proportional size (lambda) of the first distribution.
$lik: The negative log likelihood
$counts: A two-element integer vector giving the number of calls to ‘fn’ and ‘gr’ respectively. See ?optim() for details.
$convergence: An integer code. ‘0’ indicates successful completion (which is always the case for ‘"SANN"’ and ‘"Brent"’). Possible error codes are:
‘1’ indicates that the iteration limit ‘maxit’ had been reached.
‘10’ indicates degeneracy of the Nelder-Mead simplex.
‘51’ indicates a warning from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
‘52’ indicates an error from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
$message: A character string giving any additional information returned by the optimizer, or ‘NULL’.
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M4A(testdata)
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M4A(testdata)
Run Maximum likelihood estimation for model M4B.
M4B(data, BadStart, nchains, method, niter, lambda.min)
M4B(data, BadStart, nchains, method, niter, lambda.min)
data |
A vector of class 'circular' |
BadStart |
An integer to replace the log likelihood when starting parameters of the optimizer fall outside the preset bounds. This is usually set to a large number. Can also be set to Inf, but will result in an error if a method other than "Nelder-Mead" is chosen. (default = 10^9) |
nchains |
A positive integer indicating the number of chains to run. Only the chain with the lowest log likelihood is returned (default = 5) |
method |
A character string indicating the optimizing algorithm to use. Either "BFGS" or "Nelder-Mead" are recommended. See ?optim for more details. (default = "BFGS") |
niter |
The maximum number of iterations for the optimizing algorithm. Equivalent to the 'maxit' control parameter of the optim() function. See ?optim for more details. (default = 5000) |
lambda.min |
The minimum proportional size of the first distribution. Must be between 0 and 1. (default = 0.25) |
A list with elements (same as for function optim()):
$par: Vector with the optimized mean angle (mu1), concentration parameter (kappa1), concentration parameter (kappa2), and proportional size (lambda) of the first distribution.
$lik: The negative log likelihood
$counts: A two-element integer vector giving the number of calls to ‘fn’ and ‘gr’ respectively. See ?optim() for details.
$convergence: An integer code. ‘0’ indicates successful completion (which is always the case for ‘"SANN"’ and ‘"Brent"’). Possible error codes are:
‘1’ indicates that the iteration limit ‘maxit’ had been reached.
‘10’ indicates degeneracy of the Nelder-Mead simplex.
‘51’ indicates a warning from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
‘52’ indicates an error from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
$message: A character string giving any additional information returned by the optimizer, or ‘NULL’.
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M4B(testdata)
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M4B(testdata)
Run Maximum likelihood estimation for model M5A.
M5A(data, BadStart, nchains, method, niter, lambda.min, q.diff)
M5A(data, BadStart, nchains, method, niter, lambda.min, q.diff)
data |
A vector of class 'circular' |
BadStart |
An integer to replace the log likelihood when starting parameters of the optimizer fall outside the preset bounds. This is usually set to a large number. Can also be set to Inf, but will result in an error if a method other than "Nelder-Mead" is chosen. (default = 10^9) |
nchains |
A positive integer indicating the number of chains to run. Only the chain with the lowest log likelihood is returned (default = 5) |
method |
A character string indicating the optimizing algorithm to use. Either "BFGS" or "Nelder-Mead" are recommended. See ?optim for more details. (default = "BFGS") |
niter |
The maximum number of iterations for the optimizing algorithm. Equivalent to the 'maxit' control parameter of the optim() function. See ?optim for more details. (default = 5000) |
lambda.min |
The minimum proportional size of the first distribution. Must be between 0 and 1. (default = 0.25) |
q.diff |
The minimum difference (in radians) in preferred direction for bimodal models. Must be set between 0 and pi. (default = pi/4) |
A list with elements (same as for function optim()):
$par: Vector with the optimized mean angle (mu1), concentration parameter (kappa1), mean angle (mu2), and proportional size (lambda) of the first distribution.
$lik: The negative log likelihood
$counts: A two-element integer vector giving the number of calls to ‘fn’ and ‘gr’ respectively. See ?optim() for details.
$convergence: An integer code. ‘0’ indicates successful completion (which is always the case for ‘"SANN"’ and ‘"Brent"’). Possible error codes are:
‘1’ indicates that the iteration limit ‘maxit’ had been reached.
‘10’ indicates degeneracy of the Nelder-Mead simplex.
‘51’ indicates a warning from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
‘52’ indicates an error from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
$message: A character string giving any additional information returned by the optimizer, or ‘NULL’.
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M5A(testdata)
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M5A(testdata)
Run Maximum likelihood estimation for model M5B.
M5B(data, BadStart, nchains, method, niter, lambda.min, q.diff)
M5B(data, BadStart, nchains, method, niter, lambda.min, q.diff)
data |
A vector of class 'circular' |
BadStart |
An integer to replace the log likelihood when starting parameters of the optimizer fall outside the preset bounds. This is usually set to a large number. Can also be set to Inf, but will result in an error if a method other than "Nelder-Mead" is chosen. (default = 10^9) |
nchains |
A positive integer indicating the number of chains to run. Only the chain with the lowest log likelihood is returned (default = 5) |
method |
A character string indicating the optimizing algorithm to use. Either "BFGS" or "Nelder-Mead" are recommended. See ?optim for more details. (default = "BFGS") |
niter |
The maximum number of iterations for the optimizing algorithm. Equivalent to the 'maxit' control parameter of the optim() function. See ?optim for more details. (default = 5000) |
lambda.min |
The minimum proportional size of the first distribution. Must be between 0 and 1. (default = 0.25) |
q.diff |
The minimum difference (in radians) in preferred direction for bimodal models. Must be set between 0 and pi. (default = pi/4) |
A list with elements (same as for function optim()):
$par: Vector with the optimized mean angle (mu1), concentration parameter (kappa1), mean angle (mu2), concentration parameter (kappa2), and proportional size (lambda) of the first distribution.
$lik: The negative log likelihood
$counts: A two-element integer vector giving the number of calls to ‘fn’ and ‘gr’ respectively. See ?optim() for details.
$convergence: An integer code. ‘0’ indicates successful completion (which is always the case for ‘"SANN"’ and ‘"Brent"’). Possible error codes are:
‘1’ indicates that the iteration limit ‘maxit’ had been reached.
‘10’ indicates degeneracy of the Nelder-Mead simplex.
‘51’ indicates a warning from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
‘52’ indicates an error from the ‘"L-BFGS-B"’ method; see component ‘message’ for further details.
$message: A character string giving any additional information returned by the optimizer, or ‘NULL’.
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M5B(testdata)
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) M5B(testdata)
Plot the observed data and specific model from circ_mle output
plot_circMLE(data, table, model, bins, shrink, col, lwd, lty)
plot_circMLE(data, table, model, bins, shrink, col, lwd, lty)
data |
A vector of class 'circular' |
table |
A list containing the output from the circ_mle function |
model |
The name of the model to be plotted. (default = first model of "table") |
bins |
The number of bins for the circular histogram. (defualt = 18) |
shrink |
The value by which to shrink the size of the plotted circle. Larger numbers shrink the circle, smaller numbers expand the circle. (default = 1.5) |
col |
Vector of colors used for plotting, up to four colors can be specified. The order is: histogram color, mean vector color, model density color, predicted mean direction(s) color(s). (default = c("grey", "red", "black", "black")) |
lwd |
Vector of line weights used for plotting, up to 3 weights can be specified. The order is: mean vector weight, model density weight, predicted mean direction(s) weight(s). (default = c(2, 2, 2)) |
lty |
Vector of line weights used for plotting, up to 3 weights can be specified. The order is: mean vector weight, model density weight, predicted mean direction(s) weight(s). (default = c("solid", "dashed", "dashed")) |
A plot is returned to the default image device.
In the resulting plot, the observed vector length is equal to rho (vector strength). However, the predicted direction(s) from the model are drawn with vector length of 1. Also, if the model "M1" is selected, by definition no predicted direction is plotted.
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) out = circ_mle(testdata) plot_circMLE(testdata, out) plot_circMLE(testdata, out, model = "M4A")
testdata = circular::rvonmises(100, mu = circular::circular(pi), kappa = 3) out = circ_mle(testdata) plot_circMLE(testdata, out) plot_circMLE(testdata, out, model = "M4A")
Perform the Pycke test.
pycke_test(data, iter = 9999)
pycke_test(data, iter = 9999)
data |
A vector of class 'circular', or numeric vector of angles measured in radians |
iter |
The number of bootstrap replicates to perform in order to estimate the p-value of the test. (default = 9999) |
A numeric vector of the test statistic (T) and associated p-value
testdata = circular::rvonmises(20, mu = circular::circular(pi), kappa = 3) pycke_test(testdata, iter = 999)
testdata = circular::rvonmises(20, mu = circular::circular(pi), kappa = 3) pycke_test(testdata, iter = 999)