sample: Draw random egocentric subsamples

Description Usage Arguments Value Note Examples

View source: R/egor.R

Description

Implementations of the base::sample() function for egor::egor() data.

Usage

1
2
3
4
5
6
7
sample(x, size, replace = FALSE, prob = NULL, ...)

## Default S3 method:
sample(x, ...)

## S3 method for class 'egor'
sample(x, size, replace = FALSE, prob = NULL, ...)

Arguments

x, size, replace, prob

see base::sample().

...

extra arguments, currently unused.

Value

An egor::egor() object whose egos have been resampled in accordance with the arguments. Note that its egor::ego_design() information is overwritten in favor of the selection probabilities used in the sampling.

Note

A reimplementation of sample as a generic was necessary because base::sample() is not a generic and cannot take data-frame-alikes as arguments.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
data(faux.mesa.high)
fmh.ego <- as.egor(faux.mesa.high)

# Create a tiny weighted sample:
(s3 <- sample(fmh.ego, 3, replace=TRUE, prob=1:nrow(fmh.ego$ego)))
# Resampling with prob=weights(egor) creates a self-weighted
# sample:
(sample(s3, 3, replace=TRUE, prob=weights(s3)))

# Create a large weighted sample, oversampling 12th-graders:
p <- ifelse(as_tibble(fmh.ego$ego)$Grade==12, 2, 1)
s2000 <- sample(fmh.ego, 2000, replace=TRUE, prob=p)

# Summary function adjusts for weights:
(summ.net <- summary(faux.mesa.high ~ edges + nodematch("Grade") +
                     nodefactor("Race") + gwesp(0,fix=TRUE)))
(summ.ego <- summary(s2000 ~ edges + nodematch("Grade") + 
                     nodefactor("Race") + gwesp(0,fix=TRUE),
                     scaleto=network.size(faux.mesa.high)))

statnet/ergm.ego documentation built on April 26, 2021, 4:46 a.m.