Skip to contents

Utility function to merge two objects of class "prova_pr" (probability), having same Y and X variates but different values.

Usage

# S3 method for class 'prova_pr'
merge(x, y, ...)

Arguments

x, y

Objects of class "prova_pr" (probability), obtained with Pr().

...

Not used, left for consistency with generic base::merge().

Value

An object of class "prova_pr" (probability), concatenating the x and y objects either along the Y values or along the X values.

Details

This function combines two probability objects of class "prova_pr" (probability) into one. The two objects must have exactly the same sets (and ordering) of Y variates. They must also have the same sets (and ordering) of X variates, unless one or both have NULL X.

The Pr() function allows to calculate point and tail probabilities for any given variate, but not both kinds at the same time. For example, Pr() can calculate the probability that a variate "age" is equal to 30, storing the result in a "prova_pr" probability object; or that it is larger than 35, storing the result in another probability object. But these two calculations cannot be done within one call to Pr(), storing both results at once in one probability object. With the merge function such an object can nevertheless be created from the previous two.

If the values of the X variates are the same, then the probabilities corresponding to different Y values are concatenated. If the values of the Y variates are the same, then the probabilities corresponding to different X values are concatenated. If neither values are in common, the function throws an error.

See also

Pr(), to generate probability objects.

subset.prova_pr(), to subset a probability object.

plot.prova_pr() to plot probabilities and quantiles calculated by `Pr()'.

hist.prova_pr() to plot histograms of the probability distributions calculated by Pr().

Kexample an example "K" object included with Prova.

Examples

## Load the example `K`nowledge object calculated from the "penguins" dataset;
## variates: 'species' and 'bill_len'
K <- Kexample

## Calculate the probability that bill_len <= 43
## given that the species is 'Adelie':
probs1 <- Pr(
  data.frame(bill_len = 43),
  data.frame(species = 'Adelie'),
  K,
  tails = list(bill_len = '<=')
)

probs1
#> , , |species = Adelie
#> 
#>         probability
#> bill_len value  +/-    Q5.5%  Q25%   Q75%   Q94.5%
#>     <=43 0.9364 0.0013 0.9098 0.9259 0.9482 0.9590
#> 

## Calculate the probability that bill_len >= 43.1
## given that the species is 'Adelie':
probs2 <- Pr(
  data.frame(bill_len = 43.1),
  data.frame(species = 'Adelie'),
  K,
  tails = list(bill_len = '>=')
)

probs2
#> , , |species = Adelie
#> 
#>         probability
#> bill_len value  +/-    Q5.5%  Q25%   Q75%   Q94.5%
#>   >=43.1 0.0636 0.0013 0.0410 0.0518 0.0741 0.0902
#> 

## Combine the two tail probabilities for bill_len in one object
probs <- merge(probs1, probs2)

probs
#> , , |species = Adelie
#> 
#>         probability
#> bill_len value  +/-    Q5.5%  Q25%   Q75%   Q94.5%
#>   <=43   0.9364 0.0013 0.9098 0.9259 0.9482 0.9590
#>   >=43.1 0.0636 0.0013 0.0410 0.0518 0.0741 0.0902
#>