Code/03_code_for_rats_raw_results_function.R

#plotting data for rats
#starting from csv file and plot_all_dat1?think??
#feb2020

## ----data-rats-----------------------------------------------------------
#from the data
#length of df = 144

#newer tibble structure
plot.dat.all1 <- read_csv("./data/plot-all-data1.csv")


# N = mouse abundance estimate
#add other abundances (seed, rats etc)

#var is a list of N outputs
# at length 144
# dat_abund$var
# grid.id (8) x trip (20)

# abund_rats <-

# Cleaning up total dataset
plot.dat.all1  <- plot.dat.all1 %>%
  mutate(trip = as.character(trip))# already done!

# rats have only 80 estimates not 144
meanR <- read_csv("C://data/mna_allrat.csv") %>%
  dplyr::select (valley, grid ,trip.no ,n) %>%
  # select (grid ,trip.no ,n) %>%
  mutate(trip = as.character(trip.no),
         grid = grid,
         rat.mna = n,
         Valley = factor(valley, labels = c("Eglinton", "Hollyford")))

joined.rats <- left_join(plot.dat.all1, meanR, by = c("grid", "Valley", "trip"))

# summaries
rat.mean <- joined.rats %>%
  group_by(Control, Valley, Date) %>%
  summarise(mean.rat = mean(rat.mna, na.rm = TRUE),
            sd.rat = sd(rat.mna, na.rm = TRUE),
            se.rat = sd.rat / sqrt(length(rat.mna)) * 1.96,
            lcl.rat = mean.rat - (sd.rat / sqrt(length(rat.mna)) *
                                    1.96),
            ucl.rat = mean.rat + (sd.rat / sqrt(length(rat.mna)) *
                                    1.96)
  ) %>%
  ungroup() %>%
  mutate(Valley = Valley,
         gp.treat = factor(paste(Valley, Control)),
         N = mean.rat,
         Rats = factor("Full")
  )

# glimpse(joined.rats)


## ------------------------------------------------------------------------
kableExtra::kable(head(rat.mean), format = "markdown")


## ----old-rats------------------------------------------------------------
rat.mean <- joined.rats %>%
  group_by(Control, Valley, Date) %>%
  summarise(mean.rat = mean(rat.mna, na.rm = TRUE),
            sd.rat = sd(rat.mna, na.rm = TRUE),
            se.rat = sd.rat / sqrt(length(rat.mna)) * 1.96,
            lcl.rat = mean.rat - (sd.rat / sqrt(length(rat.mna)) *
                                    1.96),
            ucl.rat = mean.rat + (sd.rat / sqrt(length(rat.mna)) *
                                    1.96)
  ) %>%
  ungroup() %>%
  mutate(Valley = Valley,
         gp.treat = factor(paste(Valley, Control)),
         N = mean.rat,
         Rats = factor("Full")
  )
davan690/beech-publication-wr documentation built on March 29, 2020, 11:09 a.m.