check_strat: Check Strata

Description Usage Arguments Details Value Examples

View source: R/check_strat.R

Description

Visualize which strata were visited in each year, and how many strata were visited in all but N years

Usage

1
2
3
4
check_strat(X, reg = c("ai", "ebs", "gmex", "goa", "neus", "newf", "sa",
  "sgulf", "shelf", "wcann", "wctri"), gridSize = 1,
  append_keep_strat = FALSE, prompt_strat_tol = FALSE, strat_tol,
  plot = TRUE)

Arguments

X

A trawl data.table

reg

region name

gridSize

grid size to be passed to ll2strat

append_keep_strat

Logical, whether to add the keep_strat column to X

prompt_strat_tol

Logical, if in interactive mode, prompt user for tolerance? If not, and if append_keep_strat is TRUE and strat_tol is left missing, then a default will be selected for strat_tol

strat_tol

The maximum number of unsampled years that is tolerated for any stratum before all rows corresponding to that stratum have their value in the "keep_strat" column set to FALSE

plot

Logical, visualize strata over time and the number of strata sampled in all but N years?

Details

The aim of the function is to guide the selection of which strata to exclude from analysis because they are not sampled often enough. Having fewer gaps in your data set is better, but sometimes tolerating a tiny amount of missingness can result in huge increases in data; the visualization provided by this funciton will help gauge that tradeoff.

Value

Nothing. However, potentially modifies X, and may create a figure.

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# quick example for goa
check_strat(clean.goa[,c("year"):=list(as.integer(year))], "goa")

# a more thorough data processing example for shelf
## Not run: 
	# trim shelf
	shelf <- trawlTrim("shelf", c.add=c("val.src", "flag"))
	shelf <- shelf[
		(taxLvl=="species" |taxLvl=="subspecies") & 
		(flag!="bad" | is.na(flag)) & 
		(val.src!="m3" | (!is.na(flag) & flag!="bad"))
	]

	# aggregate species within a haul (among individuals)
	# this means taking the sum of many bio metrics
	shelf <- trawlAgg(
		X=shelf,
		bioFun=sumna,
		envFun=meanna,
		bio_lvl="spp", space_lvl="haulid", time_lvl="haulid",
		bioCols=c("wtcpue"),
		envCols=c("btemp"),
		metaCols=c("reg","common","year","datetime","stratum", "lon", "lat"),
		meta.action=c("unique1")
	)

	# aggregate within a species within stratum
	# refer to the time_lvl column from previous trawlAgg()
	# can use mean for both bio and env
	shelf[,stratum:=ll2strat(lon, lat)]
	shelf <- trawlAgg(
		X=shelf,
		FUN=meanna,
		bio_lvl="spp", space_lvl="stratum", time_lvl="year",
		bioCols=c("wtcpue"),
		envCols=c("btemp"),
		metaCols=c("reg","common", "lon", "lat"),
		meta.action=c("FUN"),
		metaFun=list(reg=unique, common=unique, lon=mean, lat=mean)
	)
	setnames(shelf, "time_lvl", "year")
	shelf[,year:=as.integer(as.character(year))]
	setcolorder(shelf, c(
		"reg", "year", "stratum", "lon", "lat", 
		"spp", "common", "btemp", "wtcpue", "nAgg"
	))
	setkey(shelf, reg, year, stratum, spp, common)

## End(Not run)

rBatt/trawlData documentation built on May 26, 2019, 7:45 p.m.