DanOvando / zissou

Repository for causal effect ot MLPA
0 stars 1 forks source link

Write length-to-weight function #1

Closed DanOvando closed 7 years ago

DanOvando commented 7 years ago

Write a function that converts total lengths observed in UCSB_FISH raw thru 2013.csv to weights, using the allometric relationships in VRG Fish Life History in MPA_04_08_11_12 11-Mar-2014.csv

There's a start to this in documents/ahnold_labbook.Rmd, line 254

jcvdav commented 7 years ago

@DanOvando could yo check the functions and tell me if they seem alright? I have included the fixed csv of life hist params there, which was generated with this script. The key function is length2weight(), which assumes all your allometric parameters convert from cm to gr, TL or SL are handleded within the function. This should allow you to do something like:

Estimate weight of each record or row (i.e. individual fish weight * abundance)

#read the corrected allometric parameters
life_history_params <- read.csv("./JC_DirectedResearch/functions/life_history_fixed.csv")

#calculate biomass with length2weight()
count_data <- read.csv("../data/UCSB_FISH raw thru 2013.csv") %>% 
  left_join(life_history_params, by = "classcode") %>% 
  mutate(weight = length2weight(count, fish_tl, wl_a, wl_b, wl_input_length, lc.a._for_wl, lc.b._for_wl))

Group it by species, site, side, and year using transects as unit of sampling effort

grouped_biomass <- count_data %>% 
  group_by(classcode, site, side, year, transect) %>% 
  summarise(total_biomass_g = sum(weight)) %>% 
  group_by(classcode, site, side,year) %>% 
  summarise(mean_biomass_g = mean(total_biomass_g, na.rm = T)) %>% 
  mutate(biomass_g_per_m2 = mean_biomass_g / (60*4),
         biomass_g_per_hectare = biomass_g_per_m2 * 10000,
         biomass_ton_per_hectare = biomass_g_per_hectare * 1e-6)
DanOvando commented 7 years ago

Thanks Juan, I'll take a look at this on the plane this week, and will try and get the ball rolling with the OST stuff as well