  We calculate the mean and variance of sums of the M\"obius function and the
indicator function of the squarefrees, in both short intervals and arithmetic
progressions, in the context of the ring of polynomials over a finite field of
$q$ elements, in the limit $q\to \infty$. We do this by relating the sums in
question to certain matrix integrals over the unitary group, using recent
equidistribution results due to N. Katz, and then by evaluating these
integrals. In many cases our results mirror what is either known or conjectured
for the corresponding problems involving sums over the integers, which have a
long history. In some cases there are subtle and surprising differences. The
ranges over which our results hold is significantly greater than those
established for the corresponding problems in the number field setting.
