Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Argument "by" is missing, with no default

Here is my reprodicible sample and code:

set.seed(42)
n <- 1000
dat <- data.frame(Confidence=1:5, 
                  Type = ("Your confidence"),
                  Correct=sample(0:1, n, replace=TRUE)
)

dat %>%
  group_by(Confidence,Type) %>%
  summarize(Accuracy = mean(Correct),
            se = (sd(Correct, na.rm = TRUE)/sqrt(n())))%>%
  ggplot(aes(x=Confidence, y= Accuracy, color = Type, group = Type)) +
  geom_line() + 
  geom_errorbar(aes(ymin = Accuracy - se, ymax = Accuracy + se), color = "Black", size = .15, width = .3) + 
  geom_point(size = 2)+ 
  scale_y_continuous(labels = scales::percent)+ 
  labs(y= "YOU ARE RIGHT ___% OF THE TIME.", x = "WHEN YOU ARE ___ % CONFIDENT IN YOUR ANSWER...")+
  theme_minimal() + 
  scale_color_brewer(palette = "Set1")

When I run this i get this error:

Error in summarize(., Accuracy = mean(Correct), se = (sd(Correct, na.rm = TRUE)/sqrt(n()))) : 
  argument "by" is missing, with no default

Has anyone seen this error before and know how to fix it? Thank you!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

summarize is found in multiple packages and if we load many packages that have the summarize (depending on the order of loading the package) it could mask the function. e.g. the error seems to be coming from Hmisc::summarize

> dat %>%
+   group_by(Confidence,Type) %>%
+   Hmisc::summarize(Accuracy = mean(Correct),
+             se = (sd(Correct, na.rm = TRUE)/sqrt(n())))%>%
+   ggplot(aes(x=Confidence, y= Accuracy, color = Type, group = Type)) +
+   geom_line() + 
+   geom_errorbar(aes(ymin = Accuracy - se, ymax = Accuracy + se), color = "Black", size = .15, width = .3) + 
+   geom_point(size = 2)+ 
+   scale_y_continuous(labels = scales::percent)+ 
+   labs(y= "YOU ARE RIGHT ___% OF THE TIME.", x = "WHEN YOU ARE ___ % CONFIDENT IN YOUR ANSWER...")+
+   theme_minimal() + 
+   scale_color_brewer(palette = "Set1")
Error in Hmisc::summarize(., Accuracy = mean(Correct), se = (sd(Correct,  : 
  argument "by" is missing, with no default

If we change it to dplyr::summarize

dat %>%
  group_by(Confidence,Type) %>%
  dplyr::summarize(Accuracy = mean(Correct),
            se = (sd(Correct, na.rm = TRUE)/sqrt(n())))%>%
  ggplot(aes(x=Confidence, y= Accuracy, color = Type, group = Type)) +
  geom_line() + 
  geom_errorbar(aes(ymin = Accuracy - se, ymax = Accuracy + se), color = "Black", size = .15, width = .3) + 
  geom_point(size = 2)+ 
  scale_y_continuous(labels = scales::percent)+ 
  labs(y= "YOU ARE RIGHT ___% OF THE TIME.", x = "WHEN YOU ARE ___ % CONFIDENT IN YOUR ANSWER...")+
  theme_minimal() + 
  scale_color_brewer(palette = "Set1")

-output

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading