Error in Regression

I'm trying to do a regression

When I execute this code:

olsreg <- lm(Y ~ as.matrix(X))

I get this error message

Error in `[[<-.data.frame`(`*tmp*`, i, value = c(2L, 3L, 3L, 3L, 3L, 3L, : replacement has 1316371 rows, data has 188053

The X matrix has values from seven 7 variables. Seven is precisely 1316371 / 188053 = 7

Can you help me solving this error?

Hi,

In order for us to help you with your question, please provide us a minimal reproducible example where you provide a minimal (dummy) dataset and code that can recreate the issue. Once we have that, we can go from there. For help on creating a Reprex, see this guide:

Good luck!
PJ

1 Like

I had a bad specification of the model.

I wanted to do a linear regression, a logit regression and a probit regression with categorical factor variables with several levels.

I used the following three links to correctly specify the models:

CODING FOR CATEGORICAL VARIABLES IN REGRESSION MODELS | R LEARNING MODULES

PROBIT REGRESSION | R DATA ANALYSIS EXAMPLES

LOGIT REGRESSION | R DATA ANALYSIS EXAMPLES

Now I have results to analyse.

Thank you @pieterjanvc

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.