Recent

Author Topic: regression testing with gnu  (Read 1619 times)

flori

  • Full Member
  • ***
  • Posts: 196
regression testing with gnu
« on: January 28, 2022, 04:19:33 pm »
hi!
I got gnuplot_laz from WP. I am very grateful! :)
I tried Simple Linear Regression on gnuplot. I calculated R2 which I put on the linear.png

Does anyone know how  can I show png on TImage  on the TForm? How to display in real time? (beacuse just export to folder)
has anyone tried this before?
watch demo

Thanks



Thaddy

  • Hero Member
  • *****
  • Posts: 11926
Re: regression testing with gnu
« Reply #1 on: January 28, 2022, 05:07:11 pm »
LoadFromFile? Or LoadFromStream?
Black themes should be banned.

wp

  • Hero Member
  • *****
  • Posts: 10060
Re: regression testing with gnu
« Reply #2 on: January 28, 2022, 05:08:51 pm »
It's already prepared in the GnuplotSettings. The output is written to the GnuplotSettings.OutputFilename. This filename is hard-coded in your gnuplot script (set output 'linear.png'). Therefore, you should set GnuplotSettings.outputFileName := 'linear.png'. You can do this in the OnCreate handler of the form.

There are other issues, though:
  • In your program the script is defined in the memo. The memo, however, has word-wrap on. Therefore, long lines are wrapped into multiple lines, and gnuplot gets confused. Simply set the memo's WordWrap to false and turn on the memo's Scrollbars.
  • The gnuplot text output was originally thought to be an error message only (FCmdThreadErrMsg). However, you catch the calculation results in it. That's fine, but it's not an error message any more. Look at TMainform.CmdThreadTerminate. The image is loaded only if (FCmdThread.Runner.ExitStatus = 0) and (FCmdThreadErrMsg = ''). FCmdThreadErrMsg, however, is the gnuplot text output and is not empty. So simply remove this condition from the "if" and the program should work.
  • There is one final, less important, issue: the plot does not look very nicely. Your script defines the plot file to have the size 1024x746, which does not match the values in the GnuPlotSettings. Therefore the large png file is scaled down to the smaller TImage size defined by the GnuPlotSettings, which degrades quality because of the thin drawing lines. Set GnuPlotSettings.OutputWidth to 1024 and GnuPlotSettings.OutputHeight to 746, and the plot should be ok
I am attaching a modified version of the program which contains all these changes.

When I comes to linear fitting only, you can do the same job even with the TAChart package which comes with Lazarus. In this case you can even create an interactive chart with zooming and panning etc. Just add a TFitSeries to the chart, and set its "FitEquation" to feLinear - that's all. If you need the fit parameters you can query them from the Param[index] property, and you get statistics on fit quality etc in the FitStatistics record. See https://wiki.lazarus.freepascal.org/TAChart_documentation#Fit_series and the extensive demo program in folder components/tachart/demo/fit of your Lazarus installation.

[EDIT]
I am attaching also a TAChart version of the fit. Note, however, that TAChart can only do linear (or linearizable) fits. If you need a non-linear fit you'll be back with gnuplot.
« Last Edit: January 28, 2022, 06:16:24 pm by wp »

flori

  • Full Member
  • ***
  • Posts: 196
Re: regression testing with gnu
« Reply #3 on: January 28, 2022, 07:18:27 pm »
Thank you.  :)
I can only see it now.. before I just tested other data. I used y (log10). I just tried.
All the best

Its also non linear model !
« Last Edit: January 28, 2022, 07:21:11 pm by flori »

wp

  • Hero Member
  • *****
  • Posts: 10060
Re: regression testing with gnu
« Reply #4 on: January 28, 2022, 07:53:03 pm »
Is this a question?

y = a exp (b*x) is not linear, but after taking the log on both sides, log(y) = log(a) + b*x, and replacing log(y) by Y and log(y) by A , it becomes linear: Y = A + b*x. - That's what I meant with "linearizable".

There is not need to calculate the logs yourself. The fit series has the exponential fit as an option in the property FitEquation. And to get the log axis you can add the logarithmic axis transformation to the chart. There is a tutorial about exponential fitting and log axis: https://wiki.lazarus.freepascal.org/TAChart_Tutorial:_ListChartSource,_Logarithmic_Axis,_Fitting. Ask again if you do not get the log axis right.

flori

  • Full Member
  • ***
  • Posts: 196
Re: regression testing with gnu
« Reply #5 on: January 28, 2022, 08:24:02 pm »
Thanks for the link. I just tried  how is work regression analysis in lazarus or compare gnuplot. I usually  use Rstat for my work (agrochemistry).
Yes I know what is the  nonlinear (but linearizable) regression functions:logarithmic,power, exp, logistic,s,quadratic,growth etc... to normalise the variables transform by ln (x+0.001) to ensure that the absolute values of skewness and kurtosis. The normality of residuals i checked again by the absolute values of their skewness and kurtosis.
For a logarithm function, the variable y is linear with the logarithm of x context, i.e. y reacts additively to the product of x. In the case of an exponential relation, in contrast to the logarithm function, y its logarithm is linearly related to x. The exponential in the context of y the rate of increase of proportional to v has already been reached value. For a power function, the logarithm of y is linear with the logarithm of x context. The parabolic function and the quadratic function are polynomial belongs to a family of functions, this family of functions is practically any suitable for describing the relationship, but the lawfulness of the relationship most of the time they are not characterized. In the case of a logistic function, the values ​​of the dependent variable are slow first and then they grow faster and faster and then slow down again toward an upper limit approaching.

In my work I usually use Shapiro-Wilk normality test or KS.(before ANOVA, et). Test of normality...
For example ANOVA is robust for mild impairment of the normality condition, in which case it is sufficient to check a weaker condition. Peak skewness test is used when normality is not acceptable with conventional tests used for normality testing. The essence of the method is that the quotient of the shortness (kurtosis) and the standard error, as well as the ratio of the skewness and the standard error should not exceed 3.3.

All the best.

 

TinyPortal © 2005-2018