stats_by_group: stats_by_group

Description Usage Arguments Value Examples

View source: R/stats_by_group.R

Description

Calculate summary and spatial statistics across multiple images within groups.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
stats_by_group(
  img_list,
  metadata = NULL,
  idvar = NULL,
  grouping_var = NULL,
  round_val = NULL,
  calc_connectivity = FALSE,
  conn_threshold = 1.5,
  patches = TRUE,
  style = "C",
  img_proj = NULL,
  img_extent = NULL,
  sum_stats = c("mean", "max", "min"),
  return_vals = c("df", "patches", "pstats")
)

Arguments

img_list

List or stack of numeric temperature matrices or rasters.

metadata

A dataframe denoting the grouping of different images. Defaults to NULL as this is not required when img_list provided as a raster stack (where each raster layer assumed to represent each 'group').

idvar

Name of the metadata variable that identifies unique images. Should match element names in the image list. Defaults to NULL as this is not required when img_list provided as a raster stack (where idvar is assumed to be the names of the raster layers).

grouping_var

The name of the metadata variable that denotes the grouping of images. Defaults to NULL, where it is assumed to equal idvar (each group is assumed to have only one image).

round_val

Value to round to. Defaults to NULL.

calc_connectivity

Whether or not to calculate thermal connectivity across pixels (slow for large rasters). Defaults to FALSE.

conn_threshold

Climate threshold to use for calculation of thermal connectivity (i.e. the amount of change that organisms would be seeking to avoid). See ThermStats::connectivity. Defaults to 1.5°C.

patches

Whether to identify hot and cold spots. Defaults to TRUE.

style

Style to use when calculating neighbourhood weights using spdep::nb2listw. Defaults to 'C' (globally standardised).

img_proj

Spatial projection. Optional, but necessary for geographic data to plot correctly.

img_extent

Spatial extent. Optional, but necessary for geographic data to plot correctly.

sum_stats

Summary statistics that should be calculated across all pixels. Several helper functions are included for use here: perc_5, perc_95, SHDI, SIDI, kurtosis and skewness.

return_vals

Which values to return? Any combination of the dataframe (df), SpatialPolygonsDataFrame of hot and cold patches (patches) and patch statistics dataframe (pstats), although pstats will always be returned – if this is not desired, use get_patches instead.

Value

A list containing:

df

A dataframe with one row for each pixel, and variables denoting: the pixel value (val); the spatial location of the pixel (x and y); its patch classification (G_bin) into a hot (1), cold (-1) or no patch (0) according to the Z value (see spdep::localG); the unique ID of the patch in which the pixel fell; the image ID (if applicable); and the original spatial location of the pixel (x_orig and y_orig).

If calculating thermal connectivity, df will also contain: the unique ID of the coldest destination pixel that can be reached by traversing a gradient of hotter to cooler pixels (dest_pixel); the pixel value of the destination pixel (dest_val); the unique IDs of pixels traversed from origin to destination (inter_pixel); the temperature difference between the origin and destination pixel (diff_potential); and the thermal connectivity (therm_conn), which is diff_potential minus conn_threshold.

patches

A list of SpatialPolygonsDataFrames of hot and cold patches, named according to grouping_var. Hot patches have a value of 1, and cold patches a value of -1.

pstats

A dataframe with patch statistics for hot patches and cold patches, respectively. See patch_stats for details of all the statistics returned.

If calculating thermal connectivity, there will also be statistics for the minimum, mean, median and maximum temperature difference (diff_potential) and thermal connectivity (conn_threshold).

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
50
51
52
# Load raw data
raw_dat <- flir_raw$raw_dat
camera_params <- flir_raw$camera_params
metadata <- flir_metadata

# Batch convert
img_list <- batch_convert(raw_dat, write_results = FALSE)

## Not run: 
# Calculate patch and pixel stats -------------------------------------------

# Pixel stats = mean, max and min
patch_stats_1 <-
    stats_by_group(img_list = img_list,
                   metadata = metadata,
                   idvar = "photo_no",
                   style = "C",
                   grouping_var = "rep_id",
                   round_val = 0.5,
                   sum_stats = c("mean", "max", "min"))

# Pixel stats = kurtosis and sknewness
patch_stats_2 <-
    stats_by_group(img_list = img_list,
                   metadata = metadata,
                   idvar = "photo_no",
                   style = "C",
                   grouping_var = "rep_id",
                   round_val = 0.5,
                   sum_stats = c("kurtosis", "skewness"))

# Pixel stats = 5th and 95th percentiles
patch_stats_3 <-
    stats_by_group(img_list = img_list,
                   metadata = metadata,
                   idvar = "photo_no",
                   style = "C",
                   grouping_var = "rep_id",
                   round_val = 0.5,
                   sum_stats = c("perc_5", "perc_95"))

# Pixel stats = Shannon and Simpson Diversity Indices
patch_stats_4 <-
    stats_by_group(img_list = img_list,
                   metadata = metadata,
                   idvar = "photo_no",
                   style = "C",
                   grouping_var = "rep_id",
                   round_val = 0.5,
                   sum_stats = c("SHDI", "SIDI"))

## End(Not run)

rasenior/PatchStatsFLIR documentation built on Oct. 28, 2020, 11:53 p.m.