File: summary.statcheck.R

package info (click to toggle)
r-cran-statcheck 1.5.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 764 kB
  • sloc: makefile: 2
file content (65 lines) | stat: -rw-r--r-- 2,029 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#' Summary method for statcheck
#' 
#' Gives the summaries for a \code{statcheck} object.
#' 
#' @param object a \code{statcheck} object.
#' @param ... additional arguments affecting the summary produced.
#' 
#' @return A data frame containing for each source of statistics:
#' \describe{
#'     \item{source}{Name of the file/origin of which the statistics are 
#'     extracted}
#'     \item{nr_p_values}{The number of extracted reported p values per article}
#'     \item{nr_errors}{The number of errors per article}
#'     \item{nr_decision_errors}{The number of decision errors per article}
#' }
#' 
#' @examples 
#' txt <- "blablabla the effect was very significant (t(100)=1, p < 0.001)"
#' stat <- statcheck(txt)
#' summary(stat)
#' 
#' @export


summary.statcheck <-
  function(object, ...) {
    x <- object
    
    # Source
    Source <-
      c(as.vector(plyr::ddply(x, VAR_SOURCE, function(x)
        unique(x[[VAR_SOURCE]]))[, 1]), "Total")
    
    # Number of p values extracted per article and in total
    pValues <- c(plyr::ddply(x, VAR_SOURCE, function(x)
      nrow(x))[, 2], nrow(x))
    
    # Number of errors per article and in total
    Errors <-
      c(plyr::ddply(x, VAR_SOURCE, function(x)
        sum(x[[VAR_ERROR]], na.rm = TRUE))[, 2], 
        sum(x[[VAR_ERROR]], na.rm = TRUE))
    
    # Number of decision errors per article and in total
    DecisionErrors <-
      c(plyr::ddply(x, VAR_SOURCE, function(x)
        sum(x[[VAR_DEC_ERROR]], na.rm = TRUE))[, 2],
        sum(x[[VAR_DEC_ERROR]], na.rm = TRUE))
    
    # Results in dataframe
    res <- data.frame(
      Source = Source,
      pValues = pValues,
      Errors = Errors,
      DecisionErrors = DecisionErrors
    )
    
    # Rename columns based on constants in constants.R file
    colnames(res) <- c(VAR_SOURCE, VAR_NR_PVALUES, VAR_NR_ERRORS, 
                       VAR_NR_DEC_ERRORS)
    
    class(res) <- c("statcheck", "data.frame")
    
    return(res)
  }