The pre() function (and, similarly, the PRE() function) will calculate the PRE value for a model.
Example 1:
Below are various methods for indexing the model in the argument of the pre() function (they will all produce the same output). For any of these, pre() can be replaced with PRE().
# Method 1: Find the PRE value for the Sex model of Thumb
pre(Thumb ~ Sex, data = Fingers)
# Method 2: Save the model first
Sex_model <- lm(Thumb ~ Sex, data = Fingers)
pre(Sex_model)
# Method 3: Use the lm() function within the pre() function
pre(lm(Thumb ~ Sex, data = Fingers))
Example output:
Example 2:
Below is an example of using the pre() function to generate a sampling distribution of PRE, then plotting the distribution, and plotting the sample PRE value on the graph.
# Generate 1000 PREs from randomized (shuffled) data
# and save them into an object called sdoPRE
sdoPRE <- do(1000) * pre(shuffle(Thumb) ~ Sex, data = Fingers)
# Save and print out the sample PRE value
sample_pre <- pre(Thumb ~ Sex, data = Fingers)
sample_pre
# Plot the sampling distribution with the sample PRE
gf_histogram(~ pre, data = sdoPRE, fill = ~lower(pre, .95)) %>%
gf_point(0 ~ sample_pre, color = "red")