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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
|
error_test <- function(reported_p, test_type, test_stat,
df1, df2,
p_comparison, test_comparison,
p_dec, test_dec,
two_tailed,
alpha, pZeroError) {
# replace 'ns' for > alpha -----------------------------------------------
reported_p[p_comparison == "ns"] <- alpha
p_comparison[p_comparison == "ns"] <- ">"
# compute p-values -------------------------------------------------------
# take into account that the reported test statistic may have been rounded
# to that end, compute the upper and lower bound of the test statistic
# based on the number of decimals that it was reported with. E.g.,
# a t-value of 2.0 could have been rounded from anywhere between 1.95-2.05.
if(test_stat >= 0){
low_stat <- test_stat - (.5 / 10 ^ test_dec)
up_stat <- test_stat + (.5 / 10 ^ test_dec)
# switch around for negative test statistics
} else if (test_stat < 0){
low_stat <- test_stat + (.5 / 10 ^ test_dec)
up_stat <- test_stat - (.5 / 10 ^ test_dec)
}
# Compute the p-values that belong to the upper and lower bound of the test
# statistic. This is the range of p-values that would be correct.
up_p <- compute_p(test_type = test_type,
test_stat = low_stat,
df1 = df1,
df2 = df2,
two_tailed = two_tailed)
low_p <- compute_p(test_type = test_type,
test_stat = up_stat,
df1 = df1,
df2 = df2,
two_tailed = two_tailed)
# p values smaller or equal to zero are errors ---------------------------
if(pZeroError == TRUE & reported_p <= 0){
error <- TRUE
return(error)
}
# check errors for different combinations of <>= -------------------------
if(test_comparison == "="){
if(p_comparison == "="){
error <- reported_p > round(up_p, p_dec) | reported_p < round(low_p, p_dec)
return(error)
} else if(p_comparison == "<"){
error <- reported_p < low_p
return(error)
} else if(p_comparison == ">"){
error <- reported_p > up_p
return(error)
}
} else if(test_comparison == "<"){
if(p_comparison == "="){
error <- reported_p < round(up_p, p_dec)
return(error)
} else if(p_comparison == "<"){
error <- reported_p < up_p
return(error)
}
else if(p_comparison == ">"){
error <- FALSE
return(error)
}
} else if(test_comparison == ">"){
if(p_comparison == "="){
error <- reported_p > round(low_p, p_dec)
return(error)
} else if(p_comparison == "<"){
error <- FALSE
return(error)
} else if(p_comparison == ">"){
error <- reported_p > low_p
return(error)
}
}
return(NA)
}
|