<jupyter_start><jupyter_text>Headline Analysis Example (assignment one)[<NAME>](https://natematias.com), [COMM 4940](https://natematias.com/courses/comm4940/) (Jan 2020)This code includes an analysis example for the [Week 2 Headline Experiment](https://github.com/natematias/design-governance-experiments/tree/master/assignments/1-headline-experiment). DATASET DESCRIPTIONEach row in *headline-experiment-impressions.csv* represents a single "impression" - a browser that viewed a given headline:* **hed**: which headline number was used (the actual headline text is in *headline-experiment-heds.csv*)* **click**: whether that participant clicked on the article to read further<jupyter_code>## LOAD LIBRARIES
library(ggplot2) ## FOR PLOTS
library(gmodels) ## FOR CrossTable

## SET GGPLOT TO USE WIDE BUT NOT TOO TALL PLOTS
options(repr.plot.width=6, repr.plot.height=4)
# load participants file
participants     <- read.csv("headline-experiment-impressions.csv")
# convert headline to a factor, to simplify analysis later on
participants$hed <- factor(participants$hed)
# relevel the factors so that the 4th headline is the "reference factor" for the regression model
participants$hed <- relevel(participants$hed, ref="4", data=participants)


headlines        <- read.csv("headline-experiment-heds.csv")<jupyter_output><empty_output><jupyter_text>Show Headlines<jupyter_code>headlines<jupyter_output><empty_output><jupyter_text>Show a CrossTable of the Data<jupyter_code>CrossTable(participants$hed, participants$click, 
           prop.r =FALSE, prop.c=TRUE, prop.t=FALSE,prop.chisq=FALSE)<jupyter_output>Cell Contents
|-------------------------|
|                       N |
|           N / Col Total |
|-------------------------|

 
Total Observations in Table:  14950 

 
                 | participants$click 
participants$hed |         0 |         1 | Row Total | 
-----------------|-----------|-----------|-----------|
               4 |      3720 |        17 |      3737 | 
                 |     0.251 |     0.143 |           | 
-----------------|-----------|-----------|-----------|
               1 |      3716 |        40 |      3756 | 
                 |     0.251 |     0.336 |           | 
-----------------|-----------|-----------|-----------|
               2 |      3670 |        24 |      3694 | 
                 |     0.247 |     0.202 |           | 
-----------------|-----------|-----------|-----------|
               3 |      3725 |        38 |      3763 | 
                 |     0.251 |     0.319 |           | 
-----------------|-----------|-----------|-----------|
    Col[...]<jupyter_text>Estimate Results With Confidence Intervals<jupyter_code>summary(result.lm <- lm(click ~ hed, data=participants))
# generate a dataframe with a row for each headline
# so we can generate and store the estimates for each one
estimate.df <- data.frame(hed=factor(c(1,2,3,4)))

# use the predict() method with the result object
# to create estimates and confidence intervals for each 
preds.df <- data.frame(predict(result.lm, estimate.df, se.fit=TRUE, interval="confidence")$fit)

estimate.df$estimate <- preds.df$fit
estimate.df$estimate.lwr <- preds.df$lwr
estimate.df$estimate.upr <- preds.df$upr

print("Estimates and confidence intervals for each arm.")
estimate.df<jupyter_output>[1] "Estimates and confidence intervals for each arm."<jupyter_text>Plot Results using ggplot<jupyter_code>print(paste("max estimate:", max(estimate.df$estimate.upr)))
ggplot(estimate.df, aes(estimate.df$hed, estimate)) +
    geom_point() +
    geom_errorbar(ymin=estimate.df$estimate.lwr, ymax=estimate.df$estimate.upr, width=0.15) +
    theme_bw() +
    scale_y_continuous(limits=c(0,0.03), breaks=(seq(0,0.04, 0.0025)),labels = scales::percent) +
    coord_flip() + ## This line converts the vertical plot to a horizontal plot
    xlab("") +
    ylab("ASSIGNMENT TODO: Label AXIS")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.18785094435936703, 'fraction_numerical': 0.03139356814701378, 'mean_word_length': 2.3581833761782347, 'pattern_counts': {'":': 0, '<': 30, '<?xml version=': 0, '>': 20, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '664003', 'license': 'MIT', 'n_tokens_mistral': 1294, 'n_tokens_neox': 1160, 'n_words': 275, 'path': 'assignments/1-headline-experiment/headline-analysis-example.R.ipynb', 'repo_name': 'notconfusing/design-governance-experiments', 'size': '3928'}