Acceptance and tailed tests

I wish to us ggplot2 in RStudio to make a diagram which displays the acceptance regions of my null hypothesis given my data. I know that I must use the function ggplot() although I don't know what to enter in as the parameters and how to make it specific for what I want. Also I am not sure what kind of data I should be entering in since I have different types of values I found, if anyone can inform me some more on how to perform the tailed statistical tests this way I would appreciate a lot.

Here is an example where the null distribution is a t-distribution. The blue vertical bars represent the significance thresholds at the 0.05 significance level.


## Generate 10 random values from a normal distribution and compute test statistic for the mean

## Compute upper and lower significance thresholds 

## Create data for the null distribution, a t-distribution with 10-1=9 d.f.

## Create the plot with blue vertical bars for significance thresholds and a red vertical bar for the observed sample

In the future, if you don't want to use a graph, you can also compute a p-value for a two-sided test:


You can change the t-distribution to the distribution that fits your purpose. For example, dt, "t density", could be replaced by the normal density, dnorm, and the quantile function qt by qnorm. In that case you won't need the degrees of freedom argument.

This is a great resource to get you started, specifically Chapter 3 on data visualization. It will walk you through the basics on ggplot and help you make your first visualization.

Hope this helps!

This is both a statistical question and an R question. The statistical question would take a chapter to answer in general. Let's simplify it to one small case. Suppose you have a normal curve with mean 0 and SD 1, and you wish to reject the null hypothesis when the probability is in the 5% right tail. That critical z value is qnorm(.95) which is 1.644854. The following code graphs a normal curve and shades the critical region.

z <- qnorm(.95)
ggplot(data = data.frame(x = c(-3, 3)), aes(x)) +
stat_function(fun = dnorm, n = 101, args = list(mean = 0, sd = 1)) + ylab("") +
scale_y_continuous(breaks = NULL) +
geom_segment(x = z, y = 0, xend = z, yend = dnorm(z, mean = 0, sd = 1)) +
stat_function(fun = dnorm, geom = "area", fill = "red", xlim = c(z, 3))


This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.