Skip to contents

Wrapper function to calculate global and local Moran's I by discrete area.

Usage

moran_stats(
  dat,
  project,
  varofint,
  zoneid,
  spat,
  cat,
  lon.dat = NULL,
  lat.dat = NULL,
  lon.spat = NULL,
  lat.spat = NULL
)

Arguments

dat

Primary data containing information on hauls or trips. Table in FishSET database contains the string 'MaindataTable'.

project

String, name of project.

varofint

Numeric variable from dat to test for spatial autocorrelation.

zoneid

Variable in dat that identifies the individual zones or areas. Define if exists in dat and is not named `ZoneID`. Defaults to NULL.

spat

Spatial data containing information on fishery management or regulatory zones. Shape, json, geojson, and csv formats are supported.

cat

Variable or list in spat that identifies the individual areas or zones. If spat is class sf, cat should be name of list containing information on zones.

lon.dat

Longitude variable from dat.

lat.dat

Latitude variable from dat.

lon.spat

Variable or list from spat containing longitude data. Required for csv files. Leave as NULL if spat is a shape or json file.

lat.spat

Variable or list from spat containing latitude data. Required for csv files. Leave as NULL if spat is a shape or json file.

Value

Returns a plot and map of Moran’s I. Output is saved to the Output folder.

Details

Measure degree of spatial autocorrelation. Function utilizes the localmoran and knearneigh functions from the spdep package. The spatial input is a row-standardized spatial weights matrix for computed nearest neighbor matrix, which is the null setting for the nb2listw function. The function requires a map file with lat/lon defining boundaries of area/zones and varofint for to test for spatial autocorrelation. If zonal centroid is not included in the map file, then the find_centroid function is called to calculate the centroid of each zone. If the variable of interest is not associated with an area/zone then assignment_column is called to assign each observation to a zone. Arguments to identify centroid and assign variable of interest to area/zone are optional and default to NULL.

Examples

if (FALSE) {
moran_stats(pcodMainDataTable, project='pcod', varofint='OFFICIAL_MT_TONS',
spat=spatdat, lon.dat='LonLat_START_LON', lat.dat ='LonLat_START_LAT', cat='NMFS_AREA')
}