I am using the package circular in R to fit a von Mises distribution to a set of data:
Mises <- mle.vonmises(x = angle, mu = NULL, kappa = NULL, bias = FALSE, control.circular = list())
The results are from the class circular. Is there a way to extract both mu and kappa to have them as numerics? I need to do that many times (I guess using group_by()
), so writing down manually the displayed values of mu and kappa is not an option.
Thanks for the help!
CodePudding user response:
The output of mle.vonmises
is a list
.
> str(Mises)
List of 8
$ call : language mle.vonmises(x = x)
$ mu : 'circular' num -0.0264 # it is a numeric value
..- attr(*, "circularp")=List of 6
.. ..$ type : chr "angles"
.. ..$ units : chr "radians"
.. ..$ template: chr "none"
.. ..$ modulo : chr "asis"
.. ..$ zero : num 0
.. ..$ rotation: chr "counter"
$ kappa : num 5.21
$ se.mu : num 0.0654
$ se.kappa : num 0.973
$ est.mu : num 1
$ est.kappa: num 1
$ bias : logi FALSE
- attr(*, "class")= chr "mle.vonmises"
We can use standard extractors to extract the list
elements ie. $
or [[
. Regarding conversion to numeric
, the mu
is already numeric
class.
> class(Mises$mu)
[1] "circular" "numeric"
It also include some attr
ibutes with an additional class circular
built on top of numeric
which can be removed by either wrapping with as.numeric
or as.vector
or set the attributes to NULL
as.numeric(Mises$mu)
#[1] -0.02639894
Mises$kappa
[1] 5.214254
data
library(circular)
x <- rvonmises(n=50, mu=circular(0), kappa=5)
Mises <- mle.vonmises(x)