Question

Function is as below: calculateMeanVar <- function(x) { x_mean <- mean(x) x_var <- var(x) return(data.frame(xmean =...

Function is as below:

calculateMeanVar <- function(x) {

x_mean <- mean(x)

x_var <- var(x)

return(data.frame(xmean = x_mean, xvar = x_var))

}

Now, test you function on the petal length of iris data set (Built in data set in R):

- Include standard error in the function

- Include the standard error in the output of the function (i.e., in the return() portion).

Homework Answers

Answer #1

Rcode:

to get the standard error=standard deviation/sqrt(sample size),use sd function and length function.

calculateMeanVar <- function(x) {
  
x_mean <- mean(x)
  
x_var <- var(x)
x_sd <- sd(x)
x_len <- length(x)
x_SE <- x_sd/sqrt(x_len)
  
return(data.frame(xmean = x_mean, xvar = x_var,xSE=x_SE))
  
}

To test the above function on iris petal length:

calculateMeanVar(iris$Petal.Length)

Output:

petal length standard error=0.144136

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Suppose that the return of stock A is normally distributed with mean 4% and standard deviation...
Suppose that the return of stock A is normally distributed with mean 4% and standard deviation 5%, the return of stock B is normally distributed with mean 8% and standard deviation 10%, and the covariance between the returns of stock A and stock B is −30(%)2 . Now you have an endowment of 1 dollar, and you decide to invest w dollar in stock A and 1 − w dollar in stock B. Let rp be the overall return of...
Below is the R output of a study of ACT scores for the first year of...
Below is the R output of a study of ACT scores for the first year of college students. This helps to see if the test scores can predict a GPA. Simply put, this ACT helps to be an explanatory var and GPA would be a response var. Call: Im(formula = GPA ~ ACT, data = gpadata) Residuals: Min 1Q Median 3Q Max -2.74004 -0.33827 0.04062 0.44064 1.22737 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept) 2.11405 .32089 6.588 1.3e-09 ***...
Write an R function that will simulate 2 data sets from gamma distributions (``rgamma'' function, this...
Write an R function that will simulate 2 data sets from gamma distributions (``rgamma'' function, this gives us skewed samples) then does a standard t-test comparing the 2 means (``t.test'' function) and returns the p-value. The function should have 2 sample sizes and 2 sets of parameters as input. Now use the function to simulate a case with small sample sizes and the null hypothesis being true (equal means) and see how the type I error rate is affected by...
1.) A sample of 125 campus students who responded to a questionnaire had a mean age...
1.) A sample of 125 campus students who responded to a questionnaire had a mean age of 22.0 and a standard deviation of 5.0. The mean hypothesized population age for all campus students is 25.0. a)  Set up the hypothesis (one sample t test) for these data at the 95% confidence level. Be sure to include the null hypothesis and alternative hypothesis in your response. b) Compute the t test statistic for these data. c) Are you able to reject the...
Solve the following problem using the MATLAB environment Write a function [approx_root, num_its] = bisection(f,a,b,tol) that...
Solve the following problem using the MATLAB environment Write a function [approx_root, num_its] = bisection(f,a,b,tol) that implements the bisection method. You function should take as input 4 arguments with the last argument being optional, i.e, if the user does not provide the accuracy tol use a default of 1.0e-6 (use varargin to attain this). Your function should output the approximate root, approx_root and the number of iterations it took to attain the root, num_its. However, if the user calls the...
Use the data below to estimate the mean x ̄ and standard deviation s. If you...
Use the data below to estimate the mean x ̄ and standard deviation s. If you put list data into your calculator, write down the lists you used. Tar (mg) in cigarettes Frequency 10–13 14–17 18–21 22–25 26–29 Frequency 2 1 14 8 3
Question Set 2: Mean Test Score A course coordinator is examining scores on an exam. In...
Question Set 2: Mean Test Score A course coordinator is examining scores on an exam. In a representative sample of 35 students, the mean Test score was 87.9 points with a standard deviation of 6.8 points. A. Use Minitab Express to determine if there is evidence that the mean Test score is different from 90 points in the population of all test takers. Use the five-step hypothesis testing procedure outlined below. Remember to include all relevant Minitab Express output and...
For the data set shown​ below, complete parts​ (a) through​ (d) below. x 3 4 5...
For the data set shown​ below, complete parts​ (a) through​ (d) below. x 3 4 5 7 8 y 4 7 8 12 13 (a) Find the estimates of β0 and β1. β0 ≈b0 = ____ ​(Round to three decimal places as​ needed.) β1 ≈b1 = ____ (Round to three decimal places as​ needed.) ​(b)  Compute the standard​ error, the point estimate for σ. se= ______ ​(c)  Assuming the residuals are normally​ distributed, determine sb1 . Sb1= _____ (d) ​Assuming...
Question 10 Please answer the following set of questions, based on the information provided below. The...
Question 10 Please answer the following set of questions, based on the information provided below. The data listed below give information for 10 middle-level managers at a particular company. The first column is years of experience [X] and the second column is annual salary (in thousands) [Y]. We are going to examine the relationship between salary in thousands [Y] and years of experience[X]. Below is the regression output. Manager#     (X)     (Y) 1 xx 66 2 xx 69 3...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop...
STRICT DOWNVOTE IF NOT DONE FULLY, WILL REPORT ALSO IF COPY PASTED OR MODIFIED ANSWER Develop a class, using templates, to provide functionality for a set of recursive functions. The functions specified as recursive must be written recursively (not iterativly). The UML class specifications are provided below. A main will be provided. Additionally, a make file will need to be developed and submitted. ● Recursion Set Class The recursion set template class will implement the template functions. recursionSet -length: int...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT