How do I perform regression on this equation and calculate correlation

59 Views Asked by At

I have a Function f(R) which models Temperature(°C) as a function of Resistance(Ω)

$$ f(R)= \frac{1}{A +B\cdot\ln{R}+C\cdot\ln^3{R}} -273.15 $$ And I have a data

Temp: {0.7,2.,5.3,8.06,9.95,14.82,20.4,29.6,41.,49.1,53.9,60.,65.,70.,74.4,78.3} Resistance: {22976.98,21263.83,17935,15690.9,14003.87,11851.83,9262.09,6926.95,4575.89,3430.07,2987.74,2436.42,2070.49,1806.5,1489.12,1349.3}

Which has a scatter plot that looks like this: Scatter
(source: sanjit.wtf)

How would I perform regression for such a function, and how would I calculate the r^2 correlation coefficient for the function?

1

There are 1 best solutions below

1
On BEST ANSWER

The model $$f(R)= \frac{1}{A +B\cdot\ln(R)+C\cdot\ln^3(R)} -273.15$$ is nonlinear; this means thzt you will need by the end to run a nonlinear regression and this requires reasonable estimates.

You can get those in a preliminary step by lineraization. Rewrite $$\frac 1{f(R)+273.15}=A +B\cdot\ln(R)+C\cdot\ln^3(R)$$ and define $$z_i=\frac 1{f(R_i)+273.15}\qquad x_i=\ln(R_i)\qquad y_i=\ln^3(R_i)$$ which makes the temporary model $$z=A+B x+C y$$ which is a simple linear regresion from which you will get the estimates of $(A,B,C)$.

Now, you have all elements to start the nonlinear regression. You must do it because what has been measured is $f(R)$ and not any of its possible transforms.

Concerning the $R^2$, it is well defined for linear regression (for example, for your problem $R^2=0.999994$ for the preliminary step). It is much delicate for nonlinear regression even if many software produce ... a number.

Edit

Keeping the notations I used in the first part, the nonlinear regression of the model $$z=\frac 1 {A + B x + C y}$$ will correspond to the minimization of $$SSQ=\frac 12\sum_{i=1}^n r_i^2 \qquad \text{where} \qquad r_i=\frac 1 {A + B x_i + C y_i}-z_i$$ This minimum will be obtained solving three equations for the three parameters, namely $$\frac{\partial SSQ}{\partial A}=\sum_{i=1}^n r_i \frac{\partial r_i}{\partial A}=0\qquad \text{where} \qquad \frac{\partial r_i}{\partial A}=-\frac{1}{(A+B x_i+C y_i)^2}$$ $$\frac{\partial SSQ}{\partial B}=\sum_{i=1}^n r_i \frac{\partial r_i}{\partial B}=0\qquad \text{where} \qquad \frac{\partial r_i}{\partial B}=-\frac{x_i}{(A+B x_i+C y_i)^2}$$ $$\frac{\partial SSQ}{\partial C}=\sum_{i=1}^n r_i \frac{\partial r_i}{\partial C}=0\qquad \text{where} \qquad \frac{\partial r_i}{\partial C}=-\frac{y_i}{(A+B x_i+C y_i)^2}$$

Since the first step gave good estimates of $(A,B,C)$, solve these three equations using Newton-Raphson method. To avoid the problem of writing the cross derivatives, just evaluate them using finite differences.