0% found this document useful (0 votes)
3 views3 pages

Statistics Problem Set with R Solutions

The document is a problem set focusing on statistics using R programming. It includes tasks such as creating vectors, calculating statistical measures, and analyzing datasets from the MASS package. The document also covers probability calculations related to widget inspections and student test scores.

Uploaded by

Trinh Lê
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Statistics Problem Set with R Solutions

The document is a problem set focusing on statistics using R programming. It includes tasks such as creating vectors, calculating statistical measures, and analyzing datasets from the MASS package. The document also covers probability calculations related to widget inspections and student test scores.

Uploaded by

Trinh Lê
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

---

title: '4.18 Problem Set: Statistics'


author: 'Trinh Le'
---
[Link] three vectors of numbers. For each, print the vector, the mean, the median, the
variance, and the standard deviation.
[Link] 1 should have the mean and median equal.
```{r}
vector1 <- c(5, 5, 5, 5, 5, 5)
print(vector1)
mean(vector1)
median(vector1)
var(vector1)
sd(vector1)
```

[Link] 2 should have the mean greater than the median.


```{r}
vector2 <- c(1, 2, 3, 100)
print(vector2)
mean(vector2)
median(vector2)
var(vector2)
sd(vector2)
```

[Link] 3 should have the mean less than the median.


```{r}
vector3 <- c(1, 2, 3, -100)
print(vector3)
mean(vector3)
median(vector3)
var(vector3)
sd(vector3)
```
[Link] R to solve each of the following problems.
[Link] head of quality control stops by a factory to inspect the next 20 widgets produced.
Over the past six months, 98% of widgets have passed inspection. What is the probability
that less than 10 widgets pass inspection?
```{r}
pbinom(9, size = 20, prob = 0.98)
```

[Link] average test score in a large college statistics course with multiple sections is 85
and the standard deviation is five points. If you choose a student at random, what is the
probability that their score is between 80 and 85?
```{r}
mean_score <- 85
sd_score <- 5
pnorm(85, mean = mean_score, sd = sd_score) - pnorm(80, mean = mean_score, sd = sd_score)
```

[Link] the past three years at the farm you manage, the watermelons average about nine
pounds each with a standard deviation of two pounds. What is the probability that a
watermelon randomly selected from your harvest will weigh more than 10 pounds?
```{r}
mean_weight <- 9
sd_weight <- 2
pnorm(10, mean = mean_weight, sd = sd_weight, [Link] = FALSE)
```

[Link] manage a help desk. 90% of your tickets are resolved with the first reply. If you
randomly select 10 tickets for review, what is the probability that all 10 were resolved
with the first reply?
```{r}
pbinom(10, size = 10, prob = 0.90, [Link] = TRUE)
```

[Link] the MASS package, import the dataset “immer.”


```{r}
library(MASS)
data(immer)
head(immer)
#The immer dataset records the yield of barley at two locations over two years with two
varieties.
str(immer)
summary(immer)
```
[Link] the documentation and describe the dataset in your own words.
```{r}
#The immer dataset records the yield of barley at two locations over two years with two
varieties.
```
[Link] this data tidy? If not, tidy it and print the tidy dataset. Save your tidy dataset in
a variable and work with it through the rest of the problem set.
```{r}
#The data is tidy.
```
[Link] any tools that you like in R to answer the following questions.
[Link] values are present in the location variable? How many rows are there for each
value?
```{r}
table(immer$Loc)
```
[Link] values are present in the variety variable? How many rows are there for each
value?
```{r}
table(immer$Var)
```
[Link] many years are represented in the dataset? How many rows are there for each year?
```{r}
table(immer$Y1)
```
[Link] is the mean yield?
```{r}
mean(immer$Y2)
```
[Link] is the first quartile, median, and third quartile for yield?
```{r}
quantile(immer$Y2, probs = c(0.25, 0.50, 0.75))
```
[Link] are the minimum and maximum values for yield?
```{r}
min(immer$Y2)
max(immer$Y2)
```
[Link] are the variance and standard deviation for yield?
```{r}
var(immer$Y2)
sd(immer$Y2)
```
[Link] two boxplots for yield.
[Link] first boxplot should have bars that extend from the minimum to the maximum.
```{r}
boxplot(immer$Y2, main = "Boxplot: Min to Max")
```
[Link] second boxplot should have bars that extend from (Q1 - 1.5 x IQR) to (Q3 + 1.5
x IQR).
```{r}
Q1 <- quantile(immer$Y2, 0.25)
Q3 <- quantile(immer$Y2, 0.75)
IQR <- Q3 - Q1
lower_limit <- Q1 - 1.5 * IQR
upper_limit <- Q3 + 1.5 * IQR

boxplot(immer$Y2, range = 1.5, main = "Boxplot: IQR Range")


```
[Link] the MASS package, import the dataset “[Link].”
```{r}
library(MASS)
data("[Link]")
head([Link])

str([Link])
summary([Link])
```
[Link] the documentation and describe the data in your own words.
```{r}
#The [Link] dataset records the health information - including glucose, age, blood
pressure, and other health metrics
```
[Link] the data tidy? If not, tidy it.
```{r}
#The data is tidy
```
[Link] a loop that calculates and prints the mean of each numeric variable.
```{r}
for (col in names([Link])) {
if ([Link]([Link][[col]])) {
cat("Mean of", col, ":", mean([Link][[col]]), "\n")
}
}
```

You might also like