context("Functions used in one-sided-tolerance-intervall testing")
# check function kc by compareing results with tabulated values in ISO 16269-6 in table c1-c4 ----
test_that("kc-value equals tabulated values in C.1",{
c1 <- data.frame(n=c(3,4,5,6),
alpha=0.1,p=0.9,
kc=c(4.2582,3.1897,2.7424,2.4937))
expect_equal(kc(p=0.9,alpha=0.1,n=c(3,4,5,6)),subset(c1,n==c(3,4,5,6))$kc,tolerance=0.001)
expect_equal(kc(p=0.9,alpha=0.1,n=2),10.2528,tolerance=0.001)
expect_equal(kc(p=0.9,alpha=0.1,n=20),1.7653,tolerance=0.001)
expect_equal(kc(p=0.95,alpha=0.1,n=5),3.3999,tolerance=0.001)
})
test_that("kc-value equals tabulated values in C.2",{
expect_equal(kc(p=0.99,alpha=0.05,n=5),5.7411,tolerance=0.001)})
test_that("example 1 iso 16269 can be reproduced",{
obs <- c(228.6,232.7,238.8,317.2,315.8,275.1,222.2,236.7,224.7,252.1,210.4,270.7)
expect_equal(mean(obs) - kc(p = 0.95, alpha = 0.05, n = length(obs)) * sd(obs),154.7,tolerance=0.1)
})
# p_reject_ostit -------------
test_that("p_reject_ostit equals power in borderline-case",{
for (p_min in seq(0.6, 0.9, by = 0.1)){
for (power in seq(0.1, 0.3, by = 0.1)){
for (sample_size in 3:10){
for (spec_limit in seq(10, 100, by = 10)){
for (process_sd in seq(5, 30, by = 5)){
process_mean <- spec_limit + qnorm(p = p_min) * process_sd
expect_equal(p_reject_ostit(process_mean = process_mean,
process_sd = process_sd,
sample_size = sample_size,
spec_limit = spec_limit,
spec_type = "lsl",
p_min = p_min,
power = power),
power)
}
}
}
}
}
})
test_that("p_reject_ostit is less than power in i.o.-case",{
for (p_min in seq(0.6, 0.9, by = 0.1)){
for (power in seq(0.1, 0.6, by = 0.1)){
for (sample_size in 3:10){
for (spec_limit in seq(10, 50, by = 10)){
for (process_sd in seq(5, 25, by = 5)){
for (slope_inflation in seq(1.2, 2, by = 0.4 ))
{
process_mean <- spec_limit + slope_inflation * qnorm(p = p_min) * process_sd
expect_true(p_reject_ostit(process_mean = process_mean,
process_sd = process_sd,
sample_size = sample_size,
spec_limit = spec_limit,
spec_type = "lsl",
p_min = p_min,
power = power) < power)
}
}
}
}
}
}
})
# sample_size_hint_ostit ---------
test_that("returns NA and throws warning in case of missing arguments",
{
expect_equal(sample_size_hint_ostit(p_success = 0.6,
process_mean = NA,
process_sd = 3,
spec_limit = 70,
spec_type = "lsl",
p_min = 0.9,
power = 0.3),
NA)
expect_equal(sample_size_hint_ostit(p_success = 0.6,
process_mean = 80,
process_sd = NaN,
spec_limit = 70,
spec_type = "lsl",
p_min = 0.9,
power = 0.3),
NA)
expect_equal(sample_size_hint_ostit(p_success = 0.6,
process_mean = 80,
process_sd = 3,
spec_limit = NA,
spec_type = "lsl",
p_min = 0.9,
power = 0.3),
NA)
})
test_that("sample_size_hint_ostit returns NA and throws warning in case of p_success < (1-power)",{
expect_warning(
sample_size_hint_ostit(p_success = 0.6,
process_mean = 80,
process_sd = 3,
spec_limit = 70,
spec_type = "lsl",
p_min = 0.9,
power = 0.3
)
)
expect_equal(
sample_size_hint_ostit(p_success = 0.6,
process_mean = 80,
process_sd = 3,
spec_limit = 70,
spec_type = "lsl",
p_min = 0.9,
power = 0.3
),
NA
)
})
test_that("sample_size_hint_ostit returns 2 in case of excellent process",
{
expect_equal(
sample_size_hint_ostit(p_success = 0.8,
process_mean = 800,
process_sd = 1,
spec_limit = 70,
spec_type = "lsl",
p_min = 0.9,
power = 0.3
),
3
)
expect_equal(
sample_size_hint_ostit(p_success = 0.8,
process_mean = 20,
process_sd = 1,
spec_limit = 700,
spec_type = "usl",
p_min = 0.9,
power = 0.3
),
3
)
}
)
test_that("sample_size_int_ostit returns 10000 and warning in case of borderline i.o. process",
{
expect_equal(
sample_size_hint_ostit(p_success = 0.8,
process_mean = 70 + 1.01 * qnorm(0.9) * 15,
process_sd = 15,
spec_limit = 70,
spec_type = "lsl",
p_min = 0.9,
power = 0.3
),
10000
)
expect_warning(
sample_size_hint_ostit(p_success = 0.8,
process_mean = 70 - 1.01 * qnorm(0.9) * 15,
process_sd = 15,
spec_limit = 70,
spec_type = "usl",
p_min = 0.9,
power = 0.3
)
)
}
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.