# NOT RUN {
# These examples take some time to run, so be cautious
# }
# NOT RUN {
set.seed(101)
# Type "discrete"
d_dis <- new_d(data.frame(x = 1:4, prob = 1:4/10), "discrete")
# Estimate of distribution of mean
form_estimate(d_dis, stat = mean, sample_size = 10)
# To change type of output, supply it in `args_new`
form_estimate(
d_dis, stat = mean, sample_size = 10,
args_new = list(type = "continuous")
)
# Type "continuous"
d_unif <- as_d(dunif)
# Supply extra named arguments for `stat` in `...`
plot(form_estimate(d_unif, stat = mean, sample_size = 10, trim = 0.1))
lines(
form_estimate(d_unif, stat = mean, sample_size = 10, trim = 0.3),
col = "red"
)
lines(
form_estimate(d_unif, stat = median, sample_size = 10),
col = "blue"
)
# Statistic can return single logical value
d_norm <- as_d(dnorm)
all_positive <- function(x) {all(x > 0)}
# Probability of being true should be around 0.5^5
form_estimate(d_norm, stat = all_positive, sample_size = 5)
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab