Learn R Programming

ergm.ego (version 0.5)

egodata: Convert to or Construct egodata Objects

Description

as.egodata is a generic function to construct egodata objects from a variety of sources. egodata function is the standard constructor, taking two data frames. For other methods for this class, see the Miscellaneous Methods section.

Usage

egodata(egos, alters, egoWt = 1, ..., egoIDcol = "egoID")

as.egodata(object, ..., egoIDcol = "egoID")

# S3 method for data.frame as.egodata(object, alters, egoWt = 1, ..., egoIDcol = "egoID", alterIcol = "alterInd", alterIDcol = "alterID")

Arguments

alters

The data.frame containing at least the column named in egoIDcol, whose values do not have to be unique, and not every ego has to be represented. Other columns contain information about the alters.

For the data.frame method in which the object argument also contains alter information in ‘wide’ format, a list with the following information:

columns

A character, integer, or logical vector identifying which columns contain the alters' information.

count

The name of the column containing the number of alters nominated by that ego.

name.sep

A one-character string or an empty string (defaulting to ".") specifying the character, if any, used to separate alter attribute name from alter's index within the ego. If an empty string (""), attribute name is assumed to be made of letters, with any numbers being the alter index.

egoIDcol, whose values do not have to be unique, and not every ego must be represented. Other columns contain information about the alters.

egoWt

A vector of the same length as number of rows in egos or object, containing the relative sampling weight of each ego.

Additional arguments; currently unused.

egoIDcol

Name of the column in the ego table containing the unique ego identifier.

object, egos

The object from which the egocentric data should be constructed. For the data.frame methods and egodata itself, a data frame containing at least the column named in egoIDcol, whose values must all be unique. Other columns contain information about the egos.

For the data.frame method, it may also contain the information about the alters in a ‘wide’ format, in the form of additional columns with names like ATTRNAME1, ATTRNAME2, etc. for attribute ATTRNAME of alter 1, 2, etc., as well as a column containing the number of alters nominated by that ego.

alterIcol

Column name to use for the within-ego index of the alter.

alterIDcol

Column name to use for the unique ID of each alter, constructed by concatenating the ID of the ego that nominated them and their index within that ego.

Value

An egodata object. The object is a list containing the following elements:

egos

A data frame with one row for each ego, containing at least the column named in egoIDcol, and other columns containing attributes of the egos.

alters

A data frame containing at least the column named in egoIDcol, and other columns containing attributes of the alters.

egoWt

A vector of the same length as the number of egos, containing the relative sampling weight of each ego.

egoIDcol

Name of the column in the ego table containing the unique ego identifier.

Miscellaneous Methods

The following “standard” methods have also been implemented for egodata:

"dim.egodata"

A vector with three elements containing the “dimensions” of the egodata object: number of egos, number of columns in the egos table, and number of columns in the alters table, inclsive of the ego identifier column. As a corollary, nrow returns the number of egos in the dataset.

"dimnames.egodata"

A list with three elements containing the “dimension names” of the egodata object: ego IDs, column names of the egos table, and column names of the alters table, inclsive of the ego identifier column.

"sample.egodata"

As sample, but takes and returns a simulated egodata dataset by resampling egos, adjusting ego weights as necessary, if weighted sampling was used.

"head.egodata"

As head, but returns the first n rows of egos, alters, and weights.

"na.omit.egodata"

As na.omit.data.frame, but takes and returns an egodata dataset, with egos with NA in their rows or in their alters' rows. An optional argument relevant, defaulting to all columns, can be used to select (by index or name) based on which columns an ego may be dropped. (I.e., NAs in those not “relevant” are ignored.)

See Also

ergm.ego for examples, as.network.egodata, as.egodata.network, subset.egodata, [.egodata