texlive[73123] Master/texmf-dist: linearregression (14dec24)
commits+karl at tug.org
commits+karl at tug.org
Sat Dec 14 22:19:11 CET 2024
Revision: 73123
https://tug.org/svn/texlive?view=revision&revision=73123
Author: karl
Date: 2024-12-14 22:19:10 +0100 (Sat, 14 Dec 2024)
Log Message:
-----------
linearregression (14dec24)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/latex/linearregression/README.txt
trunk/Master/texmf-dist/doc/latex/linearregression/linearregression.pdf
trunk/Master/texmf-dist/source/latex/linearregression/linearregression.dtx
trunk/Master/texmf-dist/source/latex/linearregression/linearregressionpkg.ins
trunk/Master/texmf-dist/tex/latex/linearregression/linearregression.sty
Modified: trunk/Master/texmf-dist/doc/latex/linearregression/README.txt
===================================================================
--- trunk/Master/texmf-dist/doc/latex/linearregression/README.txt 2024-12-14 21:18:58 UTC (rev 73122)
+++ trunk/Master/texmf-dist/doc/latex/linearregression/README.txt 2024-12-14 21:19:10 UTC (rev 73123)
@@ -1,4 +1,4 @@
-2024-11-23
+2024-12-14
---------------------------------------------------------------------
This file is ** README.txt ** for the ** linearregression ** package
---------------------------------------------------------------------
Modified: trunk/Master/texmf-dist/doc/latex/linearregression/linearregression.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/source/latex/linearregression/linearregression.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/linearregression/linearregression.dtx 2024-12-14 21:18:58 UTC (rev 73122)
+++ trunk/Master/texmf-dist/source/latex/linearregression/linearregression.dtx 2024-12-14 21:19:10 UTC (rev 73123)
@@ -21,7 +21,7 @@
\keepsilent
\preamble
------------------------------------------------------------------------
-[2024-11-23]
+[2024-12-14]
This file is part of the (expanded) distribution of linearregression
The author of linearregression is Battista Benciolini
<benciolinibattista at gmail dot com >
@@ -120,7 +120,7 @@
% \end{quotation}
% A summary description of the problem is therefore the following.
% A set of data pairs is available and each pair is represented as a point
-% in the plain. A straight line is searched that optimally approximates
+% in the plane. A straight line is searched that optimally approximates
% the points. The first step is therefore the choice of an optimality criterion.
% This choice is the topic of the next section. \par
% From the text we also know that the possible deviation of $y$
@@ -179,7 +179,7 @@
% The distance between the given point and the just defined point on the line
% is a reasonable measure of the discrepancy between the empirical data and the
% corresponding theoretical model.
-% The distances we are speaking about are the length of the segments shown
+% The distances we are speaking about are the lengths of the segments shown
% in the leftmost scheme of figure (\ref{fig:criteria}).
% To obtain a global discrepancy measure that considers all the points
% at once we perform the sum of the squares of the lengths
@@ -211,7 +211,7 @@
% direction orthogonal to the line itself. The rightmost scheme of
% figure (\ref{fig:criteria}) shows the segments that are considered.
% The global measure of discrepancy is again obtained as the sum
-% of the squares of the length of the mentioned orthogonal segments.
+% of the squares of the lengts of the mentioned orthogonal segments.
% The procedure that obtain the optimal line that
% minimize the just defined global discrepancy is named
% \textit{symmetrical linear regression}.\par
@@ -218,7 +218,7 @@
% Some arguments of the present section will be repeated in section
% \ref{package} from the algebraic and computational point of view.
%
-% \section{General information on the proposed solution, including limitations}
+% \section{Information on the realised solution, including limitations}
% The code that implements the solution is recorded in two files, that are
% a package (sty) file and a main interactive document.
% The file |linearregression.sty| provides several commands
@@ -234,10 +234,8 @@
% The style of the graphic output is quite minimalist
% (e.g.:\ no colors, no variations of line styles).\par
%
-% \section{Some comments about the programming aspect of the package
-% and its documentation}
+% \section{Some comments about the programming of the package}
% Large part of the code is written using the |expl3| language.
-% (Is it also named simply L3 ? Does expl still means experimental ?)
% I have tried to be compliant with the various recommendations and
% prescriptions for a correct use of the language,
% but I probably only partly succeeded.\par
@@ -244,7 +242,7 @@
% Different more elegant and more coherent solutions probably exist
% both for the general structure of the package and for some specific part
% of the code, but this is what I have been able to do.
-% Some perhaps problematic aspects are mentioned here after\par
+% Some perhaps problematic aspects are mentioned here after.\par
% Several used variables are global and they are accessed by various functions.
% This makes the various parts of the package
% quite connected to each other and creates strong dependencies. \par
@@ -251,18 +249,11 @@
% The layered programming style is only partially applied.
% The partition between document command and lower level functions is present,
% but part of the low level code is directly in the document commands.
-% Variants are not used.\par
-% One more remarks concern the documentation.
-% I was uncertain about the opportunity of using the class |l3doc|. I decided to
-% remain using |ltxdoc|. This is the reason why I do not use the environment
-% |macro| and the command |\cs| in the documentation of some auxiliary
-% functions named according with the |expl3| standard.
-% (I have just an interim far from optimal solution
-% for a reasonable formatting.)
+% Variants are not used.
%
% \section{A ready to use simple user interface\label{main}}
% The main file asks the user for the name of a
-% file containing the data and generates a one (or two) page output.
+% file containing the data and generates a one page output.
%\iffalse
%<*main>
%\fi
@@ -274,7 +265,8 @@
\pagestyle{empty}
\lraskfilename
\lrcomputation
-\lrplot{12.0}{+}{+}{-}{-}
+\lrplotparameters{0.16}{11.0}
+\lrplot{11.0}{+}{+}{-}{-}
\lrprint
\end{document}
% \end{macrocode}
@@ -282,8 +274,8 @@
%</main>
%\fi
% The plot just includes the points and the line obtained with the classical
-% linear regression. Line 8 must be modified if a different result is desired.
-% See the next section for details.
+% linear regression. Lines 8 and 9 of the code must be modified if a different
+% result is desired. See the next section for details.
%
% \section{A user manual for the package\label{manual}}
% The various analysis of a data set and the representation of the data
@@ -312,14 +304,18 @@
% The macro \DescribeMacro{\lrprint}
% \cs{lrprint} generates a table with all the estimated
% parameters and some information about the data.
-% (The computed numbers are printed with four decimal digit.
-% The choice is quite arbitrary.)
+% The computed numbers are printed with four decimal digit maximum by default,
+% but this number can be set to any desired value with the command
+% \DescribeMacro{\lrnumdigit} \cs{lrnumdigit}\marg{number}.
+% The mandatory argument is the desired maximum number of digits.
% \par
% The macro \DescribeMacro{\lrplot}
% \cs{lrplot}\marg{imagewidth}\marg{key1}\marg{key2}\marg{key3}\marg{key4}
% really generates the plot. The first argument is the
-% width of the plot, while the height is computed according
-% to the distribution of the points. The other four arguments are referred
+% width of the plot in centimetrs, while the height is computed according
+% to the distribution of the points or it is recorded with the command
+% \cs{lrplotparameters} (see below).
+% The other four arguments are referred
% to the data points, to the lines determined with classical regression,
% with classical regression with inverted role of the coordinates and
% with symmetric regression.
@@ -329,6 +325,31 @@
% in any other case. Furthermore the lines are accompanied by a label made
% by the corresponding |key|, unless it is just a |+| or a |-|.
% \par
+% The command \DescribeMacro{\lrplotparameters}
+% \cs{lrplotparameters}\marg{diameter}\marg{imageheight}
+% is used to record some more parameters that are related to the generation
+% of the plot.
+% The first argument \marg{diameter} is the diameter in centimeters of the discs
+% that represent the points. It must be a real positive number.
+% The default value is 0.2.
+% The second argument \marg{imageheight} is the height of the plot
+% in centimeters.
+% It must be a real number with a special meaning of any non positive value.
+% If the number is positive it is really used as the height and the variables are
+% independently scaled to fill the width and the height of the plot.
+% If the value is not positive or if the command is not used the
+% two variables are scaled with the same factor and the height is computed
+% accordingly. This can generate reasonable results only if the ranges
+% of the two variables are not too much different.
+% All the arguments are mandatory.
+% \par
+% The use of \cs{lrnumdigit} and \cs{lrplotparameters} is a convenient solution
+% to introduce some flexibility in the output and to completely preserve
+% compatibility with the previous version of the package.
+% Some more elegant solution could be realized with the use of optional
+% arguments and perhaps of key-value pairs, but the implemented solution
+% is preferred because it is extremely simple.
+% \par
% Few words are necessary about the format of the data file.
% Each record of the file hold the two values related to a point.
% The two values must be separated by any number (one is needed as a minimum) of
@@ -337,7 +358,7 @@
%
% \section{An example\label{example}}
% The data reported here after will be available in |sampledata.txt|
-% and will be used in the example presented in this section .
+% and will be used in the examples presented in this section .
%\iffalse
%<*data>
%\fi
@@ -377,7 +398,7 @@
% is operated by a code similar to the following
% (see table \ref{tab:sampledata}). \\
% |\lrfilename{sampledata.txt}| \\ |\lrcomputation| \\
-% |\begin{table}| \\
+% |\lrnumdigit{5}| \\ |\begin{table}| \\
% | \lrprint| \\
% | \caption{Analysis of ... }| \\ |\label{tab:sampledata}\end{table}|
% \par
@@ -393,11 +414,24 @@
% |\lrplot{10.}{+}{-}{-}{+}|
% \\ |\caption{|\ctext|}|\\ | \label{fig:sampledataB} \end{figure}|
%
-% \lrfilename{sampledata.txt} \lrcomputation
+% \lrfilename{sampledata.txt} \lrcomputation \lrnumdigit{5}
% \begin{table} \lrprint \caption{Analysis of the sample data}
% \label{tab:sampledata} \end{table}
% \begin{figure} \lrplot{6.}{-}{AA}{BB}{S} \hfill \lrplot{6.}{+}{-}{-}{+}
% \caption{\ctext} \label{fig:sampledataB} \end{figure}
+% The same data are used to show the effect of the command
+% \cs{lrplotparameters}.
+% \begin{figure}
+% \lrplotparameters{0.12}{5.} \lrplot{4.}{+}{-}{-}{+} \hfill
+% \lrplotparameters{0.10}{3.} \lrplot{4.}{+}{-}{-}{+} \hfill
+% \lrplotparameters{0.11}{-1.} \lrplot{4.}{+}{-}{-}{+}
+% \caption{Three different version of a plot to demonstrate the use of
+% the command \cs{lrplotparameters}} \label{fig:sampledataC} \end{figure}
+% The commands:\\ |...| \\
+% |\lrplotparameters{0.12}{5.} \lrplot{4.}{+}{-}{-}{+} \hfill | \\
+% |\lrplotparameters{0.10}{3.} \lrplot{4.}{+}{-}{-}{+} \hfill | \\
+% |\lrplotparameters{0.11}{-1.} \lrplot{4.}{+}{-}{-}{+} | \\ |...| \\
+% generate the figure (\ref{fig:sampledataC}).
%
% \section{A package for linear regression
% and the theory behind it\label{package}}
@@ -411,11 +445,11 @@
% The coordinates of a generic point are $y_1$ and $y_2$
% and they are collected in the vector $\point$.
% Any given point is identified with the index $\ipoint$.
-% (Explicit indices $(\dots)_1$ or $(\dots)_2$ always refer to the first
+% Explicit indices $(\dots)_1$ or $(\dots)_2$ always refer to the first
% or second coordinate of a point or to the first or second component
% of a vector in the plane.
% Symbolic index $(\dots)\ipoint$ always refers to the different points. Few
-% formulas require both indices $(\dots)_{1\ipoint}$, $(\dots)_{2\ipoint}$.)\par
+% formulas require both indices $(\dots)_{1\ipoint}$, $(\dots)_{2\ipoint}$.\par
% With more then two points a criterion of best approximation
% is needed to select the optimal line that describes the data. \par
% Lower case symbols are used for scalars. Lower case underlined
@@ -432,7 +466,7 @@
% that is introduced as usual. Most of the macros require
% the \LaTeX3 syntax.
% \begin{macrocode}
-\ProvidesPackage{linearregression}[2024-11-23]
+\ProvidesPackage{linearregression}[2024-12-14]
\RequirePackage{pict2e}
\ExplSyntaxOn
% \end{macrocode}
@@ -475,14 +509,17 @@
\str_const:Nn \c_BBLR_comma_str {,}
\str_const:Nn \c_BBLR_plus_str {+}
\str_const:Nn \c_BBLR_minus_str {-}
-\bool_new:N \g_BBLR_plot_points_bool
-\bool_new:N \g_BBLR_plot_lineA_bool
-\bool_new:N \g_BBLR_plot_lineB_bool
-\bool_new:N \g_BBLR_plot_lineS_bool
+\bool_new:N \g_BBLR_plot_points_bool
+\bool_new:N \g_BBLR_plot_lineA_bool
+\bool_new:N \g_BBLR_plot_lineB_bool
+\bool_new:N \g_BBLR_plot_lineS_bool
+\bool_new:N \g_BBLR_two_scale_bool
+\bool_gset_false:N \g_BBLR_two_scale_bool
\fp_new:N \g_BBLR_base_fp
\fp_new:N \g_BBLR_height_fp
\fp_new:N \g_BBLR_Xbase_fp
\fp_new:N \g_BBLR_Xheight_fp
+\fp_new:N \g_BBLR_XXheight_fp
\fp_new:N \g_BBLR_Dabscissa_fp
\fp_new:N \g_BBLR_Dordinate_fp
\fp_new:N \g_BBLR_diameter_fp
@@ -489,10 +526,13 @@
\fp_gset:Nn \g_BBLR_diameter_fp{0.2}
\fp_new:N \g_BBLR_line_base_length_fp
\fp_new:N \g_BBLR_scale_factor_fp
-\str_new:N \c_BBLR_point_code_str
+\fp_new:N \g_BBLR_scale_factor_H_fp
+\str_new:N \g_BBLR_point_code_str
\str_new:N \g_BBLR_labelA_str
\str_new:N \g_BBLR_labelB_str
\str_new:N \g_BBLR_labelS_str
+\int_new:N \g_BBLR_num_dec_dig_int
+\int_gset:Nn \g_BBLR_num_dec_dig_int{4}
% \end{macrocode}
%
% \subsection{Preparing data input}
@@ -514,8 +554,7 @@
% \end{macrocode}
% \end{macro}
%
-% \subsection{Main command declaration, computation of
-% first and second order moments}
+% \subsection{Computation}
% \begin{macro}{\lrcomputation}
% The command \cs{lrcomputation} reads the data file and
% performs all the relevant computations to solve the
@@ -524,6 +563,7 @@
\NewDocumentCommand{\lrcomputation}{}{%
% \end{macrocode}
%
+% \subsubsection{Computation of first and second order moments}
% In the sequel it will results that the first and second order moments
% of the data provide everything needed to solve the problem.
% The barycenter of the data is defined as
@@ -533,8 +573,7 @@
% It is convenient to scan the data to accumulate the sum
% that appears in \reff{barycenter}.
% The coordinates of each point are read from the file
-% and they are immediately used.
-% It is therefore not necessary to globally record the data.
+% and they are immediately used. The data are not globally recorded.
% \begin{macrocode}
\bool_gset_false:N \g_BBLR_data_eof_bool
\int_zero:N \g_BBLR_number_of_points_int
@@ -627,7 +666,7 @@
% \end{macrocode}
% A single pass algorithm exists, but it is numerically less stable.
%
-% \subsection{Classical linear regression \label{classical}}
+% \subsubsection{Classical linear regression \label{classical}}
% A line in the plane is described by the equation
% \begin{equation} y_2=ay_1+b \label{eqab} \end{equation}
% that contains the parameters $a$ and $b$.
@@ -700,10 +739,7 @@
% If the role of the two coordinates is exchanged the result
% for $a$ becomes (still with reference to \reff{eqab})
% \begin{equation} a=\mc_{22}/\mc_{12}.\end{equation}
-% A complete treatment of this different situation would include
-% the redefinition of $e_\ipoint$ and of $\psi$.
-% The slope and the intercept can be computed according with
-% the different assumption.
+% The slope and the intercept can be computed accordingly.
% \begin{macrocode}
\fp_gset:Nn \g_BBLR_slope_B_fp
{\g_BBLR_ordinate_SecOrdMoment_fp / \g_BBLR_mixed_SecOrdMoment_fp}
@@ -711,7 +747,7 @@
{\g_BBLR_mean_ordinate_fp - \g_BBLR_slope_B_fp * \g_BBLR_mean_abscissa_fp}
% \end{macrocode}
%
-% \subsection{Symmetric linear regression \label{symmetric}}
+% \subsubsection{Symmetric linear regression \label{symmetric}}
% If both the coordinates of the experimental points are affected
% by the same uncertainty it is advisable to use a more symmetric
% optimality criterion and it is convenient to use a different model equation.
@@ -842,7 +878,7 @@
{\g_BBLR_abscissa_SecOrdMoment_fp - \g_BBLR_ordinate_SecOrdMoment_fp}
\fp_gset:Nn \g_BBLR_eig_diff_fp
{sqrt(\g_BBLR_diag_diff_fp * \g_BBLR_diag_diff_fp +
- 4 * \g_BBLR_mixed_SecOrdMoment_fp * \g_BBLR_mixed_SecOrdMoment_fp)}
+ 4 * \g_BBLR_mixed_SecOrdMoment_fp * \g_BBLR_mixed_SecOrdMoment_fp)}
% \end{macrocode}
% The computation of $c$ and $s$ is obtained from \reff{spectral}
% taking into account that $c^2+s^2=1$.
@@ -890,7 +926,8 @@
\fp_gset:Nn \g_BBLR_slope_S_fp
{\g_BBLR_sin_fp / \g_BBLR_cos_fp }
\fp_gset:Nn \g_BBLR_intercept_S_fp
-{\g_BBLR_mean_ordinate_fp - \g_BBLR_slope_S_fp * \g_BBLR_mean_abscissa_fp}
+{\g_BBLR_mean_ordinate_fp -
+\g_BBLR_slope_S_fp * \g_BBLR_mean_abscissa_fp}
}
% \end{macrocode}
%
@@ -906,15 +943,17 @@
\NewDocumentCommand{\lrprint}{}{
\begin{center}
\begin{tabular}{| l | r |} \hline
- Data~File: & \g_BBLR_file_name_tl \\ \hline
- Number~of~points: & \int_use:N\g_BBLR_number_of_points_int \\ \hline
- Mean~values~of~the~coordinates: &%
+ Data~File & \g_BBLR_file_name_tl \\
+ \hline
+ Number~of~points & \int_use:N\g_BBLR_number_of_points_int \\
+ \hline
+ Mean~values~of~the~coordinates &%
$\BBLR_print_fp:N \g_BBLR_mean_abscissa_fp$ \\ &
$\BBLR_print_fp:N \g_BBLR_mean_ordinate_fp$ \\ \hline
- Minimum~values~of~the~coordinates: &%
+ Minimum~values~of~the~coordinates &%
$\BBLR_print_fp:N \g_BBLR_min_abscissa_fp$ \\ &
$\BBLR_print_fp:N \g_BBLR_min_ordinate_fp$ \\ \hline
- Maximum~values~of~the~coordinates: &%
+ Maximum~values~of~the~coordinates &%
$\BBLR_print_fp:N \g_BBLR_max_abscissa_fp$ \\ &
$\BBLR_print_fp:N \g_BBLR_max_ordinate_fp$ \\ \hline
{Second~order~moments}\phantom{xxxxxxxxx}{abscissa} &%
@@ -923,13 +962,19 @@
$\BBLR_print_fp:N \g_BBLR_mixed_SecOrdMoment_fp$ ~ \\
\multicolumn{1}{|r|}{ordinate} & %
$\BBLR_print_fp:N \g_BBLR_ordinate_SecOrdMoment_fp$ \\ \hline
- Slope~and~intercept~of~optimal~line & $\BBLR_print_fp:N \g_BBLR_slope_A_fp$ \\
- (estimated~with~errors~in~ordinate)&$\BBLR_print_fp:N \g_BBLR_intercept_A_fp$\\ \hline
- Slope~and~intercept~of~optimal~line & $\BBLR_print_fp:N \g_BBLR_slope_B_fp$ \\
- (estimated~with~errors~in~abscissa)&$\BBLR_print_fp:N \g_BBLR_intercept_B_fp$\\ \hline
- Components~of~unit~vector~along~the~line & $\BBLR_print_fp:N \g_BBLR_cos_fp$ \\
+ Slope~and~intercept~of~optimal~line & $\BBLR_print_fp:N
+ \g_BBLR_slope_A_fp$ \\
+ (estimated~with~errors~in~ordinate)&$\BBLR_print_fp:N
+ \g_BBLR_intercept_A_fp$\\ \hline
+ Slope~and~intercept~of~optimal~line & $\BBLR_print_fp:N
+ \g_BBLR_slope_B_fp$ \\
+ (estimated~with~errors~in~abscissa)&$\BBLR_print_fp:N
+ \g_BBLR_intercept_B_fp$\\ \hline
+ Unit~vector~along~the~line & $\BBLR_print_fp:N
+ \g_BBLR_cos_fp$ \\
& $\BBLR_print_fp:N \g_BBLR_sin_fp$ \\
- Slope~and~intercept~of~optimal~line &$\BBLR_print_fp:N \g_BBLR_slope_S_fp$ \\
+ Slope~and~intercept~of~optimal~line &$\BBLR_print_fp:N
+ \g_BBLR_slope_S_fp$ \\
(estimated~with~symmetric~regression) &
$\BBLR_print_fp:N \g_BBLR_intercept_S_fp$\\ \hline
\end{tabular}
@@ -938,6 +983,16 @@
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}{\lrnumdigit}
+% The command \cs{lrnumdigit} records the maximum number of digits
+% used in the table for computed numbers. The default value is $4$.
+% \begin{macrocode}
+\NewDocumentCommand{\lrnumdigit}{m}{
+\int_gset:Nn \g_BBLR_num_dec_dig_int{#1}
+}
+% \end{macrocode}
+% \end{macro}
+%
% \subsection{Plot of points and lines}
% \begin{macro}{\lrplot}
% The command \cs{lrplot} produce a framed plot of the data
@@ -948,13 +1003,24 @@
% \end{macrocode}
% The plotting area is divided into a main plotting area for
% the representation of points and line(s) and a small surrounding free space.
-% The height is computed taking into account the distribution of the points.
+% The height is computed taking into account the distribution of the points,
+% if it is not explicitelly given..
% \begin{macrocode}
\fp_gset:Nn \g_BBLR_base_fp {#1}
\fp_gset:Nn \g_BBLR_Xbase_fp {\g_BBLR_base_fp - 0.6}
-\fp_gset:Nn \g_BBLR_scale_factor_fp{\g_BBLR_Xbase_fp / \g_BBLR_Dabscissa_fp}
-\fp_gset:Nn \g_BBLR_Xheight_fp {\g_BBLR_Dordinate_fp * \g_BBLR_scale_factor_fp}
+\fp_gset:Nn \g_BBLR_scale_factor_fp{\g_BBLR_Xbase_fp /
+\g_BBLR_Dabscissa_fp}
+\bool_if:NTF \g_BBLR_two_scale_bool
+{\fp_gset:Nn \g_BBLR_height_fp {\g_BBLR_XXheight_fp}
+\fp_gset:Nn \g_BBLR_Xheight_fp {\g_BBLR_height_fp - 0.6}
+\fp_gset:Nn \g_BBLR_scale_factor_H_fp{\g_BBLR_Xheight_fp /
+\g_BBLR_Dordinate_fp}
+}
+{\fp_gset:Nn \g_BBLR_Xheight_fp {\g_BBLR_Dordinate_fp *
+\g_BBLR_scale_factor_fp}
\fp_gset:Nn \g_BBLR_height_fp {\g_BBLR_Xheight_fp + 0.6}
+\fp_gset:Nn \g_BBLR_scale_factor_H_fp {\g_BBLR_scale_factor_fp }
+}
% \end{macrocode}
% The information about the items to be plotted is in the remaining arguments.
% \begin{macrocode}
@@ -989,15 +1055,30 @@
\thicklines
\bool_if:nT {\g_BBLR_plot_points_bool}{\BBLR_plot_points:}
\bool_if:nT {\g_BBLR_plot_lineA_bool}{
-\BBLR_draw_line:NNN \g_BBLR_slope_A_fp\g_BBLR_intercept_A_fp\g_BBLR_labelA_str}
+\BBLR_draw_line:NNN \g_BBLR_slope_A_fp\g_BBLR_intercept_A_fp
+\g_BBLR_labelA_str}
\bool_if:nT {\g_BBLR_plot_lineB_bool}{
-\BBLR_draw_line:NNN \g_BBLR_slope_B_fp\g_BBLR_intercept_B_fp\g_BBLR_labelB_str}
+\BBLR_draw_line:NNN \g_BBLR_slope_B_fp\g_BBLR_intercept_B_fp
+\g_BBLR_labelB_str}
\bool_if:nT {\g_BBLR_plot_lineS_bool}{
-\BBLR_draw_line:NNN \g_BBLR_slope_S_fp\g_BBLR_intercept_S_fp\g_BBLR_labelS_str}
+\BBLR_draw_line:NNN \g_BBLR_slope_S_fp\g_BBLR_intercept_S_fp
+\g_BBLR_labelS_str}
\end{picture}
}%
% \end{macrocode}
% \end{macro}
+% \begin{macro}{\lrplotparameters}
+% The command \cs{lrplotparameters} records two parameters related to
+% the generation of the plot and sets a boolean variable.
+% \begin{macrocode}
+\NewDocumentCommand{\lrplotparameters}{mm}{
+\fp_gset:Nn \g_BBLR_diameter_fp{#1}
+\fp_gset:Nn \g_BBLR_XXheight_fp{#2}
+\bool_gset:Nn \g_BBLR_two_scale_bool
+{\fp_compare_p:nNn {\g_BBLR_XXheight_fp}>{0.}}
+}
+% \end{macrocode}
+% \end{macro}
%
% \subsection{Functions for internal use}
% The functions listed here after are for internal
@@ -1054,7 +1135,7 @@
\fp_gset:Nn \g_tmpa_fp{(\g_BBLR_abscissa_fp-\g_BBLR_min_abscissa_fp)*
\g_BBLR_scale_factor_fp}
\fp_gset:Nn \g_tmpb_fp{(\g_BBLR_ordinate_fp-\g_BBLR_min_ordinate_fp)*
- \g_BBLR_scale_factor_fp}
+ \g_BBLR_scale_factor_H_fp}
\put(\fp_use:N\g_tmpa_fp, \fp_use:N\g_tmpb_fp){
{\circle*{\fp_use:N\g_BBLR_diameter_fp}}}
}
@@ -1087,17 +1168,19 @@
\fp_gset:Nn \g_BBLR_max_draw_abscissa_fp { \g_BBLR_max_abscissa_fp }
}}
% \end{macrocode}
-% Some parameters (i.e.\ starting point and base-length)
+% Some parameters (coordinates of starting point, base-length, scaled slope)
% are computed and the line is drawn.
% \begin{macrocode}
\fp_gset:Nn \fp_tmpa_fp {(\g_BBLR_min_draw_abscissa_fp -
\g_BBLR_min_abscissa_fp)* \g_BBLR_scale_factor_fp}
\fp_gset:Nn \fp_tmpb_fp {(#1 * \g_BBLR_min_draw_abscissa_fp + #2 -
-\g_BBLR_min_ordinate_fp)* \g_BBLR_scale_factor_fp}
+\g_BBLR_min_ordinate_fp)* \g_BBLR_scale_factor_H_fp}
\fp_gset:Nn \fp_BBLR_line_base_length_fp{(\g_BBLR_max_draw_abscissa_fp -
\g_BBLR_min_draw_abscissa_fp) * \g_BBLR_scale_factor_fp}
+\fp_gset:Nn \fp_scaled_slope_fp
+{(#1 * \g_BBLR_scale_factor_H_fp / \g_BBLR_scale_factor_fp)}
\put(\fp_use:N\fp_tmpa_fp, \fp_use:N\fp_tmpb_fp){
-\line(1.,\fp_use:N #1){\fp_use:N\fp_BBLR_line_base_length_fp}}
+\line(1.,\fp_use:N\fp_scaled_slope_fp){\fp_use:N\fp_BBLR_line_base_length_fp}}
% \end{macrocode}
%The third parameter is used as a label, if it is not a |+|.
% \begin{macrocode}
@@ -1121,9 +1204,10 @@
% of decimal digit.
%
% \begin{macrocode}
-\cs_new_protected:Nn \BBLR_print_fp:N { {\fp_eval:n{trunc(#1 ,4)}}}
+\cs_new_protected:Nn \BBLR_print_fp:N {%
+{\fp_eval:n{trunc(#1 ,\g_BBLR_num_dec_dig_int)}}
+}
% \end{macrocode}
-
%
% \begin{macrocode}
\ExplSyntaxOff
@@ -1134,12 +1218,11 @@
%</package>
%\fi
%
-% \section{Versions and possible improvements}
+% \section{Versions}
% 2024-06-10: first post on CTAN.\par
% 2024-11-23: small changes in the text,
% different format of numbers in the table.\par
-% Desired improvements:
-% more code comment (text), flexible output (code).
+% 2024-12-14: more flexibe output, some changes in the text.
%
% \section{Acknowledgments}
% The colleagues Paolo Zatelli, Alfonso Vitti and Giulia Graldi
@@ -1146,7 +1229,7 @@
% read some preliminary version
% of this text and suggested several improvements.
% Claudio Beccari usefully commented about the first version
-% when I was preparating the second version. \par
+% when I was preparing the second version. \par
%
% \section{Citations and references}
% \subsection*{Mathematics}
Modified: trunk/Master/texmf-dist/source/latex/linearregression/linearregressionpkg.ins
===================================================================
--- trunk/Master/texmf-dist/source/latex/linearregression/linearregressionpkg.ins 2024-12-14 21:18:58 UTC (rev 73122)
+++ trunk/Master/texmf-dist/source/latex/linearregression/linearregressionpkg.ins 2024-12-14 21:19:10 UTC (rev 73123)
@@ -2,7 +2,7 @@
\keepsilent
\preamble
------------------------------------------------------------------------
-[2024-06-10]
+[2024-12-14]
This file is part of the (expanded) distribution of linearregression
The author of linearregression is Battista Benciolini
<benciolinibattista at gmail dot com >
Modified: trunk/Master/texmf-dist/tex/latex/linearregression/linearregression.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/linearregression/linearregression.sty 2024-12-14 21:18:58 UTC (rev 73122)
+++ trunk/Master/texmf-dist/tex/latex/linearregression/linearregression.sty 2024-12-14 21:19:10 UTC (rev 73123)
@@ -6,7 +6,7 @@
%%
%% linearregression.dtx (with options: `package')
%% ------------------------------------------------------------------------
-%% [2024-06-10]
+%% [2024-12-14]
%% This file is part of the (expanded) distribution of linearregression
%% The author of linearregression is Battista Benciolini
%% <benciolinibattista at gmail dot com >
@@ -18,7 +18,7 @@
%% the conditions of the LaTeX Project Public License.
%% (see: http://www.latex-project.org/lppl.txt)
%% ------------------------------------------------------------------------
-\ProvidesPackage{linearregression}[2024-11-23]
+\ProvidesPackage{linearregression}[2024-12-14]
\RequirePackage{pict2e}
\ExplSyntaxOn
\ior_new:N \g_BBLR_file_ior
@@ -58,14 +58,17 @@
\str_const:Nn \c_BBLR_comma_str {,}
\str_const:Nn \c_BBLR_plus_str {+}
\str_const:Nn \c_BBLR_minus_str {-}
-\bool_new:N \g_BBLR_plot_points_bool
-\bool_new:N \g_BBLR_plot_lineA_bool
-\bool_new:N \g_BBLR_plot_lineB_bool
-\bool_new:N \g_BBLR_plot_lineS_bool
+\bool_new:N \g_BBLR_plot_points_bool
+\bool_new:N \g_BBLR_plot_lineA_bool
+\bool_new:N \g_BBLR_plot_lineB_bool
+\bool_new:N \g_BBLR_plot_lineS_bool
+\bool_new:N \g_BBLR_two_scale_bool
+\bool_gset_false:N \g_BBLR_two_scale_bool
\fp_new:N \g_BBLR_base_fp
\fp_new:N \g_BBLR_height_fp
\fp_new:N \g_BBLR_Xbase_fp
\fp_new:N \g_BBLR_Xheight_fp
+\fp_new:N \g_BBLR_XXheight_fp
\fp_new:N \g_BBLR_Dabscissa_fp
\fp_new:N \g_BBLR_Dordinate_fp
\fp_new:N \g_BBLR_diameter_fp
@@ -72,10 +75,13 @@
\fp_gset:Nn \g_BBLR_diameter_fp{0.2}
\fp_new:N \g_BBLR_line_base_length_fp
\fp_new:N \g_BBLR_scale_factor_fp
-\str_new:N \c_BBLR_point_code_str
+\fp_new:N \g_BBLR_scale_factor_H_fp
+\str_new:N \g_BBLR_point_code_str
\str_new:N \g_BBLR_labelA_str
\str_new:N \g_BBLR_labelB_str
\str_new:N \g_BBLR_labelS_str
+\int_new:N \g_BBLR_num_dec_dig_int
+\int_gset:Nn \g_BBLR_num_dec_dig_int{4}
\NewDocumentCommand{\lrfilename}{m}{
\tl_gset:Nn \g_BBLR_file_name_tl {#1}
}
@@ -164,7 +170,7 @@
{\g_BBLR_abscissa_SecOrdMoment_fp - \g_BBLR_ordinate_SecOrdMoment_fp}
\fp_gset:Nn \g_BBLR_eig_diff_fp
{sqrt(\g_BBLR_diag_diff_fp * \g_BBLR_diag_diff_fp +
- 4 * \g_BBLR_mixed_SecOrdMoment_fp * \g_BBLR_mixed_SecOrdMoment_fp)}
+ 4 * \g_BBLR_mixed_SecOrdMoment_fp * \g_BBLR_mixed_SecOrdMoment_fp)}
\fp_gset:Nn \g_BBLR_cos_fp%
{sqrt((1 + \g_BBLR_diag_diff_fp / \g_BBLR_eig_diff_fp) / 2)}
\fp_gset:Nn \g_BBLR_sig_sin_fp {\fp_sign:n {\g_BBLR_mixed_SecOrdMoment_fp}}
@@ -173,20 +179,23 @@
\fp_gset:Nn \g_BBLR_slope_S_fp
{\g_BBLR_sin_fp / \g_BBLR_cos_fp }
\fp_gset:Nn \g_BBLR_intercept_S_fp
-{\g_BBLR_mean_ordinate_fp - \g_BBLR_slope_S_fp * \g_BBLR_mean_abscissa_fp}
+{\g_BBLR_mean_ordinate_fp -
+\g_BBLR_slope_S_fp * \g_BBLR_mean_abscissa_fp}
}
\NewDocumentCommand{\lrprint}{}{
\begin{center}
\begin{tabular}{| l | r |} \hline
- Data~File: & \g_BBLR_file_name_tl \\ \hline
- Number~of~points: & \int_use:N\g_BBLR_number_of_points_int \\ \hline
- Mean~values~of~the~coordinates: &%
+ Data~File & \g_BBLR_file_name_tl \\
+ \hline
+ Number~of~points & \int_use:N\g_BBLR_number_of_points_int \\
+ \hline
+ Mean~values~of~the~coordinates &%
$\BBLR_print_fp:N \g_BBLR_mean_abscissa_fp$ \\ &
$\BBLR_print_fp:N \g_BBLR_mean_ordinate_fp$ \\ \hline
- Minimum~values~of~the~coordinates: &%
+ Minimum~values~of~the~coordinates &%
$\BBLR_print_fp:N \g_BBLR_min_abscissa_fp$ \\ &
$\BBLR_print_fp:N \g_BBLR_min_ordinate_fp$ \\ \hline
- Maximum~values~of~the~coordinates: &%
+ Maximum~values~of~the~coordinates &%
$\BBLR_print_fp:N \g_BBLR_max_abscissa_fp$ \\ &
$\BBLR_print_fp:N \g_BBLR_max_ordinate_fp$ \\ \hline
{Second~order~moments}\phantom{xxxxxxxxx}{abscissa} &%
@@ -195,24 +204,43 @@
$\BBLR_print_fp:N \g_BBLR_mixed_SecOrdMoment_fp$ ~ \\
\multicolumn{1}{|r|}{ordinate} & %
$\BBLR_print_fp:N \g_BBLR_ordinate_SecOrdMoment_fp$ \\ \hline
- Slope~and~intercept~of~optimal~line & $\BBLR_print_fp:N \g_BBLR_slope_A_fp$ \\
- (estimated~with~errors~in~ordinate)&$\BBLR_print_fp:N \g_BBLR_intercept_A_fp$\\ \hline
- Slope~and~intercept~of~optimal~line & $\BBLR_print_fp:N \g_BBLR_slope_B_fp$ \\
- (estimated~with~errors~in~abscissa)&$\BBLR_print_fp:N \g_BBLR_intercept_B_fp$\\ \hline
- Components~of~unit~vector~along~the~line & $\BBLR_print_fp:N \g_BBLR_cos_fp$ \\
+ Slope~and~intercept~of~optimal~line & $\BBLR_print_fp:N
+ \g_BBLR_slope_A_fp$ \\
+ (estimated~with~errors~in~ordinate)&$\BBLR_print_fp:N
+ \g_BBLR_intercept_A_fp$\\ \hline
+ Slope~and~intercept~of~optimal~line & $\BBLR_print_fp:N
+ \g_BBLR_slope_B_fp$ \\
+ (estimated~with~errors~in~abscissa)&$\BBLR_print_fp:N
+ \g_BBLR_intercept_B_fp$\\ \hline
+ Unit~vector~along~the~line & $\BBLR_print_fp:N
+ \g_BBLR_cos_fp$ \\
& $\BBLR_print_fp:N \g_BBLR_sin_fp$ \\
- Slope~and~intercept~of~optimal~line &$\BBLR_print_fp:N \g_BBLR_slope_S_fp$ \\
+ Slope~and~intercept~of~optimal~line &$\BBLR_print_fp:N
+ \g_BBLR_slope_S_fp$ \\
(estimated~with~symmetric~regression) &
$\BBLR_print_fp:N \g_BBLR_intercept_S_fp$\\ \hline
\end{tabular}
\end{center}
}
+\NewDocumentCommand{\lrnumdigit}{m}{
+\int_gset:Nn \g_BBLR_num_dec_dig_int{#1}
+}
\NewDocumentCommand{\lrplot}{mmmmm}{%
\fp_gset:Nn \g_BBLR_base_fp {#1}
\fp_gset:Nn \g_BBLR_Xbase_fp {\g_BBLR_base_fp - 0.6}
-\fp_gset:Nn \g_BBLR_scale_factor_fp{\g_BBLR_Xbase_fp / \g_BBLR_Dabscissa_fp}
-\fp_gset:Nn \g_BBLR_Xheight_fp {\g_BBLR_Dordinate_fp * \g_BBLR_scale_factor_fp}
+\fp_gset:Nn \g_BBLR_scale_factor_fp{\g_BBLR_Xbase_fp /
+\g_BBLR_Dabscissa_fp}
+\bool_if:NTF \g_BBLR_two_scale_bool
+{\fp_gset:Nn \g_BBLR_height_fp {\g_BBLR_XXheight_fp}
+\fp_gset:Nn \g_BBLR_Xheight_fp {\g_BBLR_height_fp - 0.6}
+\fp_gset:Nn \g_BBLR_scale_factor_H_fp{\g_BBLR_Xheight_fp /
+\g_BBLR_Dordinate_fp}
+}
+{\fp_gset:Nn \g_BBLR_Xheight_fp {\g_BBLR_Dordinate_fp *
+\g_BBLR_scale_factor_fp}
\fp_gset:Nn \g_BBLR_height_fp {\g_BBLR_Xheight_fp + 0.6}
+\fp_gset:Nn \g_BBLR_scale_factor_H_fp {\g_BBLR_scale_factor_fp }
+}
\str_gset:Nn \g_BBLR_point_code_str {#2}
\str_gset:Nn \g_BBLR_labelA_str {#3}
\str_gset:Nn \g_BBLR_labelB_str {#4}
@@ -238,13 +266,22 @@
\thicklines
\bool_if:nT {\g_BBLR_plot_points_bool}{\BBLR_plot_points:}
\bool_if:nT {\g_BBLR_plot_lineA_bool}{
-\BBLR_draw_line:NNN \g_BBLR_slope_A_fp\g_BBLR_intercept_A_fp\g_BBLR_labelA_str}
+\BBLR_draw_line:NNN \g_BBLR_slope_A_fp\g_BBLR_intercept_A_fp
+\g_BBLR_labelA_str}
\bool_if:nT {\g_BBLR_plot_lineB_bool}{
-\BBLR_draw_line:NNN \g_BBLR_slope_B_fp\g_BBLR_intercept_B_fp\g_BBLR_labelB_str}
+\BBLR_draw_line:NNN \g_BBLR_slope_B_fp\g_BBLR_intercept_B_fp
+\g_BBLR_labelB_str}
\bool_if:nT {\g_BBLR_plot_lineS_bool}{
-\BBLR_draw_line:NNN \g_BBLR_slope_S_fp\g_BBLR_intercept_S_fp\g_BBLR_labelS_str}
+\BBLR_draw_line:NNN \g_BBLR_slope_S_fp\g_BBLR_intercept_S_fp
+\g_BBLR_labelS_str}
\end{picture}
}%
+\NewDocumentCommand{\lrplotparameters}{mm}{
+\fp_gset:Nn \g_BBLR_diameter_fp{#1}
+\fp_gset:Nn \g_BBLR_XXheight_fp{#2}
+\bool_gset:Nn \g_BBLR_two_scale_bool
+{\fp_compare_p:nNn {\g_BBLR_XXheight_fp}>{0.}}
+}
\cs_new_protected:Nn \BBLR_decode_data: {
\tl_trim_spaces:N \g_BBLR_file_line_tl
\int_gzero:N \g_tmpa_int
@@ -283,7 +320,7 @@
\fp_gset:Nn \g_tmpa_fp{(\g_BBLR_abscissa_fp-\g_BBLR_min_abscissa_fp)*
\g_BBLR_scale_factor_fp}
\fp_gset:Nn \g_tmpb_fp{(\g_BBLR_ordinate_fp-\g_BBLR_min_ordinate_fp)*
- \g_BBLR_scale_factor_fp}
+ \g_BBLR_scale_factor_H_fp}
\put(\fp_use:N\g_tmpa_fp, \fp_use:N\g_tmpb_fp){
{\circle*{\fp_use:N\g_BBLR_diameter_fp}}}
}
@@ -311,11 +348,13 @@
\fp_gset:Nn \fp_tmpa_fp {(\g_BBLR_min_draw_abscissa_fp -
\g_BBLR_min_abscissa_fp)* \g_BBLR_scale_factor_fp}
\fp_gset:Nn \fp_tmpb_fp {(#1 * \g_BBLR_min_draw_abscissa_fp + #2 -
-\g_BBLR_min_ordinate_fp)* \g_BBLR_scale_factor_fp}
+\g_BBLR_min_ordinate_fp)* \g_BBLR_scale_factor_H_fp}
\fp_gset:Nn \fp_BBLR_line_base_length_fp{(\g_BBLR_max_draw_abscissa_fp -
\g_BBLR_min_draw_abscissa_fp) * \g_BBLR_scale_factor_fp}
+\fp_gset:Nn \fp_scaled_slope_fp
+{(#1 * \g_BBLR_scale_factor_H_fp / \g_BBLR_scale_factor_fp)}
\put(\fp_use:N\fp_tmpa_fp, \fp_use:N\fp_tmpb_fp){
-\line(1.,\fp_use:N #1){\fp_use:N\fp_BBLR_line_base_length_fp}}
+\line(1.,\fp_use:N\fp_scaled_slope_fp){\fp_use:N\fp_BBLR_line_base_length_fp}}
\bool_if:nF {\str_if_eq_p:NN #3 \c_BBLR_plus_str}{
\fp_gset:Nn \fp_tmpa_fp
{0.08 * \g_BBLR_min_draw_abscissa_fp + 0.92 * \g_BBLR_max_draw_abscissa_fp}
@@ -329,8 +368,9 @@
\put(\fp_use:N\fp_tmpa_fp, \fp_use:N\fp_tmpb_fp){#3}
}
}
-\cs_new_protected:Nn \BBLR_print_fp:N { {\fp_eval:n{trunc(#1 ,4)}}}
-
+\cs_new_protected:Nn \BBLR_print_fp:N {%
+{\fp_eval:n{trunc(#1 ,\g_BBLR_num_dec_dig_int)}}
+}
\ExplSyntaxOff
\endinput
%%
More information about the tex-live-commits
mailing list.