Test the hypothesis that the average price of diamonds in the available data is larger than $4500 after filtering out the cheapest diamonds (< $1000)
result <- single_mean(
diamonds,
var = "price",
comp_value = 4500,
alternative = "greater",
data_filter = "price >= 1000"
)
summary(result)
Single mean test
Data : diamonds
Filter : price >= 1000
Variable : price
Confidence: 0.95
Null hyp. : the mean of price = 4500
Alt. hyp. : the mean of price is > 4500
mean sd n n_missing
5,100.963 4,028.164 2,186 0
diff se t.value p.value df 5% 100%
600.963 86.155 6.975 < .001 2185 4959.19 Inf ***
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(result, plots = c("hist", "simulate"))
Compare diamond prices by the quality of the ‘cut’. It seems that diamonds with a premium cut cost more than diamonds with a ideal cut. Seems strange. Perhaps we should use regression to control for the carats of the diamond. Try it!
result <- compare_means(
dataset = diamonds,
var1 = "cut",
var2 = "price",
adjust = "bonf",
data_filter = "price >= 1000"
)
summary(result, show = FALSE)
Pairwise mean comparisons (t-test)
Data : diamonds
Filter : price >= 1000
Variables : cut, price
Samples : independent
Confidence: 0.95
Adjustment: Bonferroni
cut mean n sd se ci
Fair 4,701.771 96 3,742.952 382.013 758.393
Good 5,141.244 213 3,663.915 251.047 494.869
Very Good 5,206.187 492 3,897.686 175.721 345.258
Premium 5,462.115 593 4,261.665 175.006 343.707
Ideal 4,802.742 792 4,037.949 143.482 281.651
Null hyp. Alt. hyp. diff p.value
Fair = Good Fair not equal to Good -439.473 1
Fair = Very Good Fair not equal to Very Good -504.416 1
Fair = Premium Fair not equal to Premium -760.344 0.725
Fair = Ideal Fair not equal to Ideal -100.972 1
Good = Very Good Good not equal to Very Good -64.943 1
Good = Premium Good not equal to Premium -320.871 1
Good = Ideal Good not equal to Ideal 338.502 1
Very Good = Premium Very Good not equal to Premium -255.928 1
Very Good = Ideal Very Good not equal to Ideal 403.445 0.756
Premium = Ideal Premium not equal to Ideal 659.372 0.036
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(result, plots = c("scatter", "density", "bar"))
Visualize the relationship between diamond prices, carats, and the cut of the diamond.
visualize(diamonds,
xvar = "carat",
yvar = "price",
type = "scatter",
facet_row = "cut",
color = "cut",
data_filter = "price >= 1000",
custom = FALSE
)