Error Message trying to perform Levene Test

I keep trying to perform a levene test on data and keep getting this error:

Error: unexpected symbol in "leveneTest(cellphone$Night Mins~International Plan" data=cellphone)

Are you missing a comma? Do you have the quote marks in the right place?

Please forgive that I am a total novice to the space but I did follow the syntax I believe What is tricky is the column that I am pulling the data from. It populates with those singular quotes.... Night Mins maybe change the quotation directions? I am clueless at the moment.

The best way to get an answer is to make a Reproducible Example. But as a start, copy and paste here the line of code that gives the error.

Hello,

I tried several combinations and I cannot reproduce your problem with the sample data from car. You might be better off to copy your code from leveneTest() and encapsulate it in triple backtick followed by an r (```r) as well as another triple backticks. This way you create a code chunk in the forum editor and your code will be properly formatted.

Here is my attempt to reproduce the problem:

library(car)
#> Loading required package: carData
Data <- Moore
# change names to mimic your problem
Data$`International Plan` <- Data$fcategory
Data$`Night Mins` <- Data$conformity
# Perform Levene Test
leveneTest(Data$`Night Mins` ~ Data$`International Plan`, data = Data)
#> Levene's Test for Homogeneity of Variance (center = median)
#>       Df F value Pr(>F)
#> group  2   0.046 0.9551
#>       42
leveneTest(`Night Mins` ~ `International Plan`, data = Data)
#> Levene's Test for Homogeneity of Variance (center = median)
#>       Df F value Pr(>F)
#> group  2   0.046 0.9551
#>       42
leveneTest(Data$`Night Mins` ~ `International Plan`, data = Data)
#> Levene's Test for Homogeneity of Variance (center = median)
#>       Df F value Pr(>F)
#> group  2   0.046 0.9551
#>       42

Created on 2022-10-16 with reprex v2.0.2

Kind regards

@emmeemme look where @FactOREO puts his quote (or backtick) marks and comma, as compared to where you put yours.

leveneTest(Data$`Night Mins` ~ Data$`International Plan`, data = Data)

It looks like you have some spaces in the column names. You can remove these and other complications with the function janitor::clean_names().

So, after installing the janitor package (install.packages("janitor"), you could run

cellphone <- janitor::clean_names(cellphone)
names(cellphone)

and rerun your model with the new names

This topic was automatically closed 42 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.