/
betaMC-delta-r-sq-mc.R
84 lines (84 loc) · 2.32 KB
/
betaMC-delta-r-sq-mc.R
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
#' Estimate Improvement in R-Squared
#' and Generate the Corresponding Sampling Distribution
#' Using the Monte Carlo Method
#'
#' @author Ivan Jacob Agaloos Pesigan
#'
#' @details The vector of improvement in R-squared
#' (\eqn{\Delta R^{2}})
#' is derived from each randomly generated vector of parameter estimates.
#' Confidence intervals are generated by obtaining
#' percentiles corresponding to \eqn{100(1 - \alpha)\%}
#' from the generated sampling
#' distribution of \eqn{\Delta R^{2}},
#' where \eqn{\alpha} is the significance level.
#'
#' @return Returns an object
#' of class `betamc` which is a list with the following elements:
#' \describe{
#' \item{call}{Function call.}
#' \item{args}{Function arguments.}
#' \item{thetahatstar}{Sampling distribution of
#' \eqn{\Delta R^{2}}.}
#' \item{vcov}{Sampling variance-covariance matrix of
#' \eqn{\Delta R^{2}}.}
#' \item{est}{Vector of estimated
#' \eqn{\Delta R^{2}}.}
#' \item{fun}{Function used ("DeltaRSqMC").}
#' }
#'
#' @inheritParams BetaMC
#'
#' @examples
#' # Data ---------------------------------------------------------------------
#' data("nas1982", package = "betaMC")
#'
#' # Fit Model in lm ----------------------------------------------------------
#' object <- lm(QUALITY ~ NARTIC + PCTGRT + PCTSUPP, data = nas1982)
#'
#' # MC -----------------------------------------------------------------------
#' mc <- MC(
#' object,
#' R = 100, # use a large value e.g., 20000L for actual research
#' seed = 0508
#' )
#'
#' # DeltaRSqMC ---------------------------------------------------------------
#' out <- DeltaRSqMC(mc, alpha = 0.05)
#'
#' ## Methods -----------------------------------------------------------------
#' print(out)
#' summary(out)
#' coef(out)
#' vcov(out)
#' confint(out, level = 0.95)
#'
#' @family Beta Monte Carlo Functions
#' @keywords betaMC deltarsq
#' @export
DeltaRSqMC <- function(object,
alpha = c(0.05, 0.01, 0.001)) {
sr <- SCorMC(object)
out <- list(
call = match.call(),
args = list(
object = object,
alpha = alpha
),
thetahatstar = lapply(
X = sr$thetahatstar,
FUN = function(x) {
x^2
}
),
est = (sr$est)^2,
fun = "DeltaRSqMC"
)
class(out) <- c(
"betamc",
class(out)
)
return(
out
)
}