How do I count thee? Let me count the ways?

How easily can you be identified on the Internet?

How easily can you be identified on the Internet? Suppose you finish your meal at a restaurant, you are about to pay the check, and t...

Tuesday, April 21, 2020

“Those who can, do; those who can’t – use computer simulation.”

          “Those who can, do; those who can’t – use computer simulation.” This quote was inspired by playwright George Bernard Shaw. Computer simulation is a powerful tool that attempts to reproduce the behavior of some real-world system by sampling from one or more probability distributions. It can help explain and illustrate difficult concepts such as the Monty Hall game show problem. It can also solve problems that are hard or impossible to solve directly.

          One example of a problem of this latter type is the probability distribution of the sum of n independent random variables each having probability distribution g, where n is also a random variable having probability distribution f. This is a special case of a statistical subject called convolutions, where one calculates the convolution of all possible values of the individual distributions. For certain choices of f and g, such as Poisson for f and gamma for g, the resulting convolution is an integrateable function and there is no need for simulation. But for many choices of f and g, simulation or some other numerical method is needed.

          A real-world use of this type of simulation is in modeling loss events of a business entity such as a bank or insurance company. The entity will have some random number of events n per year of random sizes that is modeled by a frequency distribution f such as Poisson or negative binomial. A number n is randomly selected from the frequency distribution. Then n random numbers are randomly selected from a severity distribution g such as lognormal or gamma to simulate the sizes of the n loss events. The n loss amounts are added to produce a total value of losses for one year. The process is repeated some large number of times, say 10,000, and the 10,000 numbers are ranked. If the entity is interested in the 99.9th percentile such loss, that value is the 9,990th largest value.

          Base R provides functions to simulate from many probability distributions. For example, rpois(n, lamda) produces n Poisson distributed samples from a distribution having population mean lambda. Poisson is a single parameter distribution with variance equal to the mean. An alternative frequency distribution with a more flexible option for the variance is the negative binomial distribution. Its R function is rnbinom(n, mu, size) which produces n negative binomial distributed samples from a distribution having population mean mu and dispersion parameter size, where size = mu^2 / (variance – mu).

          Most severity distributions are not symmetrical but rather are positively skewed with low mean and long positive tail. A random variable is lognormally distributed if the logarithm of the random variable is normally distributed. Its R function is rlnorm(n, meanlog, sdlog) which produces n lognormally distributed samples from a distribution having population mean m and standard deviation s, and here meanlog = LN(m) – .5*LN((s/m)^2 + 1)) and sdlog = .5*LN((s/m)^2+1)).

          It is helpful to plot the resulting histogram of the 10,000 simulations. The real-world purpose of the exercise may be to identify the 99.9th percentile value. The R quantile function quantile(x, probs) returns the percentile value equal to probs. To display the percentile value on a plot, use the text and arrow functions. R has a text function that adds text a plot, text(x, y, label), which adds a label at coordinate (x,y). Further, R has an arrows function, arrows(x0, y0, x1, y1, code=2), which draws an arrow from (x0, y0) to (x1, y1) with code 2 drawing the arrowhead at (x1, y1).

          The following is the R code and resulting histogram plot of a negative binomial frequency and lognormal severity simulation. The user input values are based on the mean and standard deviation values of a dataset.

# Monte Carlo simulation. Negative binomial frequency, lognormal severity.
# negbinom
nb_m <- 50 # This is a user input.
nb_sd <- 10 # This is a user input.
nb_var <- nb_sd^2
nb_size <- nb_m^2/(nb_var – nb_m)
# lognorm
xbar <- 60 # This is a user input.
sd <- 40 # This is a user input.
l_mean <- log(xbar) – .5*log((sd/xbar)^2 + 1)
l_sd <- sqrt(log((sd/xbar)^2 + 1))
num_sims <- 10000 # This is a user input.
set.seed(1234) # This is a user input.
rtotal <- vector()
for (i in 1:num_sims)
{
nb_random <- rnbinom(n=1, mu=nb_m, size=nb_size)
l_random <- rlnorm(nb_random, meanlog=l_mean, sdlog=l_sd)
rtotal[i] <- sum(l_random)
rtotal <- sort(rtotal)
m <- round(mean(rtotal), digits=0)
percentile_999 <- round(quantile(rtotal, probs=.999), digits=0)
print(paste(“Mean = “, m, ” 99.9th percentile = “, percentile_999))
hist(rtotal, breaks=20, col=”red”, xlab=”Annual Loss”, ylab=”Frequency”,
main=”Monte Carlo Simulation”)
text(percentile_999, 100, “99.9th Percentile”)
arrows(percentile_999,75, percentile_999,0, code=2)

8 Crayola Crayons

Many of my friends know I am color-challenged. Not colorblind; I see some colors, just not as many as most people see. I don't recall always being this way. In my earliest elementary school years I had a box of 8 Crayola crayons, and I did just fine. My problems began when Crayola started adding more and more colors including combinations like green yellow and yellow green. With nothing better to do, I just wrote a little program in R, and here are the original eight colors, which I still identify just fine. There is no meaning to the heights of the bars.

title <- c("Original 8 Crayola Crayons")
subtitle <- c("According to https://en.wikipedia.org/wiki/History_of_Crayola_crayons")
temp <- c(5,7,6,4,8,5,2,5) # meaningless
colors <- c("red", "yellow", "blue", "green", "orange", "brown", "violet", "black")
hex <- c("#FF0000", "#FFFF00", "#0000FF", "#008001", "#FF6600", "#964B00", "#6A0DAD", "#000000")
barplot(temp, col=hex, main=title, sub=subtitle, names.arg=colors)

Wednesday, July 4, 2018

Math in the news
Every July 1 there will be something in the news on the New York Mets paying retired baseball player Bobby Bonilla $1.19 million per year, even though he last played for the Mets in 1999.

The Mets released him in 1999, but they still owed him $5.9 million in 2000 for the last year of a 5-year contract. The Mets and his agent negotiated a deal where the Mets would pay him 25 deferred payments of $1,193,248 per year starting in 2011 and ending in 2035. This was calculated at an 8% interest rate. The Mets were willing to do this because they thought they were earning 12% to 15% on investments with Bernie Madoff which turned out to be fictional.

From Bonilla’s viewpoint these 25 payments of $1,193,248 per year, deferred 10 years from 2001, has a present value equal to the $5.9 million he otherwise was due: (1/1.08^10) * 1193248 * (1 - 1.08^-25)/.08 equals 5.9 million, so at 8% interest this was a fair deal for him. At today’s low interest rates, 8% looks pretty high. From the Mets’ viewpoint, even if they only earned 10%, the present value is $4.2 million, which is lower than the $5.9 million they originally owed him. Of course the Mets did not earn 10% on their Madoff investment.

These formulas appear in many math and finance textbooks under the subject of math and finance. Accountants were no doubt involved in the negotiations. I just want to suggest that math and accounting are sometimes in the news.

Tuesday, July 25, 2017

Hi.

A high school Social Studies teacher may have a degree in History, but may be called upon to teach Economics, Business Law, Personal Finance, Sociology, Psychology, Criminal Science, or whatever subjects fall under Social Science, despite having little or zero background in that subject. We just assume the teacher will learn what he or she needs.

A high school or college Math teacher may have a degree in Math, but that doesn't mean he or she has taken every possible Math course. College Geometry? Finite Math? Statistics? Cryptography? A Math teacher may be called upon to teach one of these, despite having little or zero background in that subject. We just assume the teacher will learn what he or she needs.

So when a small college puts Accounting in its Math department, and decides that Accounting will fulfill a student's Math requirement, is it so surprising that the college will ask a Math teacher to teach Accounting? They did, and I am.

I did take a semester of college Accounting, decades ago. I have worked in my non-academic career with accountants. And trust me, Accounting 1 is not rocket science. So I am teaching Accounting.

The part that bothers me is that unlike the claim I make when I teach Math, I do not have a passion for Accounting.

Any comments? Would you agree to teach Accounting?

Monday, January 2, 2017

Math is hard.  Although so is putting on eyeliner - not that I've done a lot of that.




Hi.  Something not discussed in my various teacher trainings is normalizing the difficulty of an exam.  In teaching a course for the first time, I borrow another teacher's exams, and then I try to create mine that seem about equal in difficulty.  But how difficult is my exam, and is it the appropriate level of difficulty?  For a gen ed community college math course, I sort of think the very best student should get close to 100, and the class average ought to be about 75.  Of course this assumes students attend nearly every class, pay attention in class, take notes in class, do the assigned homework, etc.; assumptions that have not been exactly true in my classes.  Maybe this also assumes I am a decent teacher.  I have been curving my exams about 15 points to account for the fact that maybe my exams were too hard, and I was perhaps not the most effective teacher. Hopefully I will improve my exam creation with experience and curve less in the future.

Friday, October 30, 2015

Why do I have to study math?

     “Why do I have to study math? I’ll never use it.”
      I’m sure every math teacher has heard this question. It’s not easy to answer. I have heard several possible answers, but I’m not completely satisfied with any of them. I have a somewhat different reply, which I learned from - of all people - an English teacher.
      One possible answer is how important math is in the real world. Each of us has our favorite real world problems that illustrate the importance of math. But these problems seem contrived, and are not the problems ordinary people encounter. The book When Are We Ever Gonna Have to Use This contains math examples from nearly 100 occupations, but most of these merely use arithmetic or pre-algebra.
      Another possible answer is that many occupations require math, and a student limits his future options by avoiding math. My reply is that most students are not going to choose such occupations.       A third possible answer is that math helps us to think logically. But many people who are quite logical thinkers and good problem solvers know minimal math. If the purpose is to teach logical thinking, maybe we should teach logic.
      Here is my reply, which I discovered during a team project in an education course. I was teamed with an English teacher, and we were trying to find some common ground between us. To my surprise, she explained that when she analyzes a poem, she searches for various patterns in the poem.
      Searching for patterns? As the math person, I thought I had exclusive rights on searching for patterns. But then I came to an epiphany: We’re all searching for patterns. The toddler who tries to learn which behaviors will elicit attention. The physician who tries to investigate the cause of an illness (think of the TV show “House”), who is similar to the police detective who tries to solve a series of crimes. The art critic and the movie critic. (I once heard a movie critic explain that when the major character travels across a bridge, there is about to be a personality change.) The plumber who searches for the leak. I’m sure you can think of many others.
      We are all searching for patterns in life, and we do this with our own unique lens on we how we view the world. As math people we look for quantitative patterns. It seems to me that the more tools we have to discover patterns, the richer our lives are. I think students should study math to give them one more tool in their toolbox to discover life’s patterns.

Saunders, H. 1988. When Are We Ever Gonna Have to Use This. White Plains, NY: Dale Seymour Publications.

Sunday, April 26, 2015

Math is math, except in social science

"So how are the eggs?" "Eggs are eggs." "Eggs are eggs. That is very profound. By the same token, couldn't you say fish is fish? I don't think so." 

So goes a Seinfeld dialog.  Similarly Sigmund Freud is alleged to have said, "Sometimes a cigar is just a cigar," although researchers question whether he really said it.

And by the same logic, math is math, whether it is taught in high school or college, a 2 year community college or a 4 year college, etc. Right?  I found a counter-example of this in statistics.

I recently taught an intro to statistics class in a psychology department using a statistics book for the behavioral sciences.  This book defines the sample standard deviation for descriptive purposes as SX with an N denominator while defining the sample standard deviation for inferential purposes as sX with an N-1 denominator.  I found a second statistics book for behavioral sciences that agrees with this.

Is there a recent textbook in the math or statistics world that defines the sample standard deviation with an N denominator?  I haven't seen it.  And not only will the student of this psychology class find this definition conflicts with the math world, but she will also find (and did find) it conflicts with the Excel world, not only for the Excel standard deviation function but for the Excel statistics Data Analysis add-in functions.

Why can't we all just get along?