CreateSpatialNeighbours: Distances between related family members, formatted for...

View source: R/create-spatial-neighbours.R

CreateSpatialNeighboursR Documentation

Distances between related family members, formatted for spatial analysis.

Description

This helper function formats the LinksPair datasets so it can be used in some types of spatial analyses. The spdep (Spatial Dependence) uses a sparse matrix (actually a base::data.frame) to represent neighbours.

Usage

CreateSpatialNeighbours(linksPairsDoubleEntered)

Arguments

linksPairsDoubleEntered

A base::data.frame containing the links, preferably created by a function like CreatePairLinksDoubleEntered().

Details

There is one row per unique pair of subjects, respecting order. This has twice as many rows as Links79Pair and Links79PairExpanded (which have one row per unique pair of subjects, irrespective of order).

CreateSpatialNeighbours() accepts any paired relationships in a base::data.frame, as long as it contains the columns SubjectTag_S1, SubjectTag_S2, and R. See Links79Pair for more details about these columns.

Value

An S3 spdep::spatial.neighbours object to work with functions in the spdep package.

SubjectTag_S1 is renamed 'from'.

SubjectTag_S2 is renamed 'to'.

R is renamed 'weight'.

The attribute region.id specifies each unique SubjectTag.

The attribute n specifies the number of unique subjects.

Note

Notice the British variant of 'neighbours' is used, to be consistent with the spdep::spatial.neighbour class.

Author(s)

Will Beasley and David Bard

References

Bard, D.E., Beasley, W.H., Meredith, K., & Rodgers, J.L. (2012). Biometric Analysis of Complex NLSY Pedigrees: Introducing a Conditional Autoregressive Biometric (CARB) Mixed Model. Behavior Genetics Association 42nd Annual Meeting. Slides.

Bivand, R., Pebesma, E., & Gomez-Rubio, V. (2013). Applied Spatial Data Analysis with R. New York: Springer. (Especially Chapter 9.)

Banerjee, S., Carlin, B.P., & Gelfand, A.E. (2004). Hierarchical Modeling and Analysis for Spatial Data. Boca Raton: CRC Press.

Lawson, A.B (2013). Bayesian Disease Mapping: Hierarchical Modeling in Spatial Epidemiology, Second Edition. Boca Raton: CRC Press.

The spdep package documentation: spdep: Spatial dependence: weighting schemes, statistics and models.

Examples

dsLinksAll <- Links79Pair
dsLinksGen1Housemates <- dsLinksAll[dsLinksAll$RelationshipPath == "Gen1Housemates", ]
dsLinksGen2Siblings <- dsLinksAll[dsLinksAll$RelationshipPath == "Gen2Siblings", ]

spGen1 <- CreateSpatialNeighbours(dsLinksGen1Housemates)
spGen2 <- CreateSpatialNeighbours(dsLinksGen2Siblings)

head(spGen2)
# Returns:
#   from  to weight
# 3  201 202   0.50
# 6  301 302   0.50
# 7  301 303   0.50
# 9  302 303   0.50
# 24  401 403   0.25
# 28  801 802   0.50

table(spGen2$weight)
# Returns:
# 0.25 0.375   0.5  0.75     1
# 3442   610  6997    12    27

nlsy-links/NlsyLinks documentation built on March 13, 2024, 4:05 a.m.