AnyLogic supports a convenient way of collecting statistics for population of agents.

There are several statistics types supported:
Count,
Sum,
Average,
Min
and
Max.

- Count. Counts agents satisfying the specified Condition.
- Sum. Iterates through all agents and evaluates the specified Expression for each agent. Returns the sum of obtained values.
- Average. Iterates through all agents and evaluates the specified Expression for each agent. Returns average of obtained values.
- Min. Iterates through all agents and evaluates the specified Expression for each agent. Returns the minimum obtained value.
- Max. Iterates through all agents and evaluates the specified Expression for each agent. Returns the maximum obtained value.

Sum,
Average,
Min
and
Max
can be calculated only for those agents, who meet the optional
Condition. Say, we want to calculate the average age of product adopters in agent based
Bass Diffusion
model. Let's assume we have
people
defined by agent type
Person
in this model. This type has a statechart with
PotentialAdopter
and
Adopter
states and
age
parameter defining the person's age. In this case our statistics should look like the following:

To define new statistics function for a population of agents

- Select the population element in the graphical editor or in the Projects view.
- Open the Statistics section of the Properties view.
- Click the Add statistics button to create a new section defining one statistics field.

- Edit the name of the statistics function in the Name field. This name is used to identify and access this statistics function.
- Choose the type of statistics function using the Type group of buttons.
- Specify Expression and/or Condition using the controls below. While writing code in these fields, you can access an individual element of a population (an agent) as item.
- To add more statistics fields, please repeat steps 3-6. If you do not need some statistics any more, you can remove the corresponding section by clicking the button.