For simplicity, we use the terminology of a consumer-resource system, although the model outlined here applies to a large range of other species interactions (e.g. host–parasite, predator–prey or mutualistic interactions).

#### A per-individual interaction model

Assume we observe *N* resource individuals, with individual *i* being a member of species *r*_{i} (1 ≤ *r*_{i} ≤ *R*) and M consumer individuals, with individual *j* being a member of species *c*_{j} (1 ≤ *c*_{j }≤ *C*). If no individual-level data are available for either resource or consumer species (e.g. if individual flowers are observed, with all pollinator visits being recorded without pollinators being distinguished), then we can lump all individuals of each species into one, and set *N *= *R* or *M *= *C*, and what follows simplifies (in the most simplified case, counts usually reduce to the presence/absence data and the model outlined below reduces to a logistic regressions model, Fig. 1).

For each resource individual *i,* we observe *X*_{ij} interactions with consumer individual *j*. We can model these as occurring at a rate λ_{ij}, so that the total number of events observed over a time period *t* follows a Poisson distribution:

- (eqn 1)

where, λ_{ij} is the per-individual interaction strength, so λ_{ij}* *= 0 if the species never interact.

We can model *λ*_{ij} further, for example, by adding the effects of covariates or letting it vary between individuals. In particular,we can assume the interaction is affected multiplicatively by both species-specific components linked to *r*_{i} and *c*_{j} and their interaction as well as interaction-specific components linked to individuals *i* and *j*, so that

- (eqn 2)

where *b(r*_{i}, *c*_{j}*)* is the average species-level and g(*i*,*j*) is the individual-level effect. Some of the parameters can, of course, be modelled further as functions of various environment or species traits (e.g. phylogeny or functional type). In particular, it is convenient to decompose the species-level and individual-level effects:

- (eqn 3a)

- (eqn 3b)

where *ρ*(*r*_{i}) and *χ*(*c*_{j}) are the species-level effects on the interactions, for example, different activity rates (e.g. search efficiency or ‘hungriness’) in the different consumers would lead to variation in *χ*(*c*_{j}), and similarly different palatability or encounter rates of resources would make *ρ(r*_{i}*)* vary. Thus, *τ*(*r*_{i}*, c*_{j}) is related to specialization: a large variance in *τ(r*_{i}*, c*_{j}*)* suggests extreme specialization, with some consumers preferring some resources much more than average. *ι(i)*,* φ(j)* and *t(i,j)* have similar interpretations, but at the individual level, so (for example) variation in palatability between resource individuals can be modelled in *ι(i)*.

Constraints will usually have to be put on the parameters (e.g. that the terms sum to zero, so *a* is the overall average interaction rate), to avoid over-parameterization; here, we will make these constraints in the statistical analysis, but drop them in the mathematical development.

If we only look at the species level, summing over individuals, we can define

- (eqn 4)

where (*r*,*c*) = exp(*b*(*r*,*c*)) is the species-level mean interaction strength and is independent of sample size. Λ*rc* is the summary of interaction frequencies base on per-species interactions strength and the number of individuals sampled in the field and is what is commonly observed (e.g. in pollinator networks, when the visits of a pollinator species to a plant are recorded, but without individuals being marked).

Equation 4 also illustrates the effects that abundances of the interactors have on the observed networks and makes it clear that changes in abundance can cause changes in the aggregated interaction network. This model has been developed in terms of counts, but we can convert counts to probabilities easily, for example

- (eqn 5)

from which we can calculate any summary statistics, such as commonly used network statistics (e.g. Blüthgen & Menzel 2006). This conversion is the same as used in classical statistics to move between logit and log-linear models (e.g. McCullagh & Nelder 1989).

#### Model fitting

As much of the work on ecological networks is empirical, we want to be able to fit the model outlined above to field data. The data are typically counts of events, for example, the number of visits of a frugivore to a plant, or the number of animals of a species eaten by a consumer. The Poisson assumption naturally leads to modelling the counts with a log-linear model (McCullagh & Nelder 1989). At the simplest level, if we only have species-level information, we can use the following model:

Where the response is Count, Consumer and Resource are factors (r(*r*_{i}) and *χ*(*c*_{j}) in (eqn 3a)) and Consumer : Resource is the interaction (*τ*(*r*_{i}, *c*_{j}) in (eqn 3a)), and offset() denotes an offset, that is, a covariate in a model with the regression coefficient fixed to 1 (see O'Hara 2009 for more details about writing this model). The offset term (which is *t*, see (eqn 1)) can be deleted if observation time is constant over all observed combinations of individuals; however, the model has then to be interpreted as the rates per observation time interval. From this, we can extract estimates of *ρ*(*r*_{i}), *χ*(*c*_{i}), and *τ*(*r*_{i}, *c*_{j}) and calculate statistics which summarize the network structure. Two aspects of this experimental design should be noted: (1) the interaction is the same as the overdispersion (so specialization is confounded with any extra-Poisson variation) and (2) the model assumes that all species interact, but at varying rates.

The first problem can only be overcome with more detailed data, for example replicate observations of several resource individuals (e.g. trees) can be used to model the overdispersion. More generally, the model can be developed to incorporate extra individual-level information, which should help to improve the species-level estimates that are usually the main focus. Mathematically this involves adding terms in (eqn 3b) into the model, and then possibly modelling them further.

Interactions may not be observed for two reasons: they may genuinely not take place, or they do occur but are not observed. It is therefore likely that zeros in the data are a mixture of true and false values (Farewell & Sprott 1988). This motivates the use of zero-inflated distributions, where the rate λ*ij* is modelled as being either 0 (or, equivalently, that *τ*(*r*_{i}, *c*_{j}) is −∞) or an estimated positive value. This can be written by introducing an indicator, *I*(*r*,* c*) that resource *r* and consumer *c* interact, that is, if *I*(*r*_{i}, *c*_{j}) = 1, *r* interacts with *c*, and defining

- (eqn 6)

We can then, if necessary, also build a model for *I*(*r*_{i}, *c*_{j}), using a logistic regression framework (e.g. Farewell & Sprott 1988).

The complexity of the resulting model, and the desirability of estimating complex functions of the model, suggests using a Bayesian framework to fit the model. However, there is no necessity to do so and in practice simpler versions of the model are probably better fitted with classical techniques.

#### Simulation study

We use simulated data to explore the effects of using our model outlined earlier, in particular to compare the behaviour of network statistics calculated from the model and from the raw data and see how sample size affected them.

We assume a network of 12 resource species, *r,* and nine consumer species, *c,* (e.g. fruiting trees visited by mammal species) and all individuals are marked and individually surveyed for interaction. We generated an arbitrary matrix of species-level interaction probabilities of 0 ≤ ≤0·75 with the idea that some generalist consumer species are more frequently visiting some resource species than others, while specialist consumers are only attracted to a small range of resource species (Table 1). These values do not necessarily match properties of real-world interactions and ecological networks but are suitable for illustrating the effects of uncertainty due to low interaction probability and different kinds of specialization.

Table 1. Artificial values for interaction strength for a hypothetical community of 12 resource and nine consumer species. For data generation, we assumed equal sample size *N* for different resource species. For consumer species, sample size *M* was either assumed to be equal for all species or variable within or among clusters. We assumed a detection probability of 1. Note that combinations and values are not based on any natural system or empirical data setType | | Generalist | Opportunist | Specialist |
---|

| Detection probability | *1* | *1* | *1* | *1* | *1* | *1* | *1* | *1* | *1* |

| Sample size | *M/M* (1) | *M/M* (2) | *M/M* (3) | *M/M* (4) | *M/M* (5) | *M/M* (6) | *M/M* (7) | *M/M* (8) | *M/M* (9) |

| | Species | C1 | C2 | C3 | C4 | C5 | C6 | C7 | C8 | C9 |

Generalist | *N* | R1 | 0·75 | 0·75 | 0·75 | 0·05 | 0·05 | 0·05 | 0 | 0 | 0 |

*N* | R2 | 0·75 | 0·75 | 0·75 | 0·05 | 0·05 | 0·05 | 0 | 0 | 0 |

*N* | R3 | 0·75 | 0·75 | 0·75 | 0·05 | 0·05 | 0·05 | 0 | 0 | 0 |

Opportunist | *N* | R4 | 0·2 | 0·2 | 0·2 | 0·01 | 0·01 | 0·01 | 0 | 0 | 0 |

*N* | R5 | 0·2 | 0·2 | 0·2 | 0·01 | 0·01 | 0·01 | 0 | 0 | 0 |

*N* | R6 | 0·2 | 0·2 | 0·2 | 0·01 | 0·01 | 0·01 | 0 | 0 | 0 |

Specialist | *N* | R7 | 0·01 | 0·01 | 0·01 | 0 | 0 | 0 | 0·2 | 0·2 | 0·2 |

*N* | R8 | 0·01 | 0·01 | 0·01 | 0 | 0 | 0 | 0·2 | 0·2 | 0·2 |

*N* | R9 | 0·01 | 0·01 | 0·01 | 0 | 0 | 0 | 0·2 | 0·2 | 0·2 |

Erratic | *N* | R10 | 0·05 | 0·05 | 0·05 | 0·01 | 0·01 | 0·01 | 0 | 0 | 0 |

*N* | R11 | 0·05 | 0·05 | 0·05 | 0·01 | 0·01 | 0·01 | 0 | 0 | 0 |

*N* | R12 | 0·05 | 0·05 | 0·05 | 0·01 | 0·01 | 0·01 | 0 | 0 | 0 |

We investigated the effects of sample size and per-species interaction strength on possible outcomes of observed interaction frequencies (the generated data), by arranging per-species interaction probabilities between species in a cluster design with each of three consumer species (‘generalist’, ‘opportunist’ and ‘specialist’) and four resource species (‘generalist’, ‘opportunist’, ‘specialist’ and ‘erratic’) having the same combinations of (see Table 1). Arranging the combinations of sample sizes of resource and consumer species into *N *×* M* matrices for all species, we generated individual-level interaction frequencies by drawing them from a Poisson distribution with of the respective species pair. We assumed three replicate ‘surveys’ for each individual of resource species. We explored the effect of overall sample sizes on network inference by using equal sample sizes for all *N* and *M* of 3, 5, 10, 15, 20 and 25 individuals for all resource and consumer species. To demonstrate the effect of unequal sample size on network inference, we chose four scenarios with either 5, 10, 15 or 20 individuals for the three ‘generalist’ consumer species combined with constant sample sizes of three individuals for the six remaining consumer species and five individuals of all resource species. For each of these ten sampling scenarios, we generated 50 sets of simulated data.

For illustration, we estimated the community-level index of specialization H2 based on Kullback–Leibler distances. This index was developed to account for heterogeneity in the number of observed interactions in plant–pollinator webs and is among the indices least affected by the number of interactions assembled into aggregated data, that is, sample size on the species-level of aggregated data (Blüthgen & Menzel 2006). As our focus is not on particular indices, we expect this index to perform reasonably well in providing a summary measure of how the differences in sample size influence inference of network attributes from aggregated data. The interest in the individual-level hierarchical model, in turn, is in how far such model is able to disentangle the different sources of variation and allows accurate parameter estimation and expression of uncertainty; in our simulations study, we thus asked whether and uncertainty in the number of unobserved interactions on the species-level can be reasonably well estimated from the different sampling scenarios. For these models, we calculated the index H2 based on the posterior estimates of each interaction strength and 1000 Poisson random draws for each of the 10 000 model iterations. As a comparative measure of H2 from ‘true’ values of interaction strength, we also calculated H2 from interaction strengths and 1000 Poisson random draws for each interaction, repeating this calculations 1000 times (i.e. estimating Poisson error).

The model was fitted in a Bayesian framework, with the following priors, chosen to be vague: for all variance terms U(0,10) and for all sample means N(0,1). When *I*(*r*_{i},*c*_{j}) = 0, the parameters that influence λ*ij* are not affected by the likelihood, so they are only updated from their prior distributions. This can adversely affect mixing (as their sampled values are only occasionally close to the posterior for when *I*(*r*_{i},*c*_{j}) = 1), so we used G(1,100) pseudopriors (Carlin & Chib 1995) to improve the mixing.

We fitted the model with Markov Chain Monte Carlo (MCMC) based on the Gibbs sampler in OpenBUGS 3.1.1 (Lunn *et al*. 2009). Posteriors were gathered by running 10 000 iterations of two chains after discarding 50 000 iterations. Convergence and mixing was assessed visually. MCMC results are given as posterior mode with 95% and 50% highest posterior density credible intervals (CI). The model code is given in Appendix S1.