Created
March 3, 2014 06:57
-
-
Save samuelleach/9319739 to your computer and use it in GitHub Desktop.
Tableau calculated field using R to predict values using a polynomial fit of degree two. Data may contain zeroes which are excluded from the fit, but are predicted by the model.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SCRIPT_REAL(" | |
xdata <- .arg1 | |
ydata <- .arg2 | |
indices <- which( abs(ydata) < 0.01 ) | |
ndata <- length( ydata ) | |
weights <- rep(1, ndata) | |
weights[indices] = 0 | |
model <- lm( ydata ~ xdata + I(xdata^2), weights=weights ) | |
model$fitted | |
", | |
SUM( [year] ), SUM( [13-17] ) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment