knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>" 
)
library(MATH4752Projects1)

Introduction

This package consist of four functions and a file named fire. The three functions are, mybin which makes a table and barplot for a binomial simulation. The Myf function makes a square root function. The myci function returns a 95% confidence interval. Lastly the myncurve function makes normal curve probability and shades the required area.

mybin

mybin=function(iter=100,n=10, p=0.5){

sam.mat=matrix(NA,nr=n,nc=iter, byrow=TRUE)

succ=c() for( i in 1:iter){

sam.mat[,i]=sample(c(1,0),n,replace=TRUE, prob=c(p,1-p))

succ[i]=sum(sam.mat[,i])

}

succ.tab=table(factor(succ,levels = 0:n))

iter.lab =paste0("iter =", iter) n.lab = paste0("n = ", n) p.lab = paste0("p =", p) lab= paste(iter.lab,p.lab,sep = ", ")

barplot(succ.tab/(iter), col=rainbow(n+1), main="Binomial simulation", xlab="Number of successes") succ.tab/iter }

myf

myf=function(x){ x^2 }

myci

myci<- function(x){ n<-length(x) std <- sd(x) t<-qt(1-0.05/2,n-1) mp <- c(-1,1) mean(x)+ mptstd/sqrt(n)

}

mycurve

myncurve = function(mu, sigma, a){ bottom=mu-3sigma top=mu+ 3sigma curve(dnorm(x,mean=mu,sd=sigma), xlim = c(bottom, top)) xcurve=seq(bottom,a,length=1000) ycurve=dnorm(xcurve,mean=mu,sd=sigma) polygon(c(bottom,xcurve,a),c(0,ycurve,0),col="Red")

prob=pnorm(a,mean=mu,sd=sigma)-pnorm(bottom,mean=mu,sd=sigma) prob=round(prob,4) text(a,dnorm(a,mu,sigma), paste0("Area = ", prob,sep=""))

}



Vert0000/MATH4752Projects1 documentation built on Dec. 31, 2020, 5:40 p.m.