Have a question around this project? sign up because that a free thedesigningfairy.com account to open an issue and also contact the maintainers and the community.

choose a username Email resolve Password authorize up because that thedesigningfairy.com

By clicking “Sign up because that thedesigningfairy.com”, friend agree come our terms of service and privacy statement. We’ll occasionally send girlfriend account related emails.

currently on thedesigningfairy.com? sign in to your account




You are watching: Error: number of levels of each grouping factor must be < number of observations

*
andrewpbray" />
*
*
muschellij2 commented jan 13, 2020

#> attaching package: "dplyr"#> The adhering to objects space masked native "package:stats":#> #> filter, lag#> The adhering to objects room masked indigenous "package:base":#> #> intersect, setdiff, setequal, unionlibrary(stringr)library(infer)set.seed(2017)fli_small % sample_n(size = 500) %>% mutate(half_year = case_when( between(month, 1, 6) ~ "h1", between(month, 7, 12) ~ "h2" )) %>% mutate(day_hour = case_when( between(hour, 1, 12) ~ "morning", between(hour, 13, 24) ~ "not morning" )) %>% select(arr_delay, dep_delay, half_year, day_hour, origin, carrier)">

library(nycflights13)library(dplyr)#> #> attaching package: "dplyr"#> The following objects room masked indigenous "package:stats":#> #> filter, lag#> The following objects room masked from "package:base":#> #> intersect, setdiff, setequal, unionlibrary(stringr)library(infer)set.seed(2017)fli_small flights %>% sample_n(size = 500) %>% mutate(half_year = case_when( between(month, 1, 6) ~ "h1", between(month, 7, 12) ~ "h2" )) %>% mutate(day_hour = case_when( between(hour, 1, 12) ~ "morning", between(hour, 13, 24) ~ "not morning" )) %>% select(arr_delay, dep_delay, half_year, day_hour, origin, carrier)
% t_test(formula = arr_delay ~ half_year)#> Error in t.test.formula(formula = formula, data = ., different = alternative, : grouping aspect must have specifically 2 levels">

fli_small %>% t_test(formula = arr_delay ~ half_year)#> Error in t.test.formula(formula = formula, data = ., alternative = alternative, : grouping element must have precisely 2 levels
% count(half_year)#> # A tibble: 2 x 2#> half_year n#> #> 1 h1 255#> 2 h2 245">

fli_small %>% count(half_year)#> # A tibble: 2 x 2#> half_year n#> #> 1 h1 255#> 2 h2 245
#> Welch 2 Sample t-test#> #> data: arr_delay through half_year#> t = 0.27655, df = 487.94, p-value = 0.7822#> alternative hypothesis: true difference in way is no equal to 0#> 95 percent trust interval:#> -5.739868 7.620333#> sample estimates:#> mean in group h1 mean in group h2 #> 5.156000 4.215768">

t.test(arr_delay ~ half_year, data = fli_small)#> #> Welch two Sample t-test#> #> data: arr_delay through half_year#> t = 0.27655, df = 487.94, p-value = 0.7822#> different hypothesis: true distinction in method is no equal come 0#> 95 percent to trust interval:#> -5.739868 7.620333#> sample estimates:#> mean in group h1 average in group h2 #> 5.156000 4.215768
Can use tidy:


% do(broom::tidy(t.test(.$arr_delay ~ .$half_year)))#> # A tibble: 1 x 10#> estimate estimate1 estimate2 statistic p.value parameter conf.low conf.high#> #> 1 0.940 5.16 4.22 0.277 0.782 488. -5.74 7.62#> # … v 2 more variables: technique , alternative ">

fli_small %>% do(broom::tidy(t.test(.$arr_delay ~ .$half_year)))#> # A tibble: 1 x 10#> estimate estimate1 estimate2 statistic p.value parameter conf.low conf.high#> #> 1 0.940 5.16 4.22 0.277 0.782 488. -5.74 7.62#> # … v 2 much more variables: technique , different
Session info
Updated inferI think the error is far better in the newer version that infer, but just unsure why default is no the instance for 2 level data:




See more: Nfl Tom Brady Game Worn Jersey S, Coronavirus: Tom Brady Auctioning 1St Game

Session info