Survey on Durham’s LGBTQIA needs

The LGBTQ Center of Durham (North Carolina) and local residents were recently invited by Durham County Department of Public Health to help identify and describe the dynamic health needs of Durham’s LGBTQIA community. On July 5th we brainstormed some of the major health issues facing the community and we want to hear from from Durham residents about whether we’re on the right track. Below is a link to a survey that we are urging Durham, NC residents to take. Results will help inform what topics we will discuss.

As a back story, every 3 years the Health Department, in association with Partnership for a Healthy Durham (where I volunteer), produces a Community Health Assessment (CHA). For the first time there will be a LGBTQIA section in the CHA. While we identified issues we thought were important, we wanted to hear Durham’s opinion to see if our issues were in concordance with the broader community’s issues.

Create a random list generator in R that runs multiple times

We are often showing participants different stimuli that are randomly ordered to prevent ordering effects. To randomize the stimuli we often used’s list randomizer, but a current limitation of their site is you can only randomize a list once. So, for instance, if we were testing 4 stimuli with four people, we would need to use to randomize that list four different times.

Here is some simple code to create a random list generator that will resample a list as many times as you want. You enter the number of items in your list, the number of times you want to draw down your entire list, and define the items in your list. The code below puts the list items into a single column and then prints the results to a CSV file. The example code has 4 items in the list and will randomize those 4 items 2 separate times. Sampling is done without replacement.

# Enter the number of items in your list
x <- 4

#Enter the number of times you want the list to run
r <- 2

#Add the items that are in your list. Add to or remove the number of items if necessary
mylist <- c('Item 1','Item 2','Item 3','Item 4')

#Below is the randomizer
randommatrix <- matrix(nrow=x,ncol=r)
for (i in 1:r)
y <- x*r
randommatrixlist <- matrix(randommatrix,nrow=y,ncol=1)

#Optional: Print your randomization list to a CSV file. Delete the "#" to activate

Continue reading “Create a random list generator in R that runs multiple times”

Create a formatted contingency table for Word using R

One of the bigger challenges I have had with R is getting output into a shareable format. There are helpful packages, such as gmodels, that can produce nice-looking contingency tables in the console, but getting the results out of the console and into Word is difficult. For example, gmodels can produce a table like this…

   Cell Contents
|                       N |
| Chi-square contribution |
|           N / Row Total |
|           N / Col Total |
|         N / Table Total |

Total Observations in Table:  248 

                 | infert$induced 
infert$education |         0 |         1 |         2 | Row Total | 
          0-5yrs |         4 |         2 |         6 |        12 | 
                 |     1.232 |     0.506 |     9.898 |           | 
                 |     0.333 |     0.167 |     0.500 |     0.048 | 
                 |     0.028 |     0.029 |     0.162 |           | 
                 |     0.016 |     0.008 |     0.024 |           | 
         6-11yrs |        78 |        27 |        15 |       120 | 
                 |     1.121 |     1.059 |     0.471 |           | 
                 |     0.650 |     0.225 |     0.125 |     0.484 | 
                 |     0.545 |     0.397 |     0.405 |           | 
                 |     0.315 |     0.109 |     0.060 |           | 
         12+ yrs |        61 |        39 |        16 |       116 | 
                 |     0.518 |     1.627 |     0.099 |           | 
                 |     0.526 |     0.336 |     0.138 |     0.468 | 
                 |     0.427 |     0.574 |     0.432 |           | 
                 |     0.246 |     0.157 |     0.065 |           | 
    Column Total |       143 |        68 |        37 |       248 | 
                 |     0.577 |     0.274 |     0.149 |           | 

…which is nice, but doesn’t work well for Word.

I found this wonderful solution as suggested by David Gohel in this forum comment post. (David is also the author of the ReporteRs package).

Continue reading “Create a formatted contingency table for Word using R”

Traveler Preferences for Reporting During the 2014-2016 Ebola Epidemic

During the 2016 National Conference on Health Communication, Marketing and Media, I presented with my colleagues a poster titled “Traveler Preferences for Reporting to State and Local Public Health Authorities as Part of Post-Arrival Monitoring During the 2014-2016 Ebola Epidemic”. The poster examined how travelers arriving from countries with Ebola outbreaks reported (e.g. by phone, text) their temperature and symptoms to public health authorities versus how they wanted to report. We also examined if there was an association between how someone reported and their self-reported compliance with post-arrival monitoring.

State and local public health departments would find the results salient as they prepare for intaking reporting data from the public for future epidemics that require monitoring.

You can view the poster here.

Williams, P., Macom, J., Johnson, M., Zulkiewicz, B., Taylor, O., Ray, S., … Southwell, B. (2016). Traveler Preferences for Reporting to State and Local Public Health Authorities as Part of Post-Arrival Monitoring During the 2014-2016 Ebola Epidemic. Presented at the National Conference on Health Communication, Marketing, and Media, Atlanta, GA.

HIV Primer Videos for Public Health and Medical Audiences

This summer I took the PUBH 725 course at the UNC School of Public Health that dealt with HIV topics. While I work on HIV topics often for my public health research job, I still found the class quite interesting.

The lectures have been posted publicly for anyone to view. If you are interested in HIV I think you’ll enjoy these videos. If you have time for only one video, I would watch the Myron Cohen video from Week 5. The week 2 videos are also quite interesting, especially the one on mental health.

Continue reading “HIV Primer Videos for Public Health and Medical Audiences”

Getting RStudio Markdown to work the first time

As I mentioned earlier, I’m the process of learning R and RStudio. As I hit stumbling blocks with RStudio, I’m posting solutions here. I’m posting partially as a reference for me so I can remember how to fix a problem, but also in hopes it helps others.

Problem: Running a command in the console works perfectly, but when creating an R Markdown file in R Studio, it fails.

Imagine that I have a data frame called “farmers” that contains data on the amount of produce a farmer sells at farmer’s market. The data frame came from a .csv file that I imported into RStudio. 

There is a column of data called “Quantity” that contains the quantity of produce that is sold. In RStudio, I run the following command in the console:


And the following result is returned in the console:

Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
182.0   452.5   782.0  1696.0   969.5  9183.0 

I put the exact same command in the R Markdown file as follows:


And this error message is returned:

Error in summary(farmers$Quantity) : object ‘farmers’ not found Calls: … withCallingHandler -> withVisible -> eval -> eval -> summary 

Execution halted

This is a terribly arcane message that, when translated to English, is saying that the data frame “farmers” could not be found. This is puzzling because in the console RStudio is able to find the data frame. If it works in the console, why not in R Markdown? 

The issue is involves the spirit of replicability that is so important to R. The R Markdown file requires to you to show all the steps you took to produce your data, and this includes showing the step where you loaded your data frame.

To fix this problem you first need to, if you have not already, save your data frame as an .Rdata file. With my data frame called “farmers”, that console command is:

save(farmers, file = "farmers.RData")

Second, in your R Markdown file, you need to tell RStudio load that RData file. For me, code is:


Press “Knit HTML” and it should now work. RStudio can now find the data frame to produce results from. 

One thing to also note is that if you use a package, you also have to load that in your R Markdown file. Again, this goes back to the spirit of replicability and showing your work so that others could rerun the same analysis you did. An example code to load a package would be:


If the package “gmodels” was being used.

Public Health as Social Justice

“It is a peculiarity of the word ‘freedom’ that its meaning has become so distorted and stretched as to lend itself as a defense against nearly every attempt to extend equal health protection to all persons.

“This is the ultimate irony.

“The idea of liberty should mean, above all else, the liberation of society from the injustices of preventable disability and early death.”

From:  “Public Health as Social Justice” by Dan E. Beauchamp