I estimated linear regression by using maximum likelihood in R. V7 is the dependent variable. The other variables are the independent variables. First, I did simple regression, put the data into matrices for the MLE procedure, and estimated the model. I used the following code and I got the following error. What should I do to fix it?
Asked
Active
Viewed 168 times
0
-
can you please add a reproducible example? https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Otto Kässi Apr 17 '20 at 14:30
-
I am not sure why you are using `lmtest`, but you need to install it before importing (`install.packages("lmtest")`). – Otto Kässi Apr 17 '20 at 14:32
-
Try to tell R that V7, V8, etc are columns in a dataframe. Instead of `as.matrix(V8)`, type `as.matrix(data$V8)`. – Otto Kässi Apr 17 '20 at 14:34
-
Thank you for your comments. They are very helpful. – user13908 Apr 17 '20 at 15:08
-
Thanks to you, I could fix the error. After fixing the error, I proceed and estimated the model. I've attached the screenshot of the code. Can you review the code and let me know what I should do to fix it? – user13908 Apr 17 '20 at 15:34
-
Please provide a *reproducible example*. This includes: some data and minimal code that we can edit. We do not know the contents of data4.txt nor llik.regress. Usually, when preparing an answer, one wants to copy-paste your code. This cannot be done from a screenshot. – Otto Kässi Apr 21 '20 at 12:03
-
Your current problem stems from `ncol(x)`. You do not have an object named `x` loaded (this is why `nrow(x) = NULL`). I suspect that `K` should be `7` as you have 6 regressors and a constant term in your regression but I cannot be sure. – Otto Kässi Apr 21 '20 at 12:05