Test - Spline with Simultaneous Confidence Interval
Fits a spline and computes a simultaneous confidence interval. See this blog article for other ways to create smoothing lines in visualizations and charts.
How to run this test
- In Displayr, go to Insert > More > Test > Variance > Spline with Simultaneous Confidence Interval. In Q, go to Create > Test > Variance > Spline with Simultaneous Confidence Interval
- Specify the variables to use under Inputs > Outcome and Inputs > Predictor.
- Adjust the any other settings as required.
Example
An example output is shown below:
Options
Outcome The outcome variable.
Predictor The predictor variable.
Regression type Whether to fine a spline with a linear or logit link function.
Confidence level (%) Controls width of the confidence interval around the spline.
Draws to show Number of possible trend lines to super-impose.
Weight Where a weight has been set for the R Output, a new data set is generated via resampling, and this new data set is used in the estimation.
Filter The data is automatically filtered using any filters prior to estimating the model.
Seed Initialize the randomization used in the algorithm. Different values will cause slight changes in the draws shown and confidence interval.
More information
See this blog article for other ways to create smoothing lines in visualizations and charts.
Acknowledgements
This code is adapted from <https://www.fromthebottomoftheheap.net/2016/12/15/simultaneous-interval-revisited/ a post by Gavin Simpson>.
Code
var __webpack_modules__ = ({});
// The module cache
var __webpack_module_cache__ = {};
// The require function
function __webpack_require__(moduleId) {
// Check if module is in cache
var cachedModule = __webpack_module_cache__[moduleId];
if (cachedModule !== undefined) {
return cachedModule.exports;
}
// Create a new module (and put it into the cache)
var module = (__webpack_module_cache__[moduleId] = {
exports: {}
});
// Execute the module function
__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
// Return the exports of the module
return module.exports;
}
// webpack/runtime/rspack_version
(() => {
__webpack_require__.rv = () => ("1.7.2")
})();
// webpack/runtime/rspack_unique_id
(() => {
__webpack_require__.ruid = "bundler=rspack@1.7.2";
})();
var heading_text = "Spline with Simultaneous Confidence Interval";
if (!!form.setObjectInspectorTitle)
form.setObjectInspectorTitle(heading_text, heading_text);
else
form.setHeading(heading_text);
form.dropBox({ label: "Outcome",
types: ["Variable: Numeric, Date, Money, Categorical, OrderedCategorical"],
name: "formOutcomeVariable",
prompt: "Independent target variable to be predicted" });
form.dropBox({ label: "Predictor",
types: ["Variable: Numeric, Date, Money"],
name: "formPredictorVariable", multi: false,
prompt: "Dependent input variables" });
// ALGORITHM
form.comboBox({ label: "Regression type",
alternatives: ["Linear", "Binary Logit"],
name: "formRegressionType",
default_value: "Binary Logit",
prompt: "Select type according to outcome variable type" });
form.numericUpDown({ label: "Confidence level (%)",
name: "formConfidence",
default_value: 95, minimum: 0, maximum: 100 });
// Draws
form.numericUpDown({ name: "formDraws",
label: "Draws to show",
increment: 1,
minimum: 0,
maximum: 500,
default_value: 30 });
form.numericUpDown({ name: "formSeed", label: "Random seed", default_value: 12321, minimum: 1, maximum: 1000000 });
library(flipPlots)
SplineWithSimultaneousConfIntervals(formOutcomeVariable, formPredictorVariable,
type = formRegressionType, subset = QFilter, weights = QPopulationWeight,
seed = formSeed, number.draws = formDraws, confidence = formConfidence/100)