knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
library(MATH4753bird0023)
This package is a collection of functions that I have used over the course of the MATH 4753 course.
There are two data frames stored in this package.
The first is fire
, which is about fire damage. It has 15 observations of fire damage. There are two variables, the distance in miles from a fire station and the amount of damage caused in thousands of dollars.
head(fire)
The second is DDT
, which is about DDT contamination in fish. There are six variables: the river the fish was caught in, the distance from the river mouth the fish was caught, the fish's species, the length of the fish in centimetres, the weight of the fish in grams, and the DDT in the fish in parts per million.
head(ddt)
This function graphs a binomial distribution, iterated a certain number of times, given the size and success probability of a binomial distribution. It illustrates what it means for a binomial distribution to have 'successes' and 'failures'.
mybinomial(iter=10000, n=20, p=0.3)
This function bootstraps a confidence interval, given a distribution, the confidence level (alpha), and a statistic to estimate. For example, a 95% confidence interval of the mean, given a normally distributed sample, is:
sam <- rnorm(10, mean = 5, sd = 2) myboot(iter = 10000, sam, fun = "mean", alpha = 0.05)
This function demonstrates the central limit theorem by sampling a Poisson distribution a certain number of times and displaying a distribution of the sample means. By the central limit theorem, the distribution of these means will be approximately normal.
par(mar=c(2,2,2,2)) mycltp(n = 5, iter = 10000, lambda = 5)
The first function added to this package. Very simply returns the working directory.
mygetwd()
Uses the method of maximum likelihood to estimate a parameter passed to the function. Requires a log likelihood function, a vector of prior outcomes, and the parameter that gets passed to the distribution (p, (\lambda), etc.)
mymaxlik(function (x, param) log(dbinom(x, prob=param, size=20)), c(1,2,3,4), seq(0,1,length=1000))
A visual representation of pnorm
. For a normal distribution (Y \sim N(\mu, \sigma)), this function will give a visual representation of (P(Y \leq a)). Displays a graph and also returns the calculated value.
myncurve(mu = 10, sigma = 2, a = 8)
This function combines a histogram and a scatterplot.
with(fire, scatterhist(x = DISTANCE, y = DAMAGE, xlab = "Distance (mi)", ylab = "Damage ($'000)"))
This creates a ggplot of length vs weight of a species in the DDT dataset, colour-coded by river.
myddt(ddt, "CCATFISH")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.