Jesse001
Jesse001

Reputation: 924

How to extract the SES from summary of an EcosimR output

I'm trying to automate the extraction of the standardized effect size from the output of a summary function so I can automate plotting downstream.

Specifically, I'm summarizing the output of cooc_null_model(x=co-occurrence_data) and I'd like to output the "Standardized Effect Size (SES)" which is the final value in the printed results.

How would I go about doing this?

example code from help section:

library(EcoSimR)

## Run the null model 
finchMod <- cooc_null_model(dataWiFinches, algo = "sim9", nReps = 10000, burn_in = 500)

## Summary and plot info 
summary(finchMod)

I was hoping it'd be something of the sort: finchMod$Standardized_Effect_Size but I can't seem to find the target value through those means.

Any and all help is appreciated!!

Upvotes: 0

Views: 161

Answers (1)

Rui Barradas
Rui Barradas

Reputation: 76615

Here is an account of what I have done to find out where is your statistic of interest, SES.

Step one:

Run the model and check

class(finchMod)
#[1] "coocnullmod"

str(finchMod)
#List of 13
# $ Obs            : num 3.79
# $ Sim            : num [1:10000] 2.59 2.59 2.59 2.59 2.6 ...
# $ Elapsed.Time   : chr "1.7 secs"
# $ Time.Stamp     : chr "Fri Jun 22 18:35:52 2018"
# $ Metric         : chr "c_score"
# $ Algorithm      : chr "sim9"
# $ N.Reps         : num 10000
# $ SaveSeed       : logi FALSE
# $ RandomSeed     : NULL
# $ Randomized.Data: num [1:17, 1:19] 0 0 0 0 0 0 0 1 0 1 ...
#  ..- attr(*, "dimnames")=List of 2
#  .. ..$ : NULL
#  .. ..$ : chr [1:19] "Cuba" "Hispaniola" "Jamaica" "Puerto_Rico" #...
# $ Data           : num [1:17, 1:19] 0 0 0 0 1 0 0 0 0 1 ...
#  ..- attr(*, "dimnames")=List of 2
#  .. ..$ : NULL
#  .. ..$ : chr [1:19] "Cuba" "Hispaniola" "Jamaica" "Puerto_Rico" #...
# $ burn.in        : num 500
# $ burn.in.metric : num [1:500] 3.68 3.68 3.65 3.65 3.65 ...
# - attr(*, "class")= chr "coocnullmod"

As you can see, there is no SES. This means that its value is computed by the method summary.coocnullmod or by some function this method calls. See, for instance, R FAQ 8.1.

Step two:

Check the code of summary.coocnullmod. At an R prompt, the name of a function without parenthesis prints its body.

summary.coocnullmod
Error: object 'summary.coocnullmod' not found

So use getAnywhere.

getAnywhere(summary.coocnullmod)
A single object matching ‘summary.coocnullmod’ was found
It was found in the following places
  registered S3 method for summary from namespace EcoSimR
  namespace:EcoSimR
with value

function (object, ...) 
{
   nullmodObj <- object

   [...etc...]
   [...last code line...]

    cat("Standardized Effect Size (SES): ", format((nullmodObj$Obs - 
        mean(nullmodObj$Sim))/sd(nullmodObj$Sim), digits = 5), 
        "\n")
}
<environment: namespace:EcoSimR>

Step three:

So now you have everything that is needed to automate your computation of the SES.

ses <- function(object){
  (object$Obs - mean(object$Sim))/sd(object$Sim)
}

ses(finchMod)
#[1] 5.69756

Upvotes: 1

Related Questions