Question 1

\[\text{Spinner} = [\text{Red},\text{Blue},\text{Green},\text{Red},\text{Blue},\text{Yellow},\text{Green}]\]

Given the spinner above, construct a table of probabilities of each color using a Monte Carlo simulation.

set.seed(123) # for reproducibility
spinner <- c("Red","Blue","Green","Red","Blue","Yellow","Green")
simulation <- sample(x = spinner,size = 1e6,replace = T) # 1e6: 1 million trials
probabilities <- prop.table(table(simulation))
probabilities
## simulation
##     Blue    Green      Red   Yellow 
## 0.285767 0.285770 0.285954 0.142509

Question 2

Ten volunteers took part in a trial of a food that the manufacturer claimed would help people to lose weight. At the end of the trial, nine of them had lost \([7,1,2,1,0.5,1,0.5,0,1.5]\) kg and one of them gained 1 kg. Assuming that the weight losses are a random sample from a Normal distribution with population mean \(\mu\), carry out a two-tailed t-test at the 5% level of significance using the following null and alternative hypotheses: \(H_0: \mu = 0\) and \(H_1: \mu \neq 0\).

weight_losses_gains <- c(-7,-1,-2,-1,-0.5,-1,-0.5,0,-1.5,1) # -(number): weight loss, +(number): weight gain
t.test(weight_losses_gains,mu = 0,conf.level = 0.05,alternative = "two.sided")
## 
##  One Sample t-test
## 
## data:  weight_losses_gains
## t = -1.9875, df = 9, p-value = 0.07811
## alternative hypothesis: true mean is not equal to 0
## 5 percent confidence interval:
##  -1.393796 -1.306204
## sample estimates:
## mean of x 
##     -1.35

Question 3

What is \(\int \sin(x) dx\)?

# install.packages(c("ggformula","mosaicCalc"))
library(ggformula)
## Warning: package 'ggformula' was built under R version 4.5.2
## Loading required package: ggplot2
## Loading required package: scales
## Loading required package: ggiraph
## Warning: package 'ggiraph' was built under R version 4.5.2
## Loading required package: ggridges
## Warning: package 'ggridges' was built under R version 4.5.2
## 
## New to ggformula?  Try the tutorials: 
##  learnr::run_tutorial("introduction", package = "ggformula")
##  learnr::run_tutorial("refining", package = "ggformula")
library(mosaicCalc)
## Warning: package 'mosaicCalc' was built under R version 4.5.2
## Registered S3 method overwritten by 'mosaic':
##   method                           from   
##   fortify.SpatialPolygonsDataFrame ggplot2
## 
## Attaching package: 'mosaicCalc'
## The following object is masked from 'package:stats':
## 
##     D
f <- makeFun(sin(x) ~ x)
anti_f <- antiD(f(x) ~ x)
anti_f
## function (x, C = 0) 
## C - cos(x)