Skip to Content

EXPECTILE

Overview

The EXPECTILE function calculates the expectile of a dataset, which is a generalization of the mean. While quantiles are based on sorting the data, expectiles are based on minimizing a squared error loss function. The alpha parameter determines the asymmetry of the loss function, where alpha=0.5 corresponds to the mean. For more details, see the SciPy documentation.

This example function is provided as-is without any representation of accuracy.

Usage

To use the function in Excel:

=EXPECTILE(data, [alpha], [weights])
  • data (2D list, required): A 2D column of numeric data.
  • alpha (float, optional, default=0.5): The expectile to compute, a value between 0 and 1.
  • weights (2D list, optional, default=None): A 2D column of weights for each data point. Must have the same dimensions as data.

The function returns a single value (float): the calculated expectile of the dataset.

Examples

Example 1: Mean as an Expectile

This example calculates the expectile with alpha=0.5, which is equivalent to the mean of the data.

Inputs:

dataalphaweights
10.5
2
3
4
5

Excel formula:

=EXPECTILE({1;2;3;4;5}, 0.5)

Expected output:

Result
3.0

Example 2: Low Expectile

This example calculates a low expectile (alpha=0.2), which will be smaller than the mean.

Inputs:

dataalphaweights
10.2
2
3
4
5

Excel formula:

=EXPECTILE({1;2;3;4;5}, 0.2)

Expected output:

Result
2.14

Example 3: High Expectile with Weights

This example calculates a high expectile (alpha=0.8) with uniform weights.

Inputs:

dataalphaweights
10.81
21
31
41
51

Excel formula:

=EXPECTILE({1;2;3;4;5}, 0.8, {1;1;1;1;1})

Expected output:

Result
3.86

Example 4: Weighted Expectile

This example demonstrates the effect of non-uniform weights on the expectile calculation.

Inputs:

dataalphaweights
10.51
21
31
41
104

Excel formula:

=EXPECTILE({1;2;3;4;10}, 0.5, {1;1;1;1;4})

Expected output:

Result
6.25

Python Code

from scipy.stats import expectile as scipy_expectile import numpy as np def expectile(data, alpha=0.5, weights=None): """ Calculates the expectile of a dataset. Args: data (list[list[float]]): A 2D column of numeric data. alpha (float, optional): The expectile to compute, between 0 and 1. Defaults to 0.5. weights (list[list[float]], optional): A 2D column of weights. Defaults to None. Returns: float: The calculated expectile. This example function is provided as-is without any representation of accuracy. """ if not isinstance(data, list) or not data: return "Invalid input: data must be a non-empty 2D list." try: a = [row[0] for row in data] except (TypeError, IndexError): return "Invalid input: data must be a 2D list." if not (0 <= alpha <= 1): return "Invalid input: alpha must be between 0 and 1." w = None if weights is not None: if not isinstance(weights, list) or len(weights) != len(a): return "Invalid input: weights must be a 2D list with the same length as data." try: w = [row[0] for row in weights] except (TypeError, IndexError): return "Invalid input: weights must be a 2D list." result = scipy_expectile(a=a, alpha=alpha, weights=w) return round(result, 2)

Live Notebook

Edit this function in a live notebook.

Live Demo

Last updated on