hacking_religion_textbook/docs/search.json

156 lines
77 KiB
JSON
Raw Normal View History

2023-10-02 10:52:45 +00:00
[
{
"objectID": "index.html",
"href": "index.html",
"title": "Hacking Religion: TRS & Data Science in Action",
"section": "",
"text": "Preface\nThis is a Quarto book.\nTo learn more about Quarto books visit https://quarto.org/docs/books."
},
{
"objectID": "intro.html#why-this-book",
"href": "intro.html#why-this-book",
2023-10-12 16:08:37 +00:00
"title": "Introduction: Hacking Religion",
"section": "Why this book?",
"text": "Why this book?\nData science is quickly consolidating as a new field, with new tools and user communities emerging seemingly every week! At the same time the field of academic research has opened up into new interdisciplinary vistas, with experts crossing over into new fields, transgressing disciplinary boundaries and deploying tools in new and unexpected ways to develop knowledge. There are many gaps yet to be filled, but one which I found to be particularly glaring is the lack of applied data science documentation around the subject of religion. On one hand, scholars who are working with cutting edge theory seldom pick up the emerging tools of data science. On the other hand, data scientists rarely go beyond dabbling in religious themes. This book aims to bring these two things together: introducing the tools of data science in an applied way, whilst introducing some of the complexities and cutting edge theories which help us to conceptualise and frame our understanding of this knowledge."
2023-10-02 10:52:45 +00:00
},
{
"objectID": "intro.html#the-hacker-way",
"href": "intro.html#the-hacker-way",
2023-10-12 16:08:37 +00:00
"title": "Introduction: Hacking Religion",
"section": "The hacker way",
"text": "The hacker way\nIts worth emphasising at the outset that this isnt meant to be a generic data science book. My own training as a researcher lies in the field of religious ethics, and my engagement with digital technology has, from the very start, been a context for exploring matters of personal values, and social action. A fair bit of ink has been spilled in books, magazines, blogs, zines, and tweets unpacking what exactly it means to be a hacker. Pressing beyond some of the more superficial cultural stereotypes, I want to explain a bit here about how hacking can be a much more substantial vision for ethical engagement with technology and social transformation.\nBack in the 1980s Steven Levy tried to capture some of this in his book Hackers: Heroes of the Computer Revolution. As Levy put it, the hacker ethic included: (1) sharing, (2) openness, (3) decentralisation, (4) free access to computers and (5) world improvement. The key point here is that hacking isnt just about writing and breaking code, or testing and finding weaknesses in computer systems and networks. It can be a more substantial ethical code.\nThis emphasis on ethics is especially important when were doing data science because this kind of research work will put you in positions of influence and grant you power over others. You might think this seems a bit overstated, but it never ceases to amaze me how much bringing a bar chart which succinctly shows some sort of social trend can sway a conversation or decision making process. There is something unusually persuasive that comes with the combination of aesthetics, data and storytelling. Ive met many people who have come to data science out of a desire to bring about social transformation in some sphere of life. People want to use technology and communication to make the world better. However, its possible that this can quickly get out of hand. Its important to have a clear sense of what sorts of convictions guide your work in this field, a hacker code of sorts. With this in mind, Id like to share with you my own set of principles:\nIt never ceases to amaze me how often people think that, when theyre working for something they think is important it is acceptable to conceal bad news or amplify good or compelling information beyond its real scope. There are always consequences, eventually. When people realise youve been misleading or manipulating them your platform and credibility will evaporate. Good work mixed with bad will all get tossed out. And sometimes, our convictions can lead us beyond our true apprehension of a situation.\nPresenting through facts an argument can become unnaturally compelling. Wrapping those facts up in something that uses colour, line and shape in a way that is aesthetically pleasing, even beautiful, enhances this allure even further. As you take up the hacker way, its vitally important that you always strive to tell the truth. This includes a willingness to acknowledge the limits of your information, and to share the whole set of information. The easiest way to do this is to work with visualation in a responsible way (Ill get into this a bit more in Chapter 1) and to open up your data and code to scrutiny. By allowing others to try, criticise, edit, and reappropriate your code and data in their own ways, you contribute to knowledge help to build up a community of accountability. The upside of this is that its also a lot more fun and interesting to work alongside others.\nFar too often, scholarly research (and theology) has been criticised for being disconnected from reality, making abstract pie-in-the-sky claims about how life should be lived. When exposed to the uncomfortable pressures of reality, these claims can crumble, or even turn sinister. One of the upsides of working with empirical research is that you have a chance to engage with the real world. For this reason, I love to do ethics in a way that arises - bottom-up - from real world experiences and relationships. Theres also the potential
2023-10-02 10:52:45 +00:00
},
{
"objectID": "intro.html#learning-to-code-my-way",
"href": "intro.html#learning-to-code-my-way",
2023-10-12 16:08:37 +00:00
"title": "Introduction: Hacking Religion",
"section": "Learning to code: my way",
"text": "Learning to code: my way\nThis guide is a little different from other textbooks targetting learning to code. I remember when I was first starting out, I went through a fair few guides, and they all tended to spend about 200 pages on various theoretical bits, how you form an integer, or data structures, subroutines, the logical structure of algorithms or whatever. It was usuallyweeks of reading before I got to actually do anything. I know some people may prefer this approach, but I prefer a problem-focussed approach to learning. Give me something that is broken, or a problem to solve, which engages the things I want to figure out and the motivation for learning just comes much more naturally. And we know from research in cognitive science that these kinds of problem-focussed approaches can tend to faciliate faster learning and better retention, so its not just my personal preference, but also justified! It will be helpful for you to be aware of this approach when you get into the book as it explains some of the editorial choices Ive made and the way Ive structured things. Each chapter focusses on a problem which is particularly salient for the use of data science to conduct research into religion. That problem will be my focal point, guiding choices of specific aspects of programming to introduce to you as we work our way around that data set and some of the crucial questions that arise in terms of how we handle it. If you find this approach unsatisfying, luckily there are a number of really terrific guides which lay things out slowly and methodically and I will explicitly signpost some of these along the way so that you can do a “deep dive” when you feel like it. Otherwise, Ill take an accelerated approach to this introduction to data science in R. I expect that you will identify adjacent resources and perhaps even come up with your own creative approaches along the way, which incidentally is how real data science tends to work in practice.\nThere are a range of terrific textbooks out there which cover all these elements in greater depth and more slowly. In particular, Id recommend that many readers will want to check out Hadley Wickhams “R For Data Science” book. Ill include marginal notes in this guide pointing to sections of that book, and a few others which unpack the basic mechanics of R in more detail."
2023-10-02 10:52:45 +00:00
},
{
"objectID": "intro.html#getting-set-up",
"href": "intro.html#getting-set-up",
2023-10-12 16:08:37 +00:00
"title": "Introduction: Hacking Religion",
"section": "Getting set up",
"text": "Getting set up\nEvery single tool, programming language and data set we refer to in this book is free and open source. These tools have been produced by professionals and volunteers who are passionate about data science and research and want to share it with the world, and in order to do this (and following the “hacker way”) theyve made these tools freely available. This also means that you arent restricted to a specific proprietary, expensive, or unavailable piece of software to do this work. Ill make a few opinionated recommendations here based on my own preferences and experience, but its really up to your own style and approach. In fact, given that this is an open source textbook, you can even propose additions to this chapter explaining other tools youve found that you want to share with others.\nThere are, right now, primarily two languages that statisticians and data scientists use for this kind of programmatic data science: python and R. Each language has its merits and I wont rehash the debates between various factions. For this book, well be using the R language. This is, in part, because the R user community and libraries tend to scale a bit better for the work that Im commending in this book. However, its entirely possible that one could use python for all these exercises, and perhaps in the future well have volume two of this book outlining python approaches to the same operations.\nBearing this in mind, the first step youll need to take is to download and install R. You can find instructions and install packages for a wide range of hardware on the The Comprehensive R Archive Network (or “CRAN”): https://cran.rstudio.com. Once youve installed R, youve got some choices to make about the kind of programming environment youd like to use. You can just use a plain text editor like textedit to write your code and then execute your programs using the R software youve just installed. However, most users, myself included, tend to use an integrated development environment (or “IDE”). This is usually another software package with a guided user interface and some visual elements that make it faster to write and test your code. Some IDE packages, will have built-in reference tools so you can look up options for libraries you use in your code, they will allow you to visualise the results of your code execution, and perhaps most important of all, will enable you to execute your programs line by line so you can spot errors more quickly (we call this “debugging”). The two most popular IDE platforms for R coding at the time of writing this textbook are RStudio and Visual Studio. You should download and try out both and stick with your favourite, as the differences are largely aesthetic. I use a combination of RStudio and an enhanced plain text editor Sublime Text for my coding.\nOnce you have R and your pick of an IDE, you are ready to go! Proceed to the next chapter and well dive right in and get started!"
2023-10-02 10:52:45 +00:00
},
{
"objectID": "chapter_1.html",
"href": "chapter_1.html",
2023-10-12 16:08:37 +00:00
"title": "1  The 2021 UK Census",
2023-10-02 10:52:45 +00:00
"section": "",
"text": "References"
},
{
2023-10-05 13:29:31 +00:00
"objectID": "chapter_1.html#your-first-project-the-uk-census",
"href": "chapter_1.html#your-first-project-the-uk-census",
2023-10-12 16:08:37 +00:00
"title": "1  The 2021 UK Census",
"section": "1.1 Your first project: the UK Census",
"text": "1.1 Your first project: the UK Census\nLets start by importing some data into R. Because R is what is called an object-oriented programming language, well always take our information and give it a home inside a named object. There are many different kinds of objects, which you can specify, but usually R will assign a type that seems to fit best.\nIf youd like to explore this all in a bit more depth, you can find a very helpful summary in R for Data Science, chapter 8, “data import”.\nIn the example below, were going to read in data from a comma separated value file (“csv”) which has rows of information on separate lines in a text file with each column separated by a comma. This is one of the standard plain text file formats. R has a function you can use to import this efficiently called “read.csv”. Each line of code in R usually starts with the object, and then follows with instructions on what were going to put inside it, where that comes from, and how to format it:\n\nsetwd(\"/Users/kidwellj/gits/hacking_religion_textbook/hacking_religion\")\nlibrary(here) |> suppressPackageStartupMessages()\nlibrary(tidyverse) |> suppressPackageStartupMessages()\nhere::i_am(\"chapter_1.qmd\")\n\nhere() starts at /Users/kidwellj/gits/hacking_religion_textbook/hacking_religion\n\n# Set up local workspace:\nif (dir.exists(\"data\") == FALSE) {\n dir.create(\"data\") \n}\nif (dir.exists(\"figures\") == FALSE) {\n dir.create(\"figures\") \n}\nif (dir.exists(\"derivedData\") == FALSE) {\n dir.create(\"derivedData\")\n}\n\nuk_census_2021_religion <- read.csv(here(\"example_data\", \"census2021-ts030-rgn.csv\"))"
2023-10-02 10:52:45 +00:00
},
{
2023-10-05 13:29:31 +00:00
"objectID": "chapter_1.html#examining-data",
"href": "chapter_1.html#examining-data",
2023-10-12 16:08:37 +00:00
"title": "1  The 2021 UK Census",
"section": "1.2 Examining data:",
"text": "1.2 Examining data:\nWhats in the table? You can take a quick look at either the top of the data frame, or the bottom using one of the following commands:\n\nhead(uk_census_2021_religion)\n\n geography total no_religion christian buddhist hindu jewish\n1 North East 2647012 1058122 1343948 7026 10924 4389\n2 North West 7417397 2419624 3895779 23028 49749 33285\n3 Yorkshire and The Humber 5480774 2161185 2461519 15803 29243 9355\n4 East Midlands 4880054 1950354 2214151 14521 120345 4313\n5 West Midlands 5950756 1955003 2770559 18804 88116 4394\n6 East 6335072 2544509 2955071 26814 86631 42012\n muslim sikh other no_response\n1 72102 7206 9950 133345\n2 563105 11862 28103 392862\n3 442533 24034 23618 313484\n4 210766 53950 24813 286841\n5 569963 172398 31805 339714\n6 234744 24284 36380 384627\n\n\nThis is actually a fairly ugly table, so Ill use an R tool called kable to give you prettier tables in the future, like this:\n\nknitr::kable(head(uk_census_2021_religion))\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\ngeography\ntotal\nno_religion\nchristian\nbuddhist\nhindu\njewish\nmuslim\nsikh\nother\nno_response\n\n\n\n\nNorth East\n2647012\n1058122\n1343948\n7026\n10924\n4389\n72102\n7206\n9950\n133345\n\n\nNorth West\n7417397\n2419624\n3895779\n23028\n49749\n33285\n563105\n11862\n28103\n392862\n\n\nYorkshire and The Humber\n5480774\n2161185\n2461519\n15803\n29243\n9355\n442533\n24034\n23618\n313484\n\n\nEast Midlands\n4880054\n1950354\n2214151\n14521\n120345\n4313\n210766\n53950\n24813\n286841\n\n\nWest Midlands\n5950756\n1955003\n2770559\n18804\n88116\n4394\n569963\n172398\n31805\n339714\n\n\nEast\n6335072\n2544509\n2955071\n26814\n86631\n42012\n234744\n24284\n36380\n384627\n\n\n\n\n\nYou can see how Ive nested the previous command inside the kable command. For reference, in some cases when youre working with really complex scripts with many different libraries and functions, they may end up with functions that have the same name. You can specify the library where the function is meant to come from by preceding it with :: as weve done knitr:: above. The same kind of output can be gotten using tail:\n\nknitr::kable(tail(uk_census_2021_religion))\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\ngeography\ntotal\nno_religion\nchristian\nbuddhist\nhindu\njewish\nmuslim\nsikh\nother\nno_response\n\n\n\n\n5\nWest Midlands\n5950756\n1955003\n2770559\n18804\n88116\n4394\n569963\n172398\n31805\n339714\n\n\n6\nEast\n6335072\n2544509\n2955071\n26814\n86631\n42012\n234744\n24284\n36380\n384627\n\n\n7\nLondon\n8799728\n2380404\n3577681\n77425\n453034\n145466\n1318754\n144543\n86759\n615662\n\n\n8\nSouth East\n9278068\n3733094\n4313319\n54433\n154748\n18682\n309067\n74348\n54098\n566279\n\n\n9\nSouth West\n5701186\n2513369\n2635872\n24579\n27746\n7387\n80152\n7465\n36884\n367732\n\n\n10\nWales\n3107494\n1446398\n1354773\n10075\n12242\n2044\n66947\n4048\n15926\n195041"
2023-10-05 13:29:31 +00:00
},
{
"objectID": "chapter_1.html#parsing-and-exploring-your-data",
"href": "chapter_1.html#parsing-and-exploring-your-data",
2023-10-12 16:08:37 +00:00
"title": "1  The 2021 UK Census",
"section": "1.3 Parsing and Exploring your data",
"text": "1.3 Parsing and Exploring your data\nThe first thing youre going to want to do is to take a smaller subset of a large data set, either by filtering out certain columns or rows. Now lets say we want to just work with the data from the West Midlands, and wed like to omit some of the columns. We can choose a specific range of columns using select, like this:\nYou can use the filter command to do this. To give an example, filter can pick a single row in the following way:\n\nuk_census_2021_religion_wmids <- uk_census_2021_religion %>% filter(geography==\"West Midlands\") \n\nNow well use select in a different way to narrow our data to specific columns that are needed (no totals!).\nSome readers will want to pause here and check out Hadley Wickhams “R For Data Science” book, in the section, “Data visualisation” to get a fuller explanation of how to explore your data.\nIn keeping with my goal to demonstrate data science through examples, were going to move on to producing some snappy looking charts for this data."
2023-10-05 13:29:31 +00:00
},
{
"objectID": "chapter_1.html#making-your-first-data-visulation-the-humble-bar-chart",
"href": "chapter_1.html#making-your-first-data-visulation-the-humble-bar-chart",
2023-10-12 16:08:37 +00:00
"title": "1  The 2021 UK Census",
"section": "1.4 Making your first data visulation: the humble bar chart",
"text": "1.4 Making your first data visulation: the humble bar chart\nWeve got a nice lean set of data, so now its time to visualise this. Well start by making a pie chart:\n\nuk_census_2021_religion_wmids <- uk_census_2021_religion_wmids %>% select(no_religion:no_response)\nuk_census_2021_religion_wmids <- gather(uk_census_2021_religion_wmids)\n\nThere are two basic ways to do visualisations in R. You can work with basic functions in R, often called “base R” or you can work with an alternative library called ggplot:\n\n1.4.1 Base R\n\ndf <- uk_census_2021_religion_wmids[order(uk_census_2021_religion_wmids$value,decreasing = TRUE),]\nbarplot(height=df$value, names=df$key)\n\n\n\n\n\n\n1.4.2 GGPlot\n\nggplot(uk_census_2021_religion_wmids, aes(x = key, y = value)) +\n geom_bar(stat = \"identity\")\n\n\n2\n\nWell re-order the column by size.\n\n\n\n\n\n\n2ggplot(uk_census_2021_religion_wmids, aes(x= reorder(key,-value),value)) + geom_bar(stat =\"identity\")\n\n\n\n\nLets assume were working with a data set that doesnt include a “totals” column and that we might want to get sums for each column. This is pretty easy to do in R:\n\n1uk_census_2021_religion_totals <- uk_census_2021_religion %>% select(no_religion:no_response)\nuk_census_2021_religion_totals <- uk_census_2021_religion_totals %>%\n2 summarise(across(everything(), ~ sum(., na.rm = TRUE)))\n3uk_census_2021_religion_totals <- gather(uk_census_2021_religion_totals)\n4ggplot(uk_census_2021_religion_totals, aes(x= reorder(key,-value),value)) + geom_bar(stat =\"identity\")\n\n\n1\n\nFirst, remove the column with region names and the totals for the regions as we want just integer data.\n\n2\n\nSecond calculate the totals. In this example we use the tidyverse library dplyr(), but you can also do this using base R with colsums() like this: uk_census_2021_religion_totals <- colSums(uk_census_2021_religion_totals, na.rm = TRUE). The downside with base R is that youll also need to convert the result into a dataframe for ggplot like this: uk_census_2021_religion_totals <- as.data.frame(uk_census_2021_religion_totals)\n\n3\n\nIn order to visualise this data using ggplot, we need to shift this data from wide to long format. This is a quick job using gather()\n\n4\n\nNow plot it out and have a look!\n\n\n\n\n\n\n\nYou might have noticed that these two dataframes give us somewhat different results. But with data science, its much more interesting to compare these two side-by-side in a visualisation. We can join these two dataframes and plot the bars side by side using bind() - which can be done by columns with cbind() and rows using rbind():\n\nuk_census_2021_religion_merged <- rbind(uk_census_2021_religion_totals, uk_census_2021_religion_wmids)\n\nDo you notice theres going to be a problem here? How can we tell one set from the other? We need to add in something idenfiable first! This isnt too hard to do as we can simply create a new column for each with identifiable information before we bind them:\n\nuk_census_2021_religion_totals$dataset <- c(\"totals\")\nuk_census_2021_religion_wmids$dataset <- c(\"wmids\")\nuk_census_2021_religion_merged <- rbind(uk_census_2021_religion_totals, uk_census_2021_religion_wmids)\n\nNow were ready to plot out our data as a grouped barplot:\n\nggplot(uk_census_2021_religion_merged, aes(fill=dataset, x= reorder(key,-value), value)) + geom_bar(position=\"dodge\", stat =\"identity\")\n\n\n\n\nIf youre looking closely, you will notice that Ive added two elements to our previous ggplot. Ive asked ggplot to fill in the columns with reference to the dataset column weve just created. Then Ive also asked ggplot to alter the position=\"dodge\" which places bars side by side rather than stacked on top of one another. You can give it a try without this instruction to see how this works. We will use stacked bars in a later chapter, so remember this feature.\nIf you inspect our chart, you can see that were getting closer, but its not really that
2023-10-05 13:29:31 +00:00
},
{
"objectID": "chapter_1.html#is-your-chart-accurate-telling-the-truth-in-data-science",
"href": "chapter_1.html#is-your-chart-accurate-telling-the-truth-in-data-science",
2023-10-12 16:08:37 +00:00
"title": "1  The 2021 UK Census",
"section": "1.5 Is your chart accurate? Telling the truth in data science",
"text": "1.5 Is your chart accurate? Telling the truth in data science\nThere is some technical work yet to be done fine-tuning the visualisation of our chart here. But Id like to pause for a moment and consider an ethical question. Is the title of this chart truthful and accurate? On one hand, it is a straight-forward reference to the nature of the question asked on the 2021 census survey instrument. However, as you will see in the next chapter, large data sets from the same year which asked a fairly similar question yield different results. Part of this could be attributed to the amount of non-respose to this specific question which, in the 2021 census is between 5-6% across many demographics. Its possible (though perhaps unlikely) that all those non-responses were Sikh respondents who felt uncomfortable identifying themselves on such a survey. If even half of the non-responses were of this nature, this would dramatically shift the results especially in comparison to other minority groups. So there is some work for us to do here in representing non-response as a category on the census.\nIts equally possible that someone might feel uncertain when answering, but nonetheless land on a particular decision marking Christian when they wondered if they should instead tick no religion. Some surveys attempt to capture uncertainty in this way, asking respondents to mark how confident they are about their answers, but the census hasnt capture this so we simply dont know. If a large portion of respondents in theChristian category were hovering between this and another response, again, they might shift their answers when responding on a different day, perhaps having just had a conversation with a friend which shifted their thinking. Even the inertia of survey design can have an effect on this, so responding to other questions in a particular way, thinking about ethnic identity, for example, can prime a person to think about their religious identity in a different or more focussed way, altering their response to the question. For this reason, some survey instruments randomise the order of questions. This hasnt been done on the census (which would have been quite hard work given that most of the instruments were printed hard copies!), so again, we cant really be sure if those answers given are stable.\nFinally, researchers have also found that when people are asked to mark their religious affiliation, sometimes they can prefer to mark more than one answer. A person might consider themselves to be Muslim but also Spiritual but not religious preferring the combination of those identities. It is also the case that respondents can identify with more unexpected hybrid religious identities, such as Christian and Hindu. The census only allows respondents to tick a single box for the religion category. It is worth noting that, in contrast, the responses for ethnicity allow for combinations. Given that this is the case, its impossible to know which way a person went at the fork in the road as they were forced to choose just one half of this kind of hybrid identity. Finally, it is interesting to wonder exactly what it means for a person when they tick a box like this. Is it because they attend synagogue on a weekly basis? Some persons would consider weekly attendance at workship a prerequisite for membership in a group, but others would not. Indeed we can infer from surveys and research which aims to track rates of participation in weekly worship that many people who tick boxes for particular religious identities on the census have never attended a worship service at all.\nWhat does this mean for our results? Are they completely unreliable and invalid? I dont think this is the case or that taking a clear-eyed look at the force and stability of our underlying data should be cause for despair. Instead, the most appropriate response is humility. Someone has made a statement which is recorded in the census, of this we can be sure. They felt it to be an accurate response on some
2023-10-05 13:29:31 +00:00
},
2023-10-05 13:42:06 +00:00
{
"objectID": "chapter_1.html#making-our-script-reproducible",
"href": "chapter_1.html#making-our-script-reproducible",
2023-10-12 16:08:37 +00:00
"title": "1  The 2021 UK Census",
"section": "1.6 Making our script reproducible",
"text": "1.6 Making our script reproducible\nLets take a moment to review our hacker code. Ive just spent some time addressing how we can be truthful in our data science work. We havent done much yet to talk abour reproducibility."
2023-10-05 13:42:06 +00:00
},
2023-10-05 13:29:31 +00:00
{
"objectID": "chapter_1.html#multifactor-visualisation",
"href": "chapter_1.html#multifactor-visualisation",
2023-10-12 16:08:37 +00:00
"title": "1  The 2021 UK Census",
"section": "1.7 Multifactor Visualisation",
"text": "1.7 Multifactor Visualisation\nOne element of R data analysis that can get really interesting is working with multiple variables. Above weve looked at the breakdown of religious affiliation across the whole of England and Wales (Scotland operates an independent census), and by placing this data alongside a specific region, weve already made a basic entry into working with multiple variables but this can get much more interesting. Adding an additional quantative variable (also known as bivariate data) into the mix, however can also generate a lot more information and we have to think about visualising it in different ways which can still communicate with visual clarity in spite of the additional visual noise which is inevitable with enhanced complexity. Lets have a look at the way that religion in England and Wales breaks down by ethnicity.\n\n\n\n\n\n\nWhat is Nomis?\n\n\n\nFor the UK, census data is made available for programmatic research like this via an organisation called NOMIS. Luckily for us, there is an R library you can use to access nomis directly which greatly simplifies the process of pulling data down from the platform. Its worth noting that if youre not in the UK, there are similar options for other countries. Nearly every R textbook Ive ever seen works with USA census data, so youll find plenty of documentation available on the tools you can use for US Census data. Similarly for the EU, Canada, Austrailia etc.\nIf you want to draw some data from the nomis platform yourself in R, have a look at the companion cookbook repository.\n\n\n\n# Get table of Census 2011 religion data from nomis\nz <- readRDS(file = (here(\"example_data\", \"z.rds\")))\n\n# Filter down to simplified dataset with England / Wales and percentages without totals\nuk_census_2011_religion <- filter(z, GEOGRAPHY_NAME==\"England and Wales\" & RURAL_URBAN_NAME==\"Total\" & C_RELPUK11_NAME != \"All categories: Religion\")\n# Drop unnecessary columns\nuk_census_2011_religion <- select(uk_census_2011_religion, C_RELPUK11_NAME, OBS_VALUE)\n# Plot results\nplot1 <- ggplot(uk_census_2011_religion, aes(x = C_RELPUK11_NAME, y = OBS_VALUE)) + geom_bar(stat = \"identity\") + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))\n# ggsave(filename = \"plot.png\", plot = plot1)\n\n# grab daata from nomis for 2001 census religion / ethnicity\nz0 <- readRDS(file = (here(\"example_data\", \"z0.rds\")))\n\n# select relevant columns\nuk_census_2001_religion_ethnicity <- select(z0, GEOGRAPHY_NAME, C_RELPUK11_NAME, C_ETHHUK11_NAME, OBS_VALUE)\n# Filter down to simplified dataset with England / Wales and percentages without totals\nuk_census_2001_religion_ethnicity <- filter(uk_census_2001_religion_ethnicity, GEOGRAPHY_NAME==\"England and Wales\" & C_RELPUK11_NAME != \"All categories: Religion\")\n# Simplify data to only include general totals and omit subcategories\nuk_census_2001_religion_ethnicity <- uk_census_2001_religion_ethnicity %>% filter(grepl('Total', C_ETHHUK11_NAME))\n\n# grab data from nomis for 2011 census religion / ethnicity table\nz1 <- readRDS(file = (here(\"example_data\", \"z1.rds\")))\n\n# select relevant columns\nuk_census_2011_religion_ethnicity <- select(z1, GEOGRAPHY_NAME, C_RELPUK11_NAME, C_ETHPUK11_NAME, OBS_VALUE)\n# Filter down to simplified dataset with England / Wales and percentages without totals\nuk_census_2011_religion_ethnicity <- filter(uk_census_2011_religion_ethnicity, GEOGRAPHY_NAME==\"England and Wales\" & C_RELPUK11_NAME != \"All categories: Religion\" & C_ETHPUK11_NAME != \"All categories: Ethnic group\")\n# Simplify data to only include general totals and omit subcategories\nuk_census_2011_religion_ethnicity <- uk_census_2011_religion_ethnicity %>% filter(grepl('Total', C_ETHPUK11_NAME))\n\n# grab data from nomis for 2021 census religion / ethnicity table\nz2 <- readRDS(file = (here(\"example_data\", \"z2.rds\")))\n\n# select relevant columns\nuk_census_2021_religion_ethnicity <- select(z2, GEOGRAPHY_NAME, C2021_RELIGION_
2023-10-02 10:52:45 +00:00
},
{
"objectID": "chapter_2.html",
"href": "chapter_2.html",
2023-10-12 16:08:37 +00:00
"title": "2  Survey Data: Spotlight Project",
2023-10-02 10:52:45 +00:00
"section": "",
2023-10-12 16:08:37 +00:00
"text": "3 Loading in some data\n# R Setup -----------------------------------------------------------------\nsetwd(\"/Users/kidwellj/gits/hacking_religion_textbook/hacking_religion\")\nlibrary(here) |> suppressPackageStartupMessages()\nlibrary(tidyverse) |> suppressPackageStartupMessages()\n# used for importing SPSS .sav files\nlibrary(haven) |> suppressPackageStartupMessages()\nhere::i_am(\"chapter_2.qmd\")\n\nhere() starts at /Users/kidwellj/gits/hacking_religion_textbook/hacking_religion\n\nclimate_experience_data <- read_sav(here(\"example_data\", \"climate_experience_data.sav\"))\nThe first thing to note here is that weve drawn in a different type of data file, this time from an .sav file, usully produced by the statistics software package SPSS. This uses a different R Library (I use haven for this). The upside is that in some cases where you have survey data with both a code and a value like “1” is eqivalent to “very much agree” this will preserve both in the R dataframe that is created. Now that youve loaded in data, you have a new R dataframe called “climate_experience_data” with a lot of columns with just under 1000 survey responses.\nOne of the challenges we faced when running this study is how to gather responsible data from surveys regarding religious identity. Well dive into this in depth as we do analysis and look at some of the agreements and conflicts in terms of respondent attribution. Just to set the stage, we used the following kinds of question to ask about religion and spirituality:\nThis is one way of measuring religion, that is, to ask a person if they consider themselves formally affiliated with a particular group. This kind of question has some (serious) limitations, but well get to that in a moment.\nWe also asked respondents (Q57): “Regardless of whether you belong to a particular religion, how religious would you say you are?” and then provided a slider from 0 (not religious at all) to 10 (very religious).\nWe included some classic indicators about how often respondents go to worship (Q58): Apart from weddings, funerals and other special occasions, how often do you attend religious services? and (Q59): “Q59 Apart from when you are at religious services, how often do you pray?”\nEach of these measures a particular kind of dimension, and it is interesting to note that sometimes there are stronger correlations between how often a person attends worship services (weekly versus once a year) and a particular view, than there is between their affiliation (if they are Christian or Pagan). Well do some exploratory work shortly to see how this is the case in our sample. We also included a series of questions about spirituality in Q52 and used a nature relatedness scale Q51.\nYoull find that many surveys will only use one of these forms of question and ignore the rest. I think this is a really bad idea as religious belonging, identity, and spirituality are far too complex to work off a single form of response. We can also test out how these different attributions relate to other demographic features, like interest in politics, economic attainment, etc.\nLets dive into the data and see how this all works out. Well start with the question 56 data, around religious affiliation:\nreligious_affiliation <- as_tibble(as_factor(climate_experience_data$Q56))\nnames(religious_affiliation) <- c(\"response\")\nreligious_affiliation <- filter(religious_affiliation, !is.na(response))\nThere are few things we need to do here to get the data into initial proper shape. This might be called cleaning the data:\nIf we pause at this point to view the data, youll see its basically just a long list of survey responses. What we need is a count of each unique response (or factor). This will take a few more steps:\nreligious_affiliation_sums <- religious_affiliation %>% \n1 dplyr::count(response, sort = TRUE) %>%\n2 dplyr::mutate(response = forcats::fct_rev(forcats::fct_inorder(response)))\nreligious_affiliation_sums <- religious
2023-10-03 18:18:50 +00:00
},
{
"objectID": "chapter_2.html#q57-subsetting-based-on-religiosity",
"href": "chapter_2.html#q57-subsetting-based-on-religiosity",
2023-10-12 16:08:37 +00:00
"title": "2  Survey Data: Spotlight Project",
"section": "15.1 Q57 subsetting based on Religiosity ————————————————————–",
"text": "15.1 Q57 subsetting based on Religiosity ————————————————————–\nclimate_experience_data <- climate_experience_data %>% mutate( Q57_bin = case_when( Q57_1 > mean(Q57_1) + sd(Q57_1) ~ “high”, Q57_1 < mean(Q57_1) - sd(Q57_1) ~ “low”, TRUE ~ “medium” ) %>% factor(levels = c(“low”, “medium”, “high”)) )"
2023-10-03 18:18:50 +00:00
},
{
"objectID": "chapter_2.html#subsetting-based-on-spirituality",
"href": "chapter_2.html#subsetting-based-on-spirituality",
2023-10-12 16:08:37 +00:00
"title": "2  Survey Data: Spotlight Project",
"section": "15.2 Subsetting based on Spirituality ————————————————————–",
"text": "15.2 Subsetting based on Spirituality ————————————————————–\n\n15.2.1 Nature relatedness ————————————————————–"
2023-10-02 10:52:45 +00:00
},
{
"objectID": "chapter_3.html",
"href": "chapter_3.html",
2023-10-12 16:08:37 +00:00
"title": "3  Mapping churches: geospatial data science",
2023-10-02 10:52:45 +00:00
"section": "",
2023-10-12 16:08:37 +00:00
"text": "Until recently, most data science books didnt have a section on geospatial data. It was considered a specialist form of research best left to GIS technicians who tended to use proprietary tools like ArcGIS. This has changed significantly in the past five years, but youll still be hard pressed to find an introduction to the subject which strays very far from a few simple data sets (mostly of the USA) and relatively uncomplicated geospatial operations. I actually first began learning R, back in 2013, right when open source geospatial research tools were beginning to be developed with quite a lot more energy and geospatial data is my personal favourite data science playground, so in this book were going to go much deeper than is usual. There are also good reasons to take things a few steps further in the particular forms of data and inquiry that religion takes us into.\nRecommend https://r-spatial.org/book/\nGeospatial data is, in the most basic form, working with maps. This means that most of your data can be a quite simple dataframe, e.g. just a list of names or categories associated with a set of X and Y coordinates. Once you have a set of items, however, things get interesting very quickly, as you can layer data sets on top of one another. Were going to begin this chapter by developing a geolocated data set of churches in the UK. This information is readily and freely available online thanks to the UK Ordnance Survey, a quasi-governmental agency which maintains the various (now digital) maps of Britain. Lucky for us, the Ordnance Survey has an open data product that anyone can use!\nBefore we begin, there are some key things we should note about geospatial data. Geospatial data tends to fall into one of two kinds: points and polygons. Points can be any kind of feature: a house, a church, a pub, someones favourite ancient oak tree, or some kind of sacred relic. Polygons tend to be associated with wider areas, and as such can be used to describe large features, e.g. an Ocean, a local authority, or a mountain, or also demographic features, like a census Output Area with associated census summaries. Points are very simple data representations, an X and Y coordinate. Polygons are much more complex, often containing dozens or even thousands of points.\nThe most complex aspect of point data relates to the ways that coordinates are encoded, as they will aways need to be associated with a coordinate reference system (CRS) which describes how they are situated with respect to the planet earth. The most common CRS is the WGS, though for our data sets well also come into contact with the BGS, a specifically British coordinate reference system. There are dozens of CRS, usually mapping onto a specific geographical region. Bearing in mind the way that you need to use a CRS to understand how coordinates can be associated with specific parts of the earth, you can see how this is a bit like survey data, where you also need a “codebook” to understand what the specific response values map onto, e.g. a “1” means “strongly agree” and so on. We also saw, in a previous chapter, how some forms of data have the codebook already baked into the factor data, simplifying the process of interpreting the data. In a similar way, some types of geospatial data sets can also come with CRS “baked in” while well need to define CRS for other types. Here are some of the most common types of geospatial data files:\nCSV: “comma separated values” a plain text file containing various coordinates Shapefile: a legacy file format, often still in use, but being replaced by others for a variety of good reasons. For more on this see [http://switchfromshapefile.org/] Geopackage: one of the more recent ways of packaging up geospatial data. Geopackages can contain a wide variety of different data and are easily portable. GeoJSON: a file format commonly used in other forms of coding, the “JSON” (an acronym for JavaScript Object Notation) is meant to be easily interchangeable across various platforms. GeoJSON is
2023-10-02 10:52:45 +00:00
},
{
"objectID": "chapter_4.html",
"href": "chapter_4.html",
2023-10-12 16:08:37 +00:00
"title": "4  Data scraping, corpus analysis and wordclouds",
"section": "",
"text": "References"
},
{
"objectID": "chapter_5.html",
"href": "chapter_5.html",
"title": "5  Whats next?",
2023-10-02 10:52:45 +00:00
"section": "",
"text": "References"
},
2023-10-12 16:08:37 +00:00
{
"objectID": "chapter_5.html#how-to-get-more-data",
"href": "chapter_5.html#how-to-get-more-data",
"title": "5  Whats next?",
"section": "5.1 How to get more data",
"text": "5.1 How to get more data\nData can come from a wide variety of places"
},
{
"objectID": "chapter_5.html#how-to-get-help",
"href": "chapter_5.html#how-to-get-help",
"title": "5  Whats next?",
"section": "5.2 How to get help",
"text": "5.2 How to get help\nOnline forums Etiquette"
},
2023-10-02 10:52:45 +00:00
{
"objectID": "summary.html",
"href": "summary.html",
"title": "6  Summary",
"section": "",
"text": "An open textbook introducing data science to religious studies"
}
]