Relation:Name indirection

With name indirection you can give a name parameter as value instead of hardcoded.

To create a name indirection, add ^ to the name

Example

relation foo, bar
insert 1,2
insert 3,4
set X = "foo"
project X^

foo
1
3

read "ef2019.csv"
project kanton, partei, fiktive_waehlende
deserialize
program regression(X, Y)
project X^, Y^
rename X^ x
rename Y^ y
extend x2 = x*x
extend y2 = y*y
extend xy = x*y
project x count, x avg, y avg, xy sum, x2 sum, y2 sum
extend cov = xy_sum/x_count - x_avg*y_avg
extend varx = x2_sum/x_count - x_avg*x_avg
extend vary = y2_sum/x_count - y_avg*y_avg
extend r = cov / sqrt(varx*vary)
extend r2 = r*r
select (x2_sum - x_count*x_avg*x_avg) != 0
extend a = (xy_sum - x_count*x_avg*y_avg)/(x2_sum - x_count*x_avg*x_avg)
extend b = y_avg - a * x_avg
extend error = (x*a + b - y)*(x*a + b - y)
project a, b, r2, error avg
print
end program
run regression ("SP", "GPS")

a b r2 error_avg
0.72671224507753 2681.475901891783 0.92790391002911 7190313.012426351197

Comments

Indirection is useful especially when you write functions and programs in an abstract way so that they can be reused.