Inspect the teaching data

Pig feeding and diarrhoea

Dictionary and design · Analysis plan

What this starter does

These are synthetic teaching observations. The starter imports the supplied CSV and shows its size, columns, missing values and recorded animals or groups. It does not choose a question or fit a model for your group.

Read the dictionary to understand what each row and column represents. The number of recorded rows need not equal the number of animals or groups that received separate treatment assignments or were selected for observation.

Code and executed output

The code below comes directly from the supplied R inspection script. In your instructor-provided Posit Cloud project, open starter.R and run it section by section with this case folder as the working directory. The readr and dplyr packages must be installed. The displayed code loads dplyr and calls readr::read_csv() to import the data.

library("dplyr")

Attaching package: 'dplyr'
The following objects are masked from 'package:stats':

    filter, lag
The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union
# Student project: import and inspect the unchanged synthetic observations.
# Set the working directory to this case folder, or use run-project.R from root.
# readr imports the CSV; dplyr counts the recorded animals and groups.
data <- readr::read_csv("data.csv")
Rows: 40 Columns: 5
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (3): pen_id, batch, feed
dbl (2): n_pigs, n_diarrhoea

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Show the number of rows and columns, six example rows, and column types.
dim(data)
[1] 40  5
head(data, 6)
# A tibble: 6 × 5
  pen_id batch   feed      n_pigs n_diarrhoea
  <chr>  <chr>   <chr>      <dbl>       <dbl>
1 Ppen01 batch01 fermented      8           4
2 Ppen02 batch01 fermented      8           1
3 Ppen03 batch01 dry            8           4
4 Ppen04 batch01 dry            8           1
5 Ppen05 batch01 fermented      8           2
6 Ppen06 batch01 dry            8           2
str(data)
spc_tbl_ [40 × 5] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
 $ pen_id     : chr [1:40] "Ppen01" "Ppen02" "Ppen03" "Ppen04" ...
 $ batch      : chr [1:40] "batch01" "batch01" "batch01" "batch01" ...
 $ feed       : chr [1:40] "fermented" "fermented" "dry" "dry" ...
 $ n_pigs     : num [1:40] 8 8 8 8 8 8 8 8 8 8 ...
 $ n_diarrhoea: num [1:40] 4 1 4 1 2 2 2 2 2 5 ...
 - attr(*, "spec")=
  .. cols(
  ..   pen_id = col_character(),
  ..   batch = col_character(),
  ..   feed = col_character(),
  ..   n_pigs = col_double(),
  ..   n_diarrhoea = col_double()
  .. )
 - attr(*, "problems")=<pointer: 0x92efd80b0> 
# Count missing (NA) values in each column.
colSums(is.na(data))
     pen_id       batch        feed      n_pigs n_diarrhoea 
          0           0           0           0           0 
# Describe the recorded values without fitting an inferential model.
summary(data)
       pen_id         batch           feed        n_pigs   n_diarrhoea   
 Length   :40   Length   :40   Length   :40   Min.   :8   Min.   :0.000  
 N.unique :40   N.unique : 5   N.unique : 2   1st Qu.:8   1st Qu.:2.000  
 N.blank  : 0   N.blank  : 0   N.blank  : 0   Median :8   Median :2.000  
 Min.nchar: 6   Min.nchar: 7   Min.nchar: 3   Mean   :8   Mean   :2.525  
 Max.nchar: 6   Max.nchar: 7   Max.nchar: 9   3rd Qu.:8   3rd Qu.:3.000  
                                              Max.   :8   Max.   :6.000  
# Count pens and batches; feeds were assigned to whole pens.
data |>
  summarise(
    recorded_pens = n_distinct(pen_id),
    recorded_batches = n_distinct(batch)
  )
# A tibble: 1 × 2
  recorded_pens recorded_batches
          <int>            <int>
1            40                5
# Count the recorded pens for each feed within each batch.
data |> count(batch, feed)
# A tibble: 10 × 3
   batch   feed          n
   <chr>   <chr>     <int>
 1 batch01 dry           4
 2 batch01 fermented     4
 3 batch02 dry           4
 4 batch02 fermented     4
 5 batch03 dry           4
 6 batch03 fermented     4
 7 batch04 dry           4
 8 batch04 fermented     4
 9 batch05 dry           4
10 batch05 fermented     4
# Next: choose a question and submit analysis-plan.qmd in Week 10.
# Create your own analysis script, using class examples for syntax where needed.

Continue with your group’s plan

Use the analysis plan to record your biological question, study design and proposed analysis before fitting the project model. Open analysis-plan.qmd in your supplied project to edit your group’s answers.