knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
Data should be set out in the same format as in the giraffe
example data file. Note that a warning will be given for any of the possible pairs not recorded together.
library(CaptiveIndex) data(giraffe) head(giraffe)
Columns should include the following: Subject - Individual being sampled Present – list of individuals present separate by a space N.N – names of individual who is the nearest neighbour (within x metres) C.P – names of individual who is within the closet proximity (within x metres)
NB. If there is no individual for N.N or C.P record as a 0 (zero).
Use DataCreate
function to prepare data for analysis:
This function will identify the number of times pairs are together, providing a short hand descriptor of the pair using the first 3 letters of each individual.
NN.ID <- DataCreate (giraffe) head(NN.ID)
Calculate the weights for nearest neighbour and proximity values using the Weights
function:
W <- Weights(giraffe) W
Calculate the Captive Index (or association meassure) using the data created in the DataCreate
function and applying the weights from Weights
function:
Results <- CaptiveIndex(NN.ID, W$NN, W$IDist) head(Results)
Convert 'Results' output into a square matrix, then plot a sociogram using igraph.
# reshape the data frame into a square matrix # install.packages("reshape2") library(reshape2) mat <- acast(Results, Subject ~ Partner, value.var = "CaptiveIndex1")
# install.packages("igraph") library(igraph) ## Plot graph with weighted edges
g <- graph.adjacency(mat, mode="undirected", weighted=TRUE, diag=FALSE) plot.igraph(g, vertex.label = V(g)$name, layout = layout.fruchterman.reingold, edge.color = "black", edge.width = (E(g)$weight)*20, mode = "circle")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.