# read in data and get rid of extra columns (?)
fish_catch <- read_csv(here("data", "fish_catch.csv"))

keep <- c("year", "catch_m_tons")
fish_catch = fish_catch[keep]

# Mutate new column ("time") so that year 1950 is 0 
fish <- fish_catch %>% 
  mutate(time = year-1950) %>% 
  relocate(time) 

fish <- fish[-c(2) ]

# rename catch_m_tons to pop
fish <- fish %>% 
  rename(pop = catch_m_tons)

Exploratory Graphs

# In text below the exploratory graph: What type of relationship describes the trend? What does that look like mathematically (include an equation, possibly using LaTeX)? What are your initial estimates for the parameters in the model?

# look at the data
ggplot(data = fish, aes(x=time, y=pop)) +
  geom_point() +
  theme_minimal() +
  labs(x = "time (year)", y = "catch (million tons)")
**Figure 1.** Catch of wild fish over time (years)

Figure 1. Catch of wild fish over time (years)

# look at the log-transformed data
# ggplot(data = fish, aes(x= time, y = log(pop))) +
#   geom_point() +
#   theme_minimal() +
#   labs(x = "time (year)", y = "ln(catch)")

The equation for logistic growth is represented by:

\(P(t)=\frac{K}{1+Ae^{-kt}}\), where

Estimated parameters for the above graph are:

# Find estimate for K, A, and k
fish_exp <- fish %>% 
  filter(time < 40) %>% 
  mutate(ln_pop = log(pop))

# Model linear to get *k* estimate (the slope of this linear equation is an estimate of the growth rate constant):
lm_k <- lm(ln_pop ~ time, data = fish_exp)
# lm_k

# Coefficient (k) ~ 0.03562 

Nonlinear Least Squares

Our model with estimated parameters is: \[P(t) = \frac{100.28}{4.3^{-0.07t}}\]

# Make predictions for the population at all of those times (time) in the original df:
p_predict <- predict(fish_nls)

# Bind predictions to original data frame:
fish_complete <- data.frame(fish, p_predict)

# Plot them all together:
ggplot(data = fish_complete, aes(x = time, y = pop)) +
  geom_point() +
  geom_line(aes(x = time, y = p_predict)) +
  theme_minimal() +
  labs(x = "time (years)", y = "Catch (million tons)",
       title = "Wild Fish Catch over Time") +
  theme(plot.title = element_text(hjust = 0.5))

Source: Global wild fish catch and aquaculture production, compiled by Earth Policy Institute with 1950-2010 from U.N. Food and Agriculture Organization (FAO), Global Capture Production and Global Aquaculture Production, electronic databases, at www.fao.org/fishery/topic/16140/en.