How to run a regression of lognrnd?

1 view (last 30 days)
I have a vector with random data log-norm distributed and I need to run a regression of this.
  5 Comments
Fernanda Suarez Jaimes
Fernanda Suarez Jaimes on 12 Mar 2020
Yes, correct. The thing is that I transformed the time_series1 into a new "weekly" time series with 6,000 elements as well. So I can fit the two distributions together. Like this
%Converting the 'daily' ts to a to a 'weekly' one
arrayts1 = padarray (time_series1, [ceil(numel (time_series1) / 7) * 7 - numel(time_series1) 0], 0, 'post' );
time_series3 = mean (reshape (arrayts1, 7, []), 1);
Then in the Y axis are the random valued and in the X axis are the time values.
I need to get a regression of X over Y.
This is what I have so far:
scatter(time_series2,time_series3,'.') % plot the data points
hAx=gca; hAx.XScale='log'; % on semilog x axis
b=polyfit(log(time_series2),Y,1); % fit response to log(independent) Y is the meanleast square value given by the fit for the above specific dataset
yHat=polyval(b,log([min(time_series2) max(time_series2)])) % remember, it's log in X
hold on
plot([min(time_series2) max(time_series2)],yHat,'r-')
Fernanda Suarez Jaimes
Fernanda Suarez Jaimes on 12 Mar 2020
This is another option I have. The issue is that we need to do a regression of a time series. Therefore, the result of the model is not significant as it is near 0,05.
logarithms_ts2=log(time_series2); %calculating logarithm of the values in order to use GLM fuction
[regression2,dev,stats] = glmfit(xtime2,logarithms_ts2,'normal');
regression2=fitglm(xtime2,time_series2) %regression of time series 2

Sign in to comment.

Answers (1)

Steven Lord
Steven Lord on 12 Mar 2020
It sounds like you want the lognfit function.
  1 Comment
Fernanda Suarez Jaimes
Fernanda Suarez Jaimes on 12 Mar 2020
You mean something as this?
rng ( 'default' ); % So that numbers can be repeated
time_series2 = lognrnd (0,0.25,6000,1); % generating time series with mu set to zero and sigma 0.25
[pHat,pCI] = lognfit(time_series2,0.01)
The result I get is this:
pHat =
0.0017 0.2494
pCI =
-0.0066 0.2437
0.0100 0.2554

Sign in to comment.

Categories

Find more on Descriptive Statistics 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!