% Author     : C. Pierquet
% licence    : Released under the LaTeX Project Public License v1.3c
% or later, see http://www.latex-project.org/lppl.txt

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{xint-regression}[2026/02/17 0.1.3 Some classic regressions, with xint]
%0.1.3	logistic regression & r² for all regressions
%0.1.2	r and r² & new names (tks to quark67 for suggestion)
%0.1.1	Bugfix
%0.1.0	Initial version

%------Packages utiles
\RequirePackage{simplekv}
\RequirePackage{xintexpr}
\RequirePackage{listofitems}
\RequirePackage{xstring}

%régression linéaire
\defKV[CoefRegLin]{%
	coeffa=\def\RegLinCoefa{#1},%
	coeffb=\def\RegLinCoefb{#1},%
	coeffr=\def\RegLinCoefr{#1},%
	coeffrr=\def\RegLinCoefrr{#1},%
	round=\def\RegLinRound{#1}
}

\setKVdefault[CoefRegLin]{%
	coeffa=linrega,%
	coeffb=linregb,%
	coeffr=linregr,%
	coeffrr=linregrr,%
	round={}
}

\newcommand\xintlinreg[3][]{%
	\useKVdefault[CoefRegLin]%
	\setKV[CoefRegLin]{#1}% on paramètres les nouvelles clés et on les simplifie
	%listes des données
	\def\xliste{#2}%
	\def\yliste{#3}%
	\setsepchar{,}%
	\readlist*\LX{\xliste}%
	\readlist*\LY{\yliste}%
	%taille des listes
	\def\LNB{\inteval{\LXlen}}%
	%somme des LX et des LY OK
	\xdef\LXSomme{0}%
	\xdef\LYSomme{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\LXSomme{\xintfloateval{\LXSomme+(\LX[##1])}}%
		\xdef\LYSomme{\xintfloateval{\LYSomme+(\LY[##1])}}%
	}%
	%moyenne des LX et des LY OK
	\xdef\LXmoy{\xintfloateval{\LXSomme/\LNB}}%
	\xdef\LYmoy{\xintfloateval{\LYSomme/\LNB}}%
	%variance des LX et des LY OK
	\xdef\LXvar{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\LXvar{\xintfloateval{\LXvar+(\LX[##1]-(\LXmoy))*(\LX[##1]-(\LXmoy))}}%
	}
	\xdef\LXvar{\xintfloateval{\LXvar/\LNB}}%
	\xdef\LYvar{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\LYvar{\xintfloateval{\LYvar+(\LY[##1]-(\LYmoy))*(\LY[##1]-(\LYmoy))}}%
	}%
	\xdef\LYvar{\xintfloateval{\LYvar/\LNB}}%
	%covariance des XY OK
	\xdef\LXYvar{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\LXYvar{\xintfloateval{\LXYvar+(\LX[##1]-(\LXmoy))*(\LY[##1]-(\LYmoy))}}%
	}%
	\xdef\LXYvar{\xintfloateval{\LXYvar/\LNB}}%
	%COEFFS TEMPORAIRES OK
	\xdef\tmp@reg@lin@a{\xintfloateval{\LXYvar/\LXvar}}%
	\xdef\tmp@reg@lin@b{\xintfloateval{\LYmoy-(\tmp@reg@lin@a)*(\LXmoy)}}%
	%STOCKAGE
	\IfStrEq{\RegLinRound}{}%
		{%
			\expandafter\def\csname\RegLinCoefa\endcsname{\tmp@reg@lin@a}%
			\expandafter\def\csname\RegLinCoefb\endcsname{\tmp@reg@lin@b}%
		}%
		{%
			\IfSubStr{\RegLinRound}{/}%
				{%
					\StrCut{\RegLinRound}{/}{\xintarrondisreglina}{\xintarrondisreglinb}%
				}%
				{%
					\xdef\xintarrondisreglina{\RegLinRound}\xdef\xintarrondisreglinb{\RegLinRound}%
				}%
			\expandafter\def\csname\RegLinCoefa\endcsname{\xintfloateval{round(\tmp@reg@lin@a,\xintarrondisreglina)}}%
			\expandafter\def\csname\RegLinCoefb\endcsname{\xintfloateval{round(\tmp@reg@lin@b,\xintarrondisreglinb)}}%
		}%
	%R/R2
	\expandafter\def\csname\RegLinCoefr\endcsname{\xintfloateval{\LXYvar/sqrt(\LXvar*\LYvar)}}%
	\expandafter\def\csname\RegLinCoefrr\endcsname{\xintfloateval{(\csname\RegLinCoefr\endcsname)*(\csname\RegLinCoefr\endcsname)}}%
}
\NewCommandCopy\xintLINreg\xintlinreg


%régression quadratique
\defKV[CoeffRegQuad]{%
	coeffa=\def\RegQuadCoefa{#1},%
	coeffb=\def\RegQuadCoefb{#1},%
	coeffc=\def\RegQuadCoefc{#1},%
	coeffrr=\def\RegQuadCoefrr{#1},%
	round=\def\RegQuadRound{#1}
}

\setKVdefault[CoeffRegQuad]{%
	coeffa=quadrega,%
	coeffb=quadregb,%
	coeffc=quadregc,%
	coeffrr=quadregrr,%
	round={} 
}

\newcommand\xintquadreg[3][]{%
	\useKVdefault[CoeffRegQuad]%
	\setKV[CoeffRegQuad]{#1}% on paramètres les nouvelles clés et on les simplifie
	%listes des données
	\def\xliste{#2}%
	\def\yliste{#3}%
	\setsepchar{,}%
	\readlist*\LX{\xliste}%
	\readlist*\LY{\yliste}%
	%taille des listes
	\def\LNB{\inteval{\LXlen}}%
	%somme importantes
	\xdef\LXSomme{0}%
	\xdef\LXCSomme{0}%
	\xdef\LYSomme{0}%
	\xdef\LXXSomme{0}%
	\xdef\LXYSomme{0}%
	\xdef\LXXCSomme{0}%
	\xdef\LXCXCSomme{0}%
	\xdef\LXCYSomme{0}%
	%calculs
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\LXSomme{\xintfloateval{\LXSomme+(\LX[##1])}}%
		\xdef\LXCSomme{\xintfloateval{\LXCSomme+(\LX[##1])^2}}%
	}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\LYSomme{\xintfloateval{\LYSomme+(\LY[##1])}}%
	}%
	\xdef\LXmoy{\xintfloateval{\LXSomme/\LNB}}%
	\xdef\LYmoy{\xintfloateval{\LYSomme/\LNB}}%
	\xdef\LXCmoy{\xintfloateval{\LXCSomme/\LNB}}%
	%calculs suites
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\LXXSomme{\xintfloateval{\LXXSomme+(\LX[##1]-\LXmoy)^2}}%
		\xdef\LXYSomme{\xintfloateval{\LXYSomme+(\LX[##1]-\LXmoy)*(\LY[##1]-\LYmoy)}}%
		\xdef\LXXCSomme{\xintfloateval{\LXXCSomme+(\LX[##1]-\LXmoy)*((\LX[##1])*(\LX[##1])-\LXCmoy)}}%
		\xdef\LXCXCSomme{\xintfloateval{\LXCXCSomme+((\LX[##1])^2-\LXCmoy)^2}}%
		\xdef\LXCYSomme{\xintfloateval{\LXCYSomme+((\LX[##1])^2-\LXCmoy)*(\LY[##1]-\LYmoy)}}%
	}%
	%COEFFS TEMPORAIRES OK
	\xdef\tmp@reg@quad@b{\xintfloateval{(\LXYSomme*\LXCXCSomme-\LXCYSomme*\LXXCSomme)/(\LXXSomme*\LXCXCSomme-(\LXXCSomme)^2)}}%
	\xdef\tmp@reg@quad@a{\xintfloateval{(\LXCYSomme*\LXXSomme-\LXYSomme*\LXXCSomme)/(\LXXSomme*\LXCXCSomme-(\LXXCSomme)^2)}}%
	\xdef\tmp@reg@quad@c{\xintfloateval{\LYmoy-(\tmp@reg@quad@b)*\LXmoy-(\tmp@reg@quad@a)*\LXCmoy}}%
	%CALCUL R² (NOUVEAU)
	%SS_tot = somme des (y_i - moyenne_y)²
	\xdef\SStot{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\SStot{\xintfloateval{\SStot+(\LY[##1]-\LYmoy)^2}}%
	}%
	%SS_res = somme des (y_i - y_predit)² où y_predit = a*x² + b*x + c
	\xdef\SSres{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\Ypred{\xintfloateval{(\tmp@reg@quad@a)*(\LX[##1])^2+(\tmp@reg@quad@b)*(\LX[##1])+(\tmp@reg@quad@c)}}%
		\xdef\SSres{\xintfloateval{\SSres+(\LY[##1]-\Ypred)^2}}%
	}%
	%R² = 1 - SS_res/SS_tot
	\xdef\tmp@reg@quad@rr{\xintfloateval{1-(\SSres)/(\SStot)}}%
	%STOCKAGE
	\IfStrEq{\RegQuadRound}{}%
		{%
			\expandafter\def\csname\RegQuadCoefb\endcsname{\tmp@reg@quad@b}%
			\expandafter\def\csname\RegQuadCoefa\endcsname{\tmp@reg@quad@a}%
			\expandafter\def\csname\RegQuadCoefc\endcsname{\tmp@reg@quad@c}%
			\expandafter\def\csname\RegQuadCoefrr\endcsname{\tmp@reg@quad@rr}%
		}%
		{%
			\IfSubStr{\RegQuadRound}{/}%
				{%
					\StrBefore[1]{\RegQuadRound}{/}[\xintarrondisregquada]%
					\StrBetween[1,2]{\RegQuadRound}{/}{/}[\xintarrondisregquadb]%
					\StrBehind[2]{\RegQuadRound}{/}[\xintarrondisregquadc]%
				}%
				{%
					\xdef\xintarrondisregquada{\RegQuadRound}%
					\xdef\xintarrondisregquadb{\RegQuadRound}%
					\xdef\xintarrondisregquadc{\RegQuadRound}%
					
				}%
			\expandafter\def\csname\RegQuadCoefb\endcsname{\xintfloateval{round(\tmp@reg@quad@b,\xintarrondisregquadb)}}%
			\expandafter\def\csname\RegQuadCoefa\endcsname{\xintfloateval{round(\tmp@reg@quad@a,\xintarrondisregquada)}}%
			\expandafter\def\csname\RegQuadCoefc\endcsname{\xintfloateval{round(\tmp@reg@quad@c,\xintarrondisregquadc)}}%
			\expandafter\def\csname\RegQuadCoefrr\endcsname{\tmp@reg@quad@rr}%
		}%
}
\NewCommandCopy\xintQUADreg\xintquadreg

%régression puissance a*x^b
\defKV[CoeffRegPuiss]{%
	coeffa=\def\RegPuissCoefa{#1},%
	coeffb=\def\RegPuissCoefb{#1},%
	coeffrr=\def\RegPuissCoefrr{#1},%
	round=\def\RegPuissRound{#1}
}

\setKVdefault[CoeffRegPuiss]{%
	coeffa=powrega,%
	coeffb=powregb,%
	coeffrr=powregrr,%
	round={}
}

\newcommand\xintpowreg[3][]{%
	\useKVdefault[CoeffRegPuiss]%
	\setKV[CoeffRegPuiss]{#1}% on paramètres les nouvelles clés et on les simplifie
	%listes des données
	\def\xliste{#2}%
	\def\yliste{#3}%
	\setsepchar{,}%
	\readlist*\LX{\xliste}%
	\readlist*\LY{\yliste}%
	%taille des listes
	\xdef\LNB{\fpeval{min(\LXlen,\LYlen)}}%
	%somme importantes
	\xdef\LYSomme{0}%
	\xdef\LlnXSomme{0}%
	\xdef\LlnYSomme{0}%
	\xdef\LlnXlnYSomme{0}%
	\xdef\LlncXSomme{0}%
	%calculs
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\LYSomme{\xintfloateval{\LYSomme+(\LY[##1])}}%
		\xdef\LlnXSomme{\xintfloateval{\LlnXSomme+log(\LX[##1])}}%
		\xdef\LlnYSomme{\xintfloateval{\LlnYSomme+log(\LY[##1])}}%
		\xdef\LlnXlnYSomme{\xintfloateval{\LlnXlnYSomme+log(\LX[##1])*log(\LY[##1])}}%
		\xdef\LlncXSomme{\xintfloateval{\LlncXSomme+(log(\LX[##1]))^2}}%
	}%
	%calcul moyenne y (pour R²)
	\xdef\LYmoy{\xintfloateval{\LYSomme/\LNB}}%
	%COEFFS TEMPORAIRES OK
	\xdef\tmp@reg@pow@b{\xintfloateval{(\LNB*\LlnXlnYSomme-\LlnXSomme*\LlnYSomme)/(\LNB*\LlncXSomme-(\LlnXSomme)^2)}}%
	\xdef\tmp@reg@pow@a{\xintfloateval{exp(1/\LNB*\LlnYSomme-(\tmp@reg@pow@b)/\LNB*\LlnXSomme)}}%
	%CALCUL R²
	\xdef\SStot{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\SStot{\xintfloateval{\SStot+(\LY[##1]-\LYmoy)^2}}%
	}%
	\xdef\SSres{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\Ypred{\xintfloateval{(\tmp@reg@pow@a)*(\LX[##1])^(\tmp@reg@pow@b)}}%
		\xdef\SSres{\xintfloateval{\SSres+(\LY[##1]-\Ypred)^2}}%
	}%
	\xdef\tmp@reg@pow@rr{\xintfloateval{1-(\SSres)/(\SStot)}}%
	%STOCKAGE
	\IfStrEq{\RegPuissRound}{}%
		{%
			\expandafter\def\csname\RegPuissCoefb\endcsname{\xintfloateval{\tmp@reg@pow@b}}%
			\expandafter\def\csname\RegPuissCoefa\endcsname{\xintfloateval{\tmp@reg@pow@a}}%
			\expandafter\def\csname\RegPuissCoefrr\endcsname{\tmp@reg@pow@rr}%
		}%
		{%
			\IfSubStr{\RegPuissRound}{/}%
				{%
					\StrCut{\RegPuissRound}{/}{\xintarrondisregpowa}{\xintarrondisregpowb}%
				}%
				{%
					\xdef\xintarrondisregpowa{\RegPuissRound}\xdef\xintarrondisregpowb{\RegPuissRound}%
				}%
			\expandafter\def\csname\RegPuissCoefb\endcsname{\xintfloateval{round(\tmp@reg@pow@b,\xintarrondisregpowb)}}%
			\expandafter\def\csname\RegPuissCoefa\endcsname{\xintfloateval{round(\tmp@reg@pow@a,\xintarrondisregpowa)}}%
			\expandafter\def\csname\RegPuissCoefrr\endcsname{\tmp@reg@pow@rr}%
		}%
}
\NewCommandCopy\xintPOWreg\xintpowreg

%régression a*b^x
\defKV[CoeffRegExpoAB]{%
	coeffa=\def\RegExpoCoefa{#1},%
	coeffb=\def\RegExpoCoefb{#1},%
	coeffrr=\def\RegExpoCoefrr{#1},%
	round=\def\RegExpoRound{#1}
}

\setKVdefault[CoeffRegExpoAB]{%
	coeffa=expabrega,%
	coeffb=expabregb,%
	coeffrr=expabregrr,%
	round={}
}

\newcommand\xintexpabreg[3][]{%
	\useKVdefault[CoeffRegExpoAB]%
	\setKV[CoeffRegExpoAB]{#1}% on paramètres les nouvelles clés et on les simplifie
	%listes des données
	\def\xliste{#2}%
	\def\yliste{#3}%
	\setsepchar{,}%
	\readlist*\LX{\xliste}%
	\readlist*\LY{\yliste}%
	%taille des listes
	\xdef\LNB{\fpeval{min(\LXlen,\LYlen)}}%
	%somme importantes
	\xdef\LYSomme{0}%
	\xdef\LXlnYSomme{0}%
	\xdef\LXSomme{0}%
	\xdef\LlnYSomme{0}%
	\xdef\LXcSomme{0}%
	%calculs
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\LYSomme{\xintfloateval{\LYSomme+(\LY[##1])}}%
		\xdef\LXlnYSomme{\xintfloateval{\LXlnYSomme+\LX[##1]*log(\LY[##1])}}%
		\xdef\LXSomme{\xintfloateval{\LXSomme+\LX[##1]}}%
		\xdef\LlnYSomme{\xintfloateval{\LlnYSomme+log(\LY[##1])}}%
		\xdef\LXcSomme{\xintfloateval{\LXcSomme+(\LX[##1])^2}}%
	}%
	%calcul moyenne y (pour R²)
	\xdef\LYmoy{\xintfloateval{\LYSomme/\LNB}}%
	%COEFFS TEMPORAIRES OK
	\xdef\tmp@reg@expab@b{\xintfloateval{exp((\LNB*\LXlnYSomme-\LXSomme*\LlnYSomme)/(\LNB*\LXcSomme-(\LXSomme)^2))}}%
	\xdef\tmp@reg@expab@a{\xintfloateval{exp(1/\LNB*\LlnYSomme-log(\tmp@reg@expab@b)/\LNB*\LXSomme)}}%
	%CALCUL R²
	\xdef\SStot{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\SStot{\xintfloateval{\SStot+(\LY[##1]-\LYmoy)^2}}%
	}%
	\xdef\SSres{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\Ypred{\xintfloateval{(\tmp@reg@expab@a)*(\tmp@reg@expab@b)^(\LX[##1])}}%
		\xdef\SSres{\xintfloateval{\SSres+(\LY[##1]-\Ypred)^2}}%
	}%
	\xdef\tmp@reg@expab@rr{\xintfloateval{1-(\SSres)/(\SStot)}}%
	%STOCKAGE
	\IfStrEq{\RegExpoRound}{}%
		{%
			\expandafter\def\csname\RegExpoCoefb\endcsname{\tmp@reg@expab@b}%
			\expandafter\def\csname\RegExpoCoefa\endcsname{\tmp@reg@expab@a}%
			\expandafter\def\csname\RegExpoCoefrr\endcsname{\tmp@reg@expab@rr}%
		}%
		{%
			\IfSubStr{\RegExpoRound}{/}%
				{%
					\StrCut{\RegExpoRound}{/}{\xintarrondisregexpoaba}{\xintarrondisregexpoabb}%
				}%
				{%
					\xdef\xintarrondisregexpoaba{\RegExpoRound}\xdef\xintarrondisregexpoabb{\RegExpoRound}%
				}%
			\expandafter\def\csname\RegExpoCoefb\endcsname{\xintfloateval{round(\tmp@reg@expab@b,\xintarrondisregexpoabb)}}%
			\expandafter\def\csname\RegExpoCoefa\endcsname{\xintfloateval{round(\tmp@reg@expab@a,\xintarrondisregexpoaba)}}%
			\expandafter\def\csname\RegExpoCoefrr\endcsname{\tmp@reg@expab@rr}%
		}%
}
\NewCommandCopy\xintEXPABreg\xintexpabreg

%régression a+b/x
\defKV[CoeffRegHyperb]{%
	coeffa=\def\RegHyperbCoefa{#1},%
	coeffb=\def\RegHyperbCoefb{#1},%
	coeffrr=\def\RegHyperbCoefrr{#1},%
	round=\def\RegHyperbRound{#1}
}

\setKVdefault[CoeffRegHyperb]{%
	coeffa=hyprega,%
	coeffb=hypregb,%
	coeffrr=hypregrr,%
	round={}
}

\newcommand\xinthypreg[3][]{%
	\useKVdefault[CoeffRegHyperb]%
	\setKV[CoeffRegHyperb]{#1}% on paramètres les nouvelles clés et on les simplifie
	%listes des données
	\def\xliste{#2}%
	\def\yliste{#3}%
	\setsepchar{,}%
	\readlist*\LX{\xliste}%
	\readlist*\LY{\yliste}%
	%taille des listes
	\xdef\LNB{\fpeval{min(\LXlen,\LYlen)}}%
	%somme importantes
	\xdef\LinvXSomme{0}%
	\xdef\LYdivXSomme{0}%
	\xdef\LYSomme{0}%
	\xdef\LinvXcSomme{0}%
	%calculs
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\LinvXSomme{\xintfloateval{\LinvXSomme+1/\LX[##1]}}%
		\xdef\LYdivXSomme{\xintfloateval{\LYdivXSomme+\LY[##1]/\LX[##1]}}%
		\xdef\LYSomme{\xintfloateval{\LYSomme+(\LY[##1])}}%
		\xdef\LinvXcSomme{\xintfloateval{\LinvXcSomme+1/(\LX[##1])^2}}%
	}%
	%calcul moyenne y (pour R²)
	\xdef\LYmoy{\xintfloateval{\LYSomme/\LNB}}%
	%COEFFS TEMPORAIRES OK
	\xdef\tmp@reg@hyp@b{\xintfloateval{(\LNB*\LYdivXSomme-\LinvXSomme*\LYSomme)/(\LNB*\LinvXcSomme-(\LinvXSomme)^2)}}%
	\xdef\tmp@reg@hyp@a{\xintfloateval{1/\LNB*\LYSomme-(\tmp@reg@hyp@b)/\LNB*\LinvXSomme}}%
	%CALCUL R²
	\xdef\SStot{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\SStot{\xintfloateval{\SStot+(\LY[##1]-\LYmoy)^2}}%
	}%
	\xdef\SSres{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\Ypred{\xintfloateval{(\tmp@reg@hyp@a)+(\tmp@reg@hyp@b)/(\LX[##1])}}%
		\xdef\SSres{\xintfloateval{\SSres+(\LY[##1]-\Ypred)^2}}%
	}%
	\xdef\tmp@reg@hyp@rr{\xintfloateval{1-(\SSres)/(\SStot)}}%
	%STOCKAGE
	\IfStrEq{\RegHyperbRound}{}%
		{%
			\expandafter\def\csname\RegHyperbCoefb\endcsname{\tmp@reg@hyp@b}%
			\expandafter\def\csname\RegHyperbCoefa\endcsname{\tmp@reg@hyp@a}%
			\expandafter\def\csname\RegHyperbCoefrr\endcsname{\tmp@reg@hyp@rr}%
		}%
		{%
			\IfSubStr{\RegHyperbRound}{/}%
				{%
					\StrCut{\RegHyperbRound}{/}{\xintarrondisreghypa}{\xintarrondisreghypb}%
				}%
				{%
					\xdef\xintarrondisreghypa{\RegHyperbRound}\xdef\xintarrondisreghypb{\RegHyperbRound}%
				}%
			\expandafter\def\csname\RegHyperbCoefb\endcsname{\xintfloateval{round(\tmp@reg@hyp@b,\xintarrondisreghypb)}}%
			\expandafter\def\csname\RegHyperbCoefa\endcsname{\xintfloateval{round(\tmp@reg@hyp@a,\xintarrondisreghypa)}}%
			\expandafter\def\csname\RegHyperbCoefrr\endcsname{\tmp@reg@hyp@rr}%
		}%
}
\NewCommandCopy\xintHYPreg\xinthypreg

%régression a+b*ln(x)
\defKV[CoeffRegLog]{%
	coeffa=\def\RegLogCoefa{#1},%
	coeffb=\def\RegLogCoefb{#1},%
	coeffrr=\def\RegLogCoefrr{#1},%
	round=\def\RegLogRound{#1}
}

\setKVdefault[CoeffRegLog]{%
	coeffa=logrega,%
	coeffb=logregb,%
	coeffrr=logregrr,%
	round={}
}

\newcommand\xintlogreg[3][]{%
	\useKVdefault[CoeffRegLog]%
	\setKV[CoeffRegLog]{#1}% on paramètres les nouvelles clés et on les simplifie
	%listes des données
	\def\xliste{#2}%
	\def\yliste{#3}%
	\setsepchar{,}%
	\readlist*\LX{\xliste}%
	\readlist*\LY{\yliste}%
	%taille des listes
	\xdef\LNB{\fpeval{min(\LXlen,\LYlen)}}%
	%somme importantes
	\xdef\LYlnXSomme{0}%
	\xdef\LlnXSomme{0}%
	\xdef\LYSomme{0}%
	\xdef\LYlncXSomme{0}%
	%calculs
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\LYlnXSomme{\xintfloateval{\LYlnXSomme+\LY[##1]*log(\LX[##1])}}%
		\xdef\LlnXSomme{\xintfloateval{\LlnXSomme+log(\LX[##1])}}%
		\xdef\LYSomme{\xintfloateval{\LYSomme+(\LY[##1])}}%
		\xdef\LYlncXSomme{\xintfloateval{\LYlncXSomme+log(\LX[##1])^2}}%
	}%
	%calcul moyenne y (pour R²)
	\xdef\LYmoy{\xintfloateval{\LYSomme/\LNB}}%
	%COEFFS TEMPORAIRES OK
	\xdef\tmp@reg@log@b{\xintfloateval{(\LNB*\LYlnXSomme-\LlnXSomme*\LYSomme)/(\LNB*\LYlncXSomme-(\LlnXSomme)^2)}}%
	\xdef\tmp@reg@log@a{\xintfloateval{1/\LNB*\LYSomme-(\tmp@reg@log@b)/\LNB*\LlnXSomme}}%
	%CALCUL R²
	\xdef\SStot{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\SStot{\xintfloateval{\SStot+(\LY[##1]-\LYmoy)^2}}%
	}%
	\xdef\SSres{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\Ypred{\xintfloateval{(\tmp@reg@log@a)+(\tmp@reg@log@b)*log(\LX[##1])}}%
		\xdef\SSres{\xintfloateval{\SSres+(\LY[##1]-\Ypred)^2}}%
	}%
	\xdef\tmp@reg@log@rr{\xintfloateval{1-(\SSres)/(\SStot)}}%
	%STOCKAGE
	\IfStrEq{\RegLogRound}{}%
		{%
			\expandafter\def\csname\RegLogCoefb\endcsname{\tmp@reg@log@b}%
			\expandafter\def\csname\RegLogCoefa\endcsname{\tmp@reg@log@a}%
			\expandafter\def\csname\RegLogCoefrr\endcsname{\tmp@reg@log@rr}%
		}%
		{%
			\IfSubStr{\RegLogRound}{/}%
				{%
					\StrCut{\RegLogRound}{/}{\xintarrondisregloga}{\xintarrondisreglogb}%
				}%
				{%
					\xdef\xintarrondisregloga{\RegLogRound}\xdef\xintarrondisreglogb{\RegLogRound}%
				}%
			\expandafter\def\csname\RegLogCoefb\endcsname{\xintfloateval{round(\tmp@reg@log@b,\xintarrondisreglogb)}}%
			\expandafter\def\csname\RegLogCoefa\endcsname{\xintfloateval{round(\tmp@reg@log@a,\xintarrondisregloga)}}%
			\expandafter\def\csname\RegLogCoefrr\endcsname{\tmp@reg@log@rr}%
		}%
}
\NewCommandCopy\xintLOGreg\xintlogreg

%régression e^(ax+b)
\defKV[CoeffRegExpo]{%
	coeffa=\def\RegExpoNCoefa{#1},%
	coeffb=\def\RegExpoNCoefb{#1},%
	coeffrr=\def\RegExpoNCoefrr{#1},%
	round=\def\RegExpoNRound{#1}
}

\setKVdefault[CoeffRegExpo]{%
	coeffa=exprega,%
	coeffb=expregb,%
	coeffrr=expregrr,%
	Alt=false,%
	round={}
}

\newcommand\xintexpreg[3][]{%
	\useKVdefault[CoeffRegExpo]%
	\setKV[CoeffRegExpo]{#1}% on paramètres les nouvelles clés et on les simplifie
	%listes des données
	\def\xliste{#2}%
	\def\yliste{#3}%
	\setsepchar{,}%
	\readlist*\LX{\xliste}%
	\readlist*\LY{\yliste}%
	%taille des listes
	\xdef\LNB{\fpeval{min(\LXlen,\LYlen)}}%
	%somme importantes
	\xdef\LYSomme{0}%
	\xdef\LXlnYSomme{0}%
	\xdef\LXSomme{0}%
	\xdef\LlnYSomme{0}%
	\xdef\LXcSomme{0}%
	%calculs
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\LYSomme{\xintfloateval{\LYSomme+(\LY[##1])}}%
		\xdef\LXlnYSomme{\xintfloateval{\LXlnYSomme+\LX[##1]*log(\LY[##1])}}%
		\xdef\LXSomme{\xintfloateval{\LXSomme+\LX[##1]}}%
		\xdef\LlnYSomme{\xintfloateval{\LlnYSomme+log(\LY[##1])}}%
		\xdef\LXcSomme{\xintfloateval{\LXcSomme+(\LX[##1])^2}}%
	}%
	%calcul moyenne y (pour R²)
	\xdef\LYmoy{\xintfloateval{\LYSomme/\LNB}}%
	%COEFFS TEMPORAIRES
	\xdef\TmpCoeffExpoA{\xintfloateval{(\LNB*\LXlnYSomme-\LXSomme*\LlnYSomme)/(\LNB*\LXcSomme-(\LXSomme)^2)}}%
	\xdef\TmpCoeffExpoB{\xintfloateval{1/\LNB*\LlnYSomme-(\TmpCoeffExpoA)/\LNB*\LXSomme}}%
	%CALCUL R²
	\xdef\SStot{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\SStot{\xintfloateval{\SStot+(\LY[##1]-\LYmoy)^2}}%
	}%
	\xdef\SSres{0}%
	\ifboolKV[CoeffRegExpo]{Alt}%
		{%
			\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
				\xdef\Ypred{\xintfloateval{exp((\TmpCoeffExpoB))*exp((\TmpCoeffExpoA)*(\LX[##1]))}}%
				\xdef\SSres{\xintfloateval{\SSres+(\LY[##1]-\Ypred)^2}}%
			}%
		}%
		{%
			\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
				\xdef\Ypred{\xintfloateval{exp((\TmpCoeffExpoA)*(\LX[##1])+(\TmpCoeffExpoB))}}%
				\xdef\SSres{\xintfloateval{\SSres+(\LY[##1]-\Ypred)^2}}%
			}%
		}%
	\xdef\tmp@reg@expo@rr{\xintfloateval{1-(\SSres)/(\SStot)}}%
	%STOCKAGE
	\ifboolKV[CoeffRegExpo]{Alt}%
		{%
			%STOCKAGE
			\IfStrEq{\RegExpoNRound}{}%
				{%
					\expandafter\def\csname\RegExpoNCoefb\endcsname{\xintfloateval{exp(\TmpCoeffExpoB)}}%
					\expandafter\def\csname\RegExpoNCoefa\endcsname{\TmpCoeffExpoA}%
					\expandafter\def\csname\RegExpoNCoefrr\endcsname{\tmp@reg@expo@rr}%
				}%
				{%
					\IfSubStr{\RegExpoNRound}{/}%
						{%
							\StrCut{\RegExpoNRound}{/}{\xintarrondisregexpoa}{\xintarrondisregexpob}%
						}%
						{%
							\xdef\xintarrondisregexpoa{\RegExpoNRound}\xdef\xintarrondisregexpob{\RegExpoNRound}%
						}%
					\expandafter\def\csname\RegExpoNCoefb\endcsname{\xintfloateval{round(exp(\TmpCoeffExpoB),\xintarrondisregexpob)}}%
					\expandafter\def\csname\RegExpoNCoefa\endcsname{\xintfloateval{round(\TmpCoeffExpoA,\xintarrondisregexpoa)}}%
					\expandafter\def\csname\RegExpoNCoefrr\endcsname{\tmp@reg@expo@rr}%
				}%
		}%
		{%
			%STOCKAGE
			\IfStrEq{\RegExpoNRound}{}%
				{%
					\expandafter\def\csname\RegExpoNCoefb\endcsname{\TmpCoeffExpoB}%
					\expandafter\def\csname\RegExpoNCoefa\endcsname{\TmpCoeffExpoA}%
					\expandafter\def\csname\RegExpoNCoefrr\endcsname{\tmp@reg@expo@rr}%
				}%
				{%
					\IfSubStr{\RegExpoNRound}{/}%
						{%
							\StrCut{\RegExpoNRound}{/}{\xintarrondisregexpoa}{\xintarrondisregexpob}%
						}%
						{%
							\xdef\xintarrondisregexpoa{\RegExpoNRound}\xdef\xintarrondisregexpob{\RegExpoNRound}%
						}%
					\expandafter\def\csname\RegExpoNCoefb\endcsname{\xintfloateval{round(\TmpCoeffExpoB,\xintarrondisregexpob)}}%
					\expandafter\def\csname\RegExpoNCoefa\endcsname{\xintfloateval{round(\TmpCoeffExpoA,\xintarrondisregexpoa)}}%
					\expandafter\def\csname\RegExpoNCoefrr\endcsname{\tmp@reg@expo@rr}%
				}%
		}%
}
\NewCommandCopy\xintEXPreg\xintexpreg

%régression C + b*e^(ax)
\defKV[CoeffRegExpoOff]{%
	coeffa=\def\RegExpoOffCoefa{#1},%
	coeffb=\def\RegExpoOffCoefb{#1},%
	coeffrr=\def\RegExpoOffCoefrr{#1},%
	offset=\def\RegExpoOffset{#1},%
	round=\def\RegExpoOffRound{#1}
}

\setKVdefault[CoeffRegExpoOff]{%
	coeffa=expregoffa,%
	coeffb=expregoffb,%
	coeffrr=expregoffrr,%
	offset=0,%
	round={}
}

\newcommand\xintexpoffreg[3][]{%
	\useKVdefault[CoeffRegExpoOff]%
	\setKV[CoeffRegExpoOff]{#1}% on paramètres les nouvelles clés et on les simplifie
	%listes des données
	\def\xliste{#2}%
	\def\yliste{#3}%
	\setsepchar{,}%
	\readlist*\LX{\xliste}%
	\readlist*\LY{\yliste}%
	%taille des listes
	\xdef\LNB{\fpeval{min(\LXlen,\LYlen)}}%
	%somme importantes
	\xdef\LYSomme{0}%
	\xdef\LXlnYSomme{0}%
	\xdef\LXSomme{0}%
	\xdef\LlnYSomme{0}%
	\xdef\LXcSomme{0}%
	%calculs
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\LYSomme{\xintfloateval{\LYSomme+(\LY[##1])}}%
		\xdef\LXlnYSomme{\xintfloateval{\LXlnYSomme+\LX[##1]*log(\LY[##1]-\RegExpoOffset)}}%
		\xdef\LXSomme{\xintfloateval{\LXSomme+\LX[##1]}}%
		\xdef\LlnYSomme{\xintfloateval{\LlnYSomme+log(\LY[##1]-\RegExpoOffset)}}%
		\xdef\LXcSomme{\xintfloateval{\LXcSomme+(\LX[##1])^2}}%
	}%
	%calcul moyenne y (pour R²)
	\xdef\LYmoy{\xintfloateval{\LYSomme/\LNB}}%
	%COEFFS TEMPORAIRES
	\xdef\TmpCoeffExpoA{\xintfloateval{(\LNB*\LXlnYSomme-\LXSomme*\LlnYSomme)/(\LNB*\LXcSomme-(\LXSomme)^2)}}%
	\xdef\TmpCoeffExpoB{\xintfloateval{1/\LNB*\LlnYSomme-(\TmpCoeffExpoA)/\LNB*\LXSomme}}%
	%CALCUL R²
	\xdef\SStot{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\SStot{\xintfloateval{\SStot+(\LY[##1]-\LYmoy)^2}}%
	}%
	\xdef\SSres{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\Ypred{\xintfloateval{\RegExpoOffset+exp(\TmpCoeffExpoB)*exp((\TmpCoeffExpoA)*(\LX[##1]))}}%
		\xdef\SSres{\xintfloateval{\SSres+(\LY[##1]-\Ypred)^2}}%
	}%
	\xdef\tmp@reg@expoff@rr{\xintfloateval{1-(\SSres)/(\SStot)}}%
	%STOCKAGE
	\IfStrEq{\RegExpoOffRound}{}%
		{%
			\expandafter\def\csname\RegExpoOffCoefb\endcsname{\xintfloateval{exp(\TmpCoeffExpoB)}}%
			\expandafter\def\csname\RegExpoOffCoefa\endcsname{\xintfloateval{\TmpCoeffExpoA}}%
			\expandafter\def\csname\RegExpoOffCoefrr\endcsname{\tmp@reg@expoff@rr}%
		}%
		{%
			\IfSubStr{\RegExpoOffRound}{/}%
				{%
					\StrCut{\RegExpoOffRound}{/}{\xintarrondisregexpoffa}{\xintarrondisregexpoffb}%
				}%
				{%
					\xdef\xintarrondisregexpoffa{\RegExpoOffRound}\xdef\xintarrondisregexpoffb{\RegExpoOffRound}%
				}%
			\expandafter\def\csname\RegExpoOffCoefb\endcsname{\xintfloateval{round(exp(\TmpCoeffExpoB),\xintarrondisregexpoffb)}}%
			\expandafter\def\csname\RegExpoOffCoefa\endcsname{\xintfloateval{round(\TmpCoeffExpoA,\xintarrondisregexpoffa)}}%
			\expandafter\def\csname\RegExpoOffCoefrr\endcsname{\tmp@reg@expoff@rr}%
		}%
}
\NewCommandCopy\xintEXPOFFreg\xintexpoffreg

%régression cubique
\defKV[CoeffRegCubic]{%
	coeffa=\def\RegCubicCoefa{#1},%
	coeffb=\def\RegCubicCoefb{#1},%
	coeffc=\def\RegCubicCoefc{#1},%
	coeffd=\def\RegCubicCoefd{#1},%
	coeffrr=\def\RegCubicCoefrr{#1},%
	round=\def\RegCubicRound{#1}
}

\setKVdefault[CoeffRegCubic]{%
	coeffa=cubrega,%
	coeffb=cubregb,%
	coeffc=cubregc,%
	coeffd=cubregd,%
	coeffrr=cubregrr,%
	round={}
}

\newcommand\xintcubreg[3][]{%
	\useKVdefault[CoeffRegCubic]%
	\setKV[CoeffRegCubic]{#1}% on paramètres les nouvelles clés et on les simplifie
	%listes des données
	\def\xliste{#2}%
	\def\yliste{#3}%
	\setsepchar{,}%
	\readlist*\LX{\xliste}%
	\readlist*\LY{\yliste}%
	%taille des listes
	\xdef\LNB{\fpeval{min(\LXlen,\LYlen)}}%
	%somme importantes
	\xdef\LXSomme{0}%
	\xdef\LXdSomme{0}%
	\xdef\LXtSomme{0}%
	\xdef\LXqSomme{0}%
	\xdef\LXcSomme{0}%
	\xdef\LXsSomme{0}%
	\xdef\LYSomme{0}%
	\xdef\LXYSomme{0}%
	\xdef\LXdYSomme{0}%
	\xdef\LXtYSomme{0}%
	%calculs
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\LXSomme{\xintfloateval{\LXSomme+(\LX[##1])}}%
		\xdef\LXdSomme{\xintfloateval{\LXdSomme+(\LX[##1])^2}}%
		\xdef\LXtSomme{\xintfloateval{\LXtSomme+(\LX[##1])^3}}%
		\xdef\LXqSomme{\xintfloateval{\LXqSomme+(\LX[##1])^4}}%
		\xdef\LXcSomme{\xintfloateval{\LXcSomme+(\LX[##1])^5}}%
		\xdef\LXsSomme{\xintfloateval{\LXsSomme+(\LX[##1])^6}}%
		\xdef\LYSomme{\xintfloateval{\LYSomme+(\LY[##1])}}%
		\xdef\LXYSomme{\xintfloateval{\LXYSomme+(\LX[##1])*(\LY[##1])}}%
		\xdef\LXdYSomme{\xintfloateval{\LXdYSomme+(\LX[##1])^2*(\LY[##1])}}%
		\xdef\LXtYSomme{\xintfloateval{\LXtYSomme+(\LX[##1])^3*(\LY[##1])}}%
	}%
	%calcul moyenne y (pour R²)
	\xdef\LYmoy{\xintfloateval{\LYSomme/\LNB}}%
	%calculs suites, avec des matrices !!
	\def\MatA{\LXtSomme}%
	\def\MatB{\LXdSomme}%
	\def\MatC{\LXSomme}%
	\def\MatD{\LNB}%
	\def\MatE{\LXqSomme}%
	\def\MatF{\LXtSomme}%
	\def\MatG{\LXdSomme}%
	\def\MatH{\LXSomme}%
	\def\MatI{\LXcSomme}%
	\def\MatJ{\LXqSomme}%
	\def\MatK{\LXtSomme}%
	\def\MatL{\LXdSomme}%
	\def\MatM{\LXsSomme}%
	\def\MatN{\LXcSomme}%
	\def\MatO{\LXqSomme}%
	\def\MatP{\LXtSomme}%
	\def\MatBA{\LYSomme}%
	\def\MatBB{\LXYSomme}%
	\def\MatBC{\LXdYSomme}%
	\def\MatBD{\LXtYSomme}%
	\def\DETMATRICE{\xintfloateval{\MatA*\MatF*\MatK*\MatP-\MatA*\MatF*\MatL*\MatO-\MatA*\MatG*\MatJ*\MatP+\MatA*\MatG*\MatL*\MatN+\MatA*\MatH*\MatJ*\MatO-\MatA*\MatH*\MatK*\MatN-\MatB*\MatE*\MatK*\MatP+\MatB*\MatE*\MatL*\MatO+\MatB*\MatG*\MatI*\MatP-\MatB*\MatG*\MatL*\MatM-\MatB*\MatH*\MatI*\MatO+\MatB*\MatH*\MatK*\MatM+\MatC*\MatE*\MatJ*\MatP-\MatC*\MatE*\MatL*\MatN-\MatC*\MatF*\MatI*\MatP+\MatC*\MatF*\MatL*\MatM+\MatC*\MatH*\MatI*\MatN-\MatC*\MatH*\MatJ*\MatM-\MatD*\MatE*\MatJ*\MatO+\MatD*\MatE*\MatK*\MatN+\MatD*\MatF*\MatI*\MatO-\MatD*\MatF*\MatK*\MatM-\MatD*\MatG*\MatI*\MatN+\MatD*\MatG*\MatJ*\MatM}}%
	\def\MatInvA{(\MatF*\MatK*\MatP-\MatF*\MatL*\MatO-\MatG*\MatJ*\MatP+\MatG*\MatL*\MatN+\MatH*\MatJ*\MatO-\MatH*\MatK*\MatN)/\DETMATRICE}%
	\def\MatInvB{(-\MatB*\MatK*\MatP+\MatB*\MatL*\MatO+\MatC*\MatJ*\MatP-\MatC*\MatL*\MatN-\MatD*\MatJ*\MatO+\MatD*\MatK*\MatN)/\DETMATRICE}%
	\def\MatInvC{(\MatB*\MatG*\MatP-\MatB*\MatH*\MatO-\MatC*\MatF*\MatP+\MatC*\MatH*\MatN+\MatD*\MatF*\MatO-\MatD*\MatG*\MatN)/\DETMATRICE}%
	\def\MatInvD{(-\MatB*\MatG*\MatL+\MatB*\MatH*\MatK+\MatC*\MatF*\MatL-\MatC*\MatH*\MatJ-\MatD*\MatF*\MatK+\MatD*\MatG*\MatJ)/\DETMATRICE}%
	\def\MatInvE{(-\MatE*\MatK*\MatP+\MatE*\MatL*\MatO+\MatG*\MatI*\MatP-\MatG*\MatL*\MatM-\MatH*\MatI*\MatO+\MatH*\MatK*\MatM)/\DETMATRICE}%
	\def\MatInvF{(\MatA*\MatK*\MatP-\MatA*\MatL*\MatO-\MatC*\MatI*\MatP+\MatC*\MatL*\MatM+\MatD*\MatI*\MatO-\MatD*\MatK*\MatM)/\DETMATRICE}%
	\def\MatInvG{(-\MatA*\MatG*\MatP+\MatA*\MatH*\MatO+\MatC*\MatE*\MatP-\MatC*\MatH*\MatM-\MatD*\MatE*\MatO+\MatD*\MatG*\MatM)/\DETMATRICE}%
	\def\MatInvH{(\MatA*\MatG*\MatL-\MatA*\MatH*\MatK-\MatC*\MatE*\MatL+\MatC*\MatH*\MatI+\MatD*\MatE*\MatK-\MatD*\MatG*\MatI)/\DETMATRICE}%
	\def\MatInvI{(\MatE*\MatJ*\MatP-\MatE*\MatL*\MatN-\MatF*\MatI*\MatP+\MatF*\MatL*\MatM+\MatH*\MatI*\MatN-\MatH*\MatJ*\MatM)/\DETMATRICE}%
	\def\MatInvJ{(-\MatA*\MatJ*\MatP+\MatA*\MatL*\MatN+\MatB*\MatI*\MatP-\MatB*\MatL*\MatM-\MatD*\MatI*\MatN+\MatD*\MatJ*\MatM)/\DETMATRICE}%
	\def\MatInvK{(\MatA*\MatF*\MatP-\MatA*\MatH*\MatN-\MatB*\MatE*\MatP+\MatB*\MatH*\MatM+\MatD*\MatE*\MatN-\MatD*\MatF*\MatM)/\DETMATRICE}%
	\def\MatInvL{(-\MatA*\MatF*\MatL+\MatA*\MatH*\MatJ+\MatB*\MatE*\MatL-\MatB*\MatH*\MatI-\MatD*\MatE*\MatJ+\MatD*\MatF*\MatI)/\DETMATRICE}%
	\def\MatInvM{(-\MatE*\MatJ*\MatO+\MatE*\MatK*\MatN+\MatF*\MatI*\MatO-\MatF*\MatK*\MatM-\MatG*\MatI*\MatN+\MatG*\MatJ*\MatM)/\DETMATRICE}%
	\def\MatInvN{(\MatA*\MatJ*\MatO-\MatA*\MatK*\MatN-\MatB*\MatI*\MatO+\MatB*\MatK*\MatM+\MatC*\MatI*\MatN-\MatC*\MatJ*\MatM)/\DETMATRICE}%
	\def\MatInvO{(-\MatA*\MatF*\MatO+\MatA*\MatG*\MatN+\MatB*\MatE*\MatO-\MatB*\MatG*\MatM-\MatC*\MatE*\MatN+\MatC*\MatF*\MatM)/\DETMATRICE}%
	\def\MatInvP{(\MatA*\MatF*\MatK-\MatA*\MatG*\MatJ-\MatB*\MatE*\MatK+\MatB*\MatG*\MatI+\MatC*\MatE*\MatJ-\MatC*\MatF*\MatI)/\DETMATRICE}%
	%COEFFS TEMPORAIRES OK
	\xdef\tmp@reg@cub@a{\xintfloateval{\MatInvA*\MatBA+\MatInvB*\MatBB+\MatInvC*\MatBC+\MatInvD*\MatBD}}%
	\xdef\tmp@reg@cub@b{\xintfloateval{\MatInvE*\MatBA+\MatInvF*\MatBB+\MatInvG*\MatBC+\MatInvH*\MatBD}}%
	\xdef\tmp@reg@cub@c{\xintfloateval{\MatInvI*\MatBA+\MatInvJ*\MatBB+\MatInvK*\MatBC+\MatInvL*\MatBD}}%
	\xdef\tmp@reg@cub@d{\xintfloateval{\MatInvM*\MatBA+\MatInvN*\MatBB+\MatInvO*\MatBC+\MatInvP*\MatBD}}%
	%CALCUL R²
	\xdef\SStot{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\SStot{\xintfloateval{\SStot+(\LY[##1]-\LYmoy)^2}}%
	}%
	\xdef\SSres{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\Ypred{\xintfloateval{(\tmp@reg@cub@a)*(\LX[##1])^3+(\tmp@reg@cub@b)*(\LX[##1])^2+(\tmp@reg@cub@c)*(\LX[##1])+(\tmp@reg@cub@d)}}%
		\xdef\SSres{\xintfloateval{\SSres+(\LY[##1]-\Ypred)^2}}%
	}%
	\xdef\tmp@reg@cub@rr{\xintfloateval{1-(\SSres)/(\SStot)}}%
	%STOCKAGE
	\IfStrEq{\RegCubicRound}{}%
		{%
			\expandafter\def\csname\RegCubicCoefa\endcsname{\tmp@reg@cub@a}%
			\expandafter\def\csname\RegCubicCoefb\endcsname{\tmp@reg@cub@b}%
			\expandafter\def\csname\RegCubicCoefc\endcsname{\tmp@reg@cub@c}%
			\expandafter\def\csname\RegCubicCoefd\endcsname{\tmp@reg@cub@d}%
			\expandafter\def\csname\RegCubicCoefrr\endcsname{\tmp@reg@cub@rr}%
		}%
		{%
			\IfSubStr{\RegCubicRound}{/}%
				{%
					\StrBefore[1]{\RegCubicRound}{/}[\xintarrondisregcuba]%
					\StrBetween[1,2]{\RegCubicRound}{/}{/}[\xintarrondisregcubb]%
					\StrBetween[2,3]{\RegCubicRound}{/}{/}[\xintarrondisregcubc]%
					\StrBehind[3]{\RegCubicRound}{/}[\xintarrondisregcubd]%
				}%
				{%
					\xdef\xintarrondisregcuba{\RegCubicRound}%
					\xdef\xintarrondisregcubb{\RegCubicRound}%
					\xdef\xintarrondisregcubc{\RegCubicRound}%
					\xdef\xintarrondisregcubd{\RegCubicRound}%
				}%
			\expandafter\def\csname\RegCubicCoefa\endcsname{\xintfloateval{round(\tmp@reg@cub@a,\xintarrondisregcuba)}}%
			\expandafter\def\csname\RegCubicCoefb\endcsname{\xintfloateval{round(\tmp@reg@cub@b,\xintarrondisregcubb)}}%
			\expandafter\def\csname\RegCubicCoefc\endcsname{\xintfloateval{round(\tmp@reg@cub@c,\xintarrondisregcubc)}}%
			\expandafter\def\csname\RegCubicCoefd\endcsname{\xintfloateval{round(\tmp@reg@cub@d,\xintarrondisregcubd)}}%
			\expandafter\def\csname\RegCubicCoefrr\endcsname{\tmp@reg@cub@rr}%
		}%
}
\NewCommandCopy\xintCUBreg\xintcubreg

%régression logistique y = L/(1 + a*e^(-bx))
\defKV[CoeffRegLogist]{%
	coeffa=\def\RegLogistCoefa{#1},%
	coeffb=\def\RegLogistCoefb{#1},%
	coeffL=\def\RegLogistCoefL{#1},%
	coeffrr=\def\RegLogistCoefrr{#1},%
	asymptote=\def\RegLogistAsymptote{#1},%
	round=\def\RegLogistRound{#1}
}

\setKVdefault[CoeffRegLogist]{%
	coeffa=logista,%
	coeffb=logistb,%
	coeffL=logistL,%
	coeffrr=logistrr,%
	asymptote=10,%
	round={}
}

\newcommand\xintlogistreg[3][]{%
	\useKVdefault[CoeffRegLogist]%
	\setKV[CoeffRegLogist]{#1}% on paramètres les nouvelles clés et on les simplifie
	%listes des données
	\def\xliste{#2}%
	\def\yliste{#3}%
	\setsepchar{,}%
	\readlist*\LX{\xliste}%
	\readlist*\LY{\yliste}%
	%taille des listes
	\xdef\LNB{\fpeval{min(\LXlen,\LYlen)}}%
	%asymptote
	\xdef\LASYMPTOTE{\RegLogistAsymptote}%
	%somme importantes pour régression linéaire sur données transformées
	\xdef\LYSomme{0}%
	\xdef\LXSomme{0}%
	\xdef\LZSomme{0}%
	\xdef\LXZSomme{0}%
	\xdef\LXcSomme{0}%
	%calculs - transformation z = ln(L/y - 1)
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\LYSomme{\xintfloateval{\LYSomme+(\LY[##1])}}%
		\xdef\LXSomme{\xintfloateval{\LXSomme+(\LX[##1])}}%
		\xdef\LZSomme{\xintfloateval{\LZSomme+log(\LASYMPTOTE/\LY[##1]-1)}}%
		\xdef\LXZSomme{\xintfloateval{\LXZSomme+(\LX[##1])*log(\LASYMPTOTE/(\LY[##1])-1)}}%
		\xdef\LXcSomme{\xintfloateval{\LXcSomme+(\LX[##1])^2}}%
	}%
	%calcul moyenne y (pour R²)
	\xdef\LYmoy{\xintfloateval{\LYSomme/\LNB}}%
	%régression linéaire z = ln(a) - bx
	% z = c - bx où c = ln(a)
	\xdef\tmp@reg@logist@minusb{\xintfloateval{(\LNB*\LXZSomme-\LXSomme*\LZSomme)/(\LNB*\LXcSomme-(\LXSomme)^2)}}%
	\xdef\tmp@reg@logist@lna{\xintfloateval{1/\LNB*\LZSomme-(\tmp@reg@logist@minusb)/\LNB*\LXSomme}}%
	%COEFFS TEMPORAIRES
	\xdef\tmp@reg@logist@b{\xintfloateval{-(\tmp@reg@logist@minusb)}}%
	\xdef\tmp@reg@logist@a{\xintfloateval{exp(\tmp@reg@logist@lna)}}%
	\xdef\tmp@reg@logist@L{\LASYMPTOTE}%
	%CALCUL R²
	\xdef\SStot{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\SStot{\xintfloateval{\SStot+(\LY[##1]-\LYmoy)^2}}%
	}%
	\xdef\SSres{0}%
	\xintFor* ##1 in {\xintSeq{1}{\LNB}}\do{%
		\xdef\Ypred{\xintfloateval{(\tmp@reg@logist@L)/(1+(\tmp@reg@logist@a)*exp(-(\tmp@reg@logist@b)*(\LX[##1])))}}%
		\xdef\SSres{\xintfloateval{\SSres+(\LY[##1]-\Ypred)^2}}%
	}%
	\xdef\tmp@reg@logist@rr{\xintfloateval{1-(\SSres)/(\SStot)}}%
	%STOCKAGE
	\IfStrEq{\RegLogistRound}{}%
		{%
			\expandafter\def\csname\RegLogistCoefa\endcsname{\tmp@reg@logist@a}%
			\expandafter\def\csname\RegLogistCoefb\endcsname{\tmp@reg@logist@b}%
			\expandafter\def\csname\RegLogistCoefL\endcsname{\tmp@reg@logist@L}%
			\expandafter\def\csname\RegLogistCoefrr\endcsname{\tmp@reg@logist@rr}%
		}%
		{%
			\IfSubStr{\RegLogistRound}{/}%
				{%
					\StrCut{\RegLogistRound}{/}{\xintarrondisreglogista}{\xintarrondisreglogistb}%
				}%
				{%
					\xdef\xintarrondisreglogista{\RegLogistRound}\xdef\xintarrondisreglogistb{\RegLogistRound}%
				}%
			\expandafter\def\csname\RegLogistCoefa\endcsname{\xintfloateval{round(\tmp@reg@logist@a,\xintarrondisreglogista)}}%
			\expandafter\def\csname\RegLogistCoefb\endcsname{\xintfloateval{round(\tmp@reg@logist@b,\xintarrondisreglogistb)}}%
			\expandafter\def\csname\RegLogistCoefL\endcsname{\tmp@reg@logist@L}%
			\expandafter\def\csname\RegLogistCoefrr\endcsname{\tmp@reg@logist@rr}%
		}%
}
\NewCommandCopy\xintLOGISTreg\xintlogistreg

\endinput