##Preliminaries
rm(list = ls())
aliens <- read.csv ("aliens.csv", header = TRUE, stringsAsFactors = TRUE)
source('special_functions.R')
my_sample <- make.my.sample(34252777, 100, aliens)
college.table <- table(my_sample$college)
college.table
##
## Callisto Europa Ganymede Io
## 29 23 19 29
politics.table <- table(my_sample$politics)
politics.table
##
## Democrulite Independone Republicant
## 29 41 30
island.table <- table(my_sample$island)
island.table
##
## Blick Nanspucket Plume
## 32 31 37
The output of the code above is finding the table for colleges attended by the aliens in my sample. It shows the total number of aliens that attended each college within my sample of 100.
For the second table, I found the number of aliens in each political party within my sample of 100. from the results, we see that more Aliens from my sample are Independone.
For the third table, I found the amount of aliens on each island within my sample of 100. From the results we see that there are a fairly equal amount of aliens on each island, but a couple more live on Plume from my sample.
##Question 2
barplot(college.table)
barplot(island.table)
barplot(politics.table)
##Question 3
table(aliens$college, aliens$island)
##
## Blick Nanspucket Plume
## Callisto 879 719 874
## Europa 854 811 868
## Ganymede 890 748 853
## Io 881 754 869
table(aliens$antennae, aliens$politics)
##
## Democrulite Independone Republicant
## Curly 721 748 686
## Straight 2497 2704 2644
##Question 4
barplot(table(my_sample$college, my_sample$island), beside = TRUE, legend = T, ylim = c(0, 15),
xlab = "Island",
names = c("Blick", "Nanspucket", "Plume"))
The beside argument tells the graph to place the two data sets next to
each other instead of on top of each other. This allows you to see the
difference between the variables you put in your bar plot and how much
is in each bar. The legend argument tells the graph to place a key which
labels what color is associated with what college. I like the bar graph
better with the beside and legend arguments because you can clearly see
your two variables much better and compare them more easily.
##Question 5 In the graph above, there is an obvious increase in aliens from my sample attending Callisto and Lo College from Plume Island. Many aliens from Nanspucket attend Europa and Callisto and a majority from Blick Island attended Io and Ganymede College. In each group, there are two colleges that an equal number of aliens attended, demonstrating that there could be a connection between what island you are from and the college you attend.
##Question 6
hist(my_sample$anxiety)
boxplot(my_sample$anxiety)
mean(my_sample$anxiety)
## [1] 50.18
median(my_sample$anxiety)
## [1] 50
var(my_sample$anxiety)
## [1] 25.76525
sd(my_sample$anxiety)
## [1] 5.075948
hist(my_sample$intelligence)
boxplot(my_sample$intelligence)
mean(my_sample$intelligence)
## [1] 108.3
median(my_sample$intelligence)
## [1] 107
var(my_sample$intelligence)
## [1] 91.26263
sd(my_sample$intelligence)
## [1] 9.553147
hist(my_sample$income)
boxplot(my_sample$income)
mean(my_sample$income)
## [1] 69500
median(my_sample$income)
## [1] 54500
var(my_sample$income)
## [1] 4206696970
sd(my_sample$income)
## [1] 64859.05
When it comes to the alien’s anxiety, the median and mean are the same demonstrating that there is a symmetrical distribution of anxiety throughout my sample of aliens. When it comes to the alien’s intelligence the mean and median are also very similar, demonstrating a symmetrical distribution. The aliens from my sample’s income levels vary greatly, making the mean and median very different. This demonstrates that there is not a symmetrical distribution. If you look at the bar plot you can see it is rightly skewed.
##Question 7 There are only outliers within the income bar plot for the aliens in my sample. For descriptive statistics, I believe the outliers should be removed because we are trying to find the average overall, and the outliers are not included in that proportion in the bar plot. The mean would fit more towards the average alien if we got rid of the outlier because it causes the mean to increase greater than the actual mean of the majority of the aliens in my sample.
##Question 8
hist(my_sample$income, breaks = 20)
I think the best value for the breaks argument should be 20 because it
demonstrates the wide distribution of variables easily while also
clearly showing where the peak is in the histogram. It demonstrates very
well how the graph is rightly skewed and that there is a wide range of
incomes within my sample of aliens.
##Question 9
boxplot(my_sample$anxiety~my_sample$island, ylim = c(35, 65))
The ylin argument tells the barplot to start at 35 and end at 75 in the
data frame to control how big the values are and how much of the bar
plot you can see on the graph. If you change the numbers so that the
first one is small (ex. 4) and the second value is big (ex. 100) then it
will be harder to identify values on the bar plot as they will be much
smaller/narrower. If you leave out the ylin argument, the bar plot will
not show up, and there will be an error because the system does not know
what to use as its range of values. The box plot tells you that there is
a wider range of anxiety on Nanspucket within my sample of aliens and
that those on Plume and Blick Island have a mean anxiety that is roughly
equal and lower than Aliens from my sample on Nanspucket.
##Question 10
boxplot(my_sample$memory~my_sample$island, ylim = c(60, 120))
boxplot(my_sample$intelligence~my_sample$college, ylim = c(80, 130))
In the two box plots above, you can see that the aliens from my sample
that live on Blick and Plume Island have a greater mean memory score
than those from Nanspucket. There are a lot of outliers in the Aliens
from Plume Island.
In the second box plot, there is a similar mean for both Callisto and Europa colleges in the sample aliens’ intelligence scores that is lower than that of the other colleges. Ganymede and Io College both have a greater mean intelligence score, with Io having a greater variety in scores out of my sample of 100 aliens.
##Question 11
my_sample_2 <- make.my.sample(34252778, 100, aliens)
boxplot(my_sample_2$memory~my_sample$island, ylim = c(60, 120))
boxplot(my_sample_2$intelligence~my_sample$college, ylim = c(85, 135))
When it comes to memory score and the island the aliens are from, the
mean values from Nanspucket and Plume Island are close together, which
is different from my first sample. In my first sample, there were a lot
of outliers in the memory scores from the Aliens from Plume Island, and
in the new sample there is only one outlier from Nanspucket,
When it comes to intelligence scores and the colleges attended by the sample aliens, The mean of all the colleges is much closer together than in my first sample. Within my first sample, Io has the greatest mean while with my new sample, Io has the lowest mean. Within both of my samples, there were outliers from both Callisto and Ganymede College.
##Question 12
newvar <- c(95, 105, 98, 102, 103, 103, 100, 95, 105, 98,
102, 102, 103, 100, 95, 105, 99, 102, 99, 103,
100, 95, 105, 98, 102, 106, 103, 100, 95, 105,
99, 102, 97, 103, 100, 95, 105, 98, 102, 97)
hist(newvar)
boxplot(newvar)
mean(newvar)
## [1] 100.525
##Question 13
newvar2 <- c(96, 101, 99, 98, 101, 99, 102, 100, 99, 101,
101, 97, 100, 100, 100, 100, 98, 98, 99, 102,
99, 99, 102, 100, 100, 101, 98, 100, 99, 101,
99, 100, 100, 99, 101, 98, 100, 102, 101, 97, 100)
hist(newvar2)
boxplot(newvar2)
mean(newvar2)
## [1] 99.68293
newvar2 <- c(96, 101, 99, 98, 101, 99, 102, 100, 99, 101,
101, 97, 100, 100, 100, 100, 98, 98, 99, 102,
99, 99, 102, 100, 100, 101, 98, 100, 99, 101,
99, 100, 100, 99, 101, 98, 100, 102, 101, 97, 200)
hist(newvar2)
boxplot(newvar2)
mean(newvar2)
## [1] 102.122
##Question 14
newvar3 <- c (97, 98, 97, 102, 97, 98, 97, 102, 97, 98,
101, 102, 97, 98, 99, 102, 103, 104, 103, 98,
103, 101, 103, 104, 103, 99, 103, 104, 103, 104,
101, 104, 103, 98, 99, 100, 103, 100, 103, 104)
hist(newvar3)
boxplot(newvar3)
mean(newvar3)
## [1] 100.8
##Question 15
Based on questions 12-14, I think that the histogram is better at demonstrating the detailed shape of the distribution because you can see exactly where there are peaks in the data. The box plot does not demonstrate where a majority of your data points are, it only demonstrates the range and median, which is not helpful in figuring out the distribution of the data. The histograms clearly demonstrate the shape of the data and exactly what type of distribution it is.
##Question 16
I added an extremely high value to problem 13 where I had a symmetrical distribution. When I placed 200 into the data set, the mean changed very little, but the histogram changed drastically, causing it to now look skewed right instead of symmetrical. The box plot also changed drastically by shrinking in size to include the outlier within the data set.