To calculate the z score in R, we need to first find the mean and standard deviation of the variable of interest. Then, we can calculate the z score by subtracting the mean from the observed value and dividing by the standard deviation. Here is an example code:
299 chars13 lines
In this example, we generated 100 random values from a normal distribution with mean 50 and standard deviation 10. Then, we calculated the mean and standard deviation of the sample. Finally, we calculated the z score for an observation of 55 using the formula and printed the result (which should be 0.5).
gistlibby LogSnag