Title: | Bayesian Projected Normal Regression Models for Circular Data |
---|---|
Description: | Fitting Bayesian multiple and mixed-effect regression models for circular data based on the projected normal distribution. Both continuous and categorical predictors can be included. Sampling from the posterior is performed via an MCMC algorithm. Posterior descriptives of all parameters, model fit statistics and Bayes factors for hypothesis tests for inequality constrained hypotheses are provided. See Cremers, Mulder & Klugkist (2018) <doi:10.1111/bmsp.12108> and Nuñez-Antonio & Guttiérez-Peña (2014) <doi:10.1016/j.csda.2012.07.025>. |
Authors: | Jolien Cremers [aut, cre] |
Maintainer: | Jolien Cremers <[email protected]> |
License: | GPL-3 |
Version: | 2.0.3 |
Built: | 2024-11-11 07:03:31 UTC |
Source: | CRAN |
BF
gives Bayes factors for inequality constrained hypotheses on
circular mean differences.
BFc(object, hypothesis, type = "anchor")
BFc(object, hypothesis, type = "anchor")
object |
an object used to select a method. |
hypothesis |
the inequality constrained hypothesis to test. |
type |
type of hypothesis to test |
the methods BFc.bpnr and BFc.bpnme have their own help page.
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) BFc(fit.Motor, hypothesis = "Condsemi.imp < Condimp")
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) BFc(fit.Motor, hypothesis = "Condsemi.imp < Condimp")
Outputs Bayes Factors for inequality constrained hypotheses on the circular differences between several levels of a categorical variable and the baseline.
## S3 method for class 'bpnme' BFc(object, hypothesis, type = "anchor")
## S3 method for class 'bpnme' BFc(object, hypothesis, type = "anchor")
object |
a |
hypothesis |
the inequality constrained hypothesis to test. |
type |
type of hypothesis to test |
Bayes Factors for inequality constrained hypotheses on mean differences.
library(bpnreg) fit.Maps <- bpnme(pred.I = Error.rad ~ Maze + Trial.type + L.c + (1|Subject), data = Maps, its = 100, burn = 1, n.lag = 1) BFc(fit.Maps, hypothesis = "Maze1 < Trial.type1")
library(bpnreg) fit.Maps <- bpnme(pred.I = Error.rad ~ Maze + Trial.type + L.c + (1|Subject), data = Maps, its = 100, burn = 1, n.lag = 1) BFc(fit.Maps, hypothesis = "Maze1 < Trial.type1")
Outputs Bayes Factors for the circular differences between several levels of a categorical variable and the baseline.
## S3 method for class 'bpnr' BFc(object, hypothesis, type = "anchor")
## S3 method for class 'bpnr' BFc(object, hypothesis, type = "anchor")
object |
a |
hypothesis |
the inequality constrained hypothesis to test. |
type |
type of hypothesis to test |
Bayes Factors for inequality constrained hypotheses on mean differences.
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) BFc(fit.Motor, hypothesis = "Condsemi.imp < Condimp")
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) BFc(fit.Motor, hypothesis = "Condsemi.imp < Condimp")
This function fits a Bayesian circular mixed-effects model based on the projected normal distribution.
bpnme( pred.I, data, pred.II = pred.I, its = 1000, burn = 1, n.lag = 1, seed = NULL )
bpnme( pred.I, data, pred.II = pred.I, its = 1000, burn = 1, n.lag = 1, seed = NULL )
pred.I |
model equation for effects of component 1. |
data |
the dataframe used for analysis. |
pred.II |
model equation for effects of component 2. |
its |
output iterations of the MCMC sampler. |
burn |
number of burn-in iterations. |
n.lag |
amount of lag for the iterations and burn-in. |
seed |
user-specified random seed. |
Because the model is based on the projected normal distribution, a
model equation has to be given for the fixed and random effects of the two
components. By default the model equation of the second component
pred.II
is set to be equal to that of the first component. Note that
the circular outcome needs to be measured in radians on a scale from 0 to
2. For more information about the projected normal distribution
see Presnell, Morrisson & Littell (1998). The model can handle at most one
grouping factor.
A tutorial on how to use this function can be found in Cremers & Klugkist (2018). More details on the sampling algorithm and interpretation of the coefficients from the model can be found in Nuñez-Antonio & Guttiérrez-Peña (2014) and Cremers, Pennings, Mainhard & Klugkist (2019). The uninformative priors for the fixed effect regression coefficients of the two components are set to N(0, 10000). Note that the model is only developed for models with a single nesting variable.
A bpnme
object, which can be further analyzed using the
associated functions traceplot.bpnme
,
BFc.bpnme
, coef_lin.bpnme
,
coef_circ.bpnme
, coef_ran.bpnme
,
fit.bpnme
and print.bpnme
.
A bpnr
object contains the following elements (some elements are not
returned if not applicable)
beta1
A matrix of posterior samples for the fixed effects coefficients for the first component.
beta2
A matrix of posterior samples for the fixed effects coefficients for the second component.
b1
An array of posterior samples for the random effects coefficients for the first component.
b2
An array of posterior samples for the random effects coefficients for the second component.
omega1
An array of posterior samples for the random effect variances of the first component.
omega2
An array of posterior samples for the random effect variances of the second component.
predictiva
A list containing the posterior density values for all timepoints of individuals in the dataset for all iterations. The rowsums of this matrix are the likelihood values for all iterations
circular.ri
A vector of posterior samples for the circular random intercepts.
N
Number of observed cases.
its
Number of output iterations.
n.lag
One in n.lag
iterations will
be saved as output iteration. Set lag to 1 to save all iterations
(default).
burn
Burn-in time for the MCMC sampler.
p1
Number of fixed effect parameters predicting the first component.
p2
Number of fixed effect parameters predicting the second component.
q1
Number of random effect parameters predicting the first component.
q2
Number of random effect parameters predicting the second component.
a.x
A matrix of
posterior samples for a.x
which describes the location of the
inflection point of the regression curve on the axis of the predictor.
a.c
A matrix of posterior samples for a.c
which
describes the location of the inflection point of the regression curve on
the axis of the circular outcome.
b.c
A matrix of posterior
samples for b.c
which describes the slope of the tangent line at the
inflection point.
SAM
A matrix of posterior samples for the circular regression slopes at the mean.
AS
A matrix of posterior samples for the average slopes of the circular regression.
SSDO
A matrix of posterior samples for the signed shortest distance to the origin.
circ.diff
A matrix of posterior samples for the circular difference found between levels of categorical variables and the intercept.
cRSnum
A vector of posterior samples of the circular random slope estimates for the continuous variables
cRScat
A vector of posterior samples of the circular random slope estimates for the categorical variables
cRS
A vector of posterior samples of the circular random slope estimates
cRI
A vector of posterior samples of the mean resultant length of the circular random intercept, a measure of concentration.
Call
The matched call.
lin.coef.I
The mean,
mode, standard deviation and 95
posterior density of the linear fixed effect coefficients for beta1
.
lin.coef.II
The mean, mode, standard deviation and 95
confidence interval of the highest posterior density of the linear fixed
effect coefficients for beta2
.
circ.coef
The mean, mode,
standard deviation and 95
density for a.x
, a.c
, SSDO
, and the circular fixed
effect coefficients b.c
, AS
, and SAM
circ.coef.cat
The mean, mode, standard deviation and 95 confidence interval of the highest posterior density the circular difference between levels of categorical variables and the intercept.
circ.coef.means
The mean, mode, standard deviation and 95 confidence interval of the highest posterior density of circular means of the categorical variables.
model.fit
A list of information criteria for assessment of model fit.
lin.res.varrand.I
The mean, mode, standard deviation and 95 variances of the random intercepts and slopes of component I.
lin.res.varrand.II
The mean, mode, standard deviation and 95 of component II.
circ.res.varrand
The mean, mode, standard deviation and 95 random intercepts and slopes.
mm
A list of information, model matrices, sample size, etc. on the specified model.
Cremers, J., Mainhard, M.T. & Klugkist, I. (2018). Assessing a Bayesian Embedding Approach to Circular Regression Models. Methodology, 14, 69-81.
Cremers, J. & Klugkist, I. (2018). One direction? A tutorial for circular data with examples in cognitive psychology. Frontiers in Psychology: Cognitive Science.
Cremers, J., Pennings, H.J.M., Mainhard, M.T. & Klugkist, I. (2019). Circular Modelling of Circumplex Measurements for Interpersonal Behavior. Assessment, Online First.
Nuñez-Antonio, G. & Gutiérrez-Peña, E. (2014). A Bayesian model for longitudinal circular data based on the projected normal distribution. Computational Statistics and Data Analysis, 71, 506-519.
Presnell, B., Morrison, S.P. & Littell, R.C. (1998). Projected multivariate linear models for directional data. Journal of the American Statistical Association, 93 (443), 1068 - 1077.
library(bpnreg) bpnme(Error.rad ~ Maze + Trial.type + (1|Subject), Maps, its = 100)
library(bpnreg) bpnme(Error.rad ~ Maze + Trial.type + (1|Subject), Maps, its = 100)
This function fits a Bayesian circular regression model based on the projected normal distribution.
bpnr( pred.I, data, pred.II = pred.I, its = 1000, burn = 1, n.lag = 1, seed = NULL )
bpnr( pred.I, data, pred.II = pred.I, its = 1000, burn = 1, n.lag = 1, seed = NULL )
pred.I |
model equation for effects of component 1. |
data |
the dataframe used for analysis. |
pred.II |
model equation for effects of component 2. |
its |
output iterations of the MCMC sampler. |
burn |
number of burn-in iterations. |
n.lag |
amount of lag for the iterations and burn-in. |
seed |
user-specified random seed. |
Because the model is based on the projected normal distribution, a
model equation has to be given for two components. By default the equation
of the second component pred.II
is set to be equal to that of the
first component. Note that the circular outcome needs to be measured in
radians on a scale from 0 to 2. For more information about the
projected normal distribution see Presnell, Morrisson & Littell (1998).
A tutorial on how to use this function can be found in Cremers & Klugkist (2018). More details on the sampling algorithm and interpretation of the coefficients from the model can be found in Cremers, Mulder & Klugkist (2018) and Cremers, Mainhard & Klugkist (2018). The uninformative priors for the regression coefficients of the two components are set to N(0, 10000).
A bpnr
object, which can be further analyzed using the
associated functions traceplot.bpnr
, BFc.bpnr
,
coef_lin.bpnr
, coef_circ.bpnr
,
fit.bpnr
and print.bpnr
.
A bpnr
object contains the following elements (some elements are not
returned if not applicable)
beta1
A matrix of posterior samples for the
coefficients beta1
of the first component.
beta2
A matrix
of posterior samples for the coefficients beta2
for the second
component.
Likelihood
A matrix containing the posterior density values for all individuals in the dataset for all iterations. The rowsums of this matrix are the likelihood values for all iterations
its
Number of output iterations.
n.lag
One in
n.lag
iterations will be saved as output iteration. Set lag to 1 to
save all iterations (default).
burn-in
Burn-in time for the MCMC sampler.
p1
Number of parameters predicting the first component.
p2
Number of parameters predicting the second component.
theta
The circular outcome vector measured in radians.
a.x
A matrix of posterior samples for a.x
which
describes the location of the inflection point of the regression curve on
the axis of the predictor.
a.c
A matrix of posterior samples
for a.c
which describes the location of the inflection point of the
regression curve on the axis of the circular outcome.
b.c
A
matrix of posterior samples for b.c
which describes the slope of the
tangent line at the inflection point.
SAM
A matrix of posterior samples for the circular regression slopes at the mean.
AS
A matrix of posterior samples for the average slopes of the circular regression.
SSDO
A matrix of posterior samples for the signed shortest distance to the origin.
circ.diff
A matrix of posterior samples for the circular difference between levels of categorical variables and the intercept.
Call
The matched call.
lin.coef.I
The mean, mode, standard deviation and 95
confidence interval of the highest posterior density of the linear
coefficients for beta1
.
lin.coef.II
The mean, mode,
standard deviation and 95
density of the linear coefficients for beta2
.
circ.coef
The mean, mode, standard deviation and 95
confidence interval of the highest posterior density for the a.x
,
a.c
, b.c
, AS
, SAM
and SSDO
of the
circular coefficients.
circ.coef.cat
The mean, mode, standard deviation and 95 density the circular difference between levels of categorical variables and the intercept.
circ.coef.means
The mean, mode, standard deviation and 95 circular means of the categorical variables.
model.fit
A list of information criteria for assessment of model fit.
mm
A list of information, model matrices, sample size, etc. on the specified model.
Cremers, J., Mulder, K.T. & Klugkist, I. (2018). Circular interpretation of regression coefficients. British Journal of Mathematical and Statistical Psychology, 71(1), 75-95.
Cremers, J., Mainhard, M.T. & Klugkist, I. (2018). Assessing a Bayesian Embedding Approach to Circular Regression Models. Methodology, 14, 69-81.
Cremers, J. & Klugkist, I. (2018). One direction? A tutorial for circular data with examples in cognitive psychology. Frontiers in Psychology: Cognitive Science.
Presnell, B., Morrison, S.P. & Littell, R.C. (1998). Projected multivariate linear models for directional data. Journal of the American Statistical Association, 93 (443), 1068 - 1077.
library(bpnreg) bpnr(Phaserad ~ Cond + AvAmp, Motor)
library(bpnreg) bpnr(Phaserad ~ Cond + AvAmp, Motor)
circ_coef
computes the coordinates of the inflection point of
a circular effect, the slope at the inflection point and the unsigned and
signed shortest distance to the origin.
circ_coef(a1, a2, b1, b2)
circ_coef(a1, a2, b1, b2)
a1 |
intercept of the first linear component. |
a2 |
intercept of the second linear component. |
b1 |
slope of the first linear component. |
b2 |
slope of the second linear component. |
A dataframe containing the coordinates of the inflection point of a circular effect, the slope at the inflection point and the unsigned and signed shortest distance to the origin.
Compute circular coefficients
circ_coef_rcpp(a1, a2, b1, b2)
circ_coef_rcpp(a1, a2, b1, b2)
a1 |
intercept estimate of component I. |
a2 |
intercept estimate of component I. |
b1 |
slope estimate of component I. |
b2 |
slope estimate of component I. |
coef_circ
gives posterior summaries of the circular coefficients.
coef_circ(object, type = "continuous", units = "radians")
coef_circ(object, type = "continuous", units = "radians")
object |
an object used to select a method. |
type |
one of |
units |
one of |
the methods coef_circ.bpnr and coef_circ.bpnme have their own help page.
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) coef_circ(fit.Motor) coef_circ(fit.Motor, type = "categorical")
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) coef_circ(fit.Motor) coef_circ(fit.Motor, type = "categorical")
Gives the coefficients tables of the circular coefficients for a Bayesian circular mixed-effects model.
## S3 method for class 'bpnme' coef_circ(object, type = "continuous", units = "radians")
## S3 method for class 'bpnme' coef_circ(object, type = "continuous", units = "radians")
object |
a |
type |
one of |
units |
one of |
A matrix or list with posterior summaries of the circular coefficients in a Bayesian circular mixed-effects model.
library(bpnreg) fit.Maps <- bpnme(pred.I = Error.rad ~ Maze + Trial.type + L.c + (1|Subject), data = Maps, its = 100, burn = 1, n.lag = 1) coef_circ(fit.Maps)
library(bpnreg) fit.Maps <- bpnme(pred.I = Error.rad ~ Maze + Trial.type + L.c + (1|Subject), data = Maps, its = 100, burn = 1, n.lag = 1) coef_circ(fit.Maps)
Gives the coefficients tables of the circular coefficients for a Bayesian circular regression model.
## S3 method for class 'bpnr' coef_circ(object, type = "continuous", units = "radians")
## S3 method for class 'bpnr' coef_circ(object, type = "continuous", units = "radians")
object |
a |
type |
one of |
units |
one of |
A matrix or list with posterior summaries of the circular coefficients in a Bayesian circular regression model.
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) coef_circ(fit.Motor) coef_circ(fit.Motor, type = "categorical")
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) coef_circ(fit.Motor) coef_circ(fit.Motor, type = "categorical")
coef_lin
gives posterior summaries of the linear coefficients.
coef_lin(object)
coef_lin(object)
object |
an object used to select a method. |
the methods coef_lin.bpnr and coef_lin.bpnme have their own help page.
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) coef_lin(fit.Motor)
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) coef_lin(fit.Motor)
Gives the coefficients tables of the linear coefficients for a Bayesian circular mixed-effects model.
## S3 method for class 'bpnme' coef_lin(object)
## S3 method for class 'bpnme' coef_lin(object)
object |
a |
A matrix with posterior summaries of the linear coefficients in a Bayesian circular mixed-effects model.
library(bpnreg) fit.Maps <- bpnme(pred.I = Error.rad ~ Maze + Trial.type + L.c + (1|Subject), data = Maps, its = 100, burn = 1, n.lag = 1) coef_lin(fit.Maps)
library(bpnreg) fit.Maps <- bpnme(pred.I = Error.rad ~ Maze + Trial.type + L.c + (1|Subject), data = Maps, its = 100, burn = 1, n.lag = 1) coef_lin(fit.Maps)
Gives the coefficients tables of the linear coefficients for a circular regression model.
## S3 method for class 'bpnr' coef_lin(object)
## S3 method for class 'bpnr' coef_lin(object)
object |
a |
A matrix with posterior summaries of the linear coefficients in a Bayesian circular regression model.
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) coef_lin(fit.Motor)
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) coef_lin(fit.Motor)
coef_ran
gives posterior summaries of the circular or linear random
effect variances.
coef_ran(object, type = "linear")
coef_ran(object, type = "linear")
object |
an object used to select a method. |
type |
one of |
the method coef_ran.bpnme has its own help page.
library(bpnreg) fit.Maps <- bpnme(pred.I = Error.rad ~ Maze + Trial.type + L.c + (1|Subject), data = Maps, its = 100, burn = 1, n.lag = 1) coef_ran(fit.Maps) coef_ran(fit.Maps, type = "circular")
library(bpnreg) fit.Maps <- bpnme(pred.I = Error.rad ~ Maze + Trial.type + L.c + (1|Subject), data = Maps, its = 100, burn = 1, n.lag = 1) coef_ran(fit.Maps) coef_ran(fit.Maps, type = "circular")
Gives posterior summaries of the circular or linear random effect variances. The circular random intercept variance and circular random slope variance of categorical predictors is computed as 1 - mean resultant length.
## S3 method for class 'bpnme' coef_ran(object, type = "linear")
## S3 method for class 'bpnme' coef_ran(object, type = "linear")
object |
a |
type |
one of |
A matrix with posterior summaries of the random effect variances.
library(bpnreg) fit.Maps <- bpnme(pred.I = Error.rad ~ Maze + Trial.type + L.c + (1|Subject), data = Maps, its = 100, burn = 1, n.lag = 1) coef_ran(fit.Maps) coef_ran(fit.Maps, type = "circular")
library(bpnreg) fit.Maps <- bpnme(pred.I = Error.rad ~ Maze + Trial.type + L.c + (1|Subject), data = Maps, its = 100, burn = 1, n.lag = 1) coef_ran(fit.Maps) coef_ran(fit.Maps, type = "circular")
Compute Model Fit Measures Regression Model
DIC_reg(theta, beta1, beta2, Likelihood, X1, X2)
DIC_reg(theta, beta1, beta2, Likelihood, X1, X2)
theta |
circular outcome values |
beta1 |
regression coefficients for the second component for each mcmc iteration from pnr function |
beta2 |
regression coefficients for the second component for each mcmc iteration from pnr function |
Likelihood |
likelihood values for each individual and mcmc itertion from pnr function |
X1 |
model matrix for the first component |
X2 |
model matrix for the second component |
Compute Eigenvalues
eigen_val(X)
eigen_val(X)
X |
A matrix. |
Compute Eigenvectors
eigen_vec(X)
eigen_vec(X)
X |
A matrix. |
fit
gives several model fit statistics.
fit(object)
fit(object)
object |
an object used to select a method. |
the methods fit.bpnr and fit.bpnme have their own help page.
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) fit(fit.Motor)
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) fit(fit.Motor)
Outputs several model fit statistics for the Bayesian circular mixed-effects model
## S3 method for class 'bpnme' fit(object)
## S3 method for class 'bpnme' fit(object)
object |
a |
a matrix containing the computed log pointwise predictive density (lppd), Deviance Information Criterion (DIC), an alternative version of the DIC (DIC_alt), and the Watanabe-Akaike Information Criterion computed in two different ways (WAIC1, WAIC2). The matrix also contains the number of parameters or 'effective number' of parameters that the several statistics are based on. Computation of the criteria is done according to Gelman et.al (2014) in *Bayesian Data Analysis*.
library(bpnreg) fit.Maps <- bpnme(pred.I = Error.rad ~ Maze + Trial.type + L.c + (1|Subject), data = Maps, its = 100, burn = 1, n.lag = 1) fit(fit.Maps)
library(bpnreg) fit.Maps <- bpnme(pred.I = Error.rad ~ Maze + Trial.type + L.c + (1|Subject), data = Maps, its = 100, burn = 1, n.lag = 1) fit(fit.Maps)
Outputs several model fit statistics for the Bayesian circular regression model
## S3 method for class 'bpnr' fit(object)
## S3 method for class 'bpnr' fit(object)
object |
a |
a matrix containing the computed log pointwise predictive density (lppd), Deviance Information Criterion (DIC), an alternative version of the DIC (DIC_alt), and the Watanabe-Akaike Information Criterion computed in two different ways (WAIC1, WAIC2). The matrix also contains the number of parameters or 'effective number' of parameters that the several statistics are based on. Computation of the criteria is done according to Gelman et.al (2014) in *Bayesian Data Analysis*.
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) fit(fit.Motor)
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) fit(fit.Motor)
Estimate the mode by finding the highest posterior density interval
hmode(x, cip)
hmode(x, cip)
x |
a sample from which to estimate the interval |
cip |
bandwidth for the algorithm, ranging from 0 to 1 |
a scalar containing the estimate of the mode
Estimate the mode by finding the highest posterior density interval
hmodeC(x, cip)
hmodeC(x, cip)
x |
a sample from which to estimate the interval |
cip |
bandwidth for the algorithm, ranging from 0 to 1 |
a scalar containing the estimate of the mode
Find the highest density interval.
hmodeci(x, cip)
hmodeci(x, cip)
x |
a sample from which to estimate the interval |
cip |
bandwidth for the algorithm, ranging from 0 to 1 |
a vector of length 2 containing the lower and upper bound of the interval.
Find the highest density interval of a circular variable
hmodeciC(x, cip)
hmodeciC(x, cip)
x |
a sample from which to estimate the interval |
cip |
bandwidth for the algorithm, ranging from 0 to 1 |
a vector of length 2 containing the lower and upper bound of the interval
Compute the 95 percent HPD of a vector of linear data
hpd_est(x)
hpd_est(x)
x |
a vector of linear data |
library(bpnreg) hpd_est(Motor$AvAmp)
library(bpnreg) hpd_est(Motor$AvAmp)
Compute the 95 percent HPD of a vector of circular data
hpd_est_circ(x)
hpd_est_circ(x)
x |
a vector of circular data |
library(bpnreg) hpd_est_circ(subset(Motor, Cond = "exp")$Phaserad)
library(bpnreg) hpd_est_circ(subset(Motor, Cond = "exp")$Phaserad)
Compute the Likelihood of the PN distribution (mixed effects)
lik_me( theta_cos, theta_sin, X1, X2, Z1, Z2, beta1, beta2, b1, b2, N, pred, iteration )
lik_me( theta_cos, theta_sin, X1, X2, Z1, Z2, beta1, beta2, b1, b2, N, pred, iteration )
theta_cos |
A List with the cosine of the circular dependent variable. |
theta_sin |
A List with the sine of the circular dependent variable. |
X1 |
A list of fixed effect model matrices for component I. |
X2 |
A list of fixed effect model matrices for component II. |
Z1 |
A list of random effect model matrices for component I. |
Z2 |
A list of random effect model matrices for component II. |
beta1 |
estimated fixed effect coefficients of the first component |
beta2 |
estimated fixed effect coefficients of the second component |
b1 |
estimated random effect coefficients of the first component |
b2 |
estimated random effect coefficients of the second component |
N |
sample size at second level |
pred |
An empty list for likelihood computation. |
iteration |
iteration number at which likelihood is computed |
Compute the Likelihood of the PN distribution (regression)
lik_reg(X1, X2, theta, beta1, beta2, n)
lik_reg(X1, X2, theta, beta1, beta2, n)
X1 |
the model matrix of the first component |
X2 |
the model matrix of the second component |
theta |
a circular outcome value |
beta1 |
estimated linear coefficients of the first component |
beta2 |
estimated linear coefficients of the second component |
n |
sample size |
A dataset from a study by Warren et.al. (2017) on the geometry of human knowledge of navigation space.
Maps
Maps
A data frame with 160 rows and 8 variables:
a numeric variable indicating the participant number
a numeric variable indicating the trial number of the target a participant had to locate (1-8)
a between subjects factor variable indicating the type of maze a participant was in (0 = Euclidean, 1 = non-Euclidean)
a within subjects factor indicating the type of target (0 = standard, 1 = probe)
a numeric variable containing the angular error in degrees
a numeric variable indicating the number of trials a participant completed in the training phase
mean centered Learning
a numeric variable containing the angular error in radians
In their study Warren et.al. (2017) conduct an experiment in which a total of 20 participants used virtual reality headsets to navigate through one of two versions of a virtual maze. One version of the maze is the standard or Euclidean maze. The other version of the maze, the non-Euclidean maze, has exactly the same layout as the standard maze apart from that it contains wormholes by which participants can be 'teleported' from one place in the maze to another.
In a training phase participants had learned to navigate between different pairs of start and target objects in one of two versions of the maze. The number of trials each participants completed in this training phase was recorded.
In the test phase of the experiment participants first walked to a start object. When they had reached this object the maze disappeared and only a "textured groundplane" of the maze remained visible. The participants then turned toward the location of the target object that they had remembered during the training phase and started to walk toward the target. The angular difference, angular error, between the initial walking direction of a participant from the start object and the location of the target object was recorded as an outcome variable in the experiment.The angular error is a circular variable and can be described and analyzed using circular statistics.
Apart from the between-subjects factor, the type of maze, the experiment also included a within-subjects factor, trial number. All participants had to complete 8 trials in the test phase of the experiment. In each of these trials they had to walk to a specific target object. An additional within-subjects factor is the type of target object. Pairs of start and target objects were of two types: probe and standard. The probe objects were located near the entrance and exit of a wormhole whereas the standard objects were located at some distance from the wormholes. For each of these two types of objects participants had to find 4 different targets resulting in a total of 8 trials per participant.
doi:10.1016/j.cognition.2017.05.020
Compute the mean of a vector of circular data
mean_circ(theta, units = "radians")
mean_circ(theta, units = "radians")
theta |
a circular variable in radians or degrees. |
units |
measurement units of the circular variable c("radians", "degrees"). |
library(bpnreg) mean_circ(subset(Motor, Cond == "exp")$PhaseDiff, units = "degrees")
library(bpnreg) mean_circ(subset(Motor, Cond == "exp")$PhaseDiff, units = "degrees")
Create model matrices for a circular mixed-effects regression model
mmme(pred.I, data, pred.II)
mmme(pred.I, data, pred.II)
pred.I |
model equation for effects of component 1 |
data |
the dataframe used for analysis |
pred.II |
model equation for effects of component 2 |
Create model matrices circular regression
mmr(pred.I, data, pred.II)
mmr(pred.I, data, pred.II)
pred.I |
model equation for effects of component 1 |
data |
the dataframe used for analysis |
pred.II |
model equation for effects of component 2 |
Compute the mode of a vector of linear data
mode_est(x)
mode_est(x)
x |
a vector of linear data |
library(bpnreg) mode_est(Motor$AvAmp)
library(bpnreg) mode_est(Motor$AvAmp)
Compute the mode of a vector of circular data
mode_est_circ(x)
mode_est_circ(x)
x |
a vector of circular data |
library(bpnreg) mode_est_circ(subset(Motor, Cond = "exp")$Phaserad)
library(bpnreg) mode_est_circ(subset(Motor, Cond = "exp")$Phaserad)
A dataset from a study by Puglisi et.al. (2017) on the role of attention in human motor resonance.
Motor
Motor
A data frame with 42 rows and 4 variables:
a factor variable indicating the condition a participant was placed in; 1 = 'explicit', 2 = 'semi.implicit' or 3 = 'implicit'
a numeric variable the phase difference between 'observer' and 'mover' in degrees
a numeric variable indicating the average amplitude of the hand movement of the 'observer'
a numeric variable the phase difference between 'observer' and 'mover' in radians
In their research Puglisi et.al. (2017) conduct a between subjects experiment in which ‘observers’ in multiple degrees of explicitness are asked to look at the movement of a hand of the ‘mover’ or other object in order to evaluate the role of attention in motor resonant response.
The experiment has four conditions:
1. The ‘explicit observation’ condition (n = 14), where observers are explicitly instructed to observe the hand.
2. The ‘semi-implicit observation’ condition (n = 14) where the observers have to do a task that requires implicit observation of the hand.
3. The ‘implicit observation’ condition (n = 14), where observers have to do a task that is independent of the observation of the hand that is moving in front of them.
4. A baseline condition (n=14) where there is no moving hand but observers have to look at an inanimate object that moves in an identical manner to the hand.
The idea of motor resonance is then that the ‘observer’, because they are looking explicitly or implicitly at the hand of the ‘mover’, starts moving his or her hand in the same manner. This is the resonant response. In each condition the hand movements of the observers were measured and the phase difference between the observers' hand and the hand they observed (the movers' hand) was calculated. This was not done for the baseline condition because in this condition there was no periodic pattern of movement in the ‘observers’ hand.
The phase difference is a circular variable and can be described and analyzed using circular statistics.
doi:10.1371/journal.pone.0177457
Sample from a multivariate normal distribution
mvrnorm_arma_eigen(n, mu, sigma)
mvrnorm_arma_eigen(n, mu, sigma)
n |
An integer indicating the number of samples to take. |
mu |
A mean vector. |
sigma |
A variance-covariance matrix. |
A Gibbs sampler for a projected normal mixed-effects model
pnme( theta_cos, theta_sin, X1, X2, Z1, Z2, ZtZ1, ZtZ2, R, pred, its, lag, burn, N )
pnme( theta_cos, theta_sin, X1, X2, Z1, Z2, ZtZ1, ZtZ2, R, pred, its, lag, burn, N )
theta_cos |
A List with the cosine of the circular dependent variable. |
theta_sin |
A List with the sine of the circular dependent variable. |
X1 |
A list of fixed effect model matrices for component I. |
X2 |
A list of fixed effect model matrices for component II. |
Z1 |
A list of random effect model matrices for component I. |
Z2 |
A list of random effect model matrices for component II. |
ZtZ1 |
A list of transformed random effect model matrices for component I. |
ZtZ2 |
A list of transformed random effect model matrices for component II. |
R |
A list of starting values for R. |
pred |
An empty list for likelihood computation. |
its |
An integer specifying the number of iterations |
lag |
An integer specifying the amount of lag. |
burn |
An integer specifying the number of burn-in iterations. |
N |
An integer specifying the number of burn-in iterations. |
A Gibbs sampler for a projected normal regression model
pnr(theta, X1, X2, its, lag, burn)
pnr(theta, X1, X2, its, lag, burn)
theta |
A vector with the circular dependent variable. |
X1 |
A model matrix for component I. |
X2 |
A model matrix for component II. |
its |
An integer specifying the number of iterations |
lag |
An integer specifying the amount of lag. |
burn |
An integer specifying the number of burn-in iterations. |
Prints selected output from a Bayesian circular mixed-effects model.
## S3 method for class 'bpnme' print(x, ...)
## S3 method for class 'bpnme' print(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
A print of selected output from a Bayesian circular mixed-effects model.
library(bpnreg) fit.Maps <- bpnme(pred.I = Error.rad ~ Maze + Trial.type + L.c + (1|Subject), data = Maps, its = 100, burn = 1, n.lag = 1) print(fit.Maps)
library(bpnreg) fit.Maps <- bpnme(pred.I = Error.rad ~ Maze + Trial.type + L.c + (1|Subject), data = Maps, its = 100, burn = 1, n.lag = 1) print(fit.Maps)
Prints selected output from a Bayesian circular regression model.
## S3 method for class 'bpnr' print(x, ...)
## S3 method for class 'bpnr' print(x, ...)
x |
a |
... |
further arguments passed to or from other methods. |
A print of selected output from a Bayesian circular regression model.
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) print(fit.Motor)
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) print(fit.Motor)
Compute a mean resultant length
rho(theta)
rho(theta)
theta |
a circular variable in radians. |
Compute the mean resultant length of a vector of circular data
rho_circ(theta, units = "radians")
rho_circ(theta, units = "radians")
theta |
a circular variable in radians or degrees. |
units |
measurement units of the circular variable c("radians", "degrees"). |
library(bpnreg) rho_circ(subset(Motor, Cond == "exp")$PhaseDiff, units = "degrees")
library(bpnreg) rho_circ(subset(Motor, Cond == "exp")$PhaseDiff, units = "degrees")
Compute the standard deviation of a vector of circular data
sd_circ(theta, units = "radians")
sd_circ(theta, units = "radians")
theta |
a circular variable in radians or degrees. |
units |
measurement units of the circular variable c("radians", "degrees"). |
library(bpnreg) sd_circ(subset(Motor, Cond == "exp")$PhaseDiff, units = "degrees")
library(bpnreg) sd_circ(subset(Motor, Cond == "exp")$PhaseDiff, units = "degrees")
A slice sampler for the latent lengths r
slice_rcpp(X1, X2, theta, beta1, beta2, n, r)
slice_rcpp(X1, X2, theta, beta1, beta2, n, r)
X1 |
A model matrix for component I. |
X2 |
A model matrix for component II. |
theta |
A vector with the circular dependent variable. |
beta1 |
A matrix containing the coefficients of component I for the current iteration. |
beta2 |
A matrix containing the coefficients of component II for the current iteration. |
n |
An integer indicating the sample size of the data. |
r |
A matrix with the estimates of r of the previous iteration. |
Compute a mean direction
theta_bar(theta)
theta_bar(theta)
theta |
a circular variable in radians. |
Traceplot function for a bpnr object
or bpnme object
.
traceplot(object, parameter = "SAM", variable = NULL)
traceplot(object, parameter = "SAM", variable = NULL)
object |
an object used to select a method. |
parameter |
one of |
variable |
a character string with variable name(s) to indicate for which variable(s) a traceplot is required. |
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) traceplot(fit.Motor, parameter = "beta1")
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) traceplot(fit.Motor, parameter = "beta1")
General plot function for a bpnme object
.
## S3 method for class 'bpnme' traceplot(object, parameter = "SAM", variable = NULL)
## S3 method for class 'bpnme' traceplot(object, parameter = "SAM", variable = NULL)
object |
a |
parameter |
one of |
variable |
a character string with variable name(s) to indicate for
which variable(s) a traceplot is required. This cannot be used in
combination with the parameters |
library(bpnreg) fit.Maps <- bpnme(pred.I = Error.rad ~ Maze + Trial.type + L.c + (1|Subject), data = Maps, its = 100, burn = 1, n.lag = 1) traceplot(fit.Maps)
library(bpnreg) fit.Maps <- bpnme(pred.I = Error.rad ~ Maze + Trial.type + L.c + (1|Subject), data = Maps, its = 100, burn = 1, n.lag = 1) traceplot(fit.Maps)
General plot function for a bpnr object
.
## S3 method for class 'bpnr' traceplot(object, parameter = "SAM", variable = NULL)
## S3 method for class 'bpnr' traceplot(object, parameter = "SAM", variable = NULL)
object |
a |
parameter |
one of |
variable |
a character string with variable name(s) to indicate for which variable(s) a traceplot is required. |
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) traceplot(fit.Motor, parameter = "beta1")
library(bpnreg) fit.Motor <- bpnr(pred.I = Phaserad ~ 1 + Cond, data = Motor, its = 100, burn = 10, n.lag = 3) traceplot(fit.Motor, parameter = "beta1")