Interpreting error message in regression in R

Stefan

I was experimenting a bit with regression through the origin.

lm(Petal.Width ~ Petal.Length -1, iris)

Then I tried to simply subtract the individual values from both Petal.Width and Petal.Length from their respective means so that their means are zero.

lm(Petal.Width-mean(Petal.Width) ~ Petal.Length-mean(Petal.Length) -1, iris)

That gives me the following error message:

Error in model.frame.default(formula = Petal.Width - mean(Petal.Width) ~  : 
                           variable lengths differ (found for 'mean(Petal.Length)')

Now I know that I have to use the I() function to make the code work.

    lm(I(Petal.Width-mean(Petal.Width)) ~ I(Petal.Length-mean(Petal.Length)) -1, iris)

Question: But why does the error message say "variable lengths differ"? This by itself didn't really help me to figure out what was going on since the variable lengths are the same.

MrFlick

Since + and - don't have their usual meaning in formulas, Petal.Length and mean(Petal.Length) are interpreted as two separate variables. Here , Petal.Length has length 150 but mean(Petal.Length) has length 1 (the mean collapses it down to a single value). Therefore you get the message about the different variable lengths.

If you really want to dig into it, the error actually comes from model.frame(), specifically

model.frame.default(Petal.Width-mean(Petal.Width) ~ Petal.Length-mean(Petal.Length), iris[-1])

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Interpreting ridge regression in GridSearchCV

From Dev

Error in regression in r

From Dev

interpreting message in "virustotal"

From Dev

Confidence interval for regression error, R,

From Dev

Interpreting Golang Error codes

From Dev

Interpreting logistic regression feature coefficient values in sklearn

From Dev

interpreting R code function

From Dev

Suppress error message in R

From Dev

Suppress error message in R

From Dev

R: multivariate Bayesian regression with MCMCregress throws an error

From Dev

How to get rid of error with multiple regression in R?

From Dev

bestglm R package error using Poisson regression

From Dev

Error while doing Linear Regression in R

From Dev

interpreting a laconic ruby 'nil' error

From Dev

Interpreting dd Input/Output error

From Dev

Correcting an error in interpreting CSV data

From Dev

Interpreting the results of R Mclust package

From Dev

Does the sorting order matter when interpreting beta estimates in a regression model?

From Dev

R Metrics auc() error message

From Dev

Function sweep() in R error message

From Dev

If Else Statement in R Error Message

From Dev

R starts up with error message

From Dev

R function length error message

From Dev

Why is the standard error different in these two fitting methods (R Logistic Regression and Beta Regression) for a common dataset?

From Dev

R caret train Error in evalSummaryFunction: cannnot compute class probabilities for regression

From Dev

Linear Regression in R: "Error in eval(expr, envir, enclos) : object not found"

From Dev

R segmented regression predict gives error: "subscript out of bounds"

From Dev

robust and clustered standard error in R for probit and logit regression

From Dev

R caret train Error in evalSummaryFunction: cannnot compute class probabilities for regression

Related Related

  1. 1

    Interpreting ridge regression in GridSearchCV

  2. 2

    Error in regression in r

  3. 3

    interpreting message in "virustotal"

  4. 4

    Confidence interval for regression error, R,

  5. 5

    Interpreting Golang Error codes

  6. 6

    Interpreting logistic regression feature coefficient values in sklearn

  7. 7

    interpreting R code function

  8. 8

    Suppress error message in R

  9. 9

    Suppress error message in R

  10. 10

    R: multivariate Bayesian regression with MCMCregress throws an error

  11. 11

    How to get rid of error with multiple regression in R?

  12. 12

    bestglm R package error using Poisson regression

  13. 13

    Error while doing Linear Regression in R

  14. 14

    interpreting a laconic ruby 'nil' error

  15. 15

    Interpreting dd Input/Output error

  16. 16

    Correcting an error in interpreting CSV data

  17. 17

    Interpreting the results of R Mclust package

  18. 18

    Does the sorting order matter when interpreting beta estimates in a regression model?

  19. 19

    R Metrics auc() error message

  20. 20

    Function sweep() in R error message

  21. 21

    If Else Statement in R Error Message

  22. 22

    R starts up with error message

  23. 23

    R function length error message

  24. 24

    Why is the standard error different in these two fitting methods (R Logistic Regression and Beta Regression) for a common dataset?

  25. 25

    R caret train Error in evalSummaryFunction: cannnot compute class probabilities for regression

  26. 26

    Linear Regression in R: "Error in eval(expr, envir, enclos) : object not found"

  27. 27

    R segmented regression predict gives error: "subscript out of bounds"

  28. 28

    robust and clustered standard error in R for probit and logit regression

  29. 29

    R caret train Error in evalSummaryFunction: cannnot compute class probabilities for regression

HotTag

Archive