total possible number of assignments \[k^n \]
\[\frac{(k-j+1)^n - (k-j)^n}{k^n}\]
From wikipedia
## caclulate probability with cdf equation
p=.1
q=.9
k=8
paste("probability that the machine will fail after 8 years using gemoetric distribution is", 1-q^(k+1))## [1] "probability that the machine will fail after 8 years using gemoetric distribution is 0.612579511"
## compare using geometric function
paste("compare probability using geom function",pgeom(8, 0.1))## [1] "compare probability using geom function 0.612579511"
## solve for expected value
paste("expected value is", 1/p)## [1] "expected value is 10"
##solve for sd
paste("Standard deviation equals",sqrt(q/p**2))## [1] "Standard deviation equals 9.48683298050514"
From wikipedia
## find probability
lambda_1 <- .1
x=8
my_prob <- 1- exp(-lambda_1*x)
paste("probability that the machine will fail after 8 years using exponential distribution is", my_prob)## [1] "probability that the machine will fail after 8 years using exponential distribution is 0.550671035882778"
## compare using exponential function
paste("compare probability using exponential function",pexp(8, 0.1))## [1] "compare probability using exponential function 0.550671035882778"
## solve for expected value
paste("expected value is", 1/lambda_1)## [1] "expected value is 10"
##solve for sd
paste("Standard deviation equals",sqrt(1/lambda_1**2))## [1] "Standard deviation equals 10"
## Sovle for probability
n <- 8
k <- 0
p <- .1
q <- .9
my_prob <- choose(n,k)*p^k*(q)^(n-k)
paste("probability that the machine will fail after 8 years using binomial distribution is", my_prob)## [1] "probability that the machine will fail after 8 years using binomial distribution is 0.43046721"
## compare using binomial function
paste("compare probability using geom function",pbinom(0,8,.1))## [1] "compare probability using geom function 0.43046721"
## solve for expected value
paste("expected value is", n*p)## [1] "expected value is 0.8"
##solve for sd
paste("Standard deviation equals",sqrt(n*p*(1-p)))## [1] "Standard deviation equals 0.848528137423857"
Our hint tells us to assume p has x=0 successes in first 8 years
For our homework discussion I already built the poisson so I copy pasted the distribution function from there
## calculate probability
find_lambda <- function(probability,N){
N*(probability)
}
poisson_prob <- function(lambda,x_occurences){
poisson_prob <- (lambda**(x_occurences)*exp(1)**(-lambda))/(factorial(x_occurences))
return(poisson_prob)
}
probability <- 1/10
N=8
x_occurences <- 0
my_lambda <- find_lambda(probability,N)
my_poisson_probability <- poisson_prob(lambda=my_lambda,x_occurences)
paste("My poisson lambda is",my_lambda," and the probability of ",x_occurences," failures in",N," years is ",my_poisson_probability)## [1] "My poisson lambda is 0.8 and the probability of 0 failures in 8 years is 0.449328964117222"
## compare iwth poisson function
ppois(.1,.8)## [1] 0.449329
## Expected value
paste("expected value is",my_lambda)## [1] "expected value is 0.8"
## SD
paste("Std deviation is",sqrt(my_lambda))## [1] "Std deviation is 0.894427190999916"