Quantcast
Channel: Active questions tagged lm - Stack Overflow
Viewing all articles
Browse latest Browse all 124

R issue: lm() is printing NAs for rows once ncol > nrow [migrated]

$
0
0

I'm running an lm() on lagged variables as part of a network analysis, and have the following dimensions:

dim(final)[1] 197 277dim(final_lag)[1] 197 831

The final dataset contains the non-lagged variables (with each row being a date and each column being a company). The final_lag dataset contains the 3 lags of each company (hence 197 days of 277 companies x 3 lags). I'm trying to run the following:

weights <-matrix(ncol = ncol(final), nrow=ncol(final_lag))  for(i in 1:ncol(final)){    #Beta estimation from OLS     weights[,i] <- coef(lm(final[,i] ~ scale(final_lag)))[-1]    print(i)  } 

However, in my weights results matrix which is 831 x 277, I only have coefficients for rows 1-196 while 197-831 are all NAs. If I change the number of rows in final, then I get numeric coefficients again until nrow(final) is hit. Anyone know how to fix this issue/why this is occurring? Thanks.


Viewing all articles
Browse latest Browse all 124

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>