Learn R Programming

prova (version 1.0.0)

vrtgrid: Create a grid of values for a variate

Description

This function creates a set of values for a variate, based on the information from data and metadata stored in a learnt object, created by the learn() function. The set of values depends on the type of variate (nominal or continuous, rounded, and so on, see metadata). The range of values is chosen to include, and extend slightly beyond, the range observed in the data used in the learn() function. Variate domains are always respected.

Usage

vrtgrid(vrt, learnt, length.out = 129)

Value

A numeric or character vector of values.

Arguments

vrt

Character: name of the variate, must match one of the names in the metadata file provided to the learn() function.

learnt

Either a character with the name of a directory or full path for a 'learnt.rds' object, produced by the learn() function, or such an object itself.

length.out

Numeric, positive (default 129): number of values to be created; used only for continuous, non-rounded variates (see metadata).

See Also

learn(), which generates the learnt objects required by vrtgrid().

Pr() to calculate probabilities and their variability.

plot.probability() to plot probabilities and quantiles calculated by Pr().

Examples

Run this code
## Load the example `learnt` object calculated from the "penguins" dataset;
## variates: 'species' and 'bill_len'
learnt <- learntExample

## set of values for the variate "species";
## since this variate is of a nominal kind, all values are included
valuesSpecies <- vrtgrid(vrt = 'species', learnt = learnt)

print(valuesSpecies)

## create a set of values for the variate "bill length";
## this variate is continuous and rounded, only realistic values are included
valuesBill <- vrtgrid(vrt = 'bill_len', learnt = learnt)

range(valuesBill)

## let's take a subset of these values, to speed up computation
valuesBill <- valuesBill[seq(to = length(valuesBill), length.out = 65)]

## calculate the conditional probabilities for the 'bill_len' values above,
## given the values of 'species'
probs <- Pr(
  Y = data.frame(bill_len = valuesBill),
  X = data.frame(species = valuesSpecies),
  learnt = learnt, parallel = 1
)

## plot the conditional probability distributions, and their variability
plot(probs)

Run the code above in your browser using DataLab