socialEdges: Identify Edges in Social Networks

Description Usage Arguments Details Value Examples

View source: R/socialEdges.R

Description

This function identifies edges in social networks representative of instances where there are greater or fewer contacts than would be expected at random, given a pre-determined p-value threshold for significance (i.e., alpha level).

Usage

1
socialEdges(x, alpha = 0.05, weight = NULL, removeDuplicates = TRUE)

Arguments

x

A data frame created by a contactCompare function (e.g., contactCompare_chisq).

alpha

Numerical threshold for determining social significance given p-values reported in x. Observations in x with p.values >= alpha will be returned by this function.

weight

Vector of length nrow(data.frame(x)) denoting what information should be carried over from x to the function output (e.g., number of observed contacts). If the weight is not specified, the "weight" in function output is presented as the proportion of total potential contact durations that nodes were observed in contact with one another (in each separate timeblock if applicable).

removeDuplicates

Logical. If removeDuplicates == true, duplicated edges are removed are removed from the output. Defaults to TRUE.

Details

This function will automatically import defined time blocks if applicable. Furthermore, because this function is intended describe social relationships between individuals, any "totalDegree" and "totalContactDurations" metrics are not included in function output, even if they are present in x.

Value

Returns a list with three objects

Greater

Data frame of dyads with more contacts than would be expected at random given the chosen alpha level.

Fewer

Data frame of dyads with fewer contacts than would be expected at random given the chosen alpha level.

p.val_threshold

Reports the chosen alpha level.

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
53
data(calves) #load data

calves.dateTime<-datetime.append(calves, date = calves$date,
                                 time = calves$time) #add dateTime column

calves.agg<-tempAggregate(calves.dateTime, id = calves.dateTime$calftag,
                       dateTime = calves.dateTime$dateTime, point.x = calves.dateTime$x,
                       point.y = calves.dateTime$y, secondAgg = 300, extrapolate.left = FALSE,
                       extrapolate.right = FALSE, resolutionLevel = "reduced", parallel = FALSE,
                       na.rm = TRUE, smooth.type = 1) #aggregate to 5-min timepoints

calves.dist<-dist2All_df(x = calves.agg, parallel = FALSE,
                       dataType = "Point", lonlat = FALSE) #calculate  inter-calf distances

calves.contact.block<-contactDur.all(x = calves.dist, dist.threshold=1,
                       sec.threshold=10, blocking = TRUE, blockUnit = "hours", blockLength = 1,
                       equidistant.time = FALSE, parallel = FALSE, reportParameters = TRUE)

emp.summary <- summarizeContacts(calves.contact.block, 
                                 importBlocks = TRUE) #empirical contact summ.
emp.potential <- potentialDurations(calves.dist, blocking = TRUE, 
                                    blockUnit = "hours", blockLength = 1, 
                                    distFunction = "dist2All_df") 

calves.agg.rand<-randomizePaths(x = calves.agg, id = "id",
                       dateTime = "dateTime", point.x = "x", point.y = "y", poly.xy = NULL,
                       parallel = FALSE, dataType = "Point", numVertices = 1, blocking = TRUE,
                       blockUnit = "mins", blockLength = 20, shuffle.type = 0, shuffleUnit = NA,
                       indivPaths = TRUE, numRandomizations = 2) #randomize calves.agg

calves.dist.rand<-dist2All_df(x = calves.agg.rand, point.x = "x.rand",
                       point.y = "y.rand", parallel = FALSE, dataType = "Point", lonlat = FALSE)

calves.contact.rand<-contactDur.all(x = calves.dist.rand,
                       dist.threshold=1, sec.threshold=10, blocking = TRUE, blockUnit = "hours",
                       blockLength = 1, equidistant.time = FALSE, parallel = FALSE,
                       reportParameters = TRUE) #NULL model contacts (list of 2)

rand.summary <- summarizeContacts(calves.contact.rand, avg = TRUE,
                                  importBlocks = TRUE) #NULL contact summary
rand.potential <- potentialDurations(calves.dist.rand, blocking = TRUE, 
                                     blockUnit = "hours", blockLength = 1, 
                                     distFunction = "dist2All_df") 

CC1 <-contactCompare_chisq(x.summary = emp.summary, y.summary = rand.summary, 
                     x.potential = emp.potential, y.potential = rand.potential,
                     importBlocks = FALSE, shuffle.type = 0, 
                     popLevelOut = TRUE, parallel = FALSE) #no blocking

socEdges <- socialEdges(x = CC1[[1]], alpha = 0.05, weight = NULL, 
                     removeDuplicates = TRUE)

   

contact documentation built on May 17, 2021, 5:07 p.m.