Bioequivalence and Bioavailability Forum

Main page Policy/Terms of Use Abbreviations Latest Posts

 Log-in |  Register |  Search

Back to the forum  Query: 2018-05-21 13:08 CEST (UTC+2h)
 

A little off topic: data.frame members [R for BE/BA]

posted by ElMaestro - Denmark, 2018-01-22 23:49  - Posting: # 18254
Views: 1,260

Hi all,
:ok:
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).:-)

“A ten-year, double-blind study from the Mayo Clinic concluded that even in late stages of dementia, the last to go is the lobe of the brain in charge of cafeteria layout.” (Serge Storms/Tim Dorsey).


Best regards,
ElMaestro

- Bootstrapping is a relatively new hobby of mine. I am only 30 years late to the party.

Complete thread:

Back to the forum Activity
 Mix view
Bioequivalence and Bioavailability Forum | Admin contact
18,269 posts in 3,882 threads, 1,161 registered users;
14 users online (1 registered, 13 guests).

Science is wonderfully equipped to answer the question “How?”
but it gets terribly confused when you ask the question “Why?”    Erwin Chargaff

The BIOEQUIVALENCE / BIOAVAILABILITY FORUM is hosted by
BEBAC Ing. Helmut Schütz
XHTML/CSS RSS Feed