```
#======================================================================================
# Difference between two independent proportions: Agresti & Caffo
#======================================================================================
# First proportion
x1 <- 11
n1 <- 199
# Second proportion
x2 <- 1140705
n2 <- 2441147
# Apply the correction
p1hat <- (x1 + 1)/(n1 + 2)
p2hat <- (x2 + 1)/(n2 + 2)
# The original estimator
est0 <- (x1/n1) - (x2/n2)
est0
# The unmodified estimator and its standard error using the correction
est <- p1hat - p2hat
se <- sqrt(((p1hat*(1 - p1hat))/(n1 + 2)) + ((p2hat*(1 - p2hat))/(n2 + 2)))
UCL = est + (qnorm(0.975)*se)
LCL = est - (qnorm(0.975)*se)
est;UCL;LCL
install.packages("pvaluefunctions")
library(pvaluefunctions)
res <- conf_dist(
estimate = c(est)
, stderr = c(se)
, type = "general_z"
, plot_type = "p_val"
, n_values = 1e4L
, log_yaxis = FALSE
, cut_logyaxis = 0.05
, conf_level = c(0.95, 0.99)
, null_values = c(0, 0.3)
, trans = "identity"
, alternative = "two_sided"
, xlab = "Difference of proportions"
, together = FALSE
, plot_p_limit = 1 - 0.9999
, plot_counternull = FALSE
, title = "P-value function for the difference of two independent proportions"
, ylab = NULL
, ylab_sec = NULL
, inverted = FALSE
, x_scale = "default"
)
```