How to calculate r-squared in exponential fitting?
조회 수: 5 (최근 30일)
이전 댓글 표시
Hello. So I'm trying to find the r-squared in an exponencial fitting. Having x and y, I did first: Y = log(y); X = x; s_X = sum(X); s_Y = sum(Y); s_X_2 = sum(X.^2); s_XY = sum(X.*Y); N = length(X); B = (s_XY - (s_X_2 * (s_Y/s_X)))/(s_X-(s_X_2*N/s_X)); A = (s_Y - N*B)/s_X; C = exp(B);
My model is then y = C*exp(A*x). I checked in Excel and A and C are the same.
Then I did yfit = C*exp(A*X), and finally R2 = 1- (norm(yfit - Y)/norm(Y- mean(Y)))^2
However, it outputs me a negative value, of course not the same as excel
Could you help me?
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!