Del4

Author

Elijah

Quarto

Quarto enables you to weave together content and executable code into a finished document. To learn more about Quarto see https://quarto.org.

Running Code

When you click the Render button a document will be generated that includes both content and the output of embedded code. You can embed code like this:

1 + 1
[1] 2

You can add options to executable code like this

[1] 4

The echo: false option disables the printing of code (only output is displayed).

# install.packages("psych")   # Only run this once
library(psych)
describe(mtcars)
     vars  n   mean     sd median trimmed    mad   min    max  range  skew
mpg     1 32  20.09   6.03  19.20   19.70   5.41 10.40  33.90  23.50  0.61
cyl     2 32   6.19   1.79   6.00    6.23   2.97  4.00   8.00   4.00 -0.17
disp    3 32 230.72 123.94 196.30  222.52 140.48 71.10 472.00 400.90  0.38
hp      4 32 146.69  68.56 123.00  141.19  77.10 52.00 335.00 283.00  0.73
drat    5 32   3.60   0.53   3.70    3.58   0.70  2.76   4.93   2.17  0.27
wt      6 32   3.22   0.98   3.33    3.15   0.77  1.51   5.42   3.91  0.42
qsec    7 32  17.85   1.79  17.71   17.83   1.42 14.50  22.90   8.40  0.37
vs      8 32   0.44   0.50   0.00    0.42   0.00  0.00   1.00   1.00  0.24
am      9 32   0.41   0.50   0.00    0.38   0.00  0.00   1.00   1.00  0.36
gear   10 32   3.69   0.74   4.00    3.62   1.48  3.00   5.00   2.00  0.53
carb   11 32   2.81   1.62   2.00    2.65   1.48  1.00   8.00   7.00  1.05
     kurtosis    se
mpg     -0.37  1.07
cyl     -1.76  0.32
disp    -1.21 21.91
hp      -0.14 12.12
drat    -0.71  0.09
wt      -0.02  0.17
qsec     0.34  0.32
vs      -2.00  0.09
am      -1.92  0.09
gear    -1.07  0.13
carb     1.26  0.29

library(readr)
train <- read_csv("train.csv")
Rows: 891 Columns: 12
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (5): Name, Sex, Ticket, Cabin, Embarked
dbl (7): PassengerId, Survived, Pclass, Age, SibSp, Parch, Fare

ℹ 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.
?head
describe(train)
            vars   n   mean     sd median trimmed    mad  min    max  range
PassengerId    1 891 446.00 257.35 446.00  446.00 330.62 1.00 891.00 890.00
Survived       2 891   0.38   0.49   0.00    0.35   0.00 0.00   1.00   1.00
Pclass         3 891   2.31   0.84   3.00    2.39   0.00 1.00   3.00   2.00
Name*          4 891 446.00 257.35 446.00  446.00 330.62 1.00 891.00 890.00
Sex*           5 891   1.65   0.48   2.00    1.68   0.00 1.00   2.00   1.00
Age            6 714  29.70  14.53  28.00   29.27  13.34 0.42  80.00  79.58
SibSp          7 891   0.52   1.10   0.00    0.27   0.00 0.00   8.00   8.00
Parch          8 891   0.38   0.81   0.00    0.18   0.00 0.00   6.00   6.00
Ticket*        9 891 339.52 200.83 338.00  339.65 268.35 1.00 681.00 680.00
Fare          10 891  32.20  49.69  14.45   21.38  10.24 0.00 512.33 512.33
Cabin*        11 204  77.00  42.23  76.00   77.09  54.11 1.00 147.00 146.00
Embarked*     12 889   2.54   0.79   3.00    2.67   0.00 1.00   3.00   2.00
             skew kurtosis   se
PassengerId  0.00    -1.20 8.62
Survived     0.48    -1.77 0.02
Pclass      -0.63    -1.28 0.03
Name*        0.00    -1.20 8.62
Sex*        -0.62    -1.62 0.02
Age          0.39     0.16 0.54
SibSp        3.68    17.73 0.04
Parch        2.74     9.69 0.03
Ticket*      0.00    -1.28 6.73
Fare         4.77    33.12 1.66
Cabin*       0.00    -1.19 2.96
Embarked*   -1.26    -0.23 0.03
head(train)
# A tibble: 6 × 12
  PassengerId Survived Pclass Name    Sex     Age SibSp Parch Ticket  Fare Cabin
        <dbl>    <dbl>  <dbl> <chr>   <chr> <dbl> <dbl> <dbl> <chr>  <dbl> <chr>
1           1        0      3 Braund… male     22     1     0 A/5 2…  7.25 <NA> 
2           2        1      1 Cuming… fema…    38     1     0 PC 17… 71.3  C85  
3           3        1      3 Heikki… fema…    26     0     0 STON/…  7.92 <NA> 
4           4        1      1 Futrel… fema…    35     1     0 113803 53.1  C123 
5           5        0      3 Allen,… male     35     0     0 373450  8.05 <NA> 
6           6        0      3 Moran,… male     NA     0     0 330877  8.46 <NA> 
# ℹ 1 more variable: Embarked <chr>
head(train)
# A tibble: 6 × 12
  PassengerId Survived Pclass Name    Sex     Age SibSp Parch Ticket  Fare Cabin
        <dbl>    <dbl>  <dbl> <chr>   <chr> <dbl> <dbl> <dbl> <chr>  <dbl> <chr>
1           1        0      3 Braund… male     22     1     0 A/5 2…  7.25 <NA> 
2           2        1      1 Cuming… fema…    38     1     0 PC 17… 71.3  C85  
3           3        1      3 Heikki… fema…    26     0     0 STON/…  7.92 <NA> 
4           4        1      1 Futrel… fema…    35     1     0 113803 53.1  C123 
5           5        0      3 Allen,… male     35     0     0 373450  8.05 <NA> 
6           6        0      3 Moran,… male     NA     0     0 330877  8.46 <NA> 
# ℹ 1 more variable: Embarked <chr>
?head
tail(train)
# A tibble: 6 × 12
  PassengerId Survived Pclass Name    Sex     Age SibSp Parch Ticket  Fare Cabin
        <dbl>    <dbl>  <dbl> <chr>   <chr> <dbl> <dbl> <dbl> <chr>  <dbl> <chr>
1         886        0      3 "Rice,… fema…    39     0     5 382652 29.1  <NA> 
2         887        0      2 "Montv… male     27     0     0 211536 13    <NA> 
3         888        1      1 "Graha… fema…    19     0     0 112053 30    B42  
4         889        0      3 "Johns… fema…    NA     1     2 W./C.… 23.4  <NA> 
5         890        1      1 "Behr,… male     26     0     0 111369 30    C148 
6         891        0      3 "Doole… male     32     0     0 370376  7.75 <NA> 
# ℹ 1 more variable: Embarked <chr>
train[ 500:515, ]
# A tibble: 16 × 12
   PassengerId Survived Pclass Name  Sex     Age SibSp Parch Ticket   Fare Cabin
         <dbl>    <dbl>  <dbl> <chr> <chr> <dbl> <dbl> <dbl> <chr>   <dbl> <chr>
 1         500        0      3 "Sve… male     24     0     0 350035   7.80 <NA> 
 2         501        0      3 "Cal… male     17     0     0 315086   8.66 <NA> 
 3         502        0      3 "Can… fema…    21     0     0 364846   7.75 <NA> 
 4         503        0      3 "O'S… fema…    NA     0     0 330909   7.63 <NA> 
 5         504        0      3 "Lai… fema…    37     0     0 4135     9.59 <NA> 
 6         505        1      1 "Mai… fema…    16     0     0 110152  86.5  B79  
 7         506        0      1 "Pen… male     18     1     0 PC 17… 109.   C65  
 8         507        1      2 "Qui… fema…    33     0     2 26360   26    <NA> 
 9         508        1      1 "Bra… male     NA     0     0 111427  26.6  <NA> 
10         509        0      3 "Ols… male     28     0     0 C 4001  22.5  <NA> 
11         510        1      3 "Lan… male     26     0     0 1601    56.5  <NA> 
12         511        1      3 "Dal… male     29     0     0 382651   7.75 <NA> 
13         512        0      3 "Web… male     NA     0     0 SOTON…   8.05 <NA> 
14         513        1      1 "McG… male     36     0     0 PC 17…  26.3  E25  
15         514        1      1 "Rot… fema…    54     1     0 PC 17…  59.4  <NA> 
16         515        0      3 "Col… male     24     0     0 349209   7.50 <NA> 
# ℹ 1 more variable: Embarked <chr>
train[ 490:495, 1:2]
# A tibble: 6 × 2
  PassengerId Survived
        <dbl>    <dbl>
1         490        1
2         491        0
3         492        0
4         493        0
5         494        0
6         495        0
train[ 490:495, c(1,5)]
# A tibble: 6 × 2
  PassengerId Sex  
        <dbl> <chr>
1         490 male 
2         491 male 
3         492 male 
4         493 male 
5         494 male 
6         495 male 
?c()
c(1,5)
[1] 1 5
?str()
str(train)
spc_tbl_ [891 × 12] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
 $ PassengerId: num [1:891] 1 2 3 4 5 6 7 8 9 10 ...
 $ Survived   : num [1:891] 0 1 1 1 0 0 0 0 1 1 ...
 $ Pclass     : num [1:891] 3 1 3 1 3 3 1 3 3 2 ...
 $ Name       : chr [1:891] "Braund, Mr. Owen Harris" "Cumings, Mrs. John Bradley (Florence Briggs Thayer)" "Heikkinen, Miss. Laina" "Futrelle, Mrs. Jacques Heath (Lily May Peel)" ...
 $ Sex        : chr [1:891] "male" "female" "female" "female" ...
 $ Age        : num [1:891] 22 38 26 35 35 NA 54 2 27 14 ...
 $ SibSp      : num [1:891] 1 1 0 1 0 0 0 3 0 1 ...
 $ Parch      : num [1:891] 0 0 0 0 0 0 0 1 2 0 ...
 $ Ticket     : chr [1:891] "A/5 21171" "PC 17599" "STON/O2. 3101282" "113803" ...
 $ Fare       : num [1:891] 7.25 71.28 7.92 53.1 8.05 ...
 $ Cabin      : chr [1:891] NA "C85" NA "C123" ...
 $ Embarked   : chr [1:891] "S" "C" "S" "S" ...
 - attr(*, "spec")=
  .. cols(
  ..   PassengerId = col_double(),
  ..   Survived = col_double(),
  ..   Pclass = col_double(),
  ..   Name = col_character(),
  ..   Sex = col_character(),
  ..   Age = col_double(),
  ..   SibSp = col_double(),
  ..   Parch = col_double(),
  ..   Ticket = col_character(),
  ..   Fare = col_double(),
  ..   Cabin = col_character(),
  ..   Embarked = col_character()
  .. )
 - attr(*, "problems")=<externalptr> 
str(train)
spc_tbl_ [891 × 12] (S3: spec_tbl_df/tbl_df/tbl/data.frame)
 $ PassengerId: num [1:891] 1 2 3 4 5 6 7 8 9 10 ...
 $ Survived   : num [1:891] 0 1 1 1 0 0 0 0 1 1 ...
 $ Pclass     : num [1:891] 3 1 3 1 3 3 1 3 3 2 ...
 $ Name       : chr [1:891] "Braund, Mr. Owen Harris" "Cumings, Mrs. John Bradley (Florence Briggs Thayer)" "Heikkinen, Miss. Laina" "Futrelle, Mrs. Jacques Heath (Lily May Peel)" ...
 $ Sex        : chr [1:891] "male" "female" "female" "female" ...
 $ Age        : num [1:891] 22 38 26 35 35 NA 54 2 27 14 ...
 $ SibSp      : num [1:891] 1 1 0 1 0 0 0 3 0 1 ...
 $ Parch      : num [1:891] 0 0 0 0 0 0 0 1 2 0 ...
 $ Ticket     : chr [1:891] "A/5 21171" "PC 17599" "STON/O2. 3101282" "113803" ...
 $ Fare       : num [1:891] 7.25 71.28 7.92 53.1 8.05 ...
 $ Cabin      : chr [1:891] NA "C85" NA "C123" ...
 $ Embarked   : chr [1:891] "S" "C" "S" "S" ...
 - attr(*, "spec")=
  .. cols(
  ..   PassengerId = col_double(),
  ..   Survived = col_double(),
  ..   Pclass = col_double(),
  ..   Name = col_character(),
  ..   Sex = col_character(),
  ..   Age = col_double(),
  ..   SibSp = col_double(),
  ..   Parch = col_double(),
  ..   Ticket = col_character(),
  ..   Fare = col_double(),
  ..   Cabin = col_character(),
  ..   Embarked = col_character()
  .. )
 - attr(*, "problems")=<externalptr> 
#install.packages("visdat")
library(visdat)
vis_dat(train)