We are going to work with AnimalData.csv available at https://courses.edx.org/c4x/UTAustinX/UT.7.01x/asset/AnimalData.csv #descriptive analysis of Age at Intake
head(animaldata)
## Impound.No Intake.Date Intake.Type Animal.Type Neutered.Status Sex
## 1 K12-000031 1/1/12 Stray Dog Spayed Female
## 2 K12-000037 1/1/12 Stray Dog Intact Female
## 3 K12-000108 1/1/12 Stray Dog Intact Male
## 4 K12-000125 1/1/12 Stray Dog Neutered Male
## 5 K12-000157 1/1/12 Stray Dog Neutered Male
## 6 K12-000286 1/1/12 Stray Dog Neutered Male
## Age.Intake Condition Breed Aggressive
## 1 10 Injured or Sick Chihuahua Sh Mix N
## 2 3 Normal Rat Terrier Mix N
## 3 2 Normal Pit Bull Mix N
## 4 0 Normal Labrador Retr & Border Collie N
## 5 3 Injured or Sick Labrador Retr N
## 6 5 Normal Yorkshire Terr N
## Independent Intelligent Loyal Social Good.with.Kids Max.Life.Expectancy
## 1 N Y N N N 18
## 2 N Y N Y Y 14
## 3 N N Y N Y 14
## 4 Y Y Y Y Y 12
## 5 Y Y Y Y Y 12
## 6 N N Y N Y 15
## Max.Weight Dog.Group Color Weight Lab.Test
## 1 6 Toy Tan & White 3.3 Heartworm Negative
## 2 25 Terrier White & Brown 7.5 No Lab Test
## 3 90 Terrier Blue & White 74.0 Heartworm Negative
## 4 79 Sporting White & Black 22.0 No Lab Test
## 5 79 Sporting Black & White 54.0 Heartworm Negative
## 6 7 Terrier Silver & Tan 4.8 Heartworm Negative
## Outcome.Date Outcome.Type Days.Shelter
## 1 1/7/12 Adoption 6
## 2 1/3/12 Return to Owner 2
## 3 1/13/12 Humane Euthanasia 12
## 4 1/8/12 Adoption 7
## 5 4/4/12 Adoption 94
## 6 1/10/12 Return to Owner 9
table(animaldata$Sex)
##
## Female Male
## 220 253
plot(animaldata$Sex,main='Bar Chart of Animal Genders', xlab='Gender', ylab='Frequency')
how old was an animal when it enterd the shelter
hist(animaldata$Age.Intake, main='Intake Ages', xlab='Age')
femaleage<-animaldata$Age.Intake[animaldata$Sex=='Female']
maleage<-animaldata$Age.Intake[animaldata$Sex=='Male']
hist(femaleage)
hist(maleage)
change the number of bins
hist(maleage, breaks=15)
max age of intake
max(maleage)
## [1] 17
max(femaleage)
## [1] 15
which(animaldata$Age.Intake==17)
## [1] 415
animaldata[415,]
## Impound.No Intake.Date Intake.Type Animal.Type Neutered.Status
## 415 K12-020475 11/11/12 Owner Surrender Dog Neutered
## Sex Age.Intake Condition Breed Aggressive Independent
## 415 Male 17 Injured or Sick Dachshund Y N
## Intelligent Loyal Social Good.with.Kids Max.Life.Expectancy Max.Weight
## 415 N Y Y N 14 28
## Dog.Group Color Weight Lab.Test Outcome.Date Outcome.Type
## 415 Hound Brown 6.5 No Lab Test 11/15/12 Humane Euthanasia
## Days.Shelter
## 415 4
cener of numeric distribution
mean(animaldata$Age.Intake)
## [1] 2.348837
median(animaldata$Age.Intake)
## [1] 1
Sperad
sd(animaldata$Age.Intake)
## [1] 3.099837
fivenum(animaldata$Age.Intake)
## [1] 0 0 1 3 17
How many of the first 10 animals in the dataset were adopted?
animaldata[1:10,]$Outcome.Type=='Adoption'
## [1] TRUE FALSE FALSE TRUE TRUE FALSE FALSE FALSE FALSE TRUE
class(animaldata$Days.Shelter)
## [1] "integer"
class(animaldata$Outcome.Type)
## [1] "factor"
Find the number of animals that were adopted
table(animaldata$Outcome.Type)
##
## Adoption Died Humane Euthanasia Return to Owner
## 204 3 39 73
## Transfer
## 154
Pull out only adopted animals
adopted<-animaldata[animaldata$Outcome.Type=="Adoption",]
Pull out just the days in shelter for the adopted animals
daystoadopt<-adopted$Days.Shelter
visualize and describe the variable
hist(daystoadopt)
fivenum(daystoadopt)
## [1] 2 8 13 38 211
mean(daystoadopt)
## [1] 29.26471
sd(daystoadopt)
## [1] 35.71547
which(animaldata$Days.Shelter==max(daystoadopt))
## [1] 425
animaldata[425,]
## Impound.No Intake.Date Intake.Type Animal.Type Neutered.Status Sex
## 425 K12-020743 11/18/12 Stray Dog Neutered Male
## Age.Intake Condition Breed Aggressive
## 425 2 Injured or Sick Aust Cattle Dog & Labrador Retr Y
## Independent Intelligent Loyal Social Good.with.Kids
## 425 N Y Y N Y
## Max.Life.Expectancy Max.Weight Dog.Group Color Weight
## 425 16 35 Herding White & Tan 48.25
## Lab.Test Outcome.Date Outcome.Type Days.Shelter
## 425 Heartworm Negative 6/17/13 Adoption 211
Create a table to show how many adult cats and dogs are in the dataset. An animal is considered an adult if it is at least one year of age.
table(animaldata$Animal.Type)
##
## Cat Dog
## 182 291
adultanimal<-animaldata[animaldata$Age.Intake>=1,]
table(adultanimal$Animal.Type)
##
## Cat Dog
## 56 226
adultdogsweight<-adultanimal$Weight[adultanimal$Animal.Type=='Dog']
adultcatsweight<-adultanimal$Weight[adultanimal$Animal.Type=='Cat']
hist(adultdogsweight)
hist(adultcatsweight)
mean(adultcatsweight)
## [1] 8.603571
sd(adultcatsweight)
## [1] 1.911517
fivenum(adultdogsweight)
## [1] 3.30 13.50 35.25 54.00 131.00
fivenum(adultcatsweight)
## [1] 4.75 7.40 8.50 9.75 13.50
What was the most common way that dogs arrived in the shelter? (as defined by the “Intake.Type” variable)
table(animaldata$Intake.Type[animaldata$Animal.Type=='Dog'])
##
## Euthanasia Request Owner Surrender Public Assist
## 1 81 20
## Stray
## 189
alldogs<-animaldata[animaldata$Animal.Type=='Dog',]
What proportion of dogs were brought to the shelter as an owner surrender?
nrow(alldogs[alldogs$Intake.Type=="Owner Surrender",])/nrow(alldogs)
## [1] 0.2783505
Of the dogs that were brought to the shelter as an owner surrender, how many were returned to their owner?
nrow(alldogs[alldogs$Intake.Type=="Owner Surrender" & alldogs$Outcome.Type=="Return to Owner",])
## [1] 2
What was the mean number of days that these dogs spent at the shelter before being returned to their owner?
daysshelter<- alldogs[alldogs$Intake.Type=="Owner Surrender" & alldogs$Outcome.Type=="Return to Owner",]
days<-daysshelter$Days.Shelter
mean(days)
## [1] 3.5