Part 1: Iris

Setup

install.packages("psych")
psych::describe(iris)

Part 1

A. How many cases were included in the data?

describe(iris)
nrow(iris)
## [1] 150

The dataset has 150 cases

B. How many numerical variables are included in the data? Are they discrete or continuous?

str(iris)
## 'data.frame':    150 obs. of  5 variables:
##  $ Sepal.Length: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
##  $ Sepal.Width : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
##  $ Petal.Length: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
##  $ Petal.Width : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
##  $ Species     : Factor w/ 3 levels "setosa","versicolor",..: 1 1 1 1 1 1 1 1 1 1 ...
sum(sapply(iris, is.numeric))
## [1] 4

The datset has 5 variables.

4 Numeric: Sepal.Length, Sepal.Width, Petal.Length, Petal.Width

They are all continuous

C. How many categorical variables are included in the data? List the categories.

levels(iris$Species)
## [1] "setosa"     "versicolor" "virginica"

The 1 Categorical Variable is Species.

It has 3 Levels:

setosa, versicolor & virginica

D. Descriptive analysis of the data.

psych::describe(iris)
##              vars   n mean   sd median trimmed  mad min max range  skew
## Sepal.Length    1 150 5.84 0.83   5.80    5.81 1.04 4.3 7.9   3.6  0.31
## Sepal.Width     2 150 3.06 0.44   3.00    3.04 0.44 2.0 4.4   2.4  0.31
## Petal.Length    3 150 3.76 1.77   4.35    3.76 1.85 1.0 6.9   5.9 -0.27
## Petal.Width     4 150 1.20 0.76   1.30    1.18 1.04 0.1 2.5   2.4 -0.10
## Species*        5 150 2.00 0.82   2.00    2.00 1.48 1.0 3.0   2.0  0.00
##              kurtosis   se
## Sepal.Length    -0.61 0.07
## Sepal.Width      0.14 0.04
## Petal.Length    -1.42 0.14
## Petal.Width     -1.36 0.06
## Species*        -1.52 0.07

Across the 150 observations/cases, we can see that there is certainly some fluxuatuion of sepal and petal sizes. There greatest range between the top & bottom values are in Peral Length (5.9). While Sepal Width (2.4) & Petal Width (2.4) saw the least amount of variance. When we think about legnth vs width, it makes sense that we see a greater spread of values in the length variables then we do the width.

Which is further backed up when looking at the Standard Deviation and Standard Error stats. The legnth variables have higher higher values in both than the width variables. Tellilng us that the width measurements tend to be more compact than the legnth values.

IF we look at the skew values we can see that the Speal variables are positively skewed, telling us that the values are skewed to the Right. While the Petal variables are negatively skewed, trailling off to the left from its median.

#Part 2: Chicken Weight

The dataset, ChickenWeight is from an experiment on the diet of young chicks to see how it impacts their weight as they grow. The data is a collection of 578 cases over 4 variables.

Numeric Variables: weight & time

Categorical Variables: chick & diet

I picked this dataset simply because when scroling through R’s included datasets I thought the name was funny.

data("ChickWeight")
?ChickWeight
str(ChickWeight)
## Classes 'nfnGroupedData', 'nfGroupedData', 'groupedData' and 'data.frame':   578 obs. of  4 variables:
##  $ weight: num  42 51 59 64 76 93 106 125 149 171 ...
##  $ Time  : num  0 2 4 6 8 10 12 14 16 18 ...
##  $ Chick : Ord.factor w/ 50 levels "18"<"16"<"15"<..: 15 15 15 15 15 15 15 15 15 15 ...
##  $ Diet  : Factor w/ 4 levels "1","2","3","4": 1 1 1 1 1 1 1 1 1 1 ...
##  - attr(*, "formula")=Class 'formula'  language weight ~ Time | Chick
##   .. ..- attr(*, ".Environment")=<environment: R_EmptyEnv> 
##  - attr(*, "outer")=Class 'formula'  language ~Diet
##   .. ..- attr(*, ".Environment")=<environment: R_EmptyEnv> 
##  - attr(*, "labels")=List of 2
##   ..$ x: chr "Time"
##   ..$ y: chr "Body weight"
##  - attr(*, "units")=List of 2
##   ..$ x: chr "(days)"
##   ..$ y: chr "(gm)"
summary(ChickWeight)
##      weight           Time           Chick     Diet   
##  Min.   : 35.0   Min.   : 0.00   13     : 12   1:220  
##  1st Qu.: 63.0   1st Qu.: 4.00   9      : 12   2:120  
##  Median :103.0   Median :10.00   20     : 12   3:120  
##  Mean   :121.8   Mean   :10.72   10     : 12   4:118  
##  3rd Qu.:163.8   3rd Qu.:16.00   17     : 12          
##  Max.   :373.0   Max.   :21.00   19     : 12          
##                                  (Other):506

I decided to create new variables, 1 for each diet to get an idea of their respective descriptive stats in isolation.

We can see that Diet 3 has the heightest mean weight (142.9), but Diet 4 had the highest median weight (129.5). So Diet 4 chcisk seeme to grow larger/heavier on averge than the other Diets, but Diet 3 had a few heavy chicks that pushed its mean up. Case in point the heaviest chick was in Diet 3 (373), far heavier that the heaviest in Diet 2 (331) & Diet 4 (322)

Another thing was that all Diets had the same min weight (39) besies Diet 1 (35).

ChickDiet1 <- ChickWeight[ChickWeight$Diet==1, ]
ChickDiet2 <- ChickWeight[ChickWeight$Diet==2, ]
ChickDiet3 <- ChickWeight[ChickWeight$Diet==3, ]
ChickDiet4 <- ChickWeight[ChickWeight$Diet==4, ]
summary(ChickDiet1)
##      weight            Time           Chick     Diet   
##  Min.   : 35.00   Min.   : 0.00   13     : 12   1:220  
##  1st Qu.: 57.75   1st Qu.: 4.00   9      : 12          
##  Median : 88.00   Median :10.00   20     : 12          
##  Mean   :102.65   Mean   :10.48   10     : 12          
##  3rd Qu.:136.50   3rd Qu.:16.00   17     : 12          
##  Max.   :305.00   Max.   :21.00   19     : 12          
##                                   (Other):148
summary(ChickDiet2)
##      weight           Time           Chick    Diet   
##  Min.   : 39.0   Min.   : 0.00   24     :12   2:120  
##  1st Qu.: 65.5   1st Qu.: 5.50   30     :12          
##  Median :104.5   Median :11.00   22     :12          
##  Mean   :122.6   Mean   :10.92   23     :12          
##  3rd Qu.:163.0   3rd Qu.:16.50   27     :12          
##  Max.   :331.0   Max.   :21.00   28     :12          
##                                  (Other):48
summary(ChickDiet3)
##      weight           Time           Chick    Diet   
##  Min.   : 39.0   Min.   : 0.00   33     :12   3:120  
##  1st Qu.: 67.5   1st Qu.: 5.50   37     :12          
##  Median :125.5   Median :11.00   36     :12          
##  Mean   :142.9   Mean   :10.92   31     :12          
##  3rd Qu.:198.8   3rd Qu.:16.50   39     :12          
##  Max.   :373.0   Max.   :21.00   38     :12          
##                                  (Other):48
summary(ChickDiet4)
##      weight            Time           Chick    Diet   
##  Min.   : 39.00   Min.   : 0.00   45     :12   4:118  
##  1st Qu.: 71.25   1st Qu.: 4.50   43     :12          
##  Median :129.50   Median :10.00   41     :12          
##  Mean   :135.26   Mean   :10.75   47     :12          
##  3rd Qu.:184.75   3rd Qu.:16.00   49     :12          
##  Max.   :322.00   Max.   :21.00   46     :12          
##                                   (Other):46

Since there are multiple variables contributing to the data, I needed to use 2 way table commands.

The 1st one I compared Diet to Time. From the previous summary stats, Diets 3 seemed to be short a couple of cases. This table will allow me to see when the case is no longer being reported. We can see that near the end of the experiment that at time 20, we go from 10 to 9 (RIP). Likely meaning that a chick was removed from the experiment. What I couldn’t easily see from the earlier stats was that Diet 1 also seemd to loose a few chicks. Here its clear that starting at time 4, the number of time entries drops multiple times throughout the experiement. Leading me to belive that Diet 1 chicks were more prone to not completeling the experiment.

Since Diet 1 saw the most chicks dropping out, perhaps this was the control group since the other Diet groups saw all their chicks complete the experiment (minus the 1 chick in Diet 4)

table(ChickWeight$Diet, ChickWeight$Time)
##    
##      0  2  4  6  8 10 12 14 16 18 20 21
##   1 20 20 19 19 19 19 19 18 17 17 17 16
##   2 10 10 10 10 10 10 10 10 10 10 10 10
##   3 10 10 10 10 10 10 10 10 10 10 10 10
##   4 10 10 10 10 10 10 10 10 10 10  9  9

In this second table, I compared Chick to Diet. This one simply lets me see what diet each chick is assigned to. With this I can clearly see which chicks didn’t last the entire experiment.

table(ChickWeight$Chick, ChickWeight$Diet)
##     
##       1  2  3  4
##   18  2  0  0  0
##   16  7  0  0  0
##   15  8  0  0  0
##   13 12  0  0  0
##   9  12  0  0  0
##   20 12  0  0  0
##   10 12  0  0  0
##   8  11  0  0  0
##   17 12  0  0  0
##   19 12  0  0  0
##   4  12  0  0  0
##   6  12  0  0  0
##   11 12  0  0  0
##   3  12  0  0  0
##   1  12  0  0  0
##   12 12  0  0  0
##   2  12  0  0  0
##   5  12  0  0  0
##   14 12  0  0  0
##   7  12  0  0  0
##   24  0 12  0  0
##   30  0 12  0  0
##   22  0 12  0  0
##   23  0 12  0  0
##   27  0 12  0  0
##   28  0 12  0  0
##   26  0 12  0  0
##   25  0 12  0  0
##   29  0 12  0  0
##   21  0 12  0  0
##   33  0  0 12  0
##   37  0  0 12  0
##   36  0  0 12  0
##   31  0  0 12  0
##   39  0  0 12  0
##   38  0  0 12  0
##   32  0  0 12  0
##   40  0  0 12  0
##   34  0  0 12  0
##   35  0  0 12  0
##   44  0  0  0 10
##   45  0  0  0 12
##   43  0  0  0 12
##   41  0  0  0 12
##   47  0  0  0 12
##   49  0  0  0 12
##   46  0  0  0 12
##   50  0  0  0 12
##   42  0  0  0 12
##   48  0  0  0 12