How to fit a power law equation using three variables?
    9 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    Jonathan Macuroy
 el 6 de Feb. de 2020
  
    
    
    
    
    Comentada: Rik
      
      
 el 6 de Feb. de 2020
            Say I have three datasets namely X, Y, and Z. As per literature, I have to find the relationship between the three variables as given by the equation: 
 (i.e. i have to find a, b, and c).
May I ask if you know how to do this? Thanks a lot in advance.
2 comentarios
Respuesta aceptada
  John D'Errico
      
      
 el 6 de Feb. de 2020
        
      Editada: John D'Errico
      
      
 el 6 de Feb. de 2020
  
      The answer is simple, sort of. But it very much depends on your data. For example, if Z varies by multiple orders of magitude over the data, then it is likely that the small values of Z will be fit poorly in a relative sense.
Is this the case? I can only conjecture here, since I was given nothing. But when you have power law type models like that, it is VERY common to have data that does vary by multiple orders of magnitude, and as well, a heteroscedastic error structure, of some sort.
As such, a good choice is to log the model. That allows us to introduce the idea of a proportional error structure, which is often highly appropriate when you have data that does vary over multiple orders of magnitude. The idea is if your small numbers tend to have roughly the same proportional noise in them as the large values, then you needed to treat the model properly, by logging the data. Does that help any? Yes, in fact, it does. Because now your model looks like:
   log(Z) = log(a) + b*log(X) + c*log(Y)
This is now a purely linear model. As well, if the noise was proportional noise in the original case, then it is now additive noise. Essentially, the log transform changes a lognormal error structure to a tradtional Gaussian one.
I cannot see your data, of course since you show nothing. However, the simple way to perform the above fit is as easy as...
n = numel(Z);
coef = [ones(n,1),log(X(:)),log(Y(:))] \ log(Z(:));
abc = [exp(coef(1));coef(2:3)];
Here, abc is now a vector of the coefficients as [a;b;c].
Could I have used the curve fitting toolbox? Of course. It depends on your data, and if you need to log the data or not.
2 comentarios
  Rik
      
      
 el 6 de Feb. de 2020
				Here is an example using the curve fitting toolbox, although reading John's answer I would have liked to come up with something similar.
%generate some data
[X,Y]=meshgrid(linspace(0,10,100));
a=5+rand;b=2+0.1*rand;c=3+0.2*rand;
Z=a.*X.^b.*Y.^c;
fitFun=@(a,b,c,x,y) a.*x.^b.*y.^c;
f=fit([X(:) Y(:)],Z(:),fitFun,...
    'StartPoint',[4 1 1]);
clc
fprintf('true a=%.2f, fitted a=%.2f\n',a,f.a)
fprintf('true b=%.2f, fitted b=%.2f\n',b,f.b)
fprintf('true c=%.2f, fitted c=%.2f\n',c,f.c)
Más respuestas (0)
Ver también
Categorías
				Más información sobre Linear and Nonlinear Regression en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!