How to use splitapply with fitlm

조회 수: 3 (최근 30일)
Luca
Luca 2021년 4월 14일
댓글: Luca 2021년 4월 15일
Hi,
I want to run a regression for 2 diffrent stocks for each year of observation separately. So i get a new Betas for each stock and each year. The goal is to assign the residuals to ID and dates. I upload the set I'm using. The regression looks like this:
RET = Beta0 + Beta1 * MRET
RET is the returns of the stocks and MRET the return of the Market.
My idea was to you use the splitapply function. But my code isn't working. I guess the problem is in line 3.
[group6, years, ID]= findgroups(subset1.years, subset1.ID);
[group7, dates]= findgroups(subset1.years, subset1.ID);
regression = @(y) fitlm(subset1.MRET,subset1.RET);
lm2 = splitapply(regression, subset1.MRET,group6);
Resitbl = table (ID,dates, lm2.Residuals.Raw);
regress function would also work for me. But it also didn't work for me.
Thanks in advance

채택된 답변

Matt J
Matt J 2021년 4월 14일
Your regression(y) function takes an argument y that is never used.
  댓글 수: 5
Matt J
Matt J 2021년 4월 14일
편집: Matt J 2021년 4월 14일
In the photo you've shown, lm2 is a cell array, not a table.
Luca
Luca 2021년 4월 15일
Right, sorry I did not pay attention.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear Regression에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by