CS代写 title: “Probability Distributions”

title: “Probability Distributions”
output: html_document

“`{r setup, include=FALSE}

Copyright By PowCoder代写 加微信 powcoder

knitr::opts_chunk$set(echo = TRUE)

##generating random numbers

#uniform distribution

num_trials = 10000

xUnif <- 1:10000 yUnif <- runif(num_trials, start, stop) plot(xUnif,yUnif) hist(yUnif, breaks = 30, ylim = c(0,1000)) y <- as.data.frame(yUnif) sumUnif <- as.data.frame(y %>% group_by(cut(yUnif, breaks = 100)) %>% summarize(count = n()))
sumUnif$cum <- cumsum(sumUnif$count) barplot(sumUnif$count, ylim = c(0,200)) barplot(sumUnif$cum, ylim = c(0,10000)) ##Normal distribution std_dev = 5 xNorm <- 1:10000 yNorm <- rnorm(num_trials, mean, std_dev) plot(xNorm, yNorm) hist(yNorm, breaks = 30, ylim = c(0,1000)) y <- as.data.frame(yNorm) sumNorm <- as.data.frame(y %>% group_by(cut(yNorm, breaks = 100)) %>% summarize(count = n()))
sumNorm$cum <- cumsum(sumNorm$count) barplot(sumNorm$count, ylim = c(0,500)) barplot(sumNorm$cum, ylim = c(0,10000)) #Exponential Distribution xExp <- 1:10000 ## We will come back to exponential distribution in queuing models. ## There, lambda is the rate of occurrences per unit of time or, alternatively worded ## the expected time in between customers (say, 1 customer every half hour). ## 1/lambda is therefore the expected number of occurrences in the time interval (2 customers expected in one hour) lambda = .5 yExp <- -1* (1/lambda) * log(runif(10000, 0, 1)) mean(yExp) plot(xExp,yExp) y <- as.data.frame(yExp) sumExp <- as.data.frame(y %>% group_by(cut(yExp, breaks = 100)) %>% summarize(count = n()))
sumExp$cum <- cumsum(sumExp$count) barplot(sumExp$count, ylim = c(0,1000)) barplot(sumExp$cum, ylim = c(0,10000)) ##simulating a linear model xModel <- runif(100,1,50) eModel <- rnorm(100,0, 10) Slope <- 2 Intercept <- 20 yModel <- Intercept + Slope * xModel + eModel plot(xModel, yModel) OLS <- lm(yModel ~ xModel) summary(OLS) abline(OLS$coefficients[1], OLS$coefficients[2]) 程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com