rm(list = ls())
aliens <- read.csv ("aliens.csv", header = TRUE, stringsAsFactors = TRUE)
library(skimr)
source('special_functions.R')
my_sample <- make.my.sample(33002176, 30, aliens)
## Warning in RNGkind("Mersenne-Twister", "Inversion", "Rounding"): non-uniform
## 'Rounding' sampler used
2+7
## [1] 9
1-90
## [1] -89
4*3
## [1] 12
89/7
## [1] 12.71429
##Question 2
round(56.781563, digits = 3)
## [1] 56.782
head(aliens)
## ID age color island college income antennae politics anxiety depression
## 1 1 33 Blue Blick Ganymede 27000 Curly Republicant 46 92
## 2 2 47 Pink Plume Ganymede 124000 Straight Independone 49 94
## 3 3 39 Pink Plume Io 43000 Straight Democrulite 51 119
## 4 4 24 Pink Blick Io 46000 Straight Republicant 45 92
## 5 5 53 Pink Blick Io 44000 Straight Democrulite 46 93
## 6 6 36 Blue Blick Europa 28000 Curly Republicant 49 98
## sociable control memory intelligence time1 time2 time3 food1 sleep food2
## 1 108 68 94 119 5.86 4.36 4.11 5 6.0 9
## 2 110 72 109 127 5.07 4.35 4.97 8 7.8 11
## 3 79 62 83 112 5.66 6.13 6.15 7 4.4 9
## 4 117 65 88 115 7.81 8.13 6.12 6 6.0 9
## 5 109 56 106 122 5.04 4.55 4.15 8 4.8 9
## 6 101 49 103 104 4.81 3.65 5.11 10 5.5 7
## reasoning_trials
## 1 1
## 2 1
## 3 1
## 4 1
## 5 1
## 6 1
head(aliens, 10)
## ID age color island college income antennae politics anxiety
## 1 1 33 Blue Blick Ganymede 27000 Curly Republicant 46
## 2 2 47 Pink Plume Ganymede 124000 Straight Independone 49
## 3 3 39 Pink Plume Io 43000 Straight Democrulite 51
## 4 4 24 Pink Blick Io 46000 Straight Republicant 45
## 5 5 53 Pink Blick Io 44000 Straight Democrulite 46
## 6 6 36 Blue Blick Europa 28000 Curly Republicant 49
## 7 7 58 Pink Nanspucket Europa 29000 Curly Democrulite 60
## 8 8 25 Pink Blick Io 37000 Straight Republicant 51
## 9 9 38 Pink Nanspucket Europa 35000 Straight Democrulite 52
## 10 10 40 Pink Plume Europa 33000 Straight Independone 48
## depression sociable control memory intelligence time1 time2 time3 food1
## 1 92 108 68 94 119 5.86 4.36 4.11 5
## 2 94 110 72 109 127 5.07 4.35 4.97 8
## 3 119 79 62 83 112 5.66 6.13 6.15 7
## 4 92 117 65 88 115 7.81 8.13 6.12 6
## 5 93 109 56 106 122 5.04 4.55 4.15 8
## 6 98 101 49 103 104 4.81 3.65 5.11 10
## 7 107 89 42 71 86 4.88 4.09 4.35 13
## 8 99 101 55 94 116 4.24 3.80 2.69 7
## 9 83 105 68 102 108 4.69 3.35 3.89 7
## 10 106 93 56 101 104 4.78 3.89 3.04 11
## sleep food2 reasoning_trials
## 1 6.0 9 1
## 2 7.8 11 1
## 3 4.4 9 1
## 4 6.0 9 1
## 5 4.8 9 1
## 6 5.5 7 1
## 7 4.0 8 1
## 8 6.6 9 1
## 9 3.2 6 1
## 10 5.7 7 1
tail(aliens)
## ID age color island college income antennae politics anxiety
## 9995 9995 54 Pink Nanspucket Ganymede 176000 Straight Democrulite 48
## 9996 9996 66 Blue Blick Europa 52000 Straight Republicant 52
## 9997 9997 33 Pink Plume Callisto 89000 Straight Republicant 53
## 9998 9998 60 Pink Nanspucket Callisto 23000 Straight Independone 51
## 9999 9999 51 Blue Blick Europa 37000 Straight Republicant 39
## 10000 10000 24 Pink Nanspucket Io 14000 Straight Democrulite 49
## depression sociable control memory intelligence time1 time2 time3 food1
## 9995 90 115 73 84 115 11.89 11.12 9.91 7
## 9996 110 80 57 91 100 4.79 2.92 2.95 6
## 9997 108 92 74 99 108 3.71 2.88 3.89 11
## 9998 107 89 75 87 102 3.40 3.61 3.76 7
## 9999 92 108 64 106 109 6.58 6.45 5.18 6
## 10000 99 101 69 104 124 5.13 3.32 3.47 8
## sleep food2 reasoning_trials
## 9995 6.2 8 4
## 9996 5.4 7 4
## 9997 5.5 5 2
## 9998 3.9 10 3
## 9999 5.9 9 2
## 10000 6.8 7 1
##Question 3 10,000 individuals are represented in this data frame.
##Question 4 25 variables are represented in this data frame.
class(aliens$age)
## [1] "integer"
##Question 5
class(aliens$antennae)
## [1] "factor"
class(aliens$color)
## [1] "factor"
Alien’s antennae and color are both categorical.
class(aliens$anxiety)
## [1] "integer"
class(aliens$income)
## [1] "numeric"
Alien’s income and anxiety are both numerical. An Alien’s income and anxiety seem to both be continuous because the data fall into a constant sequence and both of these seem to be ordinal because the data can be categorized and ranked.
##Question 6
help(summary)
summary(aliens)
## ID age color island college
## Min. : 1 Min. :10.00 Blue:3064 Blick :3504 Callisto:2472
## 1st Qu.: 2501 1st Qu.:26.00 Pink:6936 Nanspucket:3032 Europa :2533
## Median : 5000 Median :40.00 Plume :3464 Ganymede:2491
## Mean : 5000 Mean :40.21 Io :2504
## 3rd Qu.: 7500 3rd Qu.:55.00
## Max. :10000 Max. :70.00
## income antennae politics anxiety depression
## Min. : 5000 Curly :2155 Democrulite:3218 Min. :29 Min. : 65
## 1st Qu.: 34000 Straight:7845 Independone:3452 1st Qu.:47 1st Qu.: 93
## Median : 55000 Republicant:3330 Median :50 Median :100
## Mean : 69708 Mean :50 Mean :100
## 3rd Qu.: 90000 3rd Qu.:53 3rd Qu.:107
## Max. :559000 Max. :68 Max. :140
## sociable control memory intelligence
## Min. : 35.00 Min. :21.00 Min. : 52.00 Min. : 78.0
## 1st Qu.: 94.00 1st Qu.:53.00 1st Qu.: 85.00 1st Qu.:101.0
## Median :100.00 Median :60.00 Median : 92.00 Median :109.0
## Mean : 99.99 Mean :60.07 Mean : 92.06 Mean :108.5
## 3rd Qu.:106.00 3rd Qu.:67.00 3rd Qu.: 99.00 3rd Qu.:116.0
## Max. :167.00 Max. :96.00 Max. :129.00 Max. :135.0
## time1 time2 time3 food1
## Min. : 1.740 Min. : 0.570 Min. : 0.280 Min. : 1.000
## 1st Qu.: 5.130 1st Qu.: 4.290 1st Qu.: 4.298 1st Qu.: 7.000
## Median : 6.170 Median : 5.490 Median : 5.490 Median : 9.000
## Mean : 6.615 Mean : 5.867 Mean : 5.867 Mean : 8.665
## 3rd Qu.: 7.620 3rd Qu.: 6.990 3rd Qu.: 6.970 3rd Qu.:10.000
## Max. :24.890 Max. :23.420 Max. :25.300 Max. :17.000
## sleep food2 reasoning_trials
## Min. :2.500 Min. : 0.000 Min. : 1.000
## 1st Qu.:5.400 1st Qu.: 7.000 1st Qu.: 1.000
## Median :6.000 Median : 9.000 Median : 2.000
## Mean :6.012 Mean : 8.674 Mean : 2.958
## 3rd Qu.:6.700 3rd Qu.:10.000 3rd Qu.: 4.000
## Max. :9.500 Max. :16.000 Max. :27.000
The output looks like it decribes the minimum, 1st Quartile, median, mean, 3rd quartile, and maximum outputs of each numerical category in the aliens data frame.
##Question 7 Most aliens come from the island Blick. The most popular political party among the aliens is Independone. The highest sociability score obtained by any alien is 167.00. The lowest memory score among the aliens is 52.00.
##Question 8
skim(aliens)
| Name | aliens |
| Number of rows | 10000 |
| Number of columns | 21 |
| _______________________ | |
| Column type frequency: | |
| factor | 5 |
| numeric | 16 |
| ________________________ | |
| Group variables | None |
Variable type: factor
| skim_variable | n_missing | complete_rate | ordered | n_unique | top_counts |
|---|---|---|---|---|---|
| color | 0 | 1 | FALSE | 2 | Pin: 6936, Blu: 3064 |
| island | 0 | 1 | FALSE | 3 | Bli: 3504, Plu: 3464, Nan: 3032 |
| college | 0 | 1 | FALSE | 4 | Eur: 2533, Io: 2504, Gan: 2491, Cal: 2472 |
| antennae | 0 | 1 | FALSE | 2 | Str: 7845, Cur: 2155 |
| politics | 0 | 1 | FALSE | 3 | Ind: 3452, Rep: 3330, Dem: 3218 |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| ID | 0 | 1 | 5000.50 | 2886.90 | 1.00 | 2500.75 | 5000.50 | 7500.25 | 10000.00 | ▇▇▇▇▇ |
| age | 0 | 1 | 40.21 | 17.25 | 10.00 | 26.00 | 40.00 | 55.00 | 70.00 | ▇▇▇▇▇ |
| income | 0 | 1 | 69707.90 | 50107.96 | 5000.00 | 34000.00 | 55000.00 | 90000.00 | 559000.00 | ▇▁▁▁▁ |
| anxiety | 0 | 1 | 50.00 | 5.01 | 29.00 | 47.00 | 50.00 | 53.00 | 68.00 | ▁▂▇▅▁ |
| depression | 0 | 1 | 100.00 | 10.00 | 65.00 | 93.00 | 100.00 | 107.00 | 140.00 | ▁▅▇▂▁ |
| sociable | 0 | 1 | 99.99 | 11.11 | 35.00 | 94.00 | 100.00 | 106.00 | 167.00 | ▁▁▇▁▁ |
| control | 0 | 1 | 60.07 | 9.94 | 21.00 | 53.00 | 60.00 | 67.00 | 96.00 | ▁▂▇▃▁ |
| memory | 0 | 1 | 92.06 | 10.55 | 52.00 | 85.00 | 92.00 | 99.00 | 129.00 | ▁▂▇▃▁ |
| intelligence | 0 | 1 | 108.54 | 9.48 | 78.00 | 101.00 | 109.00 | 116.00 | 135.00 | ▁▅▇▇▁ |
| time1 | 0 | 1 | 6.62 | 2.20 | 1.74 | 5.13 | 6.17 | 7.62 | 24.89 | ▇▆▁▁▁ |
| time2 | 0 | 1 | 5.87 | 2.30 | 0.57 | 4.29 | 5.49 | 6.99 | 23.42 | ▇▇▁▁▁ |
| time3 | 0 | 1 | 5.87 | 2.31 | 0.28 | 4.30 | 5.49 | 6.97 | 25.30 | ▇▇▁▁▁ |
| food1 | 0 | 1 | 8.66 | 2.09 | 1.00 | 7.00 | 9.00 | 10.00 | 17.00 | ▁▃▇▃▁ |
| sleep | 0 | 1 | 6.01 | 1.00 | 2.50 | 5.40 | 6.00 | 6.70 | 9.50 | ▁▃▇▃▁ |
| food2 | 0 | 1 | 8.67 | 2.08 | 0.00 | 7.00 | 9.00 | 10.00 | 16.00 | ▁▂▇▅▁ |
| reasoning_trials | 0 | 1 | 2.96 | 2.71 | 1.00 | 1.00 | 2.00 | 4.00 | 27.00 | ▇▁▁▁▁ |
With the skim function, I understand it shows the mean, and standard deviation I do not understand what the (p) stands for in the other sections.
##Question 9
head(aliens, 10)
## ID age color island college income antennae politics anxiety
## 1 1 33 Blue Blick Ganymede 27000 Curly Republicant 46
## 2 2 47 Pink Plume Ganymede 124000 Straight Independone 49
## 3 3 39 Pink Plume Io 43000 Straight Democrulite 51
## 4 4 24 Pink Blick Io 46000 Straight Republicant 45
## 5 5 53 Pink Blick Io 44000 Straight Democrulite 46
## 6 6 36 Blue Blick Europa 28000 Curly Republicant 49
## 7 7 58 Pink Nanspucket Europa 29000 Curly Democrulite 60
## 8 8 25 Pink Blick Io 37000 Straight Republicant 51
## 9 9 38 Pink Nanspucket Europa 35000 Straight Democrulite 52
## 10 10 40 Pink Plume Europa 33000 Straight Independone 48
## depression sociable control memory intelligence time1 time2 time3 food1
## 1 92 108 68 94 119 5.86 4.36 4.11 5
## 2 94 110 72 109 127 5.07 4.35 4.97 8
## 3 119 79 62 83 112 5.66 6.13 6.15 7
## 4 92 117 65 88 115 7.81 8.13 6.12 6
## 5 93 109 56 106 122 5.04 4.55 4.15 8
## 6 98 101 49 103 104 4.81 3.65 5.11 10
## 7 107 89 42 71 86 4.88 4.09 4.35 13
## 8 99 101 55 94 116 4.24 3.80 2.69 7
## 9 83 105 68 102 108 4.69 3.35 3.89 7
## 10 106 93 56 101 104 4.78 3.89 3.04 11
## sleep food2 reasoning_trials
## 1 6.0 9 1
## 2 7.8 11 1
## 3 4.4 9 1
## 4 6.0 9 1
## 5 4.8 9 1
## 6 5.5 7 1
## 7 4.0 8 1
## 8 6.6 9 1
## 9 3.2 6 1
## 10 5.7 7 1
tail(aliens)
## ID age color island college income antennae politics anxiety
## 9995 9995 54 Pink Nanspucket Ganymede 176000 Straight Democrulite 48
## 9996 9996 66 Blue Blick Europa 52000 Straight Republicant 52
## 9997 9997 33 Pink Plume Callisto 89000 Straight Republicant 53
## 9998 9998 60 Pink Nanspucket Callisto 23000 Straight Independone 51
## 9999 9999 51 Blue Blick Europa 37000 Straight Republicant 39
## 10000 10000 24 Pink Nanspucket Io 14000 Straight Democrulite 49
## depression sociable control memory intelligence time1 time2 time3 food1
## 9995 90 115 73 84 115 11.89 11.12 9.91 7
## 9996 110 80 57 91 100 4.79 2.92 2.95 6
## 9997 108 92 74 99 108 3.71 2.88 3.89 11
## 9998 107 89 75 87 102 3.40 3.61 3.76 7
## 9999 92 108 64 106 109 6.58 6.45 5.18 6
## 10000 99 101 69 104 124 5.13 3.32 3.47 8
## sleep food2 reasoning_trials
## 9995 6.2 8 4
## 9996 5.4 7 4
## 9997 5.5 5 2
## 9998 3.9 10 3
## 9999 5.9 9 2
## 10000 6.8 7 1
aliens$food.diff <- aliens$food1 - aliens$food2
##Question 10
head(aliens, 10)
## ID age color island college income antennae politics anxiety
## 1 1 33 Blue Blick Ganymede 27000 Curly Republicant 46
## 2 2 47 Pink Plume Ganymede 124000 Straight Independone 49
## 3 3 39 Pink Plume Io 43000 Straight Democrulite 51
## 4 4 24 Pink Blick Io 46000 Straight Republicant 45
## 5 5 53 Pink Blick Io 44000 Straight Democrulite 46
## 6 6 36 Blue Blick Europa 28000 Curly Republicant 49
## 7 7 58 Pink Nanspucket Europa 29000 Curly Democrulite 60
## 8 8 25 Pink Blick Io 37000 Straight Republicant 51
## 9 9 38 Pink Nanspucket Europa 35000 Straight Democrulite 52
## 10 10 40 Pink Plume Europa 33000 Straight Independone 48
## depression sociable control memory intelligence time1 time2 time3 food1
## 1 92 108 68 94 119 5.86 4.36 4.11 5
## 2 94 110 72 109 127 5.07 4.35 4.97 8
## 3 119 79 62 83 112 5.66 6.13 6.15 7
## 4 92 117 65 88 115 7.81 8.13 6.12 6
## 5 93 109 56 106 122 5.04 4.55 4.15 8
## 6 98 101 49 103 104 4.81 3.65 5.11 10
## 7 107 89 42 71 86 4.88 4.09 4.35 13
## 8 99 101 55 94 116 4.24 3.80 2.69 7
## 9 83 105 68 102 108 4.69 3.35 3.89 7
## 10 106 93 56 101 104 4.78 3.89 3.04 11
## sleep food2 reasoning_trials food.diff
## 1 6.0 9 1 -4
## 2 7.8 11 1 -3
## 3 4.4 9 1 -2
## 4 6.0 9 1 -3
## 5 4.8 9 1 -1
## 6 5.5 7 1 3
## 7 4.0 8 1 5
## 8 6.6 9 1 -2
## 9 3.2 6 1 1
## 10 5.7 7 1 4
tail(aliens)
## ID age color island college income antennae politics anxiety
## 9995 9995 54 Pink Nanspucket Ganymede 176000 Straight Democrulite 48
## 9996 9996 66 Blue Blick Europa 52000 Straight Republicant 52
## 9997 9997 33 Pink Plume Callisto 89000 Straight Republicant 53
## 9998 9998 60 Pink Nanspucket Callisto 23000 Straight Independone 51
## 9999 9999 51 Blue Blick Europa 37000 Straight Republicant 39
## 10000 10000 24 Pink Nanspucket Io 14000 Straight Democrulite 49
## depression sociable control memory intelligence time1 time2 time3 food1
## 9995 90 115 73 84 115 11.89 11.12 9.91 7
## 9996 110 80 57 91 100 4.79 2.92 2.95 6
## 9997 108 92 74 99 108 3.71 2.88 3.89 11
## 9998 107 89 75 87 102 3.40 3.61 3.76 7
## 9999 92 108 64 106 109 6.58 6.45 5.18 6
## 10000 99 101 69 104 124 5.13 3.32 3.47 8
## sleep food2 reasoning_trials food.diff
## 9995 6.2 8 4 -1
## 9996 5.4 7 4 -1
## 9997 5.5 5 2 6
## 9998 3.9 10 3 -3
## 9999 5.9 9 2 -3
## 10000 6.8 7 1 1
aliens$time.diff <- aliens$time1 - aliens$time2
What I did here was get a specific chunk of data based on two different rows of time described in the aliens data frame.
##Question 11
summary(my_sample)
## ID age color island college
## Min. : 84 Min. :11.00 Blue: 7 Blick : 9 Callisto: 6
## 1st Qu.:3988 1st Qu.:27.25 Pink:23 Nanspucket: 9 Europa :11
## Median :6348 Median :43.50 Plume :12 Ganymede: 6
## Mean :5709 Mean :41.87 Io : 7
## 3rd Qu.:7935 3rd Qu.:58.50
## Max. :9733 Max. :70.00
## income antennae politics anxiety
## Min. : 25000 Curly : 2 Democrulite:11 Min. :40.00
## 1st Qu.: 42000 Straight:28 Independone: 8 1st Qu.:48.00
## Median : 63000 Republicant:11 Median :50.00
## Mean : 73867 Mean :50.30
## 3rd Qu.: 89500 3rd Qu.:53.75
## Max. :272000 Max. :61.00
## depression sociable control memory
## Min. : 73.00 Min. : 66.0 Min. :42.00 Min. : 67.0
## 1st Qu.: 94.00 1st Qu.: 96.0 1st Qu.:53.00 1st Qu.: 84.0
## Median :100.00 Median :100.0 Median :60.00 Median : 91.0
## Mean : 98.07 Mean :100.5 Mean :59.20 Mean : 90.1
## 3rd Qu.:104.00 3rd Qu.:106.5 3rd Qu.:65.75 3rd Qu.: 96.0
## Max. :123.00 Max. :133.0 Max. :75.00 Max. :113.0
## intelligence time1 time2 time3
## Min. : 84.0 Min. :4.230 Min. : 3.150 Min. :2.980
## 1st Qu.: 99.0 1st Qu.:5.157 1st Qu.: 4.335 1st Qu.:4.253
## Median :105.0 Median :5.740 Median : 5.475 Median :5.345
## Mean :106.3 Mean :6.300 Mean : 5.786 Mean :5.548
## 3rd Qu.:115.8 3rd Qu.:7.410 3rd Qu.: 6.643 3rd Qu.:6.095
## Max. :123.0 Max. :9.990 Max. :10.430 Max. :9.520
## food1 sleep food2 reasoning_trials
## Min. : 4.000 Min. :4.500 Min. : 4.000 Min. : 1.000
## 1st Qu.: 7.250 1st Qu.:5.400 1st Qu.: 7.000 1st Qu.: 1.000
## Median : 9.000 Median :6.150 Median : 9.000 Median : 2.000
## Mean : 9.033 Mean :6.127 Mean : 8.833 Mean : 2.967
## 3rd Qu.:10.000 3rd Qu.:6.600 3rd Qu.: 9.750 3rd Qu.: 4.000
## Max. :13.000 Max. :9.100 Max. :14.000 Max. :10.000
Most aliens come from the island Plume. The most popular political party among the aliens is tied at 11 with Democrulite and Republicant. The highest sociability score obtained by any alien is 133.00. The lowest memory score among the aliens is 67.00.
##Question 12
skim(my_sample)
| Name | my_sample |
| Number of rows | 30 |
| Number of columns | 21 |
| _______________________ | |
| Column type frequency: | |
| factor | 5 |
| numeric | 16 |
| ________________________ | |
| Group variables | None |
Variable type: factor
| skim_variable | n_missing | complete_rate | ordered | n_unique | top_counts |
|---|---|---|---|---|---|
| color | 0 | 1 | FALSE | 2 | Pin: 23, Blu: 7 |
| island | 0 | 1 | FALSE | 3 | Plu: 12, Bli: 9, Nan: 9 |
| college | 0 | 1 | FALSE | 4 | Eur: 11, Io: 7, Cal: 6, Gan: 6 |
| antennae | 0 | 1 | FALSE | 2 | Str: 28, Cur: 2 |
| politics | 0 | 1 | FALSE | 3 | Dem: 11, Rep: 11, Ind: 8 |
Variable type: numeric
| skim_variable | n_missing | complete_rate | mean | sd | p0 | p25 | p50 | p75 | p100 | hist |
|---|---|---|---|---|---|---|---|---|---|---|
| ID | 0 | 1 | 5708.60 | 2665.99 | 84.00 | 3988.00 | 6348.50 | 7934.75 | 9733.00 | ▅▂▇▇▇ |
| age | 0 | 1 | 41.87 | 17.52 | 11.00 | 27.25 | 43.50 | 58.50 | 70.00 | ▃▇▃▅▇ |
| income | 0 | 1 | 73866.67 | 50450.89 | 25000.00 | 42000.00 | 63000.00 | 89500.00 | 272000.00 | ▇▂▁▁▁ |
| anxiety | 0 | 1 | 50.30 | 5.08 | 40.00 | 48.00 | 50.00 | 53.75 | 61.00 | ▃▃▇▆▂ |
| depression | 0 | 1 | 98.07 | 11.97 | 73.00 | 94.00 | 100.00 | 104.00 | 123.00 | ▂▂▇▃▂ |
| sociable | 0 | 1 | 100.47 | 13.50 | 66.00 | 96.00 | 100.00 | 106.50 | 133.00 | ▁▂▇▃▁ |
| control | 0 | 1 | 59.20 | 9.76 | 42.00 | 53.00 | 60.00 | 65.75 | 75.00 | ▅▅▇▇▅ |
| memory | 0 | 1 | 90.10 | 9.97 | 67.00 | 84.00 | 91.00 | 96.00 | 113.00 | ▂▅▇▃▂ |
| intelligence | 0 | 1 | 106.33 | 10.05 | 84.00 | 99.00 | 105.00 | 115.75 | 123.00 | ▁▇▇▆▇ |
| time1 | 0 | 1 | 6.30 | 1.57 | 4.23 | 5.16 | 5.74 | 7.41 | 9.99 | ▇▇▅▂▂ |
| time2 | 0 | 1 | 5.79 | 1.86 | 3.15 | 4.34 | 5.47 | 6.64 | 10.43 | ▇▇▇▂▂ |
| time3 | 0 | 1 | 5.55 | 1.67 | 2.98 | 4.25 | 5.34 | 6.10 | 9.52 | ▆▇▅▁▂ |
| food1 | 0 | 1 | 9.03 | 2.36 | 4.00 | 7.25 | 9.00 | 10.00 | 13.00 | ▂▃▆▇▃ |
| sleep | 0 | 1 | 6.13 | 0.96 | 4.50 | 5.40 | 6.15 | 6.60 | 9.10 | ▆▆▇▁▁ |
| food2 | 0 | 1 | 8.83 | 2.31 | 4.00 | 7.00 | 9.00 | 9.75 | 14.00 | ▂▇▇▃▂ |
| reasoning_trials | 0 | 1 | 2.97 | 2.40 | 1.00 | 1.00 | 2.00 | 4.00 | 10.00 | ▇▂▁▁▁ |
The most notable difference between the results of my own sample and the results for the population as a whole is that my sample, being smaller, has more specific numbers rather than even numbers seen on the sample from the population as a whole.
##Question 13
my_sample100 <- make.my.sample(33002176, 100, aliens)
## Warning in RNGkind("Mersenne-Twister", "Inversion", "Rounding"): non-uniform
## 'Rounding' sampler used
summary(my_sample100)
## ID age color island college
## Min. : 84 Min. :10.00 Blue:35 Blick :29 Callisto:30
## 1st Qu.:3538 1st Qu.:29.75 Pink:65 Nanspucket:34 Europa :25
## Median :5863 Median :43.00 Plume :37 Ganymede:28
## Mean :5448 Mean :42.58 Io :17
## 3rd Qu.:7903 3rd Qu.:57.25
## Max. :9751 Max. :70.00
## income antennae politics anxiety
## Min. : 14000 Curly :21 Democrulite:35 Min. :38.00
## 1st Qu.: 36250 Straight:79 Independone:32 1st Qu.:47.00
## Median : 56500 Republicant:33 Median :50.00
## Mean : 71990 Mean :50.17
## 3rd Qu.: 92000 3rd Qu.:53.00
## Max. :272000 Max. :61.00
## depression sociable control memory
## Min. : 73.00 Min. : 58.00 Min. :31.00 Min. : 67.00
## 1st Qu.: 94.00 1st Qu.: 94.75 1st Qu.:52.75 1st Qu.: 85.00
## Median : 99.50 Median :100.00 Median :59.50 Median : 92.00
## Mean : 99.96 Mean : 99.22 Mean :58.58 Mean : 92.13
## 3rd Qu.:106.00 3rd Qu.:105.25 3rd Qu.:66.00 3rd Qu.: 98.00
## Max. :123.00 Max. :133.00 Max. :79.00 Max. :126.00
## intelligence time1 time2 time3
## Min. : 84.0 Min. : 3.770 Min. : 2.790 Min. : 1.770
## 1st Qu.:100.0 1st Qu.: 5.067 1st Qu.: 4.553 1st Qu.: 4.218
## Median :106.0 Median : 6.060 Median : 5.530 Median : 5.425
## Mean :107.5 Mean : 6.529 Mean : 5.961 Mean : 5.755
## 3rd Qu.:115.2 3rd Qu.: 7.570 3rd Qu.: 6.803 3rd Qu.: 6.992
## Max. :128.0 Max. :14.870 Max. :13.860 Max. :13.340
## food1 sleep food2 reasoning_trials
## Min. : 3.00 Min. :3.300 Min. : 1.00 Min. : 1.00
## 1st Qu.: 7.00 1st Qu.:5.300 1st Qu.: 8.00 1st Qu.: 1.00
## Median : 9.00 Median :6.100 Median : 9.00 Median : 2.00
## Mean : 8.75 Mean :5.964 Mean : 8.92 Mean : 2.53
## 3rd Qu.:10.00 3rd Qu.:6.600 3rd Qu.:11.00 3rd Qu.: 3.00
## Max. :13.00 Max. :9.100 Max. :14.00 Max. :10.00
## food.diff time.diff
## Min. :-7.00 Min. :-0.4900
## 1st Qu.:-2.00 1st Qu.:-0.0125
## Median : 0.00 Median : 0.4450
## Mean :-0.17 Mean : 0.5685
## 3rd Qu.: 2.00 3rd Qu.: 1.1550
## Max. : 8.00 Max. : 1.9700
Most aliens come from the island Plume. The most popular political party among the aliens is Democrulite. The highest sociability score obtained by any alien is 133.00. The lowest memory score among the aliens is 67.00. The only difference with this sample rather than the sample of 30 is that the more popular political party is more specific rather than a tie.
This is a template for doing your homework assignments. It’s an R Markdown document, with the .Rmd extension.
Start by saving it with a new name, using Save As from the File menu above. Please make sure to save it in the special directory that you created for your homework (see my instructions for getting started in R). Please name it with your own name and the number of the homework assignment, followed by the .Rmd extension. For example: JohnDoeHW1.Rmd.
Make sure that you start by filling in the header information at the top of this file (e.g., name, student ID). Each time you do a new assignment, just change the file name and the header info.
Please leave in place the little block of code, above, that starts with ‘r setup’.
When you submit your homework, you will submit two files: this .Rmd file, and an .html file that you will create by **knitting* your .Rmd file. The .html file is a very nice-looking file, viewable in any internet browser (e.g., Chrome, Safari, etc.). It includes everything you’ve written in your homework file, including your code, but also includes the results of any R code that you put in your homework. In other words, by knitting the file, you are running all the code, and the output is included in the .html file along with the code that generated it.
To knit your file, go to the Knit menu above, and click Knit to HTML. The file will show up in the same directory that your .Rmd file is in.
Knitting your file will also provide a preview of what the .html file looks like, in the Viewer pane of RStudio on the right side of the screen. To make sure that you’ve got RStudio set up to give you a preview, click the little settings wheel above, and click Preview in Viewer Pane.
Try knitting this file, right now!
You can re-Knit your file as often as you like, so you can correct your mistakes. It will over-write the old version every time you do it.
For each new section of your document, make a header by typing two hash marks, followed by a space, and then the name of your section; see, for example, the header of this section.
Please make a new section for each question in the homework. That is, one section is called Question 1, the next is called Question 2, etc.
The first section of each homework assignment will be where you’ll do some preliminary things that you’ll need for the assignment, but which aren’t part of the assignment itself. You can call this section Preliminaries.
Within each section, you can write sentences, which you will need to do to answer parts of many of the questions, and you can put in blocks of R code, which will be executed when you knit your file.
There is an R Markdown formatting cheat sheet that I have put on the class Moodle page, in case you want to play with more advanced formatting. Also note that there are many resources on the internet.
Let’s say my question was, ‘What’s the mean of the numbers 7, 11, 14, and 100? What’s the median? Why is the mean higher than the median?’ You could answer this by writing a little code chunk (don’t worry, I don’t expect you to understand the details of this code yet), and then writing the explanatory part. You insert a code chunk by clicking on the drop down menu above with a letter c, and then R. When you knit the file, the code chunk will be executed, and the results will show up in your .html file right after the code.
mean(c(7,11,14,100))
## [1] 33
median(c(7,11,14, 100))
## [1] 12.5
The mean (33) is much higher than the median (14) because the mean is strongly influenced by the one extreme value (100), while the median is not.
Very important: You can run the code chunk without Knitting the entire file just by clicking the little ‘play’ symbol (triangle pointing to the right) in the upper right of the code chunk itself. It’s a very good idea to run each of your code chunks before Knitting the file, to check that they work the way you intended.
Let’s say my question was, “What kind of graph should you use to show
the relationship between weight and gas mileage in the
mtcars data set? Make the graph. Interpret it.” You could
answer it like this:
Here we are examining the relationship between two quantitative variables, so we should make a scatterplot. Here is the plot:
data(mtcars)
plot(mtcars$wt, mtcars$mpg)
As weight goes up, gas mileage goes down. The relationship between the two variables appears to be linear.
Again, you can run this little bit of code by clicking the ‘play’ symbol, and you’ll see the plot show up right under the code itself.
If there’s a problem with your code, the file will not Knit properly; you’ll get an error message. First, you should try to fix it. But if you can’t, you still don’t want that to prevent you from doing the rest of the homework. In this case, just put ‘eval = FALSE’ in your code chunk, just like this:
mean(c(7,b,14,100))
This code is ‘broken’ because I included the letter b in the
list of values that the mean function was supposed to deal
with, and this makes no sense. But because I also included ‘eval =
FALSE’, this error won’t stop my file from knitting, because the code in
this chunk won’t be run. In a case like this, you should explain in your
homework that you had an error in your code, but that you couldn’t
figure out how to fix it. (The more you explain to your TA about your
attempt to do a problem, the more partial credit you are likely to
get.)
Your TA is available to help you figure out how to format your homework assignments, and so am I. After the first one or two assignments, it will be very easy.