You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docsite/docs/guides/grammar.md
+7-4Lines changed: 7 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -26,10 +26,12 @@ unless otherwise indicated.
26
26
|`{...}`[^1]| 1 | Quotes python operations, as a more convenient way to do Python operations than `I(...)`, e.g. `` {`my|col`**2} `` | ✓ | ✗ | ✗ |
27
27
|`<function>(...)`[^1]| 1 | Python transform on column, e.g. `my_func(x)` which is equivalent to `{my_func(x)}`| ✓[^2]| ✓ | ✗ |
28
28
|-----|
29
-
|`(...)`| 1 | Groups operations, overriding normal precedence rules. All operations with the parentheses are performed before the result of these operations is permitted to be operated upon by its peers. | ✓ |✓| ✓ |
29
+
|`(...)`| 1 | Groups operations, overriding normal precedence rules. All operations with the parentheses are performed before the result of these operations is permitted to be operated upon by its peers. | ✓ |✗| ✓ |
30
30
|-----|
31
-
|**| 2 | Includes all n-th order interactions of the terms in the left operand, where n is the (integral) value of the right operand, e.g. `(a+b+c)**2` is equivalent to `a + b + c + a:b + a:c + b:c`. | ✓ | ✓ | ✓ |
32
-
| ^ | 2 | Alias for `**`. | ✓ | ✗[^3]| ✓ |
31
+
|`.`[^9]| 0 | Stands in as a wild-card for the sum of variables in the data not used on the left-hand side of a formula. | ✓ | ✗ | ✓ |
32
+
|-----|
33
+
|`**`| 2 | Includes all n-th order interactions of the terms in the left operand, where n is the (integral) value of the right operand, e.g. `(a+b+c)**2` is equivalent to `a + b + c + a:b + a:c + b:c`. | ✓ | ✓ | ✓ |
34
+
|`^`| 2 | Alias for `**`. | ✓ | ✗[^3]| ✓ |
33
35
|-----|
34
36
|`:`| 2 | Adds a new term that corresponds to the interaction of its operands (i.e. their elementwise product). | ✓[^4]| ✓ | ✓ |
35
37
|-----|
@@ -123,4 +125,5 @@ and conventions of which you should be aware.
123
125
[^5]: This somewhat confusing operator is useful when you want to include hierachical features in your data, and where certain interaction terms do not make sense (particularly in ANOVA contexts). For example, if `a` represents countries, and `b` represents cities, then the full product of terms from `a * b === a + b + a:b` does not make sense, because any value of `b` is guaranteed to coincide with a value in `a`, and does not independently add value. Thus, the operation `a / b === a + a:b` results in more sensible dataset. As a result, the `/` operator is right-distributive, since if `b` and `c` were both nested in `a`, you would want `a/(b+c) === a + a:b + a:c`. Likewise, the operator is not left-distributive, since if `c` is nested under both `a` and `b` separately, then you want `(a + b)/c === a + b + a:b:c`. Lastly, if `c` is nested in `b`, and `b` is nested in `a`, then you would want `a/b/c === a + a:(b/c) === a + a:b + a:b:c`.
124
126
[^6]: Implemented by an R package called [Formula](https://cran.r-project.org/web/packages/Formula/index.html) that extends the default formula syntax.
125
127
[^7]: Patsy uses the `rescale` keyword rather than `scale`, but provides the same functionality.
126
-
[^8]: For increased compatibility with patsy, we use patsy's signature for `standardize`.
128
+
[^8]: For increased compatibility with patsy, we use patsy's signature for `standardize`.
129
+
[^9]: Requires additional context to be passed in when directly using the `Formula` constructor. e.g. `Formula("y ~ .", context={"__formulaic_variables_available__": ["x", "y", "z"]})`; or you can use `model_matrix`, `ModelSpec.get_model_matrix()`, or `FormulaMaterializer.get_model_matrix()` without further specification.
0 commit comments