prm: Modified panel regression model

Description Usage Arguments Value References Examples

Description

Format for, fit, and predict from a panel regression model. The datalimited package includes cached data that can be used with fit_prm and a cached model that can be used with predict_prm. These functions can also be used with new data.

format_prm: Format a series of predictors for a panel regression

fit_prm: Fit a panel regression

predict_prm: Predict from a panel regression model

Usage

1
2
3
4
5
6
7
8
format_prm(year, catch, species_cat, bbmsy = NULL)

fit_prm(dat, eqn = log(bbmsy) ~ max_catch + mean_scaled_catch + scaled_catch +
  scaled_catch1 + scaled_catch2 + scaled_catch3 + scaled_catch4 + species_cat +
  catch_to_rolling_max + time_to_max + years_back + initial_slope - 1,
  type = c("lm", "gbm"), ...)

predict_prm(newdata, model = datalimited::ram_prm_model, ci = FALSE)

Arguments

year

A numeric vector of years

catch

A numeric vector of catches

species_cat

A single character value of a species category. Can be from any set of species categories as long as the same set are used in model fitting and extrapolation.

bbmsy

A numeric vector of B/B_MSY (only needed if passing the output to fit_prm; leave as NULL if passing output to predict_prm)

dat

A data frame created by format_prm

eqn

A formula describing the regression

type

Either linear model ("lm"; the original method) or a gbm model ("gbm")

...

Anything extra to pass to gbm

newdata

A data frame to predict on that has been formatted with format_prm.

model

A linear model to predict from built from fit_prm. Defaults to a cached version of a model fit to the RAM database, ram_prm_model.

ci

Should confidence intervals on B/B_MSY be returned?

Value

format_prm: A data frame formatted for use with fit_prm or predict_prm

fit_prm: A linear model for use with predict_prm

predict_prm: If ci = FALSE, a vector of predictions of B/B_MSY. If ci = TRUE, a data frame. Note that the model is fitted to log(B/B_MSY) and the output from predict_prm is exponentiated so the prediction represents an estimate of median B/B_MSY.

References

Costello, C., D. Ovando, R. Hilborn, S. D. Gaines, O. Deschenes, and S. E. Lester. 2012. Status and Solutions for the World's Unassessed Fisheries. Science 338:517-520.

Examples

 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
# combine two built in datasets:
# d <- dplyr::inner_join(ram_ts, spp_categories, by = "scientificname")

# ram_prm_dat is built into the package; it can be created with:
# ram_prm_dat <- plyr::ddply(d, "stockid", function(x) {
#   format_prm(year = x$year, catch = x$catch, bbmsy = x$bbmsy_ram,
#     species_cat = x$spp_category[1L])
# })

# ram_prm_model is built into the package, it is created in the same manner
# as this:
# m <- fit_prm(ram_prm_dat)

# now predict B/Bmsy:
d <- subset(ram_prm_dat, stockid == "BGRDRSE")
x <- predict_prm(d) # use the built in model
plot(x)

# with confidence intervals:
library("ggplot2")
x <- predict_prm(d, ci = TRUE)
ggplot(x, aes(year, bbmsy_q50)) +
  geom_ribbon(aes(ymin = bbmsy_q2.5, ymax = bbmsy_q97.5), fill = "#00000040") +
  geom_line() +
  ylab(expression(B/B[MSY]))

# format and predict on a new fake dataset:
set.seed(1)
dat <- format_prm(
  year = 1:10,
  catch = rlnorm(10),
  species_cat = "Cods, hakes, haddocks")
head(dat)
predict_prm(dat)

datalimited/datalimited documentation built on May 14, 2019, 7:44 p.m.