File: example_log_lik_array.R

package info (click to toggle)
r-cran-loo 2.9.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,836 kB
  • sloc: sh: 15; makefile: 2
file content (38 lines) | stat: -rw-r--r-- 1,096 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#' Objects to use in examples and tests
#'
#' Example pointwise log-likelihood objects to use in demonstrations and tests.
#' See the **Value** and **Examples** sections below.
#'
#' @export
#' @return
#' `example_loglik_array()` returns a 500 (draws) x 2 (chains) x 32
#' (observations) pointwise log-likelihood array.
#'
#' `example_loglik_matrix()` returns the same pointwise log-likelihood values
#' as `example_loglik_array()` but reshaped into a 1000 (draws*chains) x 32
#' (observations) matrix.
#'
#' @examples
#' LLarr <- example_loglik_array()
#' (dim_arr <- dim(LLarr))
#' LLmat <- example_loglik_matrix()
#' (dim_mat <- dim(LLmat))
#'
#' all.equal(dim_mat[1], dim_arr[1] * dim_arr[2])
#' all.equal(dim_mat[2], dim_arr[3])
#'
#' all.equal(LLarr[, 1, ], LLmat[1:500, ])
#' all.equal(LLarr[, 2, ], LLmat[501:1000, ])
#'
example_loglik_array <- function() {
  # .example_loglik_array exists in R/sysdata.R
  return(.example_loglik_array)
}

#' @rdname example_loglik_array
#' @export
example_loglik_matrix <- function() {
  ll <- example_loglik_array()
  return(llarray_to_matrix(ll))
}