# A light bulb manufacturer claims bulbs last 1000 hours on average.
# We test 50 bulbs and know from historical data that sigma = 100 hours.
lifetimes <- c(980, 1020, 950, 1010, 990, 1005, 970, 1030, 985, 995,
1000, 1015, 960, 1025, 975, 1008, 992, 1012, 988, 1002,
978, 1018, 965, 1022, 982, 1005, 995, 1010, 972, 1028,
990, 1000, 985, 1015, 968, 1020, 980, 1008, 992, 1012,
975, 1018, 962, 1025, 985, 1002, 988, 1010, 978, 1020)
# Two-sided test: H0: mu = 1000 vs H1: mu != 1000
z_test(lifetimes, mu0 = 1000, sigma = 100)
# One-sided test: are bulbs lasting less than claimed?
z_test(lifetimes, mu0 = 1000, sigma = 100, alternative = "less")
Run the code above in your browser using DataLab