STAT 360: Computational Statistics and Data Analysis

Load R Libraries, Import and Attach Relevant Data, and Specify Seed

library(rmarkdown); library(knitr); library(readxl)
set.seed(37)

EXERCISE 01

Part (a)

poundToNewton <- function(pounds)
{
  newt <- pounds*4.44822
  return(newt)
}

Part (b)

poundToNewton(70.59)
## [1] 313.9998
poundToNewton(35.75)
## [1] 159.0239

EXERCISE 02

MooseWolvesData <- read.csv("C:/Users/Sarah Chock/OneDrive - University of St. Thomas/Senior Year/STAT 360 Comp Stat and Data Analysis/Exploratory Data Analysis/Wolfies.csv")

Part (b)

nums <- which(sapply(MooseWolvesData, is.numeric))
numwolves <- as.matrix(MooseWolvesData[,nums])
numwolves
##       ï..year wolves moose Apr.May..temp..F. Jan.Feb..temp..F.
##  [1,]    1959     20   538             43.90              1.40
##  [2,]    1960     22   564             43.40              8.45
##  [3,]    1961     22   572             41.40              9.75
##  [4,]    1962     23   579             42.60              2.15
##  [5,]    1963     20   596             43.50             -0.35
##  [6,]    1964     26   620             45.75             12.40
##  [7,]    1965     28   634             43.65              1.25
##  [8,]    1966     26   661             39.20              1.70
##  [9,]    1967     22   766             39.90              2.75
## [10,]    1968     22   848             43.00              5.85
## [11,]    1969     17  1041             44.95              7.80
## [12,]    1970     18  1045             41.15              3.35
## [13,]    1971     20  1183             42.45              3.20
## [14,]    1972     23  1243             44.10             -0.05
## [15,]    1973     24  1215             42.70             10.85
## [16,]    1974     31  1203             41.55              5.65
## [17,]    1975     41  1139             42.80              9.05
## [18,]    1976     44  1070             45.95             10.45
## [19,]    1977     34   949             50.55              4.70
## [20,]    1978     40   845             44.90              3.25
## [21,]    1979     43   857             39.50             -1.15
## [22,]    1980     50   788             47.95              7.15
## [23,]    1981     30   767             44.50             11.70
## [24,]    1982     14   780             43.75              0.40
## [25,]    1983     23   830             41.10             14.45
## [26,]    1984     24   927             44.85             12.50
## [27,]    1985     22   976             47.05              5.45
## [28,]    1986     20  1014             47.45              9.80
## [29,]    1987     16  1046             49.20             17.95
## [30,]    1988     12  1116             47.30              3.10
## [31,]    1989     12  1260             43.35              6.60
## [32,]    1990     15  1315             43.15             13.05
## [33,]    1991     12  1496             48.35              9.10
## [34,]    1992     12  1697             44.15             15.20
## [35,]    1993     13  1784             42.60              9.10
## [36,]    1994     17  2017             44.60             -0.40
## [37,]    1995     16  2117             41.65              9.50
## [38,]    1996     22  2398             40.30              2.80
## [39,]    1997     24   900             40.70              8.35
## [40,]    1998     14   925             49.40             20.75
## [41,]    1999     25   997             47.35             12.40
## [42,]    2000     29  1031             45.10             12.60
## [43,]    2001     19  1120             46.00             10.05
## [44,]    2002     17  1100             41.00             16.65
## [45,]    2003     19   900             44.20              5.80
## [46,]    2004     29   750             42.05              7.60
## [47,]    2005     30   540             45.85             10.15
## [48,]    2006     30   450             48.80             15.20
## [49,]    2007     21   385             45.40              7.95
## [50,]    2008     23   650             41.55              7.75
## [51,]    2009     24   530             43.55              6.00
## [52,]    2010     19   510             49.20             10.65
## [53,]    2011     16   515             43.85              6.85
## [54,]    2012      9   750             46.50             17.15
## [55,]    2013      8   975             39.80              8.95
## [56,]    2014      9  1050             42.05             -1.05
## [57,]    2015      3  1250             44.65              3.85
## [58,]    2016      2  1300             44.20             11.95
## [59,]    2017      2  1600             43.85             15.40
## [60,]    2018      2  1475             42.70              6.05
## [61,]    2019     15  2060             41.65              3.50
##       ice.bridges..0.none..1...present.
##  [1,]                                 0
##  [2,]                                 0
##  [3,]                                 1
##  [4,]                                 1
##  [5,]                                 1
##  [6,]                                 0
##  [7,]                                 1
##  [8,]                                 1
##  [9,]                                 1
## [10,]                                 1
## [11,]                                 1
## [12,]                                 1
## [13,]                                 1
## [14,]                                 1
## [15,]                                 0
## [16,]                                 1
## [17,]                                 0
## [18,]                                 0
## [19,]                                 1
## [20,]                                 0
## [21,]                                 1
## [22,]                                 0
## [23,]                                 0
## [24,]                                 1
## [25,]                                 0
## [26,]                                 0
## [27,]                                 1
## [28,]                                 0
## [29,]                                 0
## [30,]                                 1
## [31,]                                 0
## [32,]                                 0
## [33,]                                 1
## [34,]                                 0
## [35,]                                 0
## [36,]                                 1
## [37,]                                 0
## [38,]                                 1
## [39,]                                 1
## [40,]                                 0
## [41,]                                 0
## [42,]                                 0
## [43,]                                 0
## [44,]                                 0
## [45,]                                 0
## [46,]                                 0
## [47,]                                 0
## [48,]                                 0
## [49,]                                 0
## [50,]                                 1
## [51,]                                 0
## [52,]                                 0
## [53,]                                 0
## [54,]                                 0
## [55,]                                 0
## [56,]                                 1
## [57,]                                 1
## [58,]                                 0
## [59,]                                 0
## [60,]                                 1
## [61,]                                 1

Part (c)

sumsquares <- function(param = c(0,0,0))
{
  pred <- param[1] + param[2]*numwolves[,2] + param[3]*numwolves[,4]
  res <- numwolves[,3] - pred
  resss <- (res)^2
  return(sum(resss))
}

Part (d)

sumsquares(c(2000,-10,-20))
## [1] 10650919
sumsquares(c(3000,-15,-25))
## [1] 29011491

Part (e)

The first estimation with (2000,-10,-20) is better because it had a lower residual sum of squares. This means that the actual points tend to fall closer to the prediction line.

Part (f)

optim(par = c(0,0,0), fn = sumsquares, method = "Nelder-Mead")
## $par
## [1] 2383.65262  -14.44774  -24.02888
## 
## $value
## [1] 9749433
## 
## $counts
## function gradient 
##      370       NA 
## 
## $convergence
## [1] 0
## 
## $message
## NULL

Part (g)

From this model, the number of wolves and average temperature both have a negative impact on the number of moose. For every additional wolf, mooses go down by 14ish, and for every additional degree in temp, mooses go down by 24ish. The mooses just want to live alone in the arctic.
library(cats)
here_kitty()

## meow