rvsummary is a class of objects that hold the summary information on each scalar component of a random variable (quantiles, mean, sd, number of simulations etc.)

as.rvsummary(x, ...)

is.rvsummary(x)

# S3 method for data.frame
as.rvsummary(x, quantiles = rvpar("summary.quantiles.numeric"), ...)

# S3 method for rvsummary_rvfactor
print(x, all.levels = FALSE, ...)

Arguments

x

object to be coerced or tested

...

further arguments passed to or from other methods.

quantiles

quantiles to calculate and store in the object

all.levels

logical; whether to print all levels or not (see below for details)

Value

An object of class rvsummaryand of subclass rvsummary_numeric, rvsummary_integer, rvsummary_logical, or rvsummary_rvfactor.

Details

The rvsummary class provides a means to store a concise representation of the marginal posterior distributions of the vector components. By default, the 201 quantiles

 0, 0.005, 0.01,
0.015, ..., 0.990, 0.995, 1 

are saved for each vector component in an rvsummary object.

is.rvsummary tests whether the object is an rvsummary object; as.rvsummary coerces a random vector object to a rvsummary object.

as.data.frame is another way to obtain the data frame that is produced by the summary method.

A data frame that has the format of an rv summary can be coerced into an rvsummary; if quantiles are not specified within the data frame, quantiles from the Normal distribution are filled in, if the mean and s.d. are given.

Therefore, the following (generic) functions work with rvsummary objects: rvmean, rvsd, rvvar, rvquantile, rnsims, sims, and consequently any `rv-only' function that depends only on these functions will work; e.g. is.constant, which depends only on rvnsims.

The method is.double is provided for compatibility reasons; this is needed in a function called by plot.rvsummary

The arithmetic operators and mathematical functions will not work with rvsummary objects.

The sims method returns the quantiles.

References

Kerman, J. and Gelman, A. (2007). Manipulating and Summarizing Posterior Simulations Using Random Variable Objects. Statistics and Computing 17:3, 235-244.

See also vignette("rv").

See also

Author

Jouni Kerman jouni@kerman.com

Examples


  x <- rvnorm(mean=1:12)
  sx <- as.rvsummary(x)
  print(sx)          # prints the summary of the rvsummary object
#>        mean    sd     1%   2.5%    25%    50%    75%  97.5%    99% sims
#>  [1]  1.019 0.960 -1.208 -0.928  0.373  1.006  1.695  2.839  3.237 2500
#>  [2]  2.004 0.985 -0.219  0.061  1.325  1.985  2.665  3.926  4.298 2500
#>  [3]  3.010 0.983  0.801  1.138  2.322  2.997  3.685  5.000  5.278 2500
#>  [4]  3.990 0.977  1.717  2.086  3.339  3.999  4.637  5.914  6.327 2500
#>  [5]  5.017 0.981  2.760  3.093  4.364  5.004  5.682  6.981  7.248 2500
#>  [6]  5.989 1.019  3.622  3.999  5.283  5.988  6.685  7.959  8.325 2500
#>  [7]  6.999 0.998  4.727  5.036  6.306  7.004  7.693  8.898  9.180 2500
#>  [8]  8.022 0.983  5.842  6.168  7.345  8.000  8.690  9.997 10.314 2500
#>  [9]  8.994 0.959  6.807  7.153  8.335  8.977  9.612 10.938 11.288 2500
#> [10]  9.998 1.007  7.723  8.063  9.328  9.981 10.649 12.026 12.433 2500
#> [11] 10.991 0.986  8.813  9.090 10.313 11.012 11.653 12.957 13.423 2500
#> [12] 11.973 1.013  9.573  9.929 11.312 11.969 12.656 13.906 14.358 2500
  length(sx)         # 12
#> [1] 12
  dim(sx)            # NULL
#> NULL
  dim(sx) <- c(3,4)  #   
  dimnames(sx) <- list(1:3, 1:4)
  names(sx) <- 1:12  # 
  print(sx)          # prints the names and dimnames as well  
#>       row col   name   mean    sd     1%   2.5%    25%    50%    75%  97.5%
#> [1,1]   1   1 :    1  1.019 0.960 -1.208 -0.928  0.373  1.006  1.695  2.839
#> [2,1]   2   1 :    2  2.004 0.985 -0.219  0.061  1.325  1.985  2.665  3.926
#> [3,1]   3   1 :    3  3.010 0.983  0.801  1.138  2.322  2.997  3.685  5.000
#> [1,2]   1   2 :    4  3.990 0.977  1.717  2.086  3.339  3.999  4.637  5.914
#> [2,2]   2   2 :    5  5.017 0.981  2.760  3.093  4.364  5.004  5.682  6.981
#> [3,2]   3   2 :    6  5.989 1.019  3.622  3.999  5.283  5.988  6.685  7.959
#> [1,3]   1   3 :    7  6.999 0.998  4.727  5.036  6.306  7.004  7.693  8.898
#> [2,3]   2   3 :    8  8.022 0.983  5.842  6.168  7.345  8.000  8.690  9.997
#> [3,3]   3   3 :    9  8.994 0.959  6.807  7.153  8.335  8.977  9.612 10.938
#> [1,4]   1   4 :   10  9.998 1.007  7.723  8.063  9.328  9.981 10.649 12.026
#> [2,4]   2   4 :   11 10.991 0.986  8.813  9.090 10.313 11.012 11.653 12.957
#> [3,4]   3   4 :   12 11.973 1.013  9.573  9.929 11.312 11.969 12.656 13.906
#>          99% sims
#> [1,1]  3.237 2500
#> [2,1]  4.298 2500
#> [3,1]  5.278 2500
#> [1,2]  6.327 2500
#> [2,2]  7.248 2500
#> [3,2]  8.325 2500
#> [1,3]  9.180 2500
#> [2,3] 10.314 2500
#> [3,3] 11.288 2500
#> [1,4] 12.433 2500
#> [2,4] 13.423 2500
#> [3,4] 14.358 2500