Intro to Programming and Data Science (Fall 2022)

= Course Information =
 * COM 674: Introduction to Programming and Data Science
 * Location: BRNG 2273
 * Class Hours: Thursdays, 5–7:50 pm

Instructor

 * Instructor: Jeremy Foote
 * Email: jdfoote@purdue.edu
 * Office Hours: Thursdays, 2–4 pm; BRNG 2156 or at https://meet.jit.si/JeremyOffice

= Course Overview and Learning Objectives =

This is an exciting time to be a social scientist and especially a Communication scholar! An increasing amount of our lives---and our interactions---are stored digitally. Social scientists are increasingly using that data to ask and answer questions about how the social world works. I firmly believe that computational tools have created a new frontier in the social sciences which those who develop computational skills can explore.

This class is an introduction into that world. The course is intended to give students an introduction to programming principles, the Python programming language, and data science tools and approaches. However, this is not a computer science class or a statistics class, and no prior programming experience is required or expected. We will focus on gaining access to data and basic data manipulation rather than complex statistical methods.

The main goal of the class is to help you to complete a preliminary, independent, data-centric project. As part of this project, you (on your own or in a team) will write software to collect data from web APIs, process and clean that data, and produce statistics, hypothesis tests, and graphical visualizations that address questions you are interested in.

I will consider this class a complete success if, at the end, every student can:


 * Write or modify a program to collect a dataset from a publicly available data source.
 * Read web API documentation and write Python software to parse and understand a new and unfamiliar web API.
 * Understand and follow basic version control practices.
 * Use digital data to effective answer a substantively interesting question and to present this data effectively in the context of both a formal presentation and a written report.
 * Identify multiple ways that computational approaches are being used for social science research.
 * Feel comfortable taking more advanced computational methods courses or learning new techniques on your own.

= Required resources and texts =

Laptop
Windows, Mac OS, and Linux are all fine but an iPad or Android tablet won't work. We're going to install software during the class that requires about 5GB of extra space and you'll be working on projects for homework. For the classroom assignments, nothing is terribly intensive, but your own data collection could tax the resources of an older machine.

If for some reason your laptop dies mid-course, please contact me so we can get your new one up to speed.

Readings

 * Required text: Python for Everybody [HTML Version] [PDF version] by Charles R. Severance. The book is freely licensed and available online for free. You can also buy the book if you prefer a hard copy.

I will list required chapters in the schedule below. In general, you should expect to spend far more time working on programming tasks than reading. Much like math or other technical courses, this course will build on itself every day. You should make every effort to cover the reading and exercise material every day in preparation for the next day.


 * Other readings: Throughout the module we will read and discuss examples of computational social science that I find particularly well done or interesting. Many are available through the Purdue library. I will also make all of them available on Brightspace. If you come across additional examples that you think the class would benefit from, please suggest them to me.


 * Optional readings: Matthew Salganik's book 'Bit by Bit: Social Research in the Digital Age' is a wonderful introduction to computational social science. We will not be discussing it in class but I highly recommend it.

= Course logistics =

Note About This Syllabus
Although the core expectations for this class are fixed, the details of readings and assignments may shift based on how the class goes. As a result, there are three important things to keep in mind:


 * 1) Although details on this syllabus will change, I will not change readings or assignments less than three days before they are due. If you plan to read more than three days ahead, contact me first.
 * 2) Closely monitor Discord. Because this a wiki, you will be able to track every change by clicking the history button on this page. I will also summarize these changes in a announcements that will be posted in the #announcements channel on Discord.
 * 3) I will ask the class for voluntary anonymous feedback frequently. Please let me know what is working and what can be improved.

Lectures
Our class time will follow the "flipped" classroom model. I will provide asynchronous materials (readings, recorded lectures, assignments, etc.) which you will work on before class and we will use our class time to review concepts, identify confusion, and synthesize.

The class sessions will typically follow the same format. First, we will discuss the reading for the day, with discussions generally led by a student. We will then have a discussion about the concepts that are still confusing. Next, we will go over the homework questions followed by optional co-working time to start on the next assignment.

I try to make the classes useful and to tailor them to the needs of the students, and I highly encourage you to attend as many of our sessions as possible. My teaching style is very conversational and relies on students being willing to speak up to express confusion, seek clarification, or make a well-informed point, so please participate!

Office hours and email

 * I will hold office hours from 2-4 on Thursdays and by appointment. If you come with a programming question, I will expect that you have already tried to solve it yourself in multiple ways and that you have discussed it with a classmate. This policy lets me have time to help more students, but it's also a useful strategy. Often just trying to explain your code can help you to recognize where you've gone wrong.
 * I am also available by email. You can reach me at [mailto:jdfoote@purdue.edu jdfoote@purdue.edu]. I try hard to maintain a boundary between work and home and I typically respond only on weekdays during business hours (~9-5) but during the week I will generally respond within 24 hours.

= Assignments =

There will be three main types of assignments. Each is discussed in detail below but here is a brief summary:


 * 1) Research Project: The main outcome of this course will be a research project exploring a social science question using Python, and the bulk of your grade will be based on that project. Submit these via Brightspace
 * 2) Coding Challenges: There will be daily programming assignments that I will ask you to turn in on Brightspace but which will only be graded as complete/incomplete. I will also randomly assign someone to present their solution to each of the problems during our synchronous sessions.
 * 3) Paper Discussion: Each day we will read and discuss a paper which uses computational approaches to address social science questions.

Research project
As a demonstration of your learning in this course, you will design and carry out a quantitative research project, start to finish. This means you will all:


 * Design and describe a plan for a study — The study you design should involve quantitative analysis and should be something you can complete at least a first pass on during this module.
 * Find a dataset — You should very quickly identify a dataset you will use to complete this project.
 * Analyze, visualize, report, and interpret your data — You will do this in both a short paper and a short presentation.
 * Ensure that your work is replicable — You will need to provide code and data for your analysis in a way that makes your work replicable by other researchers.

I strongly urge you to work on a project that will further your academic career outside of the class. There are many ways that this can happen. Some obvious options are to prepare a project that you can submit for publication, that you can use as pilot analysis that you can report in a grant or thesis proposal, and/or that fulfills a degree requirement. I prefer that you do projects on your own but it may be possible to work as a small team (maximum 3 people). Team projects are expected to be more ambitious than individual projects. Preliminary assignments will help you to develop your idea and to get feedback from me and others.

There are several intermediate milestones and deadlines to help you accomplish a successful research project. Unless otherwise noted, all deliverables should be submitted via Brightspace.

Project idea and dataset identification

 * Due date: September 9
 * Maximum length: 500 words (~1-2 pages)

Early on, I want you to identify and describe your final project. Your description should be short and can be either paragraphs or bullets. It should include the following:


 * An abstract of the proposed study including the topic, research question, theoretical motivation, object(s) of study, and anticipated research contribution.
 * An identification of the dataset you will use and a description of the columns or type of data it will include. If you do not currently have access to these data, explain why not and when you will have access (If you need ideas, this page lists some open datasets).
 * A short (several sentences) description of how the project will fit into your career trajectory.

Project planning document

 * Due date: October 21
 * Maximum length: ~4-5 pages

The project planning document is a basic shell/outline of an empirical quantitative research paper. The planning document should focus around three big questions:
 * Why are you planning to do this analysis? Make sure to introduce any background information about the topic, the community, your business, or anything else that will be required to properly contextualize your study.
 * How will you get the data to analyze? Describe the data sources will you collect and how they will be collected.
 * How will you analyze the data? Describe the visualizations, tables, or statistical tests that you will produce.

One approach that I have found helpful is outlined on this wiki page.

Project presentation and report

 * Report due date: December 15
 * Maximum length: 4000 words (~15 pages)


 * Presentation due date: December 9
 * Maximum length: 8 minutes

The project report
You will write a document or a Jupyter Notebook that will ideally provide the foundation for a high quality short research paper that you might revise and submit for publication. I do not expect the report to be ready for publication, but it should contain polished drafts of all the necessary components of a scholarly quantitative empirical research study. In terms of the structure, please see the page on the structure of a quantitative empirical research paper.

The great thing about a Jupyter Notebook is that it allows you to provide data, code, and any documentation sufficient to enable the replication of all analysis and visualizations. If you choose to write the report as a Word document, then you will need to include the code in a separate file.

Because the emphasis in this class is on methods and because I'm not an expert in each of your fields, I'm happy to assume that your paper, proposal, or thesis chapter has already established the relevance and significance of your study and has a comprehensive literature review, well-grounded conceptual approach, and compelling reason why this research is important. As a result, you need not focus on these elements of the work in your written submission. Instead, feel free to start with a brief summary of the purpose and importance of this research followed by an introduction of your research questions or hypotheses. If you provide more detail, that's fine, but I won't give you detailed feedback on these parts and they will not figure prominently in my assessment of the work.

Jupyter Notebooks do not have all of the tools for citations that Word or LaTeX or even Google Docs have, so while I expect you to cite related work it is OK if it isn't as polished as citation management software would make it.

The presentation
The presentation will provide an opportunity to share a brief summary of your project and findings with the other members of the class. However, don't treat it as a comprehensive overview of your paper: I would rather you tell a subset of the story well than the whole story in a rushed fashion. For instance, you can give a completely successful presentation by describing the motivation and walking through one plot in your paper. Since you will all give other research presentations throughout your career, I strongly encourage you to take the opportunity to refine your academic presentation skills.

I anticipate that most people will either create a PowerPoint presentation or will walk us through a simple Jupyter Notebook. All presentations will need to be a maximum of 8 minutes long. Concisely communicating an idea in the time allotted is an important skill in its own right. Presentations should be uploaded to the Discussion forum on Brightspace created for this purpose.

Daily Coding Challenges
Nearly every day I will give you a set of coding challenges before the end of class that will involve writing code or adding to code that I've given you. These coding challenges will be turned in on Brightspace but will not be graded. I encourage you to work together on these challenges but to make sure that you understand the concepts yourself.

Each day I will randomly select a set of students to share their solutions to a selected exercise. This will involve putting your solution on Discord at least one hour before the next day's lecture starts, and being prepared to walk us through the solution. If you can't figure out the problem that's been assigned to you, then explain where you got stuck and what you tried. I encourage you to also use Discord to ask and answer each other's questions as you work on the assignments. We will use some of our lecture time to review the problems and I will make sure that a correct solution is posted by the end of that day. As you will see over the course of the module, there are many possible solutions to many programming problems and my own approaches will often be different than yours. That's completely fine! Coding is a creative act!

Paper Discussions
Every day we will review a paper that uses computational methods. On the first day, I will ask you to sign up to lead the discussion for one or more of these papers. When leading the discussion, you will prepare a presentation as though you were presenting the paper at a conference and then lead a discussion about it.

Reflection papers
As discussed in more detail below, two times during the course I will ask you to respond to a set of reflection questions. These questions are intended to help you to think about what you have learned and accomplished and to craft goals for the remainder of the course. They are also an important way for me to gather feedback about how the course is going so that I can adjust.

= Grades =

This course will follow a "self-assessment" philosophy. I am more interested in helping you to learn things that will be useful to you than in assigning grades. The university still requires grades, so you will be leading the evaluation of your work. At the beginning of the course, I will encourage you to think about and write down what you hope to get out of the course. Three times during the course you will reflect on what you have accomplished thus far, how it has met, not met, or exceeded expectations, based both on rubrics and personal goals and objectives. At each of these stages you will receive feedback on your assessments. By the end of the semester, you should have a clear vision of your accomplishments and growth, which you will turn into a grade. As the instructor-of-record, I maintain the right to disagree with your assessment and alter grades as I see fit, but any time that I do this it will be accompanied by an explanation and discussion. These personal assessments, reflecting both honest and meaningful reflection of your work will be the most important factor in final grades.

I suggest that we use the following rubric in our assessment:


 * 25%: class participation, including attendance, participation in discussions and group work, and significant effort towards weekly assignments.
 * 5%: Final Project Idea.
 * 10%: Final Project Proposal.
 * 40%: Final Project paper/Jupyter notebook.
 * 20%: Final Presentation including your slides and presentation.

My interpretation of grade levels (A, B, C, D/F) is the following:

A: Reflects work the exceeds expectations on multiple fronts and to a great degree. Students reaching this level of achievement will:
 * Do what it takes to learn the programming principles and techniques, including looking to outside sources if necessary.
 * Engage thoughtfully with an ambitious research project.
 * Take intellectual risks, offering interpretations based on synthesizing material and asking for feedback from peers.
 * Sharing work early allowing extra time for engagement with others.
 * Write reflections that grapple meaningfully with lessons learned as well as challenges.
 * Complete all or nearly all assignments at a high level.

B: Reflects strong work. Work at this level will be of consistently high quality. Students reaching this level of achievement will:
 * Be more safe or consistent than the work described above.
 * Ask meaningful questions of peers and engage them in fruitful discussion.
 * Exceed requirements, but in fairly straightforward ways
 * Compose complete and sufficiently detailed reflections.
 * Complete many of the programming assignments at a high level

C: This reflects meeting the minimum expectations of the course. Students reaching this level of achievement will:
 * Turn in and complete required assignments on time.
 * Be collegial and continue discussion, through asking simple or limited questions.
 * Compose reflections with straightforward and easily manageable goals and/or avoid discussions of challenges.
 * Not complete programming assignments or turn some in in a hasty or incomplete manner.

D/F: These are reserved for cases in which students do not complete work or participate. Students may also be impeding the ability of others to learn.

= Schedule =

NOTE: This section will be modified throughout the course to meet the class's needs. Check back in often.

There are links to each day's slides. Note that these are slides from an earlier version of the class and will typically be updated the day of each class.

Day 1: Introduction to Python and Computational Thinking (August 26)
Assignment Due:
 * None

Required Readings:
 * Intro to Jupyter Notebooks video

Agenda:
 * Class overview and expectations — We'll walk through this syllabus.
 * Day 1 Coding challenge - Includes installing Python and going through a number of exercises.
 * Today's slides

By the end of class you will:
 * Have a working python environment on your personal laptop.
 * Have written your first program in the python language.

Day 2: Variables, conditionals, and functions (September 2)
Assignments Due:
 * Finish Day 1 exercises and tutorials
 * Fill out this short survey
 * Sign up to be a discussant here
 * Sign up for Discord and introduce yourself
 * Day 2 Coding Challenge (turn in on Brightspace)

Readings (before class):
 * Bit By bit, Introduction
 * Python for Everybody, chapters 1-4
 * Today's Jupyter Notebook (Right-click, save, and open in Jupyter)
 * Notebook walkthrough

Agenda:
 * Review Day 1 and Day 2 Exercises
 * Today's slides
 * Introduce wordplay project

Day 3: Iteration, strings, and lists (September 9)
Assignment Due:
 * Final project dataset and idea (turn in on Brightspace).
 * Day 3 Coding Challenge

Readings: chapters_to_read = [5, 6, 8]
 * Python for Everybody
 * Today's Jupyter Notebook
 * Notebook walkthrough
 * Foote, J., Shaw, A., & Hill, B.M. (2017). Computational analysis of social media scholarship. In Burgess, J., Poell, T., Marwick, A. (Eds.), The Sage Handbook of Social Media. Sage.
 * Discussant:

Agenda:
 * Programming principles (iteration, strings, and lists)
 * Go over last day's assignment
 * Today's slides

Day 4: Reading from and writing to files (September 16)
Assignment Due:
 * Day 4 Coding Challenges

Readings: book = open('Python for Everybody', 'r') for chapter in book: if chapter == '7': read(chapter) book.close
 * Today's Jupyter Notebook
 * Notebook walkthrough
 * Nelson, Laura K. 2017. "Computational Grounded Theory: A Methodological Framework." Sociological Methods and Research.
 * Discussant: Elizabeth

Agenda:
 * Reading from and writing to files
 * Today's slides

Day 5: Dictionaries and Tuples (September 23)
Assignment Due:
 * Day 5 Coding Challenges
 * Do the Twitter Authentication Setup

Readings:
 * Python for Everybody, chapters 9 and 10
 * Today's Jupyter Notebook
 * Video walkthrough
 * Margolin, D. B., Hannak, A., & Weber, I. (2018). Political Fact-Checking on Twitter: When Do Corrections Have an Effect? Political Communication, 35(2), 196–219.
 * Discussant:

Agenda:
 * Dictionaries
 * Tuples
 * Today's slides

CATCH UP Week (September 30)
Readings:
 * Shen, C., Monge, P., & Williams, D. (2014). Virtual brokerage and closure: Network structure and soci8al capital in a massively multiplayer online game. Communication Research. 41(4): 459–480.

Day 6: Dataframes and Visualization (October 7)
Assignment Due:
 * Day 6 Coding Challenges

Readings:
 * Day 6 notebook
 * Notebook walkthrough
 * Shaw, A., & Hill, B. M. (2014). Laboratories of oligarchy? How the iron law extends to peer production. Journal of Communication, 64(2), 215–238. https://doi.org/10.1111/jcom.12082

Agenda:
 * Dataframes and visualization
 * Today's slides

Day 7: Dataframes and visualization (continued) (October 14)
Assignment Due:
 * Day 7 Coding Challenges

Readings:
 * Day 7 notebook
 * Notebook walkthrough
 * Lazer, D., & Radford, J. (2017). Data ex Machina: Introduction to Big Data. Annual Review of Sociology, 43(1), 19–39.
 * Discussant: Elizabeth

Agenda:
 * Visualizations in Seaborn
 * Today's slides

Day 8: Collecting Data with APIs (October 21)
Assignment Due:
 * Day 8 Coding Challenges.
 * Video instructions to install tweepy
 * First self-assessment reflection is due (on Brightspace).
 * Project Planning Document Due

Readings:
 * Intro to APIs Notebook
 * (Long) walkthrough of notebook
 * Kieran Healy and James Moody (2014). “Data Visualization in Sociology.” American Review of Sociology. 40: 105-28.
 * Discussant:

Agenda:
 * Introduce the requests library
 * Discuss the main kinds of online data gathering: downloading, scraping, and APIs.
 * Today's slides

Day 9: Collecting Data with APIs (continued) (October 28)
Assignment Due:
 * Day 9 Coding Challenges

Readings:
 * Day 9 Notebook
 * Notebook walkthrough
 * Python for Everybody, Chapter 13
 * Vitak, J., Shilton, K., & Ashktorab, Z. (2016). Beyond the Belmont Principles: Ethical Challenges, Practices, and Beliefs in the Online Data Research Community. Proceedings of the 19th ACM Conference on Computer-Supported Cooperative Work & Social Computing, 941–953.
 * Discussant: Diane


 * (Optional) Williams, M. L., Burnap, P., & Sloan, L. (2017). Towards an Ethical Framework for Publishing Twitter Data in Social Research: Taking into Account Users’ Views, Online Context and Algorithmic Estimation: Sociology.
 * (Optional) Salganik, M. Ethics chapter from Bit By Bit.
 * (Optional) Crawford, K., & Finn, M. (2015). The limits of crisis data: Analytical and ethical challenges of using social and mobile data to understand disasters. GeoJournal, 80(4), 491–502.


 * If you are interested in doing web scraping, then look at this incredible mini-course on the topic. It is all done with Jupyter Notebooks and you have all of the prerequisite knowledge to understand it.
 * Very brief lecture on web scraping from Spring 2020.

Agenda:
 * A workflow for doing work with APIs
 * Ethics of digital trace data
 * Today's slides

Day 10: Introduction to Computational Text Analysis (November 4)
Assignment Due:
 * Day 10 Coding Challenges

Readings:
 * Today's Notebook
 * Notebook walkthrough
 * Christopher A. Bail et al. 2018. Exposure to opposing views on social media can increase political polarization. PNAS 115(37): 9216-9221
 * Discussant: Diane

Agenda:
 * Today's slides

Resources:
 * Two videos of me clumsily solving the Day 8 Problems
 * My answers to the Day 8 problems

Day 11: Data cleaning and operationalization (November 11)
Assignment Due:
 * Day 11 Coding Challenges

Readings:
 * Today's Notebook
 * Notebook walkthrough
 * Robert K. Merton. 1948. The Bearing of Empirical Research Upon the Development of Social Theory. American Sociological Review 13(5): 505-515.
 * Sara Klingenstein, Tim Hitchcock, and Simon DeDeo. 2014. The civilizing process in London’s Old Baily. Proceedings of the National Academy of Sciences 111(26): 9419-9424.
 * Discussant:

Resources:
 * Today's slides

Day 12: Organizing and storing computational projects (November 18)
Assignment Due:
 * Day 12 Coding Challenges

Readings:
 * Video introducing a way to organize code and data (from the Spring 2020 version of the class)
 * Git & GitHub Crash Course For Beginners - YouTube video (not by me) introducing Git and Github
 * Interactive git branching tutorial
 * DellaPosta, D., Shi, Y., & Macy, M. (2015). Why Do Liberals Drink Lattes? American Journal of Sociology, 120(5), 1473–1511.
 * Discussant:

Agenda:
 * Tour of Github
 * Today's slides

Resources:

Day 13: Statistical summaries and tests (December 2)
Assignment Due:
 * Day 13 Coding Challenges

Readings:
 * Day 13 Notebook
 * Notebook walkthrough
 * Tan, C. (2018). Tracing community genealogy: How new communities emerge from the old. Proceedings of the Twelfth International Conference on Web and Social Media (ICWSM ’18), 395–404.
 * Discussant: Sandra

Agenda:
 * Today's slides

Day 15: Final Project Presentation (December 9)
Assignment Due:
 * Final project presentations
 * Prepare a presentation and post it on Brightspace

Readings:
 * NONE

Agenda:
 * We will listen to and respond to each other's projects

Day 16: Final Paper Due (December 16)
Assignment Due:
 * Final paper due
 * Final self reflection due

= Additional Resources =

These are some topics we touched on in class covered in more depth


 * Using Tweepy to do full historical search on Twitter
 * Regular Expressions
 * List Comprehensions
 * Network Analysis
 * Getting data from Reddit
 * Classes and Object-oriented programming (This is a set of videos)
 * Tutorial on syntax parsing in Python (It's complicated!)

= Administrative Notes =

Attendance Policy
Attendance is very important and it will be difficult to make up for any classes that are missed. It is expected that students communicate well in advance to faculty so that arrangements can be made for making up the work that was missed. It is the your responsibility to seek out support from classmates for notes, handouts, and other information.

Incomplete
A grade of incomplete (I) will be given only in unusual circumstances. The request must describe the circumstances, along with a proposed timeline for completing the course work. Submitting a request does not ensure that an incomplete grade will be granted. If granted, you will be required to fill out and sign an “Incomplete Contract” form that will be turned in with the course grades. Any requests made after the course is completed will not be considered for an incomplete grade.

Academic Integrity
While I encourage collaboration, I expect that any work that you submit is your own. Basic guidelines for Purdue students are outlined here but I expect you to be exemplary members of the academic community. Please get in touch if you have any questions or concerns.

Nondiscrimination
I strongly support Purdue's policy of nondiscrimination (below). If you feel like any member of our classroom--including me--is not living up to these principles, then please come and talk to me about it.

Purdue University is committed to maintaining a community which recognizes and values the inherent worth and dignity of every person; fosters tolerance, sensitivity, understanding, and mutual respect among its members; and encourages each individual to strive to reach his or her own potential. In pursuit of its goal of academic excellence, the University seeks to develop and nurture diversity. The University believes that diversity among its many members strengthens the institution, stimulates creativity, promotes the exchange of ideas, and enriches campus life.

Students with Disabilities
Purdue University strives to make learning experiences as accessible as possible. If you anticipate or experience physical or academic barriers based on disability, you are welcome to let me know so that we can discuss options. You are also encouraged to contact the Disability Resource Center at: drc@purdue.edu or by phone: 765-494-1247.

Emergency Preparation
In the event of a major campus emergency, I will update the requirements and deadlines as needed.

Mental Health
If you or someone you know is feeling overwhelmed, depressed, and/or in need of mental health support, services are available. For help, such individuals should contact Counseling and Psychological Services (CAPS) at 765-494-6995 during and after hours, on weekends and holidays, or by going to the CAPS office of the second floor of the Purdue University Student Health Center (PUSH) during business hours.

= Acknowledgements =

This course is heavily based on earlier courses taught by Tommy Guy and Mako Hill at the University of Washington as well as a course taught by Laura Nelson at Northeastern University.