Description Usage Arguments Value Author(s) Examples
View source: R/stageTwoAnalysis.R
Wrapper function for twoStageTE that users can directly call on their data.
1 2 | stageTwoAnalysis(stageOne, explanatory, response, type = "IR-wald",
level = 0.95, combineData=FALSE)
|
stageOne |
Object returned from calling the function stageOneAnalysis |
explanatory |
Explanatory sample points |
response |
Observed responses at the explanatory sample points |
type |
String input of either "IR-wald" (default), "IR-likelihood" or "locLinear" |
level |
Confidence level (defaults to 0.95) |
combineData |
Optional boolean input on whether to combine data from both stages. Default is FALSE. |
List:
L1 |
Lower bound of CI |
U1 |
Upper bound of CI |
estimate |
Threshold estimate |
level |
Confidence level |
X1 |
First stage explanatory variable |
Y1 |
First stage response variable |
X2 |
Second stage explanatory variable |
Y2 |
Second stage response variable |
L2 |
Ssecond stage lower bound of CI |
U2 |
Second stage upper bound of CI |
call |
Method Call |
sigmaSq |
Estimate of variance |
deriv_d0 |
Derivative estimate |
class |
twostageTE |
Shawn Mankad
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 | X=runif(25, 0,1)
Y=X^2+rnorm(n=length(X), sd=0.1)
oneStage_IR=stageOneAnalysis(X, Y, 0.25, type="IR-wald", 0.99)
X2=runif(75,oneStage_IR$L1 ,oneStage_IR$U1)
Y2=X2^2+rnorm(n=length(X2), sd=0.1)
twoStage_IR = stageTwoAnalysis(oneStage_IR, X2, Y2, type="IR-wald", 0.95)
## The function is currently defined as
function (stageOne, explanatory, response, type = "IR-wald",
level = 0.95, combineData = FALSE)
{
cl1 <- match.call(expand.dots = TRUE)
Y_0 = stageOne$threshold
C_1 = stageOne$C_1
gamma1=1/3
if (combineData) {
explanatory = c(explanatory ,
stageOne$X1[stageOne$X1 > stageOne$L1 & stageOne$X1 < stageOne$U1])
response = c(response ,
stageOne$Y1[stageOne$X1 > stageOne$L1 & stageOne$X1 < stageOne$U1])
}
if (type == "IR-wald") {
CI = waldConfidenceInterval_ir_stageTwo(explanatory,
response, Y_0, level = level, gamma1 = gamma1, C_1 = C_1,
n1 = length(stageOne$X1))
return(structure(list(L2 = CI$lower, U2 = CI$upper, estimate = CI$estimate,
threshold = Y_0, level = level, X1 = stageOne$X1,
Y1 = stageOne$Y1, X2 = explanatory, Y2 = response,
L1 = stageOne$L1, U1 = stageOne$U1, call = cl1, sigmaSq = CI$sigmaSq,
deriv_d0 = CI$deriv_d0), class = "twostageTE"))
}
else if (type == "IR-likelihood") {
CI = likelihoodConfidenceInterval(explanatory, response,
Y_0, level = level)
return(structure(list(L2 = CI$lower, U2 = CI$upper, estimate = CI$estimate,
threshold = Y_0, level = level, X1 = stageOne$X1,
Y1 = stageOne$Y1, X2 = explanatory, Y2 = response,
L1 = stageOne$L1, U1 = stageOne$U1, call = cl1, sigmaSq = CI$sigmaSq,
deriv_d0 = CI$deriv_d0), class = "twostageTE"))
}
else if (type == "SIR") {
CI = waldConfidenceInterval_sir_stageTwo(explanatory = explanatory,
response = response, Y_0 = Y_0, gamma1 = gamma1,
C_1 = C_1, level = level)
return(structure(list(L2 = CI$lower, U2 = CI$upper, estimate = CI$estimate,
threshold = Y_0, level = level, X1 = stageOne$X1,
Y1 = stageOne$Y1, X2 = explanatory, Y2 = response,
L1 = stageOne$L1, U1 = stageOne$U1, call = cl1, sigmaSq = CI$sigmaSq,
deriv_d0 = CI$deriv_d0), class = "twostageTE"))
}
else if (type == "locLinear") {
CI = linearBootstrapConfidenceInterval_stageTwo(explanatory = explanatory,
response = response, Y_0 = Y_0, level = level)
return(structure(list(L2 = CI$lower, U2 = CI$upper, estimate = CI$estimate,
threshold = Y_0, level = level, X1 = stageOne$X1,
Y1 = stageOne$Y1, X2 = explanatory, Y2 = response,
L1 = stageOne$L1, U1 = stageOne$U1, call = cl1, sigmaSq = CI$sigmaSq,
deriv_d0 = CI$deriv_d0), class = "twostageTE"))
}
else error("stageOneAnalysis: type should be either
'IR-wald','IR-likelihood', 'SIR', or 'locLinear'")
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.