OpenIntroStat / oilabs

🛑 This package has been deprecated and datasets and functionality have been moved to the openintro package
https://github.com/OpenIntroStat/openintro
Creative Commons Zero v1.0 Universal
10 stars 19 forks source link

Error in FUN(X[[1L]], ...) #26

Closed ismayc closed 9 years ago

ismayc commented 9 years ago

In trying to run the inference function on to compare the two mean sleep hours for whether or not someone has a job, I am receiving the following error.

> inference(y = d$sleep_hrs, 
+           x = d$job, 
+           est = "mean", 
+           type = "ht", 
+           null = 0, 
+           alternative = "twosided", 
+           method = "theoretical")
Response variable: numerical, Explanatory variable: categorical
Difference between two means
Summary statistics:
n_no = 12, mean_no = 7.2083, 
Error in FUN(X[[1L]], ...) : could not find function "FUN"

I believe the error occurs in the following code of the inference function. It looks like it doesn't find the sd function.

 # summary statistics and eda plots
            cat("Summary statistics:\n")
            if (est == "mean") {
                for (i in 1:x_levels) {
                  cat("n_", names(by(y, x, length))[i], " = ", by(y, x, length)[i], ", ", sep = "")
                  cat("mean_", names(by(y, x, mean))[i], " = ", round(by(y, x, mean)[i], 4), ", ", 
                    sep = "")
                  cat("sd_", names(by(y, x, sd))[i], " = ", round(by(y, x, sd)[i], 4), "\n", sep = "")
                }
mine-cetinkaya-rundel commented 9 years ago

This is likely happening because in your environment there is a variable called sd. Can you check if this is the case?

ismayc commented 9 years ago

Thanks, Mine! I was helping one of Andrew's students and completely overlooked their declaration of sd earlier in the file. After changing that, the error went away and their document knit.