Note that there are some explanatory texts on larger screens.

plurals
  1. POmultivariate regression with missing figures in each dependent variable
    primarykey
    data
    text
    <p>The dataset I have consists of the monthly returns of 1380 hedge funds but most of the funds have missing figures. I want to regress the monthly return of each single funds to some factors like Treasury Bond Yield (TBY). I tried to use a for loop to regress the monthly return of each funds to the factors but received the following error message:</p> <pre><code>#Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : # 0 (non-NA) cases </code></pre> <p>I have done some search on the internet and believe the problem is caused by list-wise deletion. I have reproduced a simple case to illustrate:</p> <pre><code>#create a dataframe A with 8 funds and two factors A&lt;-data.frame(fund1=rnorm(5),fund2=rnorm(5),fund3=rnorm(5),fund4=rnorm(5), fund5=rnorm(5),fund6=rnorm(5),fund7=rnorm(5),fund8=rnorm(5), SP500=rnorm(5),TBY=rnorm(5)) #replace some vlaue with NA A[1,3:5]&lt;-NA A[2,1:2]&lt;-NA A[3,3]&lt;-NA A[4,2:4]&lt;-NA A[5,1]&lt;-NA A[1:5,7]&lt;-NA A # build two data frames to split funds and factors funds&lt;-as.data.frame(A[,1:8]) factors&lt;-as.data.frame(A[,9:10]) # build empty data frame to store regression outputs results&lt;-data.frame(matrix(NA,ncol=4,nrow=8)) colnames(results)&lt;-c("estimates", "residual", "t", "p") rownames(results)&lt;-as.vector(colnames(funds)) for(i in 1:8){ fit&lt;-lm(as.vector(funds[,i])~TBY,data=factors,na.action=na.omit) results[i,1]&lt;-coef(summary(fit))[1,1] results[i,2]&lt;-coef(summary(fit))[1,2] results[i,3]&lt;-coef(summary(fit))[1,3] results[i,4]&lt;-coef(summary(fit))[1,4] } results </code></pre> <p>The final result looks like:</p> <pre><code> results # estimates residual t p # fund1 0.1039720 0.2486456 0.4181535 0.7478621 # fund2 -0.1040939 0.2464246 -0.4224168 0.7455554 # fund3 0.3869647 NaN NaN NaN # fund4 0.1349445 0.2107588 0.6402796 0.6374377 # fund5 0.7470140 0.4066014 1.8372147 0.2075786 # fund6 0.8305238 0.3845686 2.1596245 0.1196180 # fund7 NA NA NA NA # fund8 NA NA NA NA </code></pre> <p>The program stops looping at fund7. I believe the main reason is that the column of fund7 contains only <code>NA</code>s so that the loop fail to continue. Can anyone give me some suggestions to keep the program going in this situation? The outcome I wish to have is the constant of each regression model. Your comments will be so much appreciated. </p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload