R {base} has four built-in functions to generate normal distribution. We will first try these functions to explore the properties of a normal distribution.
dnorm() gives height of the probability distribution at each point for a given mean and standard deviation, i.e. a PDF.
seq(), create a vector called x which contains a sequence of numbers between -10 and 10 incrementing by 0.2.dnorm(), create a vector called y which contains a series of probability density values along the vector x, with a mean of 2.5 and a standard deviation of 0.5.x and y.pnorm() gives the probability of a normally distributed random number to be less than the value of a given name, i.e. a CDF.
x which contains a sequence of numbers between -10 and 10 incrementing by 0.2.pnorm(), create a vector called y which contains a series of cumulative distribution probability along the vector x, with a mean of 2.5 and a standard deviation of 0.5.x and y.qnorm() takes the probability value and gives a number whose cumulative value matches the probability value.
x which contains a sequence of values from the minimum to the maximum, incrementing by 0.02.qnorm(), choose the mean as 2 and standard deviation as 3, and store this vector to y.x and y.qnorm(0.85, mean = 2, sd = 3) to find.rnorm() can be used to generate random numbers whose distribution is normal.
rnorm(), create a vector called x which contains a sample of 50 numbers which are normally distributed.x. Choose a smaller bin size to visualise the distribution better.x.density(), create a vector called d which contains the probability density values for x. Plot d.We will examine some real-world data that is roughly normal distributed and understand the properties of a normal distribution.
The following data contain measurements of diameter growth rate of the tropical tree Dipteryx panamensis from a long-term study at La Selva, Costa Rica. The data are log-transformed, with the original units in milimetres.
read.csv(), make sure the argument header is set to TRUE.plot(), plot the data. Add an appropriate title and axis labels.shapiro.test(), test the above hypothesis statistically.The crab spider sits on flowers and preys upon visiting honeybees. Do honeybees distinguish between flowers that have crab spiders and flowers that do not? To test this, researchers gave 33 bees a choice between two flowers: one had a crab spider and the other did not. In 24 of the 33 trials, the bees picked the flower that had the spider. In the remaining 9 trials.
rbinom(1000, 33, 24/33), plot the histogram of 1,000 trials using hist().rnorm(), simulate a normal distribution with 1,000 observations with the appropriate normal approximation from 6c to the spider data.hist(), plot the normal distribution. Do 6b and 6e look similar?