Description Usage Arguments Value Examples
View source: R/agnostic.t.test.R
Performs t-tests under the agnostic perspective.
1 2 | agnostic.t.test(x, y = 0, alternative = "two.sided", alpha = 0.05,
beta = 0.05, paired = FALSE)
|
x |
A vector of data. |
y |
A vector of data or a constant. |
alternative |
A character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". You can specify just the initial letter. |
alpha |
Desired type I probability of error. |
beta |
Desired tupe II probability of error. |
paired |
Boolean indicating if x and y are paired data vectors. |
A list containing the decision, the limits of the critical region and the test statistic value for the test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | #One sample test
agnostic.t.test(rnorm(10), 0)
#Two sample paired test
agnostic.t.test(rnorm(20, mean = 1), rnorm(20), paired = TRUE)
#Simulation example (this should take some seconds to run)
library(tidyr)
library(ggplot2)
n=10
mu.grid=seq(-2,2,length.out = 50)
B=5000
decision=matrix(NA,length(mu.grid),B)
for(i in 1:length(mu.grid))
{
#print(i/length(mu.grid))
for(b in 1:B)
{
decision[i,b]=agnostic.t.test(x=rnorm(n,mean = mu.grid[i]), alternative = "two.sided")$decision
}
}
decisions.names=c("Agnostic","Reject H0","Accept H0")
probability.decisions=t(apply(decision,1,function(x)
{
return(apply(as.matrix(decisions.names),1,function(y)
{
mean(x==y)
}))
}))
colnames(probability.decisions)=decisions.names
probability.decisions=cbind(mu.grid,as.data.frame(probability.decisions))
probability.decisions=gather(probability.decisions,"Decision","Probability",
Agnostic:`Accept H0`)
theme = theme_set(theme_minimal(base_size = 26))
theme = theme_update(legend.position="top", legend.title=element_blank(),
panel.grid.major.x=element_blank())
ggplot()+geom_line(data=probability.decisions,aes(x=mu.grid,y=Probability,
linetype=Decision,color=Decision),size=2)+
geom_hline(yintercept = 0.05)+xlab(expression(mu))+geom_vline(xintercept = 0)+
ylab("Probability of each decision")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.