Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use Rstudio thanks Q3 [3 points] 1. Calculate 3= 1 4-143-1 y+z 3 points] 2. Use

ID: 3879868 • Letter: U

Question

Use Rstudio thanks

Q3 [3 points] 1. Calculate 3= 1 4-143-1 y+z 3 points] 2. Use R to find all the prime numbers between 20 and 50. (Prime numbers: can be divided evenly only by 1 or itself.) [4 points] 3. Create a function that returns the elements on odd positions in a vector 4 points] 3. Create a Input: a vector Output: a vector of the elements only on odd positions Use the vector in your first question as an example and show the results. (5 points] 4. Create a function to calculate the confidence intervals. This function should be able to handle small data sets (n = 30 using normal distribution). Input: a data set; alpha (confidence level) Output: confidence interval (lower boundary and upper boundary) Given the following sample data of battery life: 491, 485, 503, 492, 482, 487, 490, 485, 495, 502 calculate the 95% confidence interval of the mean battery life.

Explanation / Answer

CODE TO COPY

1) Calculate the value of expression

value = 0                           # value to store sum
for(i in 1:3){                      # Z loop
for(j in 1:4){                    # y loop
    for(k in 1:j){                  # x loop
      value = value + exp(k)/(i+j)      # expression sloving and updating value
    }
}
}

print(value)

2) Print prime numbers between 20 to 50

is.prime <- function(n) n == 2L || all(n %% 2L:ceiling(sqrt(n)) != 0)    # prime number checker function

for(i in 20:50){                # running loop from 20 to 50
if(is.prime(i)){              # check if number is prime
    print(i)
}
}

3) Function that returns odd position elements

odd.position <- function(vector) {        #function declaration
i=1
while(i<=length(vector)){               #looping till the length of the vector
    print(i)                                         # printing the value
    i = i+2                                         # incrementing the loop index by 2.
}
}

4) Function that returns confidence intervals


confidence.intervals <- function(data,alpha){
n = length(data)         ## size of the data
mean = mean(data)        ## mean of the data
alpha = alpha/100        ## confidenece level
sd = sd(data)            ## standard deviation of data
error=0
if(n >= 30){    ## normal distribution
    error = qnorm(alpha+0.025)*sd/sqrt(n) # standard error
}
else{    ## t distribution
    error = qt(alpha+0.025,df=n-1)*sd/sqrt(n) # standard error
}
left = mean - error    # lower bound of interval
right = mean + error   # upper bound of interval
res = c(left,right)
print(res)
}

confidence.intervals(c(491,485,503,492,482,487,490,485,495,502),95)

If you have any doubts about my answer, please let me know in the comments so that i can help.