Who can help me fit the data using the matlab, thank you.
2 views (last 30 days)
Show older comments
Who can help me fit the data using the matlab, thank you.The fitting equation should be below:
y=b1*x1^b2 *x2^b3*x3^b4*x4^b5*x5^b6*x6^b7
2 Comments
dpb
on 5 Aug 2020
Not likely...just out of curiosity, which column is supposed to be the response variable?
>> size(data,1)
ans =
2077
>> arrayfun(@(i) numel(unique(data(:,i))),[1:size(data,2)])
ans =
1 1 5 5 1 2075 2070
>>
You didn't write enough significant digits into the data file to make observations unique. Columns 1,2 and 5 are completely degenerate with only one value, columns 3 and 4 almost so with 5 different values out of 2077 observations.
Answers (1)
Ayush Gupta
on 4 Sep 2020
Please refer to the following code on how to go about it and get the individual coefficients b1, b2, etc.
[D,S,R] = xlsread('data.xlsx');
x1 = D(:,1);
x2 = D(:,2);
x3 = D(:,3);
x4 = D(:,4);
x5 = D(:,5);
x6 = D(:,6);
z = D(:,7);
x = [x1(:) x2(:) x3(:) x4(:) x5(:) x6(:)];
coeff = [ones(numel(z),1),log(x)]\log(z);
coeff (1) = exp(Coeff (1));
4 Comments
dpb
on 7 Sep 2020
x = [x1(:) x2(:) x3(:) x4(:) x5(:) x6(:)];
is just
X=D(:,1:6);
written out for some reason -- no need to have done; more efficient to not make unecessary copies of data and multiple variables of same name with successive numbers is generally sign of inefficient MATLAB usage. Similar argument for z.
coeff = [ones(numel(z),1),log(x)]\log(z);
could have been
coeff = [ones(size(D(:,1)),log(D(:,1:6))]\log(D(:,7));
For
coeff (1) = exp(Coeff (1));
just a change in variable should make clear
b = exp(coeff);
What has done is just fitted
ln(y)=b1 + b2*ln(x1) + b3*ln(x2) + b4*ln(x3) + b5*ln(x4) + ... + b7*ln(x6)
that is OLS in log x, y. This doesn't necessarily reflect the model if were to try to fit the underlying data owing to the extreme scaling of ln() so statistic are generally dubious but the prediction/fit may be reasonable. Of course, you'll have to have real data and not just the same numbers that are in the present file and iirc, there are some real disparities in sizes between variables -- standardizing first would likely be a good idea.
Walter Roberson
on 7 Sep 2020
x = [x1(:) x2(:) x3(:) x4(:) x5(:) x6(:)];
Creates columns in an array, x. The first column is taken from x1, the second column is taken from x2, and so on.
coeff = [ones(numel(z),1),log(x)]\log(z);
The first part, ones(numel(z),1), creates a column of ones that is as long as z is (which in turn should be the same as the length of each of the x* variables.) So the left side of the \ creates an array in which the first column is all ones and the remaining columns are the logs of the x* variables.
The right side, log(z) is what it looks like, the log of the z variables.
The \ between the two asks for least squared fitting.
When you ask for least-squared fitting, then a column of ones corresponds to the constant term . The expression is finding the best values, coeff, such that
coeffs(1) + coeffs(2)*log(x1) + coeffs(3) + log(x2) + coeffs(4) * log(x3) + coeffs(5) * log(x4) + coeffs(6) * log(x5) + coeffs(7) * log(x6) fits log(z)
If you were to take exp() of this, it would be like
exp(coeffs(1)) * x1^coeffs(2) * x2^coeffs(3) * x3^coeffs(4) * x4^coeffs(5) * x5^coeffs(6) * x6^coeffs(7) fits z
and then
coeff (1) = exp(Coeff (1));
is converting the coeffs(1) that you got from the fitting to the exp(coeffs(1)) that you can see in the latter expression.
See Also
Categories
Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!