Test - Spline with Simultaneous Confidence Interval

From Q
Jump to navigation Jump to search


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

  1. 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
  2. Specify the variables to use under Inputs > Outcome and Inputs > Predictor.
  3. Adjust the any other settings as required.

Spline oi.PNG

Example

An example output is shown below:

SimultaneousConfidenceInterval.PNG

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 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)