Title: Bayesian Statistics for 2D/3D Transformations
Version: 1.0.2
Description: Fits 2D and 3D geometric transformations via 'Stan' probabilistic programming engine ( Stan Development Team (2021) https://mc-stan.org). Returns posterior distribution for individual parameters of the fitted distribution. Allows for computation of LOO and WAIC information criteria (Vehtari A, Gelman A, Gabry J (2017) <doi:10.1007/s11222-016-9696-4>) as well as Bayesian R-squared (Gelman A, Goodrich B, Gabry J, and Vehtari A (2018) <doi:10.1080/00031305.2018.1549100>).
License: GPL-3
URL: https://github.com/alexander-pastukhov/tridim-regression, https://alexander-pastukhov.github.io/tridim-regression/
BugReports: https://github.com/alexander-pastukhov/tridim-regression/issues
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.2.3
VignetteBuilder: knitr
Biarch: true
Depends: R (≥ 4.3.0), loo
Imports: methods, Rcpp (≥ 0.12.0), rstan (≥ 2.26.0), dplyr, future, glue, purrr, tidyr, Formula, bayesplot
LinkingTo: BH (≥ 1.66.0), Rcpp (≥ 0.12.0), RcppEigen (≥ 0.3.3.3.0), RcppParallel (≥ 5.0.1), rstan (≥ 2.26.0), StanHeaders (≥ 2.26.0)
SystemRequirements: GNU make
Suggests: testthat, knitr, rmarkdown, ggplot2
NeedsCompilation: yes
Packaged: 2023-09-13 08:57:45 UTC; ba7dr4
Author: Alexander (Sasha) Pastukhov ORCID iD [aut, cre], Claus-Christian Carbon ORCID iD [aut]
Maintainer: Alexander (Sasha) Pastukhov <pastukhov.alexander@gmail.com>
Repository: CRAN
Date/Publication: 2023-09-13 14:10:03 UTC

The 'TriDimRegression' package.

Description

Fits 2D and 3D geometric transformations. Provides posterior via Stan. Includes computation of LOO and WAIC information criteria, R-squared.

To fit transformation, call the main function either via a formula that specifies dependent and independent variables with the data table or by supplying two tables one containing all independent variables and one containing all dependent variables.

For the 2D data, you can fit "translation" (2 parameters for translation only), "euclidean" (4 parameters: 2 for translation, 1 for scaling, and 1 for rotation), "affine" (6 parameters: 2 for translation and 4 that jointly describe scaling, rotation and sheer), or "projective" (8 parameters: affine plus 2 additional parameters to account for projection). For 3D data, you can fit "translation" (3 for translation only), "euclidean_x", "euclidean_y", "euclidean_z" (5 parameters: 3 for translation scale, 1 for rotation, and 1 for scaling), "affine" (12 parameters: 3 for translation and 9 to account for scaling, rotation, and sheer), and "projective" (15 parameters: affine plus 3 additional parameters to account for projection). transformations. For details on transformation matrices and computation of scale and rotation parameters please see vignette("transformation_matrices", package = "TriDimRegression")

Once the data is fitted, you can extract the transformation coefficients via coef function and the matrix itself via transformation_matrix. Predicted data, either based on the original data or on the new data, can be generated via predict. Bayesian R-squared can be computed with or without adjustment via R2 function. In all three cases, you have choice between summary (mean + specified quantiles) or full posterior samples. loo and waic provide corresponding measures that can be used for comparison via loo::loo_compare() function.

Author(s)

Maintainer: Alexander (Sasha) Pastukhov pastukhov.alexander@gmail.com (ORCID)

Authors:

References

Stan Development Team (2020). RStan: the R interface to Stan. R package version 2.19.3. https://mc-stan.org

See Also

fit_transformation fit_transformation_df tridim_transformation vignette("transformation_matrices", package = "TriDimRegression") vignette("calibration", package = "TriDimRegression") vignette("comparing_faces", package = "TriDimRegression")

Examples

# Fitting via formula
euc2 <- fit_transformation(depV1 + depV2 ~ indepV1 + indepV2,
                           NakayaData, 'euclidean')
aff2 <- fit_transformation(depV1 + depV2 ~ indepV1 + indepV2,
                           NakayaData, 'affine')
prj2 <- fit_transformation(depV1 + depV2 ~ indepV1 + indepV2,
                           NakayaData, 'projective')

# summary of transformation coefficients
coef(euc2)

# statistical comparison via WAIC criterion
loo::loo_compare(waic(euc2), waic(aff2), waic(prj2))

# Fitting via two tables
euc2 <- fit_transformation_df(NakayaData[, 1:2], NakayaData[, 3:4],
  'euclidean')
tr3 <- fit_transformation_df(Face3D_W070, Face3D_W097, transformation ='translation')

Carbon, C. C. (2013), data set #1

Description

Example 1 from the domain of aesthetics to show how the method can be utilized for assessing the similarity of two portrayed persons, actually the Mona Lisa in the world famous Louvre version and the only recently re-discovered Prado version.

Usage

CarbonExample1Data

Format

A data frame with 36 observations on the following 4 variables:

depV1, depV2

numeric vectors, dependent variables

indepV1, indepV2

numeric vectors, independent variables

Source

doi:10.18637/jss.v052.c01


Carbon, C. C. (2013), data set #2

Description

Example 2 originates from the area of geography and inspects the accuracy of different maps of the city of Paris which were created over the last 350 years as compared to a recent map.

Usage

CarbonExample2Data

Format

A data frame with 13 observations on the following 4 variables:

depV1, depV2

numeric vectors, dependent variables

indepV1, indepV2

numeric vectors, independent variables

Source

doi:10.18637/jss.v052.c01


Carbon, C. C. (2013), data set #3

Description

Example 3 focuses on demonstrating how good a cognitive map recalculated from averaged cognitive distance data fits with a related real map.

Usage

CarbonExample3Data

Format

A data frame with 10 observations on the following 4 variables:

depV1, depV2

numeric vectors, dependent variables

indepV1, indepV2

numeric vectors, independent variables

Source

doi:10.18637/jss.v052.c01


Eye gaze calibration data

Description

A dataset containing a monocular eye gaze recording with calibration sequence. Courtesy of Bamberger Baby Institut: BamBI.

Usage

EyegazeData

Format

A data frame with 365 rows and 6 variables:

time

sample timestamp, in milliseconds

x, y

recorded gaze, in internal eye tracker units

target_x, target_y

location of the calibration target on the screen, in pixels

target

index of the target within the sequence

Source

https://www.uni-bamberg.de/entwicklungspsychologie/transfer/babyforschung-bambi/.


Face landmarks, male, #010

Description

Face landmarks, male, #010

Usage

Face3D_M010

Format

A data frame with 64 landmarks on the following 3 variables:

x, y, z

numeric vectors, coordinates of face landmarks

Source

Carbon, C. C. (2012). The Bamberg DADA Face Database (BaDADA). A standardized high quality Face Database with faces of Different Affective states from Different Angles. Unpublished databank. University of Bamberg, Bamberg.


Face landmarks, male, #101

Description

Face landmarks, male, #101

Usage

Face3D_M101

Format

A data frame with 64 landmarks on the following 3 variables:

x, y, z

numeric vectors, coordinates of face landmarks

Source

Carbon, C. C. (2012). The Bamberg DADA Face Database (BaDADA). A standardized high quality Face Database with faces of Different Affective states from Different Angles. Unpublished databank. University of Bamberg, Bamberg.


Face landmarks, male, #244

Description

Face landmarks, male, #244

Usage

Face3D_M244

Format

A data frame with 64 landmarks on the following 3 variables:

x, y, z

numeric vectors, coordinates of face landmarks

Source

Carbon, C. C. (2012). The Bamberg DADA Face Database (BaDADA). A standardized high quality Face Database with faces of Different Affective states from Different Angles. Unpublished databank. University of Bamberg, Bamberg.


Face landmarks, male, #092

Description

Face landmarks, male, #092

Usage

Face3D_M92

Format

A data frame with 64 landmarks on the following 3 variables:

x, y, z

numeric vectors, coordinates of face landmarks

Source

Carbon, C. C. (2012). The Bamberg DADA Face Database (BaDADA). A standardized high quality Face Database with faces of Different Affective states from Different Angles. Unpublished databank. University of Bamberg, Bamberg.


Face landmarks, female, #070

Description

Face landmarks, female, #070

Usage

Face3D_W070

Format

A data frame with 64 landmarks on the following 3 variables:

x, y, z

numeric vectors, coordinates of face landmarks

Source

Carbon, C. C. (2012). The Bamberg DADA Face Database (BaDADA). A standardized high quality Face Database with faces of Different Affective states from Different Angles. Unpublished databank. University of Bamberg, Bamberg.


Face landmarks, female, #097

Description

Face landmarks, female, #097

Usage

Face3D_W097

Format

A data frame with 64 landmarks on the following 3 variables:

x, y, z

numeric vectors, coordinates of face landmarks

Source

Carbon, C. C. (2012). The Bamberg DADA Face Database (BaDADA). A standardized high quality Face Database with faces of Different Affective states from Different Angles. Unpublished databank. University of Bamberg, Bamberg.


Face landmarks, female, #182

Description

Face landmarks, female, #182

Usage

Face3D_W182

Format

A data frame with 64 landmarks on the following 3 variables:

x, y, z

numeric vectors, coordinates of face landmarks

Source

Carbon, C. C. (2012). The Bamberg DADA Face Database (BaDADA). A standardized high quality Face Database with faces of Different Affective states from Different Angles. Unpublished databank. University of Bamberg, Bamberg.


Face landmarks, female, #243

Description

Face landmarks, female, #243

Usage

Face3D_W243

Format

A data frame with 64 landmarks on the following 3 variables:

x, y, z

numeric vectors, coordinates of face landmarks

Source

Carbon, C. C. (2012). The Bamberg DADA Face Database (BaDADA). A standardized high quality Face Database with faces of Different Affective states from Different Angles. Unpublished databank. University of Bamberg, Bamberg.


Friedman & Kohler (2003), data set #1

Description

Data from Friedman, A., & Kohler, B. (2003). Bidimensional regression: Assessing the configural similarity and accuracy of cognitive maps and other two-dimensional data sets. Psychological Methods, 8(4), 468-491. DOI: 10.1037/1082-989X.8.4.468

Usage

FriedmanKohlerData1

Format

A data frame with 4 observations on the following 4 variables:

depV1, depV2

numeric vectors, dependent variables

indepV1, indepV2

numeric vectors, independent variables

Source

doi:10.1037/1082-989X.8.4.468


Friedman & Kohler (2003), data set #2

Description

Data from Friedman, A., & Kohler, B. (2003). Bidimensional regression: Assessing the configural similarity and accuracy of cognitive maps and other two-dimensional data sets. Psychological Methods, 8(4), 468-491. DOI: 10.1037/1082-989X.8.4.468

Usage

FriedmanKohlerData2

Format

A data frame with 4 observations on the following 4 variables:

depV1, depV2

numeric vectors, dependent variables

indepV1, indepV2

numeric vectors, independent variables

Source

doi:10.1037/1082-989X.8.4.468


Nakaya (1997)

Description

Nakaya, T. (1997) Statistical inferences in bidimensional regression models. Geographical Analysis, 29(2), 169-186.

Usage

NakayaData

Format

A data frame with 19 observations on the following 4 variables:

depV1, depV2

numeric vectors, dependent variables

indepV1, indepV2

numeric vectors, independent variables

Source

doi:10.1111/j.1538-4632.1997.tb00954.x


Computes R-squared using Bayesian R-squared approach. For detail refer to: Andrew Gelman, Ben Goodrich, Jonah Gabry, and Aki Vehtari (2018). R-squared for Bayesian regression models. The American Statistician, doi:10.1080/00031305.2018.1549100.

Description

Computes R-squared using Bayesian R-squared approach. For detail refer to: Andrew Gelman, Ben Goodrich, Jonah Gabry, and Aki Vehtari (2018). R-squared for Bayesian regression models. The American Statistician, doi:10.1080/00031305.2018.1549100.

Usage

## S3 method for class 'tridim_transformation'
R2(object, summary = TRUE, probs = c(0.055, 0.945), ...)

Arguments

object

An object of class tridim_transformation

summary

Whether summary statistics should be returned instead of raw sample values. Defaults to TRUE

probs

The percentiles used to compute summary, defaults to 89% credible interval.

...

Unused.

Value

vector of values or a data.frame with summary

Examples

euc2 <- fit_transformation(depV1+depV2~indepV1+indepV2,
  NakayaData, transformation = 'euclidean')
R2(euc2)

Checks for validity of values for use as exponential distribution parameters.

Description

Should a single non-negative numeric value. Stops execution with an error.

Usage

check_exponential_prior(values, parameter)

Arguments

values

Parameter for exponential distribution.

parameter

Name of the parameter for which the prior is defined.

Value

Logical TRUE, if none of the tests fail

Examples

check_exponential_prior(1, "sigma")

Checks for validity of values for use as normal distribution parameters.

Description

Should a pair of numeric values, second value should be non-zero. Stops execution with an error.

Usage

check_normal_prior(values, parameter)

Arguments

values

Parameters for normal distribution.

parameter

Name of the parameter for which the prior is defined.

Value

Logical TRUE, if none of the tests fail

Examples

check_normal_prior(c(0, 1), "scale")

Checks validity of variables' matrix

Description

Checks whether the matrix is numeric, has expected number of columns (ncol), and has no missing/infinite data.

Usage

check_variables(var, var_label)

Arguments

var

Matrix N x ncol

var_label

Variable label for error messages

Value

Logical TRUE, if none of the tests fail

Examples

check_variables(matrix(c(1, 2, 3, 4), ncol=2), "test matrix")

Posterior distributions for transformation coefficients in full or summarized form.

Description

Posterior distributions for transformation coefficients in full or summarized form.

Usage

## S3 method for class 'tridim_transformation'
coef(
  object,
  summary = TRUE,
  probs = c(0.055, 0.945),
  convert_euclidean = FALSE,
  ...
)

Arguments

object

An object of class tridim_transformation.

summary

Whether summary statistics should be returned instead of raw sample values. Defaults to TRUE

probs

The percentiles used to compute summary, defaults to 89% credible interval.

convert_euclidean

Whether to convert matrix coefficients to scale(phi) and rotation(theta). Defaults to FALSE.

...

Unused

Value

If summary=FALSE, a list with matrix iterationsN x dimensionsN for each variable. If summary=TRUE, a data.frame with columns "dvindex" with mean for each dependent variable plus optional quantiles columns with names "dvindex_quantile".

Examples

euc2 <- fit_transformation(depV1+depV2~indepV1+indepV2,
                           data = NakayaData,
                           transformation = 'euclidean')

# full posterior distribution
transform_posterior <- coef(euc2, summary=FALSE)

# coefficients' summary with 89% CI
coef(euc2)

# scale and rotation coefficients
coef(euc2, convert_euclidean=TRUE)

Computes mean and optional quantiles for a coefficient.

Description

Computes mean and optional quantiles for a coefficient.

Usage

coef_summary(coef_name, coef_matrix, probs)

Arguments

coef_name

String, name of the coefficient.

coef_matrix

Numeric matrix samplesN x 2 or a numeric vector with length samplesN.

probs

A numeric vector of quantiles to compute.

Value

data.frame with columns "Coef", "Mean", and a column for each quantile.

Examples

coef_summary("test", c(1, 2, 3), NULL)

Fitting Bidimensional or Tridimensional Regression / Geometric Transformation Models via Formula.

Description

Fits Bidimensional or Tridimensional regression / geometric transformation models using Stan engine. The formula described dependent and independent numeric variables in the data. See also fit_transformation_df.

For the 2D data, you can fit "translation" (2 parameters for translation only), "euclidean" (4 parameters: 2 for translation, 1 for scaling, and 1 for rotation), "affine" (6 parameters: 2 for translation and 4 that jointly describe scaling, rotation and sheer), or "projective" (8 parameters: affine plus 2 additional parameters to account for projection).

For 3D data, you can fit "translation" (3 for translation only), "euclidean_x", "euclidean_y", "euclidean_z" (5 parameters: 3 for translation scale, 1 for rotation, and 1 for scaling), "affine" (12 parameters: 3 for translation and 9 to account for scaling, rotation, and sheer), and "projective" (15 parameters: affine plus 3 additional parameters to account for projection). transformations.

For details on transformation matrices and computation of scale and rotation parameters please see vignette("transformation_matrices", package = "TriDimRegression")

Usage

## S3 method for class 'formula'
fit_transformation(
  formula,
  data,
  transformation,
  priors = NULL,
  chains = 1,
  cores = NULL,
  ...
)

Arguments

formula

a symbolic description of the model to be fitted in the format Xdep + Ydep ~ Xind + Yind, where Xdep and Ydep are dependent and Xind and Yind are independent variables

data

a data frame containing variables for the model.

transformation

the transformation to be used: "translation" (both 2D and 3D), "euclidean" (2D), "euclidean_x", "euclidean_y", "euclidean_z" (3D, rotation about, respectively, x, y, and z axis), "affine" (2D and 3D), or "projective" (2D and 3D).

priors

named list of parameters for prior distributions of parameters a (translation, normal distribution), b (all other parameters, normal distribution), and sigma (residual variance, exponential). E.g., list("a" = c(0, 10), "b"= c(0, 1), "sigma"=1). Default priors are "a" = c(0, max_absolute_difference_in_means(d, iv)) / 2), "b" = c(0, max_absolute_difference_in_means(d, iv)) / 2), "sigma" = 1 * sd(dv).

chains

Number of chains for sampling.

cores

Number of CPU cores to use for sampling. If omitted, all available cores are used.

...

Additional arguments passed to sampling function.

Value

A tridim_transformation object

See Also

fit_transformation_df

Examples

# Geometric transformations of 2D data
euc2 <- fit_transformation(depV1 + depV2 ~ indepV1 + indepV2,
                                     NakayaData, 'euclidean')
aff2 <- fit_transformation(depV1 + depV2 ~ indepV1 + indepV2,
                                     NakayaData, 'affine')
prj2 <- fit_transformation(depV1 + depV2 ~ indepV1 + indepV2,
                                     NakayaData, 'projective')

# summary of transformation coefficients
coef(euc2)

# statistical comparison via WAIC criterion
loo::loo_compare(waic(euc2), waic(aff2), waic(prj2))

Fitting Bidimensional or Tridimensional Regression / Geometric Transformation Models via Two Tables.

Description

Fits Bidimensional or Tridimensional regression / geometric transformation models using Stan engine. Two sets of coordinates are supplied via iv (for an independent variable) and dv (for the dependent one). The two tables must have the same dimensions (both N×2 or N×3).

For the 2D data, you can fit "translation" (2 for translation only), "euclidean" (4 parameters: 2 for translation, 1 for scaling, and 1 for rotation), "affine" (6 parameters: 2 for translation and 4 that jointly describe scaling, rotation and sheer), or "projective" (8 parameters: affine plus 2 additional parameters to account for projection).

For 3D data, you can fit "translation" (3 for translation only), "euclidean_x", "euclidean_y", "euclidean_z" (5 parameters: 3 for translation scale, 1 for rotation, and 1 for scaling), "affine" (12 parameters: 3 for translation and 9 to account for scaling, rotation, and sheer), and "projective" (15 parameters: affine plus 3 additional parameters to account for projection). transformations.

For details on transformation matrices and computation of scale and rotation parameters please see vignette("transformation_matrices", package = "TriDimRegression")

Usage

fit_transformation_df(
  iv,
  dv,
  transformation,
  priors = NULL,
  chains = 1,
  cores = NULL,
  ...
)

Arguments

iv

a data frame containing independent variable, must by numeric only, N×2 or N×3.

dv

a data frame containing dependent variable, must by numeric only, N×2 or N×3.

transformation

the transformation to be used: "translation" (both 2D and 3D), "euclidean" (2D), "euclidean_x", "euclidean_y", "euclidean_z" (3D, rotation about, respectively, x, y, and z axis), "affine" (2D and 3D), or "projective" (2D and 3D).

priors

named list of parameters for prior distributions of parameters a (translation, normal distribution), b (all other parameters, normal distribution), and sigma (residual variance, exponential). E.g., list("a" = c(0, 10), "b"= c(0, 1), "sigma"=1). Default priors are "a" = c(0, max_absolute_difference_in_means(d, iv)) / 2), "b" = c(0, max_absolute_difference_in_means(d, iv)) / 2), "sigma" = 1 * sd(dv).

chains

Number of chains for sampling.

cores

Number of CPU cores to use for sampling. If omitted, all available cores are used.

...

Additional arguments passed to sampling function.

Value

A tridim_transformation object

See Also

fit_transformation

Examples

# Geometric transformations of 2D data
euc2 <- fit_transformation_df(NakayaData[, 1:2], NakayaData[, 3:4], 'euclidean')
tr3 <- fit_transformation_df(Face3D_W070, Face3D_W097, transformation ='translation')

Returns number of free matrix parameters in addition to translation

Description

Returns number of free matrix parameters in addition to translation

Usage

get_beta_n(dimN, transformation)

Arguments

dimN

integer, either 2 or 3

transformation

string, for 2D "translation", "euclidean", "affine", "projective". for 3D "translation", "euclidean_x", "euclidean_y", "euclidean_z", "affine", "projective".

Value

integer, number of free matrix parameters in addition to translation

Examples

get_beta_n(2, "euclidean") # should return 2
get_beta_n(3, "affine") # should return 9

Checks if argument is a tridim_transformation object

Description

Checks if argument is a tridim_transformation object

Usage

is.tridim_transformation(x)

Arguments

x

An R object

Value

Logical


Computes an efficient approximate leave-one-out cross-validation via loo library. It can be used for a model comparison via loo::loo_compare() function.

Description

Computes an efficient approximate leave-one-out cross-validation via loo library. It can be used for a model comparison via loo::loo_compare() function.

Usage

## S3 method for class 'tridim_transformation'
loo(x, ...)

Arguments

x

A tridim_transformation object

...

unused

Value

A named list, see loo::loo() for details.

Examples

euc2 <- fit_transformation(depV1+depV2~indepV1+indepV2,
  NakayaData, transformation = 'euclidean')
aff2 <- fit_transformation(depV1+depV2~indepV1+indepV2,
  NakayaData, transformation = 'affine')
loo::loo_compare(loo(euc2), loo(aff2))

2D Affine

Description

2D Affine

Usage

m2_affine(a, b)

Arguments

a

numeric, 2: translation

b

numeric, 4: all other coefficients

Value

matrix 3x3

Examples

m2_affine(c(2, 3), c(1, 0.5, 1, 5))

2D Euclidean

Description

2D Euclidean

Usage

m2_euclidean(a, b)

Arguments

a

numeric, 2: translation

b

numeric, 2: all other coefficients

Value

matrix 3x3

Examples

m2_euclidean(c(2, 3), c(1, 0.5))

2D Projective

Description

2D Projective

Usage

m2_projective(a, b)

Arguments

a

numeric, 2: translation

b

numeric, 6: all other coefficients

Value

matrix 3x3

Examples

m2_projective(c(2, 3), c(1, 0.5, 1, 5, 2, 4))

2D Translation Matrix

Description

2D Translation Matrix

Usage

m2_translation(a, b = NULL)

Arguments

a

numeric, 2: translation

b

numeric, ignored

Value

matrix 3x3

Examples

m2_translation(c(2, 3))

3D Affine

Description

3D Affine

Usage

m3_affine(a, b)

Arguments

a

numeric, 3: translation

b

numeric, 9: all other coefficients

Value

matrix 4x4

Examples

m3_affine(c(2, 3, 1), c(0.5, 0.2, 4, 2, 6, 3, 2, 5, 1))

3D Euclidean, rotation about x

Description

3D Euclidean, rotation about x

Usage

m3_euclidean_x(a, b)

Arguments

a

numeric, 3: translation

b

numeric, 2: scaling and rotation

Value

matrix 4x4

Examples

m3_euclidean_x(c(2, 3, 1), c(0.5, 0.2))

3D Euclidean, rotation about y

Description

3D Euclidean, rotation about y

Usage

m3_euclidean_y(a, b)

Arguments

a

numeric, 3: translation

b

numeric, 2: scaling and rotation

Value

matrix 4x4

Examples

m3_euclidean_y(c(2, 3, 1), c(0.5, 0.2))

3D Euclidean, rotation about z

Description

3D Euclidean, rotation about z

Usage

m3_euclidean_z(a, b)

Arguments

a

numeric, 3: translation

b

numeric, 2: scaling and rotation

Value

matrix 4x4

Examples

m3_euclidean_z(c(2, 3, 1), c(0.5, 0.2))

3D Projective

Description

3D Projective

Usage

m3_projective(a, b)

Arguments

a

numeric, 3: translation

b

numeric, 12: all other coefficients

Value

matrix 4x4

Examples

m3_projective(c(2, 3, 1), c(0.5, 0.2, 4, 2, 6, 3, 2, 5, 1, 6, 8, 9))

3D Translation Matrix

Description

3D Translation Matrix

Usage

m3_translation(a, b)

Arguments

a

numeric, 3: translation

b

numeric, ignored

Value

matrix 4x4

Examples

m3_translation(c(2, 3, 1))

Posterior interval plots for key parameters. Uses bayesplot::mcmc_intervals.

Description

Posterior interval plots for key parameters. Uses bayesplot::mcmc_intervals.

Usage

## S3 method for class 'tridim_transformation'
plot(x, convert_euclidean = FALSE, ...)

Arguments

x

A tridim_transformation object

convert_euclidean

Whether to convert matrix coefficients to scale(phi) and rotation(theta). Defaults to FALSE.

...

Extra parameters to be passed to bayesplot::mcmc_intervals()

Value

A ggplot object produced by bayesplot::mcmc_intervals()

Examples

euc2 <- fit_transformation(depV1+depV2~indepV1+indepV2,
                           data = NakayaData,
                           transformation = 'euclidean')
plot(euc2)

# same but for converted coefficients
plot(euc2, convert_euclidean=TRUE)

Computes posterior samples for the posterior predictive distribution.

Description

Predicted values based on the bi/tridimensional regression model object.

Usage

## S3 method for class 'tridim_transformation'
predict(object, newdata = NULL, summary = TRUE, probs = NULL, ...)

Arguments

object

An object of class tridim_transformation

newdata

An optional two column data frame with independent variables. If omitted, the fitted values are used.

summary

Whether summary statistics should be returned instead of raw sample values. Defaults to TRUE

probs

The percentiles used to compute summary, defaults to NULL (no CI).

...

Unused

Value

If summary=FALSE, a numeric matrix iterationsN x observationsN x variablesN. If summary=TRUE, a data.frame with columns "dvindex" with mean for each dependent variable plus optional quantiles columns with names "dvindex_quantile".

See Also

fit_transformation

Examples

euc2 <- fit_transformation(depV1+depV2~indepV1+indepV2,
  NakayaData, transformation = 'euclidean')

# prediction summary
predictions <- predict(euc2)

# full posterior prediction samples
predictions <- predict(euc2, summary=FALSE)

Prints out tridim_transformation object

Description

Prints out tridim_transformation object

Usage

## S3 method for class 'tridim_transformation'
print(x, ...)

Arguments

x

A tridim_transformation object

...

Unused

Value

Nothing, console output only.

Examples

euc2 <- fit_transformation(depV1+depV2~indepV1+indepV2,
                           data = NakayaData,
                           transformation = 'euclidean')
euc2

Summary for a tridim_transformation object

Description

Summary for a tridim_transformation object

Usage

## S3 method for class 'tridim_transformation'
summary(object, ...)

Arguments

object

A tridim_transformation object

...

Unused

Value

Nothing, console output only.

Examples

euc2 <- fit_transformation(depV1+depV2~indepV1+indepV2,
                           data = NakayaData,
                           transformation = 'euclidean')
summary(euc2)

Transformation matrix, 2D or 3D depending on data and transformation type

Description

Transformation matrix, 2D or 3D depending on data and transformation type

Arguments

object

tridim_transformation object

summary

Whether summary statistics should be returned instead of raw sample values. Defaults to TRUE

Value

matrix 3x3 for 2D transformation or matrix 4x4 for 3D transformation

Examples

euc2 <- fit_transformation(depV1+depV2~indepV1+indepV2,
                           data = NakayaData,
                           transformation = 'euclidean')
transformation_matrix(euc2)

Class tridim_transformation.

Description

Geometric transformations fitted with the fit_transformation function represented as a tridim_transformation object with information about transformation, data dimension, call formula, and fitted stanfit object,

Details

See methods(class = "tridim_transformation") for an overview of available methods.

Slots

transformation

A string with the transformation name.

formula

A formula object.

Ndim

An integer with data dimension, either 2 or 3.

data

A list containing variables used for the sampling.

stanmodel

A stanmodel used for sampling.

stanfit

a stanfit object.

See Also

fit_transformation


Computes mean and optional probabilities for a given variable.

Description

Computes mean and optional probabilities for a given variable.

Usage

variable_summary(var_name, var_matrix, probs)

Arguments

var_name

String, name of the dependent variable

var_matrix

Numeric matrix samplesN x observationsN.

probs

A numeric vector of quantiles to compute.

Value

data.frame with "var_name" column for the mean and "var_name_prob" columns for each probability.

Examples

variable_summary("test", matrix(1:1000, ncol = 1), c(0.05, 0.95))

Computes widely applicable information criterion (WAIC).

Description

Computes widely applicable information criterion via loo library. It can be used for a model comparison via loo::loo_compare() function.

Usage

## S3 method for class 'tridim_transformation'
waic(x, ...)

Arguments

x

A [tridim_transformation[tridim_transformation-class() object

...

unused

Value

A named list, see loo::waic() for details.

Examples

euc2 <- fit_transformation(depV1+depV2~indepV1+indepV2,
  NakayaData, transformation = 'euclidean')
aff2 <- fit_transformation(depV1+depV2~indepV1+indepV2,
  NakayaData, transformation = 'affine')
loo::loo_compare(waic(euc2), waic(aff2))

mirror server hosted at Truenetwork, Russian Federation.