End-to-End Data Science


End-to-End Data Science

Simon
Welcome back. Today we're exploring end-to-end data science with R, especially how data science can support equity and better outcomes for students. The focus is not just learning a technical tool, but learning how to put that tool to work on meaningful problems in education.

Corey
That distinction matters. Ryan Estrellado works with the Equity Disproportionality and Design Project at South County SELPA and SDCOE. The project works with California school districts to promote equity in special education, including learning with communities about how data can practically support equity goals.

Simon
The project also built a data tool that estimates equity-related compliance scores. That original tool was built in R, and Ryan continues to use R for diagnostics and practical data work. R is not the only option—Python and other languages can also be used for statistics—but R is the language we'll concentrate on.

Corey
And the intended audience is beginners or people who are considering learning R. So the goal is not to memorize every line of code in one session. It's to understand what is possible, learn the vocabulary and workflow, and leave with resources that make it possible to continue practicing.

Simon
There's also an important warning about how we approach the work. Ryan tells a story about a programmer who wished he could shut his office door, write code for hours, and have someone slide pizza under the door to keep him nourished. It is funny, and there is an appeal to focusing on code, but working in isolation creates two problems: it gets lonely, and it can mean missing opportunities to use data tools to improve students' lives.

Corey
So data science in education includes some unspoken work: figuring out which problems actually matter to other people and how the analysis can be useful to students. Ryan connects that idea to Donald Knuth's description of programming as an art, especially the enjoyment of writing programs that do the greatest good in some sense.

Simon
The session has three goals. First, describe the main tools: R, RStudio, R packages and R Markdown. Second, complete a live analysis in RStudio using an imaginary but plausible planning scenario. Third, briefly discuss what it is like to bring data science tools into a job where they may not already be part of the workflow.

Corey
Let's start with R itself. R is a statistical programming language. It was developed in 1991 by Ross Ihaka and Robert Gentleman at the University of Auckland in New Zealand, based on a statistical language called S. In 1995 they made R open source, which is why R and most things related to it are free.

Simon
The second tool is RStudio. R is the language, while RStudio is the software application used to write and manage the code. RStudio is not the only application you could use, but it is the one most people use and the one Ryan uses.

Corey
A useful analogy is writing in Spanish. Spanish is the language you use to express an idea, while Google Docs or Microsoft Word gives you a place to write, edit and share that idea. In the analogy, R is like Spanish and RStudio is like the writing software.

Simon
RStudio also works with R Markdown to help share an analysis. An analysis can be rendered as a PDF, placed on a website, or shared through GitHub. So R is the statistical language, RStudio helps manage the work, and R Markdown helps combine and distribute the result.

Corey
R packages are another major part of the ecosystem. Packages extend the basic installation of R with tools for tasks such as preparing data, fitting statistical models, producing graphics and creating reports. Most packages are made by the R community, so the system is strongly community-driven.

Simon
The fourth tool is R Markdown. It interweaves narrative text with code in a single document. You can knit that document to dynamically generate results from the code, producing a report that includes the explanation, the code and related graphics.

Corey
R Markdown has many features people recognize from word-processing software or Google Docs, including editable text and spell-checking. Its special feature is that code and graphics can live alongside the readable explanation, so the reader does not have to switch between a separate report and a separate code file.

Simon
All four tools—R, RStudio, R packages and R Markdown—are free to use. The session materials include links to download them, as well as references and additional resources.

Corey
Now let's move into the analysis. The imaginary scenario is a county office building a training service intended for all school districts in the county. Resources are limited, so the planning team wants to understand how many schools each district has.

Simon
That leads to several useful questions: Are the numbers similar across districts? If not, how different are they? And if the office bought one uniform quantity of materials in bulk, would that be enough? The key point is that the analysis begins with a useful question, not with a favorite tool.

Corey
The workflow has several stages. Identify the question, import a publicly available data set, prepare that data for analysis, choose a method for answering the question, make a brief visualization, analyze the data and then decide how to share the results.

Simon
The demonstration uses California Department of Education enrollment data, selecting the most recent year. The data is imported with the read_tsv function because the file is in tab-separated-values format. The imported data is named enroll so it can be referred to repeatedly.

Corey
Once loaded, the data contains 131,616 rows and 23 columns. Unlike a spreadsheet, the data is not automatically displayed in a familiar grid, so the view function can be used to open it in a spreadsheet-like form. The data covers every county and school in California.

Simon
But the data is not yet structured for the question. Each row represents a county, district, ethnicity and gender combination, rather than one individual school. Since the question asks us to count schools, we need to prepare the data so each school appears once.

Corey
The first preparation step is filtering the data to San Diego County. The filter function keeps only rows where the county variable contains San Diego. That reduces the data to 10,876 rows and confirms that the remaining records are from the county we want to study.

Simon
Next comes distinct. It removes repeated rows while keeping distinct combinations of district and school. Using both variables is important because schools can have the same name in different districts. After this step, the data contains 795 unique schools, including only one record for a school such as Wolf Canyon.

Corey
That prepared data set is named SD, for San Diego, and now we can count schools by district. The count function counts how often each district appears. Because each school now appears exactly once, the number of times a district appears is the number of schools in that district.

Simon
For example, San Diego Unified appears 223 times, which tells us it has 223 schools in this prepared data set. Chula Vista also has many schools, but fewer than San Diego Unified. Even before calculating an average, the counts suggest that districts do not all have the same or even similar numbers of schools.

Corey
The next step is choosing a method. Since the planning question asks for the average number of schools per district, we can calculate the mean of the count column. But an average alone might hide large differences, so we also calculate the standard deviation to quantify how much the district counts vary.

Simon
A quick visualization helps because people can compare lengths in a chart almost instantly. To avoid a crowded graph with roughly 50 districts, the demonstration selects the ten highest counts, although a tie results in nine districts being displayed.

Corey
The chart is created with ggplot, a tool included in the tidyverse package. ggplot builds graphics in layers: begin with the data and axes, add bars with geom_bar, reorder the districts so the values are easier to compare, and use coord_flip to turn the chart horizontally and make the labels more readable.

Simon
The resulting chart makes the difference clear. San Diego Unified has substantially more schools than the next-largest district, Chula Vista. The visualization is brief here, but ggplot can support much deeper work, and a separate session focuses specifically on data visualization.

Corey
Finally, summarise creates a compact result. The mean function applied to the count column gives the average number of schools, and the sd function gives the standard deviation. The result is about 16 schools per district on average, with a standard deviation of about 32.

Simon
That result needs to be interpreted cautiously. Saying that districts have about 16 schools on average does not mean that a district can safely be assumed to have 16 schools. The large standard deviation and the chart show substantial variation.

Corey
That variation affects the planning decision. If the office bought the same amount of materials for every district, some districts would have far too little, especially the larger ones. For a statistically knowledgeable audience, the difference between San Diego Unified and the next-largest district can be described as about seven times the standard deviation, which emphasizes how large the difference is.

Simon
At this point, a reasonable question is: why use code for this? For this simplified example, a calculator, spreadsheet or pivot table might be easier. The best tool depends on the task, and there is no reason to use R when another tool makes more sense.

Corey
The major advantage of code is scale and reproducibility. A spreadsheet can give someone the finished cookies, but code gives them both the cookies and the recipe. Someone else can inspect the steps, change the ingredients and produce a related result.

Simon
For example, the same code could be applied to ten years of data to examine whether the average and standard deviation changed over time. It could be applied to the entire state or to every county for comparison. And an R Markdown file could generate customized reports for each county.

Corey
Those tasks are much harder to repeat with Excel when the number of data sets and reports grows. Writing the code may take longer at the beginning, especially while learning, but the payoff is the ability to reuse the workflow at a larger scale.

Simon
There is one more lesson about choosing questions. When Ryan first learned R, he analyzed the relationship between time students in special education spent in the classroom and their standardized-test performance. He prepared the data, created a report containing the code, text, model and conclusions, and proudly showed it to a colleague.

Corey
The colleague looked at it and asked, essentially, what is this? Ryan realized that he had never checked whether the question mattered to anyone else. Technical quality is not enough if the analysis is disconnected from the needs of the people it is meant to serve.

Simon
So the goal is not merely to bring a fun technical hobby to work. The goal is to solve problems that matter to others and to be of service to students. Data science becomes valuable when the analysis, the communication and the purpose all connect.

Corey
One practical question is whether code must always be written directly in an R Markdown file. Ryan writes code directly in R Markdown when he wants to share tables, graphs and explanatory text, because each code chunk has controls for running that chunk or running previous code.

Simon
An ordinary R script can also be useful, especially when the goal is to output a CSV file or when the data preparation involves hundreds of lines of complicated code. That separate script can be called from within an R Markdown file, keeping the report less cluttered and making the preparation code easier to repair or reuse.

Corey
Other users may begin exploration in an R script and move the work into R Markdown once they know how they want to share it. There is no single required workflow; the choice depends on the task and on personal preference.

Simon
The main resources from the session include the slides, code, data, PDF printout, references and additional free materials. The complete demonstration can be reproduced using the materials linked through Ryan Estrellado's link tree, and R for Data Science and The Definitive Guide to R Markdown are available to read for free online.

Corey
And that brings the full workflow together: begin with a meaningful question, understand the structure of the data, prepare it carefully, choose an appropriate method, visualize and analyze the results, interpret variation responsibly, and share the work in a form others can understand and reuse.

Ask anything
We've read this whole study set, so questions about it get the best answers.