Notation for multiplying with logical ($x_i > N$)

45 Views Asked by At

For a vector $x_i$ and numeric values $\theta_j$ and $\beta_j$, I can write this vectorized calculation in R:

y = (x > theta1) * beta1 + (x > theta2) * beta2 + (x > theta3) * beta3

In programming, x > theta1 evaluates to TRUE (1) and FALSE (0) and multiplication is straightforward. But how do I write this as a mathematical expression? This was my first hunch, but I'm not sure it would fare well:

$$ \begin{align} y_i =& (x_i > \theta_1) \beta_1 + (x > \theta_2) \beta_2 + (x > \theta_3) \beta_3 \\ =& \sum_{j = 1}^{3} (x_i > \theta_j) \beta_j \end{align} $$

I would like to avoid a notation where the cumulative nature of the expression is less obvious and which quickly grows overly long. I have many more terms and comparators in actual equations.

$$ y_i = \begin{cases} \beta_1 & \text{if } x_i > \theta_1 \\ \beta_1 + \beta_2 & \text{if } x_i > \theta_2 \\ \beta_1 + \beta_2 + \beta_3 & \text{if } x_i > \theta_3 \\ \end{cases} $$

$x_i$ and $\theta_j$ are monotonically increasing.

2

There are 2 best solutions below

2
On BEST ANSWER

What you are looking for is called an indicator function, which has value 1 for true expressions and value 0 for false expressions. Conventionally it is denoted by putting the logical expression in square brackets (i.e '[]').

If you are writing this up for more than your own edification, I strongly recommend that you explicitly describe this notation up front so people don't get confused wondering why you are using 'mixed' grouping symbols.

0
On

Convenient though it undoubtedly is, I don't know if the Iverson bracket notation is widely enough accepted to be used in a paper without an explanation or a reference, e.g. one of the references in the Wikipedia article just cited, including those I gave in a comment on the other answer.

(Perhaps one of the professional mathematicians who post here could comment authoritatively on that point?)

In any case, I feel that because the sequence $\theta_1, \theta_2, \ldots$ is increasing (incidentally, I don't think it is relevant that the sequence $x_1, x_2, \ldots$ is increasing), which results in the special form of the sums for the $y_i$ as shown at the end of the question, it would be clearer (although less snappy) to write something along these general lines (vary according to taste): \begin{gather*} N_x = \max\{j : \theta_j < x\}, \\ s(x) = \sum_{j=1}^{N_x}\beta_j, \\ y_i = s(x_i). \end{gather*}