[R] Breaking the samplesize package from CRAN
Bert Gunter
bgunter@4567 @end|ng |rom gm@||@com
Thu Jul 26 21:18:23 CEST 2018
Suggest you contact the package maintainer.
?maintainer
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Thu, Jul 26, 2018 at 9:49 AM, john matthew via R-help <
r-help using r-project.org> wrote:
> Hello all,
>
> I am using the samplesize package (n.ttest function) to calculate
> number of samples per group power analysis (t-tests with unequal
> variance).
> I can break this n.ttest function from the samplesize package,
> depending on the standard deviations I input.
>
> This works very good.
>
> n.ttest(sd1 = 0.35, sd2 = 0.22 , variance = "unequal")
> # outputs
> $`Total sample size`
> [1] 8
>
> $`Sample size group 1`
> [1] 5
>
> $`sample size group 2`
> [1] 3
>
> Warning message:
> In n.ttest(sd1 = 0.35, sd2 = 0.22, variance = "unequal") :
> Arguments -fraction- and -k- are not used, when variances are unequal
> The warnings are fine and all is good.
>
>
> But if I run it again with.
> n.ttest(sd1 = 1.68, sd2 = 0.28 , variance = "unequal")
> # outputs
> Error in while (n.start <= n.temp) { :
> missing value where TRUE/FALSE needed
> In addition: Warning messages:
> 1: In n.ttest(sd1 = 1.68, sd2 = 0.28, variance = "unequal") :
> Arguments -fraction- and -k- are not used, when variances are unequal
> 2: In qt(conf.level, df = df_approx) : NaNs produced
> 3: In qt(power, df = df_approx) : NaNs produced
>
> It breaks.
> The first obvious thing is that the standard deviations are a lot
> different in the 2nd example that breaks, compared with the first run.
>
> Checking the code myself, I can see it breaks down when the variable
> "df_approx" becomes a negative number, in a while loop from the
> n.ttest function.
> Exert of the code I am talking about.
>
> while (n.start <= n.temp) {
> n.start <- n1 + n2 + 1
> n1 <- n.start/(1 + k)
> n2 <- (k * n.start)/(1 + k)
> df_approx <- 1/((gamma)^2/(n1 - 1) + (1 - gamma)^2/(n2 - 1)) #
> this calculation becomes negative and breaks subsequently
> tkrit.alpha <- qt(conf.level, df = df_approx)
> tkrit.beta <- qt(power, df = df_approx)
> n.temp <- ((tkrit.alpha + tkrit.beta)^2)/(c^2)
> }
>
> I can hard code df_approx to be an absolute value but I don't know if
> that messes up the statistics.
>
> Can anyone help or any ideas? How to fix?
>
> John.
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list