Jump to content

How to Get Maxima to Display Approximated Equation Given Some Data

Guest

Hello, everyone.  I am trying to get the program wxMaxima to display the actual equation IN THE GRAPHICAL PLOT it produces when you ask it to display an approximated function's graph, given some data.  I am doing this so far:

 

(%i1)    table: [[10,0.6],[20,0.9],[30,1.1],[40,1.3],[50,1.4]];
(table)    [[10,0.6],[20,0.9],[30,1.1],[40,1.3],[50,1.4]]
(%i3)    plot2d([[discrete, table], 2*%pi*sqrt(L/980)], [L,0,60], [style, points, lines], 
        [color, red, blue], [point_type, asterisk], [legend, "results", "theory"], 
        [xlabel, "L (cm)"], [ylabel, "T (s)"], [y,0,2]);

 

The problem is that the only pages talking about regression/fitted equations only refer to LINEAR regression (handy, but not useful for putting the equation in the plot itself, especially for non linear functions).  I want to do this for the sample data above, but the function is not linear.  Is this possible?  I consulted the Maxima Manual on plotting, and it says nothing about putting regression equations in your plot.

 

Another page in the Manual about statistics doesn't refer to graphical plotting, which is troubling (http://maxima.sourceforge.net/docs/manual/de/maxima_71.html).  Can anyone help me out?

 

Function: simple_linear_regression (x)
Function: simple_linear_regression (x option)

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:

  1. 'model: the fitted equation. Useful to make new predictions. See examples bellow.
  2. 'means: bivariate mean.
  3. 'variances: variances of both variables.
  4. 'correlation: correlation coefficient.
  5. 'adc: adjusted determination coefficient.
  6. 'a_estimation: estimation of parameter a.
  7. 'a_conf_int: confidence interval of parameter a.
  8. 'b_estimation: estimation of parameter b.
  9. 'b_conf_int: confidence interval of parameter b.
  10. 'hypotheses: null and alternative hypotheses about parameter b.
  11. 'statistic: value of the sample statistic used for testing the null hypothesis.
  12. 'distribution: distribution of the sample statistic, together with its parameter.
  13. 'p_value: p-value of the test about b.
  14. 'v_estimation: unbiased variance estimation, or residual variance.
  15. 'v_conf_int: variance confidence interval.
  16. 'cond_mean_conf_int: confidence interval for the conditioned mean. See examples bellow.
  17. 'new_pred_conf_int: confidence interval for a new prediction. See examples bellow.
  18. '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]
Link to comment
Share on other sites

Link to post
Share on other sites

What is this? MATLAB?

Sudo make me a sandwich 

Link to comment
Share on other sites

Link to post
Share on other sites

  • 4 weeks later...
On 8/8/2018 at 4:53 PM, wasab said:

What is this? MATLAB?

No, this is Maxima.  Specifically, wxMaxima (GUI for Maxima).

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×