3-function factory 3.txt - HW3 Normal distribution factory 1 Set the random seed to zero and save the random seed vector to `seed`(hint use the command

3-function factory 3.txt - HW3 Normal distribution factory...

This preview shows page 1 - 2 out of 2 pages.

#' HW3: Normal distribution factory #' #' 1. Set the random seed to zero and save the random seed vector to `seed`. (hint: use the command `seed <- .Random.seed`). ## Do not modify this line! set.seed(0) seed<-.Random.seed #' 2. Write a function `norm_factory` that takes as input two arguments `mu` and `var` and returns a function #' that takes a number `n` as argument and returns `n` samples from a normal distribution with mean `mu` and #' variance `var`. Use `rnorm` to simulate the sampling. #' Note: you should use `force()` in `norm_factory`. ## Do not modify this line! norm_factory<-function(mu,var){ force(mu) force(var) function(n){ return(rnorm(n,mean=mu,sd=sqrt(var))) } } #' 3. Use `norm_factory` to create two functions allowing to sample from distributions with the following #' characteristics: #' - `d0_1`: from a normal distribution with mean zero and standard deviation 1 #' - `d0_2`: from a normal distribution with mean zero and standard deviation 2 #' Then, use the two functions to generate two vectors of 1000 samples from each distributions, #' and store them respectively in `s0_1` and `s0_2`.
Image of page 1
Image of page 2

You've reached the end of your free preview.

Want to read both pages?

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask You can ask ( soon) You can ask (will expire )
Answers in as fast as 15 minutes