Inspect the teaching data

Calf feeding and growth

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: 320 Columns: 6
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (3): calf_id, pen_id, strategy
dbl (3): baseline_kg, week, weight_kg

ℹ 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] 320   6
head(data, 6)
# A tibble: 6 × 6
  calf_id pen_id strategy  baseline_kg  week weight_kg
  <chr>   <chr>  <chr>           <dbl> <dbl>     <dbl>
1 C001    Cpen01 flat             49.1     2      62.3
2 C001    Cpen01 flat             49.1     4      73.0
3 C001    Cpen01 flat             49.1     6      82.7
4 C001    Cpen01 flat             49.1     8      93.0
5 C001    Cpen01 flat             49.1    10     105. 
6 C002    Cpen01 step_down        51.6     2      63.8
str(data)
spc_tbl_ [320 × 6] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
 $ calf_id    : chr [1:320] "C001" "C001" "C001" "C001" ...
 $ pen_id     : chr [1:320] "Cpen01" "Cpen01" "Cpen01" "Cpen01" ...
 $ strategy   : chr [1:320] "flat" "flat" "flat" "flat" ...
 $ baseline_kg: num [1:320] 49.1 49.1 49.1 49.1 49.1 ...
 $ week       : num [1:320] 2 4 6 8 10 2 4 6 8 10 ...
 $ weight_kg  : num [1:320] 62.3 73 82.7 93 105.3 ...
 - attr(*, "spec")=
  .. cols(
  ..   calf_id = col_character(),
  ..   pen_id = col_character(),
  ..   strategy = col_character(),
  ..   baseline_kg = col_double(),
  ..   week = col_double(),
  ..   weight_kg = col_double()
  .. )
 - attr(*, "problems")=<pointer: 0xc9c934180> 
# Count missing (NA) values in each column.
colSums(is.na(data))
    calf_id      pen_id    strategy baseline_kg        week   weight_kg 
          0           0           0           0           0           0 
# Describe the recorded values without fitting an inferential model.
summary(data)
      calf_id          pen_id         strategy    baseline_kg         week   
 Length   :320   Length   :320   Length   :320   Min.   :35.37   Min.   : 2  
 N.unique : 64   N.unique :  8   N.unique :  2   1st Qu.:41.41   1st Qu.: 4  
 N.blank  :  0   N.blank  :  0   N.blank  :  0   Median :43.56   Median : 6  
 Min.nchar:  4   Min.nchar:  6   Min.nchar:  4   Mean   :44.12   Mean   : 6  
 Max.nchar:  4   Max.nchar:  6   Max.nchar:  9   3rd Qu.:46.42   3rd Qu.: 8  
                                                 Max.   :51.61   Max.   :10  
   weight_kg     
 Min.   : 43.84  
 1st Qu.: 63.20  
 Median : 76.25  
 Mean   : 76.29  
 3rd Qu.: 89.66  
 Max.   :110.29  
# Count calves and pens separately from repeated weight records.
data |>
  summarise(
    recorded_calves = n_distinct(calf_id),
    recorded_pens = n_distinct(pen_id)
  )
# A tibble: 1 × 2
  recorded_calves recorded_pens
            <int>         <int>
1              64             8
# Each row below counts the weight records from one pen.
data |> count(pen_id)
# A tibble: 8 × 2
  pen_id     n
  <chr>  <int>
1 Cpen01    40
2 Cpen02    40
3 Cpen03    40
4 Cpen04    40
5 Cpen05    40
6 Cpen06    40
7 Cpen07    40
8 Cpen08    40
# Show the number of follow-up weights for the first six calves.
data |> count(calf_id) |> head(6)
# A tibble: 6 × 2
  calf_id     n
  <chr>   <int>
1 C001        5
2 C002        5
3 C003        5
4 C004        5
5 C005        5
6 C006        5
# 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.