R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

# Linear Regression Project
# frequency of named hurricanes over time
# 1851-2022

# record variables and values - get into environment

NS <- c(6,  5,  8,  5,  5,  6,  4,  6,  8,  7,  8,  6,  9,  5,  7,  7,  9,  4,  10, 11, 8,  5,  5,  7,  6,  5,  8,  12, 8,  11, 7,  6,  4,  4,  8,  12, 19, 9,  9,  4,  10, 9,  12, 7,  6,  7,  6,  11, 10, 7,  13, 5,  10, 6,  5,  11, 5,  10, 12, 5,  6,  7,  6,  1,  6,  15, 4,  6,  5,  5,  7,  5,  9,  11, 4,  11, 8,  6,  5,  3,  13, 15, 20, 13, 8,  17, 11, 9,  6,  9,  6,  11, 10, 14, 11, 7,  10, 10, 16, 16, 12, 11, 14, 16, 13, 12, 8,  12, 14, 8,  12, 7,  10, 13, 10, 11, 8,  8,  18, 10, 13, 7,  8,  11, 9,  10, 6,  12, 9,  11, 12, 6,  4,  13, 11, 6,  7,  12, 11, 14, 8,  7,  8,  7,  19, 13, 8,  14, 12, 15, 15, 12, 16, 15, 28, 10, 15, 16, 9,  19, 19, 19, 14, 8,  11, 15, 17, 15, 18, 30, 21, 14)
NS
##   [1]  6  5  8  5  5  6  4  6  8  7  8  6  9  5  7  7  9  4 10 11  8  5  5  7  6
##  [26]  5  8 12  8 11  7  6  4  4  8 12 19  9  9  4 10  9 12  7  6  7  6 11 10  7
##  [51] 13  5 10  6  5 11  5 10 12  5  6  7  6  1  6 15  4  6  5  5  7  5  9 11  4
##  [76] 11  8  6  5  3 13 15 20 13  8 17 11  9  6  9  6 11 10 14 11  7 10 10 16 16
## [101] 12 11 14 16 13 12  8 12 14  8 12  7 10 13 10 11  8  8 18 10 13  7  8 11  9
## [126] 10  6 12  9 11 12  6  4 13 11  6  7 12 11 14  8  7  8  7 19 13  8 14 12 15
## [151] 15 12 16 15 28 10 15 16  9 19 19 19 14  8 11 15 17 15 18 30 21 14
YR<- c(1851:2022)
YR
##   [1] 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865
##  [16] 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880
##  [31] 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895
##  [46] 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910
##  [61] 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925
##  [76] 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940
##  [91] 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955
## [106] 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970
## [121] 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985
## [136] 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000
## [151] 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015
## [166] 2016 2017 2018 2019 2020 2021 2022
# next command creates data frame

xdata <- data.frame(NS,YR)
xdata
##     NS   YR
## 1    6 1851
## 2    5 1852
## 3    8 1853
## 4    5 1854
## 5    5 1855
## 6    6 1856
## 7    4 1857
## 8    6 1858
## 9    8 1859
## 10   7 1860
## 11   8 1861
## 12   6 1862
## 13   9 1863
## 14   5 1864
## 15   7 1865
## 16   7 1866
## 17   9 1867
## 18   4 1868
## 19  10 1869
## 20  11 1870
## 21   8 1871
## 22   5 1872
## 23   5 1873
## 24   7 1874
## 25   6 1875
## 26   5 1876
## 27   8 1877
## 28  12 1878
## 29   8 1879
## 30  11 1880
## 31   7 1881
## 32   6 1882
## 33   4 1883
## 34   4 1884
## 35   8 1885
## 36  12 1886
## 37  19 1887
## 38   9 1888
## 39   9 1889
## 40   4 1890
## 41  10 1891
## 42   9 1892
## 43  12 1893
## 44   7 1894
## 45   6 1895
## 46   7 1896
## 47   6 1897
## 48  11 1898
## 49  10 1899
## 50   7 1900
## 51  13 1901
## 52   5 1902
## 53  10 1903
## 54   6 1904
## 55   5 1905
## 56  11 1906
## 57   5 1907
## 58  10 1908
## 59  12 1909
## 60   5 1910
## 61   6 1911
## 62   7 1912
## 63   6 1913
## 64   1 1914
## 65   6 1915
## 66  15 1916
## 67   4 1917
## 68   6 1918
## 69   5 1919
## 70   5 1920
## 71   7 1921
## 72   5 1922
## 73   9 1923
## 74  11 1924
## 75   4 1925
## 76  11 1926
## 77   8 1927
## 78   6 1928
## 79   5 1929
## 80   3 1930
## 81  13 1931
## 82  15 1932
## 83  20 1933
## 84  13 1934
## 85   8 1935
## 86  17 1936
## 87  11 1937
## 88   9 1938
## 89   6 1939
## 90   9 1940
## 91   6 1941
## 92  11 1942
## 93  10 1943
## 94  14 1944
## 95  11 1945
## 96   7 1946
## 97  10 1947
## 98  10 1948
## 99  16 1949
## 100 16 1950
## 101 12 1951
## 102 11 1952
## 103 14 1953
## 104 16 1954
## 105 13 1955
## 106 12 1956
## 107  8 1957
## 108 12 1958
## 109 14 1959
## 110  8 1960
## 111 12 1961
## 112  7 1962
## 113 10 1963
## 114 13 1964
## 115 10 1965
## 116 11 1966
## 117  8 1967
## 118  8 1968
## 119 18 1969
## 120 10 1970
## 121 13 1971
## 122  7 1972
## 123  8 1973
## 124 11 1974
## 125  9 1975
## 126 10 1976
## 127  6 1977
## 128 12 1978
## 129  9 1979
## 130 11 1980
## 131 12 1981
## 132  6 1982
## 133  4 1983
## 134 13 1984
## 135 11 1985
## 136  6 1986
## 137  7 1987
## 138 12 1988
## 139 11 1989
## 140 14 1990
## 141  8 1991
## 142  7 1992
## 143  8 1993
## 144  7 1994
## 145 19 1995
## 146 13 1996
## 147  8 1997
## 148 14 1998
## 149 12 1999
## 150 15 2000
## 151 15 2001
## 152 12 2002
## 153 16 2003
## 154 15 2004
## 155 28 2005
## 156 10 2006
## 157 15 2007
## 158 16 2008
## 159  9 2009
## 160 19 2010
## 161 19 2011
## 162 19 2012
## 163 14 2013
## 164  8 2014
## 165 11 2015
## 166 15 2016
## 167 17 2017
## 168 15 2018
## 169 18 2019
## 170 30 2020
## 171 21 2021
## 172 14 2022
# next command creates table

knitr::kable(xdata[,], col.names = c('number of named storms','year'), caption = "Named Storms per year in the Atlantic")
Named Storms per year in the Atlantic
number of named storms year
6 1851
5 1852
8 1853
5 1854
5 1855
6 1856
4 1857
6 1858
8 1859
7 1860
8 1861
6 1862
9 1863
5 1864
7 1865
7 1866
9 1867
4 1868
10 1869
11 1870
8 1871
5 1872
5 1873
7 1874
6 1875
5 1876
8 1877
12 1878
8 1879
11 1880
7 1881
6 1882
4 1883
4 1884
8 1885
12 1886
19 1887
9 1888
9 1889
4 1890
10 1891
9 1892
12 1893
7 1894
6 1895
7 1896
6 1897
11 1898
10 1899
7 1900
13 1901
5 1902
10 1903
6 1904
5 1905
11 1906
5 1907
10 1908
12 1909
5 1910
6 1911
7 1912
6 1913
1 1914
6 1915
15 1916
4 1917
6 1918
5 1919
5 1920
7 1921
5 1922
9 1923
11 1924
4 1925
11 1926
8 1927
6 1928
5 1929
3 1930
13 1931
15 1932
20 1933
13 1934
8 1935
17 1936
11 1937
9 1938
6 1939
9 1940
6 1941
11 1942
10 1943
14 1944
11 1945
7 1946
10 1947
10 1948
16 1949
16 1950
12 1951
11 1952
14 1953
16 1954
13 1955
12 1956
8 1957
12 1958
14 1959
8 1960
12 1961
7 1962
10 1963
13 1964
10 1965
11 1966
8 1967
8 1968
18 1969
10 1970
13 1971
7 1972
8 1973
11 1974
9 1975
10 1976
6 1977
12 1978
9 1979
11 1980
12 1981
6 1982
4 1983
13 1984
11 1985
6 1986
7 1987
12 1988
11 1989
14 1990
8 1991
7 1992
8 1993
7 1994
19 1995
13 1996
8 1997
14 1998
12 1999
15 2000
15 2001
12 2002
16 2003
15 2004
28 2005
10 2006
15 2007
16 2008
9 2009
19 2010
19 2011
19 2012
14 2013
8 2014
11 2015
15 2016
17 2017
15 2018
18 2019
30 2020
21 2021
14 2022
# next command created linear regression

LR  <-lm(NS~YR)

summary(LR)
## 
## Call:
## lm(formula = NS ~ YR)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -8.2491 -2.8462 -0.2045  1.8658 15.9058 
## 
## Coefficients:
##               Estimate Std. Error t value Pr(>|t|)    
## (Intercept) -86.638332  11.354784  -7.630  1.6e-12 ***
## YR            0.049868   0.005862   8.507  8.9e-15 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 3.817 on 170 degrees of freedom
## Multiple R-squared:  0.2986, Adjusted R-squared:  0.2945 
## F-statistic: 72.38 on 1 and 170 DF,  p-value: 8.896e-15
# Call:
#lm(formula = YR ~ NS)

#Residuals:
#  Min       1Q   Median       3Q      Max 
#-103.811  -37.159    2.076   33.097   89.058 

#Coefficients:
#  Estimate Std. Error t value Pr(>|t|)    
#(Intercept) 1877.0367     7.6828 244.317  < 2e-16 ***
#  NS             5.9881     0.7039   8.507  8.9e-15 ***
#  ---
# Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

#Residual standard error: 41.83 on 170 degrees of freedom
#Multiple R-squared:  0.2986,   Adjusted R-squared:  0.2945 
#F-statistic: 72.38 on 1 and 170 DF,  p-value: 8.896e-15

#these results suggest to me that there is not a strong linear relationship for named storm frequency 
#over time


# next command creates scatter plot

plot(YR, NS)

#   main = "Named Storms in the Atlantic", xlab ="", ylab = "Year", xlim = c(0.0,25.0), sub="Figure 1. 
#    Named Storms in the Atlantic 1851 - 2022")

abline(LR, col="red")

# need to figure out what is wrong with the dates; they are not appearing properly
# need to look at the outliers

plot(YR,residuals(LR))

abline(a=0,b=0)