ncarchedi / swirl_OLD

We've moved! See README below for more info.
http://swirlstats.com
47 stars 28 forks source link

Bug in pval for Mathematical Biostatistics Boot Camp 2 module 1 #19

Closed mtaub closed 10 years ago

mtaub commented 10 years ago

Following the code for Mathematical Biostatistics Boot Camp 2 module 1, you first calculate a p-value by hand, and then use t.test to get one. The p-values do not match in the end as they are supposed to.

This line works correctly and I can see the correct value for pVal stored in my workspace variables (viewed in RStudio): pVal <- pt(tStat, df=myDF, lower.tail=FALSE)

But when the next line is executed pVal <- pVal * 2 for some reason pVal gets replaced by pVal_4 instead of pVal_2.

Not sure why this would be happening, but thanks for taking a look when you get a chance.

Cheers, Margaret

ncarchedi commented 10 years ago

Hi Margaret

I'm not sure what's happening with those p-values. I was able to replicate your problem, but I can't seem to figure out what is causing it. I'm wondering if the t.test function is computing the sample variance differently than the var function does. I don't know what else to attribute it to since the content all looks sound. I will dig deeper and let you know what I find.

Nick

On Tue, Oct 8, 2013 at 10:21 AM, mtaub notifications@github.com wrote:

Following the code for Mathematical Biostatistics Boot Camp 2 module 1, you first calculate a p-value by hand, and then use t.test to get one. The p-values do not match in the end as they are supposed to. This line works correctly and I can see the correct value for pVal stored in my workspace variables (viewed in RStudio): pVal <- pt(tStat, df=myDF, lower.tail=FALSE) But when the next line is executed pVal <- pVal * 2 for some reason pVal gets replaced by pVal_4 instead of pVal_2. Not sure why this would be happening, but thanks for taking a look when you get a chance. Cheers,

Margaret

Reply to this email directly or view it on GitHub: https://github.com/ncarchedi/swirl/issues/19

mtaub commented 10 years ago

Hi Nick,

It's not an issue with the variance -- I can actually see that the value of pVal is getting updated incorrectly when it executes the command

pVal <- pVal * 2

Running the code outside of swirl:

pVal <- (pt((mean(mtcars$mpg)-12)/sqrt(var(mtcars$mpg)/nrow(mtcars)), df=nrow(mtcars)-1, lower.tail=FALSE)) pVal [1] 7.31475e-09 pVal <- pVal * 2 pVal [1] 1.46295e-08

Whereas inside of swirl, the result of the second command is:

[1] 2.9259e-08

which is twice what it should be. Is it possible that it is executing the command two times?

Cheers, Margaret

On Oct 8, 2013, at 11:56 AM, Nick Carchedi notifications@github.com wrote:

Hi Margaret

I'm not sure what's happening with those p-values. I was able to replicate your problem, but I can't seem to figure out what is causing it. I'm wondering if the t.test function is computing the sample variance differently than the var function does. I don't know what else to attribute it to since the content all looks sound. I will dig deeper and let you know what I find.

Nick

On Tue, Oct 8, 2013 at 10:21 AM, mtaub notifications@github.com wrote:

Following the code for Mathematical Biostatistics Boot Camp 2 module 1, you first calculate a p-value by hand, and then use t.test to get one. The p-values do not match in the end as they are supposed to. This line works correctly and I can see the correct value for pVal stored in my workspace variables (viewed in RStudio): pVal <- pt(tStat, df=myDF, lower.tail=FALSE) But when the next line is executed pVal <- pVal * 2 for some reason pVal gets replaced by pVal_4 instead of pVal_2. Not sure why this would be happening, but thanks for taking a look when you get a chance. Cheers,

Margaret

Reply to this email directly or view it on GitHub: https://github.com/ncarchedi/swirl/issues/19 — Reply to this email directly or view it on GitHub.

ncarchedi commented 10 years ago

Good detective work. You must be right because now that I think about it, the test statistics were identical. I will try to figure out what's going on tonight. 

Thanks again,

Nick

On Tue, Oct 8, 2013 at 12:16 PM, mtaub notifications@github.com wrote:

Hi Nick, It's not an issue with the variance -- I can actually see that the value of pVal is getting updated incorrectly when it executes the command pVal <- pVal * 2 Running the code outside of swirl:

pVal <- (pt((mean(mtcars$mpg)-12)/sqrt(var(mtcars$mpg)/nrow(mtcars)), df=nrow(mtcars)-1, lower.tail=FALSE)) pVal [1] 7.31475e-09 pVal <- pVal * 2 pVal [1] 1.46295e-08 Whereas inside of swirl, the result of the second command is: [1] 2.9259e-08 which is twice what it should be. Is it possible that it is executing the command two times? Cheers, Margaret On Oct 8, 2013, at 11:56 AM, Nick Carchedi notifications@github.com wrote: Hi Margaret

I'm not sure what's happening with those p-values. I was able to replicate your problem, but I can't seem to figure out what is causing it. I'm wondering if the t.test function is computing the sample variance differently than the var function does. I don't know what else to attribute it to since the content all looks sound. I will dig deeper and let you know what I find.

Nick

On Tue, Oct 8, 2013 at 10:21 AM, mtaub notifications@github.com wrote:

Following the code for Mathematical Biostatistics Boot Camp 2 module 1, you first calculate a p-value by hand, and then use t.test to get one. The p-values do not match in the end as they are supposed to. This line works correctly and I can see the correct value for pVal stored in my workspace variables (viewed in RStudio): pVal <- pt(tStat, df=myDF, lower.tail=FALSE) But when the next line is executed pVal <- pVal * 2 for some reason pVal gets replaced by pVal_4 instead of pVal_2. Not sure why this would be happening, but thanks for taking a look when you get a chance. Cheers,

Margaret

Reply to this email directly or view it on GitHub: https://github.com/ncarchedi/swirl/issues/19 — Reply to this email directly or view it on GitHub.


Reply to this email directly or view it on GitHub: https://github.com/ncarchedi/swirl/issues/19#issuecomment-25904505

ncarchedi commented 10 years ago

I fixed a bug in the user_input() function that was causing swirl to evaluate parsed commands twice. This problem should be resolved now.