Finding regression values for a fixed gradient line

1 次查看(过去 30 天)
I constructed 2 simple models for wave prediction(from gradients and intercept values of a dataset) one using one variable and the other using two.
That in itself is not important however I want to compare the results of these 2 models with the real datasets the models were constructed from.
To do this I was planning on finding the regression and therefore R^2 values for the modelled datasets against a line with a gradient of 1 (i.e x=y), in a scatter graph where Y is a modelled value and X is the actual value.
However, I can't find any function where regression can be calculated from a fixed line or defined equation.
Example data:
Actual heights: 3.21076716 3.765241379 3.271988389 3.800981997 4.137206086 2.785007496 2.843378378 3.408870968 2.987673611 4.01994003
Modelled heights from one variable: 3.572947143 3.080857143 3.049232857 4.041167857 4.379332857 3.939177857 3.273523571 4.01045 3.217056429 3.477738571
Modelled heights from 2 variables: 3.361177143 3.326807857 3.407921429 3.268800714 3.161697143 2.833778571 3.136048571 3.313547857 3.146689286 3.70405
Any help would be superb!
Cheers
John

回答(2 个)

the cyclist
the cyclist 2011-2-2
What you're doing is sensible, but I suspect it is a rather non-standard way to test your models. I think you can use GLMFIT to test each model directly against the data, and see which one is better. You can use the "offset" parameter to enter your modeled fit, with no free parameters. (You must also turn off the "constant", to prevent MATLAB from adding a constant term.) You can then look at the stats output of each fit, to see which is better.
Caveat: I am pretty new to using GLMFIT, and I am not 100% this is doing what you want, but here is some simple code I constructed to help you check.
function [] = testRegressionToFixedLine()
X = (1:10)';
% Dummy variable, fixed to have no explanatory power
indVar = zeros(10,1);
% Data to be fit
Y = (1:10)' + 1.5*rand(10,1);
% Model 1 is a poor fit
model_1 = 2*X - 5;
[b_1 dev_1 stats_1] = glmfit(indVar,Y,'normal','offset',model_1,'constant','off')
% Model 2 is a good fit
model_2 = 1.1*X;
[b_2 dev_1 stats_2] = glmfit(indVar,Y,'normal','offset',model_2,'constant','off')
figure
hold
plot(X,glmval(b_1,X,'identity','offset',model_1,'constant','off'),'r.-')
plot(X,glmval(b_2,X,'identity','offset',model_2,'constant','off'),'g.-')
plot(X,Y,'bo')
end

Richard Willey
Richard Willey 2011-2-2
Here's some simple code to calculate R^2
SStot = sum((Y - mean(Y)).*(Y - mean(Y)));
resid = Y - YHat;
resid_sqrd = resid.*resid;
SSerr = sum(resid_sqrd);
R_Sqr = 1 - (SSerr/SStot)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by