Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No Docs for how to extract values from test summaries #255

Open
matthewcrews opened this issue Jun 21, 2022 · 3 comments
Open

No Docs for how to extract values from test summaries #255

matthewcrews opened this issue Jun 21, 2022 · 3 comments

Comments

@matthewcrews
Copy link

Is your feature request related to a problem? Please describe.
I am trying to perform a binom_test and extract the p-value from the result. The documentation does not cover this scenario.

Describe the solution you'd like
A simple example of how to extract values from a statistical test

Describe alternatives you've considered
There are none that I have found

Additional context
This is an example of what I am trying to do:

#r "nuget: RProvider"

open RProvider
open RProvider.stats

fsi.AddPrinter (fun (synexpr:RDotNet.SymbolicExpression) -> synexpr.Print())

let x = 10.0

let summary = R.binom_test(x, 100.0, 0.5, alternative="two.sided")
// What I would like to be able to do
let pValue : float = summary.GetValue "p.value"
@nhirschey
Copy link
Contributor

Agreed this should be improved.

You can piece it together from these two links:

Example below.

#r "nuget:Rprovider"
#r "nuget:R.NET"

open RProvider
open RProvider.stats
open RDotNet

fsi.AddPrinter FSIPrinters.rValue

let x = 10.0
let summary = R.binom_test(x, 100.0, 0.5, alternative = "two.sided")

summary.AsList().Names
(*
val it: string[] =
  [|"statistic"; "parameter"; "p.value"; "conf.int"; "estimate"; "null.value";
    "alternative"; "method"; "data.name"|]
*)
summary.AsList().["p.value"].GetValue<float>()
// val it: float = 3.063290175e-17

@matthewcrews
Copy link
Author

Thank you! The piece I was missing was the open RDotNet. I saw examples of AsList() but didn't notice the required open statement.

@AndrewIOM
Copy link
Collaborator

Documentation still needs to be clearer, but with the latest changes you should be able to directly access named list items without needing a reference to RDotNet as follows (by opening the RProvider.Operators module):

#r "nuget:RProvider"

open RProvider
open RProvider.Operators
open RProvider.stats

fsi.AddPrinter FSIPrinters.rValue

let x: float = 10.0
let summary = R.binom_test(x, 100.0, 0.5, alternative = "two.sided")
// val summary: SymbolicExpression =
  
//         Exact binomial test

// data:  10 and 100
// number of successes = 10, number of trials = 100, p-value < 2.2e-16
// alternative hypothesis: true probability of success is not equal to 0.5
// 95 percent confidence interval:
//  0.04900469 0.17622260
// sample estimates:
// probability of success 
//                    0.1 

summary?``p.value``
// val it: SymbolicExpression = [1] 3.06329e-17

summary?statistic
// val it: SymbolicExpression = number of successes 
//               10 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants