# Estimation Approach to Statistical Inference
## Basic Functions
### Confidence Interval Functions
ci <- function(y,...){
N <- length(y)
M <- mean(y,na.rm=TRUE)
SD <- sd(y,na.rm=TRUE)
SE <- SD/sqrt(N)
model <- t.test(y,...)
LL <- as.numeric(model$conf.int[1])
UL <- as.numeric(model$conf.int[2])
round(c(N=N,M=M,SD=SD,SE=SE,LL=LL,UL=UL),3)
}
### Null Hypothesis Significance Test Functions
nhst <- function(y,...){
model <- t.test(y,...)
mu <- as.numeric(model$null.value)
MD <- as.numeric(model$estimate-mu)
SE <- as.numeric(model$stderr)
t <- as.numeric(model$statistic)
df <- as.numeric(model$parameter)
p <- as.numeric(model$p.value)
round(c(Diff=MD,SE=SE,t=t,df=df,p=p),3)
}
### Confidence Interval Plot Functions
.ciPlot <- function(results,main,ylab,xlab,mu){
plot(results[,1],xaxt='n',xlim=c(.5,nrow(results)+.5),ylim=c(floor(min(results[,2])/2)*2,ceiling(max(results[,3])/2)*2),xlab=xlab,cex.lab=1.3,ylab=ylab,main=main,las=1,cex=1.5,pch=16,bty="l")
axis(1, 1:nrow(results), row.names(results))
for (i in 1:nrow(results)) lines(x=c(i,i),y=c(results[,2][i],results[,3][i]),lwd=2)
for (i in 1:nrow(results)) text(i,results[,1][i],results[,1][i],cex=.8,pos=2,offset=.5,font=2)
for (i in 1:nrow(results)) text(i,results[,2][i],results[,2][i],cex=.8,pos=2,offset=.5)
for (i in 1:nrow(results)) text(i,results[,3][i],results[,3][i],cex=.8,pos=2,offset=.5)
if (!is.null(mu)) {abline(h=mu,lty=2)}
}
.diffPlot <- function(results,graph,main,ylab,xlab){
plot(c(1,2,3),graph[,1],xaxt="n",xlim=c(.4,3.6),ylim=c(floor(min(graph[,2])/2)*2,ceiling(max(graph[,3])/2)*2),pch=c(16,16,17),cex=1.5,xlab=xlab,ylab=ylab,main=main,las=1,cex.lab=1.3,bty="l")
axis(1,at=c(1,2,3),labels=rownames(graph))
for (i in 1:3) lines(x=c(i,i), y=c(graph[,2][i],graph[,3][i]),lwd=2)
for (i in 1:2) text(i,graph[,1][i],graph[,1][i],cex=.8,pos=2,offset=.5,font=2)
for (i in 1:2) text(i,graph[,2][i],graph[,2][i],cex=.8,pos=2,offset=.5)
for (i in 1:2) text(i,graph[,3][i],graph[,3][i],cex=.8,pos=2,offset=.5)
text(3,graph[,1][3],results[,1][3],cex=.8,pos=4,offset=.5,font=2)
text(3,graph[,2][3],results[,2][3],cex=.8,pos=4,offset=.5)
text(3,graph[,3][3],results[,3][3],cex=.8,pos=4,offset=.5)
arrows(1,graph[1,1],4.5,graph[1,1],code=3,length=0,lty=2)
arrows(2,graph[2,1],4.5,graph[2,1],code=3,length=0,lty=2)
if(results[1,1]<results[2,1]) {td <- graph[1,1]-axTicks(4)[max(which(axTicks(4)<graph[1,1]))]}
if(results[1,1]>=results[2,1]) {td <- graph[1,1]-axTicks(4)[min(which(axTicks(4)>graph[1,1]))]}
val <- axTicks(4)-graph[1,1]+td
loc <- axTicks(4)+td
axis(4,at=loc,labels=val,las=1)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.