How to run a regression of lognrnd?

조회 수: 1 (최근 30일)
Fernanda Suarez Jaimes
Fernanda Suarez Jaimes 2020년 3월 12일
댓글: Fernanda Suarez Jaimes 2020년 3월 12일
I have a vector with random data log-norm distributed and I need to run a regression of this.
  댓글 수: 5
Fernanda Suarez Jaimes
Fernanda Suarez Jaimes 2020년 3월 12일
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 2020년 3월 12일
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

댓글을 달려면 로그인하십시오.

답변 (1개)

Steven Lord
Steven Lord 2020년 3월 12일
It sounds like you want the lognfit function.
  댓글 수: 1
Fernanda Suarez Jaimes
Fernanda Suarez Jaimes 2020년 3월 12일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by