← All examples
64

Canonical Grid model

Economics - Matrices and explicit observation positions

Six synthetic observations; two predictors and an explicit position array.

Scale
Small
Source
economics-matrix-authoring.grid
Length
29 lines
Collection
Advanced language
Level
Intermediate
Runtime
Portable
Version
1.0.0
economics-matrix-authoring.grid
Get Grid
MODEL "Economics - Matrices and explicit observation positions"
DESCRIPTION "Six synthetic observations; two predictors and an explicit position array."
VERSION "1.0.0"
AUTHOR "Grid"
TAGS "economics", "econometrics", "authoring"

# Commas separate predictors; semicolons separate observations.
Outcome = [2.9, 8.1, 7, 12, 11.1, 15.9]
Predictors = [1, 0; 2, 1; 3, 0; 4, 1; 5, 0; 6, 1]
Labels = {termNames: ["Constant", "Exposure", "Policy indicator"]}
Fit = REGRESS(Outcome, Predictors, "hc1", 0, TRUE, 0.95, Labels)

# Pass positions as an ordinary second array; their first value is one.
ObservationPosition = SEQUENCE(1, COLUMNS(Outcome))
AdjustedOutcome = MAP(Outcome, ObservationPosition, (value, position) => value + position)

output Comparison = REGRESS.TABLE(Fit)
output ExposureCoefficient = INDEX(Fit.coefficients, 1, 2)
output PolicyCoefficient = INDEX(Fit.coefficients, 1, 3)
output ObservationCount = ROWS(Predictors)
output PredictorCount = COLUMNS(Predictors)
output PositionExample = AdjustedOutcome

A1 = "Six rows of observations; two predictor columns"
B2 = Comparison
A4 = "Positions are explicit data supplied to MAP"
B4 = PositionExample
A6 = "Synthetic association example; no causal identification claim."
END MODEL