Module # 6 assignment

Issaiah  Jennings 
Module # 6 assignment
Consider a population consisting of the following values, which represents the number of ice cream purchases during the academic year for each of the five housemates.
8, 14, 16, 10, 11
a. Compute the mean of this population.


> # Population data

> population <- c(8, 14, 16, 10, 11)

> # Population mean

> population_mean <- mean(population)

> population_mean

[1] 11.8


b. Select a random sample of size 2 out of the five members. See the example used in the Power-point presentation slide # 13.

c. Compute the mean and standard deviation of your sample.
d. Compare the Mean and Standard deviation of your sample to the entire population of this set (8,14, 16, 10, 11).

> # Sample data

> sample_data <- c(8, 14)

> # Sample mean

> sample_mean <- mean(sample_data)

> # Calculate the squared differences from the mean

> squared_diff <- (sample_data - sample_mean)^2

> # Sample variance (n-1 in the denominator because it's a sample)

> sample_variance <- sum(squared_diff) / (length(sample_data) - 1)

> # Sample standard deviation (square root of the variance)

> sample_sd <- sqrt(sample_variance)

> # Print the results

> cat("Sample Mean:", sample_mean, "\n")

Sample Mean: 11 

> cat("Sample Variance:", sample_variance, "\n")

Sample Variance: 18 

> cat("Sample Standard Deviation:", sample_sd, "\n")

Sample Standard Deviation: 4.242641 

B. 

Suppose that the sample size n = 100 and the population proportion p = 0.95.

  1. Does the sample proportion p have approximately a normal distribution? Explain.


> # Given values

> n <- 100

> p <- 0.95

> q <- 1 - p

> # Check np and nq

> np <- n * p

> nq <- n * q

> np

[1] 95

> nq

[1] 5

> # The sample proportion has a normal distribution if np > 5 and nq > 5

> np >= 5 && nq >= 5  # This will return TRUE if both conditions are satisfied

[1] TRUE

  1. What is the smallest value of n for which the sampling distribution of p is approximately normal?  

 # Given proportion p <- 0.95 q <- 1 - p # q is 1 - p # Minimum n for np >= 5 and nq >= 5 n_p_min <- 5 / p n_q_min <- 5 / q # Output the smallest value of n for both np and nq conditions n_p_min n_q_min



The sample mean from a group of observations is an estimate of the population mean μ. Given a sample of size n, consider n independent random variables X1, X2, ..., Xn, each corresponding to one randomly selected observation. Each of these variables has the distribution of the population, with mean μ  and standard deviation σ.
A. Population mean= (8­­+14+16+10+11)/__
B. Sample of size n= ___
C. Mean of sample distribution: ____
sample 1=
sample 2=
sample 3 and so on and so forth…
And Standard Error Qm=Q/square root of n=4.4/square root of 5=
D. I am looking for table with the following variables X, x=u, and
(x-u)^2

The sample size n = 100 and the population proportion p = 0.95.

1.Does the sample proportion p have approximately a normal distribution?
The distribution is expected to be normal if both np and nq are greater...... (your turn) 
Since p = .95, q = .05. 
p * n = .95 * 100 = ......

q * n = .05 * 100 = ......

Yes it does p = 0.95 has a normal distribution because both statement np=955 and nq=55  are greater than or equal to 5 which 


> # Population data

> population <- c(8, 14, 16, 10, 11)

> population_mean <- mean(population)

> # Calculate (X - mu)^2

> deviation_squared <- (population - population_mean)^2

> # Create a data frame (table)

> table <- data.frame(X = population, 

+                     Mean = population_mean, 

+                     `(X - Mean)^2` = deviation_squared)

> print(table)

   X Mean X.X...Mean..2

1  8 11.8         14.44

2 14 11.8          4.84

3 16 11.8         17.64

4 10 11.8          3.24

5 11 11.8          0.64


C.

From our textbook, Chapter 3: Probability Exercises # 3.4 (pg. 65 on 2nd Edition)
Simulated coin tossing: is probability better done using function called rbinom than using function called sample?  Explain.

> # Simulate 10 coin tosses with rbinom

> tosses_rbinom <- rbinom(10, size = 1, prob = 0.5)

> print("Coin Tosses using rbinom:")

[1] "Coin Tosses using rbinom:"

> print(tosses_rbinom)

 [1] 1 1 1 0 1 1 0 0 1 0

> # Simulate 10 coin tosses with sample

> tosses_sample <- sample(c(0, 1), size = 10, replace = TRUE, prob = c(0.5, 0.5))

> print("Coin Tosses using sample:")

[1] "Coin Tosses using sample:"

> print(tosses_sample)

 [1] 1 1 1 0 1 1 0 0 1 0

The rbinom function is designed to simulate binomial random variables. When simulating coin tosses, it models how often we get heads in a specified number of trials, each with two possible outcomes heads or tails.

> # P(X > 3) for standard normal distribution

> p_a <- 1 - pnorm(3)

> # P(X > 42) for normal distribution with mean=35 and sd=6

> p_b <- 1 - pnorm(42, mean = 35, sd = 6)

> # P(X = 10) for binomial distribution with n=10 and p=0.8

> p_c <- dbinom(10, size = 10, prob = 0.8)

> # P(X < 0.9) for standard uniform distribution

> p_d <- punif(0.9)

> # P(X > 6.5) for chi-squared distribution with df=2

> p_e <- 1 - pchisq(6.5, df = 2)

> # Simulate 200 trials with probability of success 0.5

> result <- rbinom(1, size = 200, prob = 0.5)

> # Print results

> print(p_a)

[1] 0.001349898

> print(p_b)

[1] 0.1216725

> print(p_c)

[1] 0.1073742

> print(p_d)

[1] 0.9

> print(p_e)

[1] 0.03877421

> print(result)

[1] 96

Comments

Popular posts from this blog

The Final project in this class

Module # 8 Assignment