Archive

Archive for August, 2011

Nice R Interface

August 30, 2011 Leave a comment

This week I’m introducing R to two different classes, one is a probability class to secondary-ed math majors and the second is a Bayesian course. Recently I learned about a nice R interface called RStudio.

I’ve included a screenshot below (you first install R and then RStudio and then launch the RStudio application).

What’s so special about RStudio?

1.  RStudio partitions the screen into four sections.  The bottom left is the Console window, the top left window shows R scripts, the top right window shows all the workspace variables, and the bottom right displays the help output and any plots.  I like that you can see all parts of R at once.

2.  It has a nice interface for importing data.  One clicks on an Import Dataset button and it steps the user through the process of reading in datasets from a file or from a web location.

3.  It is user friendly when one types in commands.  It automatically completes left parentheses and brackets.  Also it has a nice Code Completion — when you hit the tab key it will give you different options for completing the typing.  Also it gives you a glimpse into the arguments of the particular function typed.

I’m sure there are more nice features.  But I found RStudio easy to use and I’ve been using it all of the time the past few months.

 

Advertisements
Categories: R work

Bayes Rule in R

August 28, 2011 Leave a comment

On Friday, I gave several examples of Bayes’ rule in class. I’ll do a slight generalization of the testing for a disease example to illustrate using a special R function bayes to do the calculations.

This special function can be read into R directly from my web site.

> source("http://personal.bgsu.edu/~albert/MATH6480/R/bayes.R")

This function has three inputs prior, likelihood, and data.

1. The prior. Here there are two models — either we have the disease (D) or we don’t (not D) — and suppose that the probability of D is only 0.0001. prior is a vector of probabilities, where we give names to the two values:

> prior = c(D = .0001, not.D = 1 - .0001)

2. The likelihood. Here the data is the test result (pos or neg) where the test result is incorrect with probability 0.01. We’ll specify the likelihood as a matrix where each row of the matrix gives the probability of pos and neg for each model.

> like.D = c(pos=.99, neg=.01)
> like.not.D = c(pos=.01, neg=.99)
> likelihood = rbind(D = like.D, not.D = like.not.D)
> likelihood
pos neg
D 0.99 0.01
not.D 0.01 0.99

3. data is a vector of data values. Suppose we get a positive test result (pos). Then

> data="pos"

So we enter as inputs prior, likelhood, and data — the output is a matrix — the first row gives the prior probs and the second row gives the posterior probabilities.

> bayes(prior, likelihood, data)

D not.D
prior 0.000100000 0.9999000
pos 0.009803922 0.9901961

Although the positive blood test result is “bad news”, it is still very unlikely that you have the disease.

Categories: Bayes rule

Increasing popularity of Bayesian thinking

August 23, 2011 Leave a comment

It is remarkable to see the growth in the development and use of Bayesian methods over my academic lifetime. One way of measuring this growth is to simply count the number of Bayesian papers presented at meetings. In Statistics, our major meeting is JSM (Joint Statistical Meeting) that is held each summer in a major U.S. city. I pulled out the program for the 1983 JSM. Scanning through the abstracts, I found 18 presented papers that had Bayes in the title. Looking at the online program for the 2011 JSM, I found 58 sessions where Bayes was in the title of the session and typically a session will include 4-5 papers. Using this data, I would guess that there were approximately 15 times as many Bayesian papers presented in 2011 than in 1983.

Another way of measuring the growth is to look at the explosion of Bayesian texts that have been recently published. At first, the Bayesian books were more advanced with limited applications. Now there are many applied statistics books that illustrate the application of Bayesian thinking in many disciplines like economics, biology, ecology, and the social sciences.

Categories: General

Welcome to MATH 6480 – Fall 2011

August 19, 2011 Leave a comment

Welcome to MATH 6480 Bayesian Statistical Analysis. I’ll be using this blog to help you with Bayesian computation (specifically R examples) and helping you with general issues that come up in this course.

g(\theta|y) \propto g(\theta) \times L(\theta)

Categories: General