If you spin the spinner, on which color is it least likely to land on? Use a Monte Carlo simulation to aid in solving the problem.
Spinner <- c("Blue","Yellow","Green","Yellow","Blue","Red","Green")
N <- 1e5 # 100,000 trials
Spins <- sample(x = Spinner,size = N,replace = T)
Probabilities <- prop.table(table(Spins))
Probabilities
## Spins
## Blue Green Red Yellow
## 0.28716 0.28590 0.14063 0.28631
What is the cube root of -343?
# install.packages("pracma")
library(pracma)
answer <- nthroot(x = -343,n = 3)
cat("The cube root of -343 is:",answer,"\n")
## The cube root of -343 is: -7
The length of time (in hours) that nine similar candles burned were: \([9.8,9.7,9.1,9.2,9.9,9.1,9.7,10.2,8.8]\). The manufacturers claim that the average burn time is 10 hours. Assuming that the times are a random sample from a Normal distribtion with population mean \(\mu\), carry out a two-tailed test at the 1% level of significance using the following null and alternative hypotheses: \(H_0: \mu = 10\), \(H_1: \mu \neq 10\).
nine_candles <- c(9.8,9.7,9.1,9.2,9.9,9.1,9.7,10.2,8.8)
t.test(nine_candles,mu = 10,conf.level = 0.01)
##
## One Sample t-test
##
## data: nine_candles
## t = -3.235, df = 8, p-value = 0.01197
## alternative hypothesis: true mean is not equal to 10
## 1 percent confidence interval:
## 9.498001 9.501999
## sample estimates:
## mean of x
## 9.5
Find the roots and graph \(f(x) = 3x^2 + 4x - 7\).
# install.packages(c("rootSolve","tidyverse"))
library(rootSolve)
##
## Attaching package: 'rootSolve'
## The following objects are masked from 'package:pracma':
##
## gradient, hessian
library(tidyverse)
## Warning: package 'lubridate' was built under R version 4.5.2
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.1 ✔ stringr 1.5.2
## ✔ ggplot2 4.0.0 ✔ tibble 3.3.0
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.1.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ purrr::cross() masks pracma::cross()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
f <- function(x) {
3 * x^2 + 4 * x - 7
}
roots <- uniroot.all(f,c(-10,10))
for (x in seq_along(roots)) {
cat("Root:",x,":",roots[x],"\n")
}
## Root: 1 : 1
## Root: 2 : -2.33328
x_values <- seq(-3,1.75,length.out = 500)
y_values <- f(x_values)
q4_data <- data.frame(x = x_values,y = y_values)
ggplot(q4_data,aes(x = x,y = y)) +
geom_line(col = "black",lwd = 1.25) +
annotate("point",x = roots[1],y = f(roots[1]),col = "blue",size = 5) +
annotate("point",x = roots[2],y = f(roots[2]),col = "blue",size = 5) +
labs(title = "Graph of f(x) = 3x^2 + 4x - 7",
caption = paste("Roots:",round(roots[1],2),"and",round(roots[2],2)),
x = "x",
y = "y") +
theme_gray(base_size = 14)
What is \(\int \frac{1}{x} dx\)?
# install.packages(c("ggformula","mosaicCalc"))
library(ggformula)
## Warning: package 'ggformula' was built under R version 4.5.2
## Loading required package: scales
##
## Attaching package: 'scales'
## The following object is masked from 'package:purrr':
##
## discard
## The following object is masked from 'package:readr':
##
## col_factor
## 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
g <- makeFun(1 / x ~ x)
anti_g <- antiD(g(x) ~ x)
anti_g
## function (x, C = 0)
## log(x) + C