Nini
Nini

Reputation: 23

How to linearize this data for a specific relationship in MATLAB?

I have data that y and x don't have a linear trend. The data as follows and if you plot y as a function of x, the plot is nonlinear.

x= [45.5976, 45.6311, 45.6599, 45.679, 45.703, 45.7461, 45.7749]
y = [0.17, 1.7, 5.1, 17, 51, 170, 510]
plot(x,y,'o')

My goal is to find an optimum value of b to make log(y) behavior with respect to log((x-b)/b) a linear relation. In other words, plot(log((x-b)/b),log(y) should produce a linear function.

Upvotes: 0

Views: 211

Answers (1)

lincolnck
lincolnck

Reputation: 312

Since I don't have enough reputation to add a comment to clarify the question, I'm trying to help in an answer. Also, typically when transforming data to fit a linear regression, if your original model is: y = b0 + b1x, then taking logs of both the predictor and response gives a new model y* = b0 + b1x* where y* = ln(y) and x* = ln(x). Why did you decide your model should be of the form: ln(y) = ln((x-b)/b)?

In any case, to find the optimal beta values for such a model in Matlab you would do something like the following:

x= [45.5976, 45.6311, 45.6599, 45.679, 45.703, 45.7461, 45.7749]';
y = [0.17, 1.7, 5.1, 17, 51, 170, 510]';
figure(1), plot(x,y,'o');

ln_y = log(y);
ln_x = log(x);
figure(2), plot(ln_x, ln_y, 'x');

ln_X = [ones(length(ln_x),1) ln_x];
B = ln_X\ln_y;

ln_y_fitted = ln_X*B;
figure(2), 
hold on
plot(ln_x, ln_y_fitted, '--', 'Color', 'r');

Given the above code, if you want to plot the various results for log(y) = log((x-b)/b), you can use something like this:

for b = 0.1:0.1:4
    ln_x = log((x-b)/b);
    figure, plot(ln_x, ln_y, 'x');
end

Upvotes: 2

Related Questions