Como calcular e mostrar um novo valor da regressão linear

Como calcular e mostrar um novo valor da regressão linear

O MWE a seguir mostra um modelo que uso na universidade para mostrar dados de calibração e a regressão linear correspondente. Agora eu estava perguntando se posso calcular um valor $X$ para um determinado valor $Y$ e mostrá-lo dentro do gráfico semelhante à imagem a seguir.

mostrar valores calculados dentro do gráfico

Até agora eu tenho que calcular os valores manualmente e dar a eles os amados pgfplots.

Espero que a questão seja suficientemente clara e que haja uma solução semiautomática.

PS: Eu uso LuaLaTeX para compilar. Para melhor usabilidade comentei a fonte que utilizo.

\documentclass{standalone}

\usepackage{luaotfload}
\usepackage[no-math]{fontspec}
%\defaultfontfeatures{Ligatures=TeX} %,Scale=MatchLowercase} still buggy
%\setmainfont{Linux Biolinum O}
%\setsansfont{Linux Biolinum O}
%\setmonofont{Linux Libertine Mono O}

\usepackage{polyglossia}
\setmainlanguage{german}
\usepackage[autostyle=true]{csquotes}

\usepackage[
    tbtags,
    sumlimits,
    intlimits,
    namelimits
    ]{amsmath}
\usepackage{amsfonts}
\usepackage{amsthm}
\usepackage{amscd}
\setcounter{MaxMatrixCols}{12}
\usepackage[german]{translator}
\usepackage[detect-all=true]{siunitx}
\sisetup{
%   strict,
    output-decimal-marker={,},
    exponent-product=\cdot,
    text-micro={\fontfamily{mdbch}\textmu},
    math-micro=\muup
}
\DeclareSIUnit\molar{M}
\usepackage[math-style=ISO,bold-style=ISO]{unicode-math}
\setmathfont{Asana Math}
\usepackage{lualatex-math}

\usepackage{tikz}
\usepackage{pgfplots,pgfplotstable}

\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    title={Kalibration für den Versuch XYZ},
    /pgf/number format/use comma,
    width=\linewidth,
    grid=major,
    grid style={dashed,gray!30},
    x label style={at={(axis description cs:.5,-.025)},anchor=north},
    y label style={at={(axis description cs:.05,.5)},anchor=south},
    xlabel=Konzentration~{[}\si{\milli\gram\per\milli\litre}{]},
    ylabel=Extinktion,
%   xtick={0,60,90,120,150,180},
    x tick label style={rotate=90,anchor=east},
    legend cell align=left,
    legend pos=north west,
    ]
    \addplot[
    only marks,
    thick,
    color=black,
    mark=*,
    mark options={fill=red},
    ] table [x=X,y=Y, row sep=\\] {
        X Y\\
        0 0\\
        25 0.17\\
        50 0.43\\
        75 0.60\\
        100 0.79\\
        125 1.01\\
        };
    \addlegendentry{Messpunkte}
    \addplot[thick,color=blue] table[row sep=\\,y={create col/linear regression={y=Y}},mark=none] {
        X Y\\
        0 0\\
        25 0.17\\
        50 0.43\\
        75 0.60\\
        100 0.79\\
        125 1.01\\
        };
    \addlegendentry{%
        $\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x
        \pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$};
    \draw[thick,color=blue] (axis cs:20,-1) -- (axis cs:20,.15609);
    \draw[thick,color=blue] (axis cs:-20,.15609) -- (axis cs:20,.155);
    \node [coordinate,pin=below right:{\scriptsize\textit{minimal effective concentration}}] at (axis cs:20,.15609) {};
    \end{axis}
    \end{tikzpicture}
\end{document}

Responder1

A maneira mais simples de desenhar essas linhas é definir todos os valores como macros e calcular o valor x com \pgfmathparse{(\myY-\pgfplotstableregressionb)/\pgfplotstableregressiona}. O resultado pode ser salvo como \pgfmathsetmacro\myX{\pgfmathresult}.

% % Y-Value % %
\def\myY{0.155}
% % % % % % % %

\def\xMin{0}
\def\yMin{0} 

Os mínimos são usados ​​para a intersecção com o eixo.

\documentclass{standalone}

\usepackage[german]{translator}
\usepackage[detect-all=true]{siunitx}
\sisetup{
%   strict,
    output-decimal-marker={,},
    exponent-product=\cdot,
    text-micro={\fontfamily{mdbch}\textmu},
    math-micro=\muup
}
\DeclareSIUnit\molar{M}


\usepackage{tikz}
\usepackage{pgfplots,pgfplotstable}

% % Y-Value % %
\def\myY{0.155}
% % % % % % % %

\def\xMin{0}
\def\yMin{0} 

\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    title={Kalibration für den Versuch XYZ},
    /pgf/number format/use comma,
    width=\linewidth,
    grid=major,
    grid style={dashed,gray!30},
    x label style={at={(axis description cs:.5,-.025)},anchor=north},
    y label style={at={(axis description cs:.05,.5)},anchor=south},
    xlabel=Konzentration~{[}\si{\milli\gram\per\milli\litre}{]},
    ylabel=Extinktion,
%   xtick={0,60,90,120,150,180},
    xmin=\xMin,
    ymin=\yMin,
    x tick label style={rotate=90,anchor=east},
    legend cell align=left,
    legend pos=north west,
    ]
    \addplot[
    only marks,
    thick,
    color=black,
    mark=*,
    mark options={fill=red},
    ] table [x=X,y=Y, row sep=\\] {
        X Y\\
        0 0\\
        25 0.17\\
        50 0.43\\
        75 0.60\\
        100 0.79\\
        125 1.01\\
        };
    \addlegendentry{Messpunkte}
    \addplot[thick,color=blue] table[row sep=\\,y={create col/linear regression={y=Y}},mark=none] {
        X Y\\
        0 0\\
        25 0.17\\
        50 0.43\\
        75 0.60\\
        100 0.79\\
        125 1.01\\
        };
    \addlegendentry{%
        $\pgfmathprintnumber{\pgfplotstableregressiona} \cdot x
        \pgfmathprintnumber[print sign]{\pgfplotstableregressionb}$};
        \pgfmathparse{(\myY-\pgfplotstableregressionb)/\pgfplotstableregressiona}     
    \pgfmathsetmacro\myX{\pgfmathresult} 
    \draw[thick,color=blue] (axis cs:\myX,\yMin) -- (axis cs:\myX,\myY);
    \draw[thick,color=blue] (axis cs:\xMin,\myY) -- (axis cs:\myX,\myY); 
    \node [coordinate,pin=below right:{\scriptsize\textit{minimal effective concentration}}] at (axis cs:\myX,\myY) {};
    \end{axis}
    \end{tikzpicture}
\end{document} 

informação relacionada