Expectations for Continuous Distributions

We can also compute the expected values of continuous distributions numerically. You should be aware that in many cases these can be done analytically: that's part of what you study in a calculus course.

The basic idea is that we can approximate areas under curves by adding up the areas of simple approximating polygons, like rectangles or trapezoids. You might find it intriguing to know that the normal distribution was invented as an approximation to the area under the histogram of the binomial distribution, ie. approximating the sum of the areas of a lot of rectangles by the area under a smooth curve!

Let's use this apparently crude method to compute the area under a standard normal curve (which should be eactly 1.0!). If we divide the range into intervals of length .1, then each little rectangle has base .1 and height equal to the height of the normal density in the interval. Of course the density is changing as we move through each interval, but we can use the height of the density at the midpoints of the intervals. Start by generating the sequence of midpoints:

	z <- seq(-4,4,.1)
	p <- dnorm(z)
	sum(p*.1)
We have approximated the area under the normal curve by the areas under rectangles of width .1 and height roughly equal to the height of the normal curve in the interval. It works pretty well. In essence this is like approximating the normal distribution by a finite discrete distribution on the set of values -4.0, -3.9, -3.8, ..., 4.0. For example, the value in z[46] defined is .5, the probability associated with it is .1*p[45], or about .037. We know how to compute the expected value of this discrete distribution already, just multiply the values by their probabilities and sum them!
	m <- sum(z*p*.1)
You won't get exactly 0, but something like -6.751869e-17, which is computer notation for -6.751869*10^(-17). In other words, 0 except for rounding error.

Variances

We can compute variances in the same way. Treat the midpoints of the intervals as the possible values, find the mean as above, then compute the average squared deviation from the mean exactly as you would for a discrete distribution.
	sum( p*.1*(z-m)^2)


Math 141 Index
Introduction to S

Albyn Jones
August 2004