A little off topic: data.frame members [🇷 for BE/BA]
Hi all,
there is something about R internals that I don 't understand and I can best exemplify it using some code from power.TOST but my question really isn't about anything in that package.
Imagine I do this in R with powerTOST:
Nice.
Now, assume I don't want all that intermediate mumbojumbo, and let us for the time being completely forget the print/verbose/details option so I just want the sample size itself as a numeric.
If I inspect the code I see the last few lines:
...and therefore I can simply do this:
(the n column is baptised as "Sample size" but is still accessible via $n)
If I look at the corresponding code snippet from
But if I go
then I get NULL.
What determines that difference in behaviour? Why does the res data.frame from both the two functions not hold an extractable $n ?
Note, this really is solely about R behaviour and R function return/internals (if I want the sample sizes I can also easily get them via [1,7] or [1,8] from the sample size object returned; all this isn't really what this question is about).
there is something about R internals that I don 't understand and I can best exemplify it using some code from power.TOST but my question really isn't about anything in that package.
Imagine I do this in R with powerTOST:
sampleN.RSABE(CV=0.3, theta0=0.95)
Nice.
Now, assume I don't want all that intermediate mumbojumbo, and let us for the time being completely forget the print/verbose/details option so I just want the sample size itself as a numeric.
If I inspect the code I see the last few lines:
res <- data.frame(design = design, alpha = alpha, CVwT = CVwT,
CVwR = CVwR, theta0 = theta0, theta1 = theta1, theta2 = theta2,
n = n, power = pwr, targetpower = targetpower, nlast = nlast)
names(res) <- c("Design", "alpha", "CVwT", "CVwR", "theta0",
"theta1", "theta2", "Sample size", "Achieved power",
"Target power", "nlast")
if (print | details)
return(invisible(res))
else return(res)
...and therefore I can simply do this:
sampleN.RSABE(CV=0.3, theta0=0.95)$n
(the n column is baptised as "Sample size" but is still accessible via $n)
If I look at the corresponding code snippet from
sampleN.TOST
we have: res <- data.frame(design = design, alpha = alpha, CV = CV,
theta0 = theta0, theta1 = theta1, theta2 = theta2, n = n,
power = pow, targetpower = targetpower)
names(res) <- c("Design", "alpha", "CV", "theta0", "theta1",
"theta2", "Sample size", "Achieved power", "Target power")
if (print)
return(invisible(res))
else return(res)
But if I go
sampleN.TOST(CV=0.3, theta0=0.95)$n
then I get NULL.
What determines that difference in behaviour? Why does the res data.frame from both the two functions not hold an extractable $n ?
Note, this really is solely about R behaviour and R function return/internals (if I want the sample sizes I can also easily get them via [1,7] or [1,8] from the sample size object returned; all this isn't really what this question is about).
—
Pass or fail!
ElMaestro
Pass or fail!
ElMaestro
Complete thread:
- A little off topic: data.frame membersElMaestro 2018-01-22 23:49 [🇷 for BE/BA]
- R-Inferno Helmut 2018-01-23 13:37
- R-Inferno d_labes 2018-01-23 15:03
- Thanks :-D ElMaestro 2018-01-23 15:26
- Safe side syntax d_labes 2018-01-23 15:39
- Thanks :-D ElMaestro 2018-01-23 15:26
- R-Inferno d_labes 2018-01-23 15:03
- A little off topic: data.frame members yjlee168 2018-01-23 17:47
- R-Inferno Helmut 2018-01-23 13:37