Skip to content

Instantly share code, notes, and snippets.

View msalganik's full-sized avatar

Matthew Salganik msalganik

View GitHub Profile
@msalganik
msalganik / rlnorm-examples.R
Created December 21, 2016 03:01
R script to explore the rlnorm() function
# R script to explore rlnorm()
# written by Malte Möser and Matthew Salganik
# Described in this blog post:
set.seed(123)
draws1 <- rlnorm(n = 1000000, mean = 7, sd = 75)
mean(draws1)
sd(draws1)
draws2 <- rlnorm(n = 1000000, meanlog = log(7), sdlog = log(75))
@msalganik
msalganik / lewis_unfavorable_2015_activity.md
Created December 21, 2016 02:01
improved activity for Chapter 4: activity inspired by Lewis and Rao (2015) about power analysis

[very hard, requires coding, my favorite] Imagine that you are working as a data scientist at a tech company. Someone from the marketing department asks for your help in evaluating an experiment that they are planning in order to measure the Return on Investment (ROI) for a new online ad campaign. ROI is defined to be the net profit from the campaign divided by the cost of the campaign. For example, a campaign that had no effect on sales would have an ROI of -100%; a campaign where profits generated were equal to costs would have an ROI of 0; and a campaign where profits generated were double the cost would have an ROI of 200%.

Before launching the experiment, the marketing department provides you with the following information based on their earlier research (in fact, these values are typical of the real online ad campaigns reported in Lewis and Rao [-@lewis_unfavorable_2015])

  • the mean sales per customer follows a log-normal distribution
@msalganik
msalganik / michel_quantitiative_2011_replication_and_extension.md
Last active December 21, 2016 01:55
revised activity for Chapter 2: replication and extension of Michel et al 2011

[very hard, data collection, requires coding, my favorite] In a widely discussed paper, Michel and colleagues [-@michel_quantitative_2011] analyzed the content of more than 5 million digitized books in an attempt to identify long-term cultural trends. The data that they used has now been released as the Google NGrams dataset, and so we can use the data to replicate and extend some of their work.

In one of the many results in the paper, Michel and colleagues argue that we are forgetting faster and faster. For a particular year, say "1883", they calculated the proportion of 1-grams published in each year between 1875 and 1975 that were "1883". The reasoned that this proportion is a measure of the interest in events that happened in that year. In Fig 3a they plot the usage trajectories for three years: 1883, 1910, and 1950. These three years share a common pattern: little use before that year, then a spike, then decay. Next, t

@msalganik
msalganik / .html
Last active August 22, 2019 20:13
example wiki survey embed code
<iframe src="https://widget.allourideas.org/innovation?info=matt_blog" frameborder="0" height="450" width="550"></iframe>
@msalganik
msalganik / .html
Last active August 22, 2019 20:13
example wiki survey embed code
<iframe src="https://widget.allourideas.org/innovation?text_on_white=000000&submit_button=0080FF&vote_button=FF0000&flag_text=0080FF&tab_hover=9944000&cant_decide_button=FF00FF&add_idea_button=8000FF&question_text=000000&text_on_color=FFCCAA" frameborder="0" height="560" width="450"></iframe>
@msalganik
msalganik / .html
Last active August 22, 2019 20:14
example of wiki survey embed code
<iframe src="https://widget.allourideas.org/innovation" frameborder="0" height="650" width="750">
@msalganik
msalganik / .html
Last active August 22, 2019 20:14
example wiki survey widget embed code
<iframe src="https://widget.allourideas.org/innovation" frameborder="0" height="450" width="550"></iframe>
var alwaysMap = {
"|":"{\\textbar}",
"<":"{\\textless}",
">":"{\\textgreater}",
"~":"{\\textasciitilde}",
"^":"{\\textasciicircum}",
"\\":"{\\textbackslash}",
"{" : "\\{",
"}" : "\\}"
};
var alwaysMap = {
"|":"{\\textbar}",
"<":"{\\textless}",
">":"{\\textgreater}",
"~":"{\\textasciitilde}",
"^":"{\\textasciicircum}",
"\\":"{\\textbackslash}",
"{" : "{",
"}" : "}"
};
var alwaysMap = {
"|":"{\\textbar}",
"<":"{\\textless}",
">":"{\\textgreater}",
"~":"{\\textasciitilde}",
"^":"{\\textasciicircum}",
"\\":"{\\textbackslash}",
"{" : "{",
"}" : "}"
};