Maxima Function
simple_linear_regression (x)
simple_linear_regression(xoption_1)
Simple linear regression, y_i=a+b x_i+e_i, where e_i are N(0,sigma) independent random variables. Argument x must be a two column matrix or a list of pairs.
Options:
'conflevel
, default 95/100
, confidence level for the confidence interval; it must
be an expression which takes a value in (0,1).
'regressor
, default 'x
, name of the independent variable.
The output of function simple_linear_regression
is an inference_result
Maxima object
with the following results:
'model
: the fitted equation. Useful to make new predictions. See examples bellow.
'means
: bivariate mean.
'variances
: variances of both variables.
'correlation
: correlation coefficient.
'adc
: adjusted determination coefficient.
'a_estimation
: estimation of parameter a.
'a_conf_int
: confidence interval of parameter a.
'b_estimation
: estimation of parameter b.
'b_conf_int
: confidence interval of parameter b.
'hypotheses
: null and alternative hypotheses about parameter b.
'statistic
: value of the sample statistic used for testing the null hypothesis.
'distribution
: distribution of the sample statistic, together with its parameter.
'p_value
: p-value of the test about b.
'v_estimation
: unbiased variance estimation, or residual variance.
'v_conf_int
: variance confidence interval.
'cond_mean_conf_int
: confidence interval for the conditioned mean. See examples bellow.
'new_pred_conf_int
: confidence interval for a new prediction. See examples bellow.
'residuals
: list of pairs (prediction, residual), ordered with respect to predictions.
This is useful for goodness of fit analysis. See examples bellow.
Only items 1, 4, 14, 9, 10, 11, 12, and 13 above, in this order, are shown by default. The rest remain
hidden until the user makes use of functions items_inference
and take_inference
.
Example:
Fitting a linear model to a bivariate sample. Input %i4
plots
the sample together with the regression line; input %i5
computes y
given x=113
; the means and the
confidence interval for a new prediction when x=113
are also calculated.
(%i1) load("stats")$ (%i2) s:[[125,140.7], [130,155.1], [135,160.3], [140,167.2], [145,169.8]]$ (%i3) z:simple_linear_regression(s,conflevel=0.99); | SIMPLE LINEAR REGRESSION | | model = 1.405999999999985 x - 31.18999999999804 | | correlation = .9611685255255155 | | v_estimation = 13.57966666666665 | (%o3) | b_conf_int = [.04469633662525263, 2.767303663374718] | | hypotheses = H0: b = 0 ,H1: b # 0 | | statistic = 6.032686683658114 | | distribution = [student_t, 3] | | p_value = 0.0038059549413203 (%i4) plot2d([[discrete, s], take_inference(model,z)], [x,120,150], [gnuplot_curve_styles, ["with points","with lines"]] )$ (%i5) take_inference(model,z), x=133; (%o5) 155.808 (%i6) take_inference(means,z); (%o6) [135.0, 158.62] (%i7) take_inference(new_pred_conf_int,z), x=133; (%o7) [132.0728595995113, 179.5431404004887]