Saturday, September 30, 2023

LIS4273 - Module 6 Assignment

 For this assignment, I will be answering the following questions:

A.

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

For the four parts of the question, I will embed each of the sub questions within the following R code.

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.

When it comes to determining if sample proportion p has an approximate normal distribution, it is important that we refer to the Central Limit Theorem which states that the larger the given sample size, the greater the chance that the sample proportion will have a normal distribution. Additionally, it is often said that if the population proportion is very close to 0 or 1, there is a higher likelihood that there must be larger sample size for there to be a normal distribution.

Given that the sample size n is 100 and the population proportion p is 0.95, this sort of scenario should be suitable enough to render a normal distribution. However, to assure that there is straight normality, a larger sample size would be needed to achieve an approximate normal distribution.

Let's break this idea down mathematically:

Using the above values, let’s solve for np and nq and determine whether it is greater than 10 for the distribution to be normal.

np = 100 * 0.95 = 95

nq = 100 * (1 – 0.95) = 5

Only np is greater than 10 so we can conclude that this may not exactly be a normal distribution. While these circumstances may not be completely unreasonable, if precision is prioritized then a larger sample size is needed.

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

To answer this question, I must preface that there is no one-size-fits-all answer when it comes achieving the smallest possible value for n for which the sampling distribution is normal. Typically, the smallest value of n is dependent on the population proportion and the desired level of approximation. Many sources have suggested n to be greater than 10 but determining the best value varies depending on the population distribution and how close p is to 0 or 1.

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) / 5 (5 represents the number of values in the set)

B. Sample of size n = 5

C. Mean of sample distribution = 11.8

We can put together some samples using some R code:

 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

Here's a little hint

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

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 = 95

q * n = .05 * 100 = 5

It is often said that there must be some kind of benchmark or value to determine normality. To have a reasonably decent normal distribution, we can refer to classic Central Limit Theorem guidelines that state that np and nq should be greater than or equal to 10. Seeing that nq is not greater than 10, this tells us that the sample proportion does not have an approximately normal distribution. What can be taken away from this is that more information is needed based on the precision level and context to determine that this is a reasonable enough normal distribution.

C.

From our textbook, Chapter 2 Probability Exercises # 2.4 Simulated coin tossing is probability better done using function called rbinom than using function called sample. Explain.

Comparing the functions rbinom and sample, we can immediately see that in the parameters taken in by rbinom, it is better equipped to handle something like a simulated coin toss as contrasted with sample. From the textbook and this week’s lecture slides, the binomial distribution maintains constant probability with each trial and these trials are always independent. Furthermore, rbinom is more suited to handle complex statistical scenarios where there are multiple trials or varying levels of probabilities for each trial. From a functional standpoint, rbinom is much more powerful as sample is a bit more general in its function.

~ Katie

Thursday, September 21, 2023

LIS4273 - Module 5 Assignment

 For this post, I will be answering the following questions.

Question 1:

The director of manufacturing at a cookie factory needs to determine whether a new machine is production a particular type of cookies according to the manufacturer's specifications, which indicate that cookies should have a mean of 70 and standard deviation of 3.5 pounds. A sample pf 49 of cookies reveals a sample mean breaking strength of 69.1 pounds.

A. State the null and alternative hypothesis

B. Is there evidence that the machine is not meeting the manufacturer's specifications for average strength? Use a 0.05 level of significance.

C. Compute the p value and interpret its meaning.

D. What would be your answer in (B) if the standard deviation was specified at 1.75 pounds?

E. What would be your answer in (B) if the sample mean was 69 pounds and the standard deviation was 3.5 pounds?

Answer:

A. Null hypothesis: The new machine is making a particular type of cookie according to the manufacturer's specifications with the mean breaking strength of 70 pounds.

    Alternative hypothesis: The new machine is NOT making a particular type of cookie according to the manufacturer's specifications with the mean breaking strength of 70 pounds.

We can write the null and alternative hypothesis as follows:


The hypotheses correspond to a two-tail test.

B. Using the values that were given to us, we must compute the test statistic to determine if there is evidence that the machine is not meeting manufacturer’s specifications.

The formula for the test statistic is as follows:

Where x bar refers to the sample mean 69.1, μ is the mean or in this case, 70. The sigma in the denominator is the standard deviation or 3.5 and n will be represented by the sample of 49 cookies. The calculation can be performed as follows: 69.1 – 70 / (3.5 / sqrt(49)) = -1.8

We must now determine the critical values at the 0.05 level of significance and we can use R to calculate this now that we have the test statistic.

The output tells us that the p_value is 0.07186064. We fail to reject the null hypothesis because there is no evidence that the machine is not meeting specifications.

C. Compute the p value and interpret its meaning.

We can calculate the p_value using this code:

The p_value is 0.07186064 and we can understand from the value that it is greater than the significance level of 0.5 or alpha so we must fail to reject the null hypothesis.

D. What would be your answer in (B) if the standard deviation were specified as 1.75 pounds?

Given different results for the test statistic (-3.6) and the p-value (0.0003182172), we would reject the null hypothesis.

E. What would be your answer in (B) if the sample mean were specified as 69 pounds and the standard deviation is 3.5 pounds?

Given different results for the test statistic (-2) and the p-value (0.04550026), we would reject the null hypothesis.

Question 2:

If x̅ = 85, σ = standard deviation = 8, and n=64, set up 95% confidence interval estimate of the population mean μ.

Answer:

Looking at the 95% confidence interval, it is important to note that the z-score will be 1.96. 1.96 will be our margin of error. With these values in mind, we can plug these values into the following equation to determine the range within which the true population mean will fall given a certain level of confidence.


At the 95% confidence interval, the population mean μ lies within the range of 83.04 to 86.96.

Question 3:

Use dataset found in week 5 folder.

The accompanying data are: x = girls, y = boys (goals, time spend on assignment)

A. Calculate the correlation coefficient for this dataset

Through the provided code from the question we generate the plot of the dataset. but we also generate a matrix of the correlation coefficient to determine the value.

Correlation matrix:

When we compare girls and boys in terms of time spent and goals, we immediately see that there is extremely high correlation. Boy goals and Girl goals are practically 1 to 1 and time spent is pretty high up there with the value of 0.9991175.

B. Pearson correlation coefficient

To calculate the Pearson correlation coefficient, we can use the following code:

Looking at the output, we can say the Pearson correlation coefficient is 1

C. Create plot of the correlation

Executing this code, brings up the following plot that shows us where these values are from a numeric perspective.


If we were to change out panel.cor for panel.shade we can see the high correlation shading in action:

~ Katie


Wednesday, September 13, 2023

LIS4273 - Module 4 Assignment

 For this week's post, I will be answering the following questions.

Question 1:

Based on Table 1, what is the probability of:

B

B1

A

10

20

A1

20

40

A1: Event A

Answer: P(A) = matching outcomes / total outcomes => 30 / 90 => 1 / 3

A2: Event B

Answer: P(B) = matching outcomes / total outcomes => 30 / 90 => 1 / 3 

A3: Event A or B

Answer: 

Using the Addition Rule: P(A OR B) = P(A) + P(B) - P(A AND B)

                                                                    1/3 + 1/3 - P(A AND B)

                                                                    2/3 - P(A AND B)

Using the Independent Events Rule: P(A AND B) = P(A) * P(B)

                                                                                    1/3 * 1/3

                                                                                    1/9

P(A OR B) = 2/3 - 1/9

                   = 5/9

A4: P(A OR B) = P(A) + P(B)

Answer: The above statement is false. Under this context, 5/9 does not equal 2/3.


Question 2:

B. Applying Bayes' Theorem

Jane is getting married tomorrow, at an outdoor ceremony in the desert. In recent years, it has rained only 5 days each year. Unfortunately, the weatherman has predicted rain for tomorrow. When it actually rains, the weatherman correctly forecasts rain 90% of the time. When it doesn't rain, he incorrectly forecasts rain 10% of the time. 

What is the probability that it will rain on the day of Jane's wedding?

Solution: The sample space is defined by two mutually-exclusive events - it rains or it does not rain. Additionally, a third event occurs when the weatherman predicts rain. Notation for these events appears below. 

Event A1: It rains on Jane's wedding.

Event A2: It does not rain on Jane's wedding.

Event B. The weatherman predicts rain.

In terms of probabilities, we know the following:

P(A1) = 5/365 =0.0136985 [It rains 5 days out of the year.]

P(A2) = 360/365 = 0.9863014 [It does not rain 360 days out of the year.]

P(B|A1) = 0.9 [When it rains, the weatherman predicts rain 90% of the time.]

P(B|A2) = 0.1 [When it does not rain, the weatherman predicts rain 10% of the time.]

We want to know P(A1|B), the probability it will rain on the day of Marie's wedding, given a forecast for rain by the weatherman. The answer can be determined from Bayes' theorem, as shown below.

P(A1|B) = P(A1) P(B|A1)

P(A1) P(B|A1) + P(A2) P(B|A2)

P(A1|B) = (0.014)(0.9) / [ (0.014)(0.9) + (0.986)(0.1) ]

P(A1|B) = 0.111

Note the somewhat unintuitive result. Even when the weatherman predicts rain, it only rains only about 11% of the time. Despite the weatherman's gloomy prediction, there is a good chance that Marie will not get rained on at her wedding.

B1. Is this answer true or false?

Answer: true

B2. Please explain why?

Tracing back to the formula used to determine the probability of whether it will rain on the day of Jane’s wedding day as predicted by the weatherman, one must simply review the above calculations to see that the chance of rain is quite unlikely. The chance of rain is only 11% while there is an 89% percent chance of it not raining on Jane’s wedding day.

To break this down further, let’s look at the variables used in the Bayes' Theorem which can be expressed as follows:


While the given variables do look a bit different than the provided example, the theorem still applies. So, let’s gather up the necessary variables.

P(A) => P(A1) => 5/365 => 0.0136985

P(B|A) => P(B|A1) => 0.9

P(B) contains a few more variables than usual so let’s break this down. The formula for P(B) as provided is:

P(B) = [P(A1)P(B|A1) + P(A2)P(B|A2)]

P(B) = [(0.014)(0.9) + (0.986)(0.1)]

P(B) = 0.1109589041

Bringing it all together:

(0.0136985)(0.9) / 0.1109589041

0.01232865 / 0.1109589041

= 0.1111100556

In conclusion, we can see that indeed, there is only a 11% percent probability of it raining on Jane’s wedding day and while there is a small chance, there is greater chance of it NOT raining than raining.

Question 3:

C. For a disease known to have a postoperative complication frequency of 20%, a surgeon suggests a new procedure. She/he tests it on 10 patients and found there are not complications. What is the probability of operating on 10 patients successfully with the traditional method?

A hint, use dbinom function - it is part of R functions that count Density, distribution function, quantile function, and random generation for the binomial distribution with parameters size and prob.

You will answer the question with

dbinom(XXX, size=XXX, prob=XXX)

Answer:

dbinom(0, size = 10, prob = 0.2)

The result is 0.1073742

~ Katie Burkhart

Tuesday, September 5, 2023

LIS4273 - Module 3 Assignment

 For this assignment, I will be examining the following two sets of data that each consist of 7 observations.

Set #1: 10, 2, 3, 2, 4, 2, 5

Set #2: 20, 12, 13, 12, 14, 12, 15

For these sets, I will compute the mean, median, and mode under Central Tendency as well as compute the range, interquartile, variance, and standard deviation under Variation. Lastly, I will compare the results between Set #1 and Set #2 by discussing the differences between the two sets.

Question 1:

Compute the mean, median, and mode under Central Tendency for both sets.

Set #1

Set #2

Question 2:

Compute the range, interquartile, variance, and standard deviation under Variation for both sets.

Set #1

Set #2

Question 3:

Compare the results between Set #1 and Set #2 by discussing the differences between the two sets.

To begin this discussion about the differences between Set1 and Set2, we can first see differences beginning to arise when we look at the results of Set1's and Set2's mean and median. Naturally, these two sets will render differing results because the vectors contain different values and are thus, not alike. 

Moving on to the mode, Set1 and Set2 are both classified as numeric by R because it seems R was unable to find a mode in either dataset. 

As for the range, both Set1 and Set2 produce differing results because once again, the two datasets contain different numeric values. In other words, the largest value in Set1 is 10 while the largest value in Set2 is 20. However, when we subtract the max value from the min values in both Set1 and Set2, both datasets result in a range of 8. 

Transitioning to the interquartile and variance calculation, we can note that the outputs of both sets are identical. Lastly, with the standard deviation of Set1 and Set2, the outputs are once again identical.

~ Katie

Monday, August 28, 2023

LIS4273 Module 2 Assignment (New)

For this assignment, I will evaluate the function myMean and the variable assignment which contains a vector of numeric values. Due to some inconsistencies between the Module 2 assignment text and Module 2 example code, I will evaluate the code described in the assignment text as well as the example code and their associated outputs.

Assignment text input:

# A vector of numeric values assigned to assignment

assignment <- c(6, 18, 14, 22, 27, 17, 19, 22, 20, 22)

myMean <- function(assignment2){

  return(sum(assignment2) / length(assignment2))

}

Output:

Assignment example code input:

# Missing the value 19 from the vector and called assignment2 rather than assignment

 assignment2 <- c(6, 18, 14, 22, 27, 17, 22, 20, 22)

myMean <- function(assignment2) {return(sum(assignment2)/length(assignment2))}

Output:

To describe what the function assignment2 does, we can see that it is an argument passed through the function. When we call the myMean function and insert the variable assignment or assignment2, it returns the simple mean of the chosen vector variable. The myMean function takes in a vector as input, and returns the sum of the vector values divided by the length of the vector.

Below are the following outputs of assignment text and assignment example code if we were to call the function and insert a variable to perform a calculation. 

Assignment text input:

myMean(assignment)

Output:

Assignment example code input:

myMean(assignment2)

Output:

As you can see, the outputs vary because the assignment vector contains the value 19 and holds 10 values as compared to the assignment2 vector containing only 9 values and is missing the value 19.

~ Katie 

Sunday, August 20, 2023

LIS 4370 R Programming - sentimentTextAnalyzer2 Final Project

For this class's major final project, I set out to make the process of analyzing textual files and URL links for sentiment insights much...