---

title: “Corn Production” format: html editor: visual ---

The Impact of Drought on Corn Production and Prices in Iowa.

Drought is a major concern for agricultural production, especially in the Midwest where corn is a significant crop. Iowa is the leading producer of corn in the United States, making it an important state to study the impact of drought on corn production and prices. This research proposal aims to investigate the following:

Ø  The historical impact of drought on corn production and prices in Iowa: This study will use historical data on drought and corn production in Iowa to analyze how drought has affected corn production and prices in the past. The analysis will also identify the key factors that contributed to the impact of drought on corn production and prices.

Ø  The potential impact of future droughts on corn production in Iowa and prices  Iowa: This study will use climate change projections and models to forecast the potential impact of future droughts on corn production and prices in Iowa. The analysis will consider the different scenarios of drought severity and their impact on corn production and prices.

Data Analysis

Here, I have plotted the trend of every variable and then explored the relation between them.

From the analysis , the climate data has a non linear relationship with corn production and hence the linear regression model doesn’t seem to work.

Also, since corn crop cycle is April to October, only these temperatures will be considered for annual metrics.

library(tidyverse) 
── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
✔ ggplot2 3.4.0     ✔ purrr   1.0.1
✔ tibble  3.1.8     ✔ dplyr   1.1.0
✔ tidyr   1.3.0     ✔ stringr 1.5.0
✔ readr   2.1.3     ✔ forcats 1.0.0
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
library(readxl)
library(tidyr)
library(dplyr)
Corn_Prod_Data <- read_csv("C:/Users/aishu/OneDrive/Desktop/Corn Production Data ( Final).csv", skip = 1)
Rows: 33 Columns: 7
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (7): Year, Average Temperature (Deg F), Precipitation (Inches), Average ...

ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
print(Corn_Prod_Data)
# A tibble: 33 × 7
    Year `Average Temperature (Deg F)` Precipi…¹ Avera…² Yeild…³ Produ…⁴ Corn …⁵
   <dbl>                         <dbl>     <dbl>   <dbl>   <dbl>   <dbl>   <dbl>
 1  1990                          47.6      29.6  -1.41      126  1.56e9    2.52
 2  1991                          46.7      32.7   0.519     117  1.43e9    2.47
 3  1992                          46.1      34.5   2.83      147  1.90e9    2.39
 4  1993                          43.2      39.4   5.87       80  8.8 e8    2.39
 5  1994                          45.4      28.0   3.63      152  1.92e9    2.50
 6  1995                          45.4      32.2   3.12      123  1.43e9    2.81
 7  1996                          43        29.9   2.52      138  1.71e9    3.67
 8  1997                          45.3      23.4   0.931     138  1.64e9    2.75
 9  1998                          49.1      31.4   0.383     145  1.77e9    2.38
10  1999                          48.1      24.8  -0.318     149  1.76e9    2.12
# … with 23 more rows, and abbreviated variable names
#   ¹​`Precipitation (Inches)`, ²​`Average Palmer Drought Severity Index (PDSI)`,
#   ³​`Yeild (BU/Acre)`, ⁴​`Production (BU)`, ⁵​`Corn Price (USD)`
# normalize the data using z-score normalization
normalized_Corn_Prod_Data <- scale(Corn_Prod_Data)

# view the normalized data
normalized_Corn_Prod_Data
            Year Average Temperature (Deg F) Precipitation (Inches)
 [1,] -1.6546806                  0.57889959            -0.12870650
 [2,] -1.5512631                  0.07909384             0.43301172
 [3,] -1.4478455                 -0.25410999             0.76098268
 [4,] -1.3444280                 -1.86459519             1.65067186
 [5,] -1.2410105                 -0.64284780            -0.42587356
 [6,] -1.1375929                 -0.64284780             0.33335204
 [7,] -1.0341754                 -1.97566314            -0.08159465
 [8,] -0.9307578                 -0.69838177            -1.25214294
 [9,] -0.8273403                  1.41190917             0.18839249
[10,] -0.7239228                  0.85656945            -1.01114771
[11,] -0.6205052                  0.02355987            -0.94591591
[12,] -0.5170877                  0.41229767            -0.10696257
[13,] -0.4136702                  0.41229767            -0.91511201
[14,] -0.3102526                 -0.19857602            -0.93685594
[15,] -0.2068351                  0.19016178             0.61783513
[16,] -0.1034175                  0.91210342             0.23188036
[17,]  0.0000000                  1.24530726            -0.51828527
[18,]  0.1034175                  0.35676370             0.74105074
[19,]  0.2068351                 -1.42032341             0.07786084
[20,]  0.3102526                 -0.92051766            -0.29178598
[21,]  0.4136702                 -0.19857602             1.59268805
[22,]  0.5170877                 -0.14304205            -0.75746851
[23,]  0.6205052                  2.18938479            -1.25395494
[24,]  0.7239228                 -0.92051766            -0.35882977
[25,]  0.8273403                 -1.30925547             0.25543628
[26,]  0.9307578                  0.85656945             0.84795841
[27,]  1.0341754                  1.41190917             1.13968948
[28,]  1.1375929                  0.91210342            -0.13051850
[29,]  1.2410105                 -0.69838177             2.44432535
[30,]  1.3444280                 -1.14265355             1.64161189
[31,]  1.4478455                  0.52336562            -1.72326145
[32,]  1.5512631                  1.07870534            -0.42406157
[33,]  1.6546806                 -0.42071191            -1.69426954
      Average Palmer Drought Severity Index (PDSI) Yeild (BU/Acre)
 [1,]                                 -1.040819677     -1.26908827
 [2,]                                 -0.273995372     -1.58371199
 [3,]                                  0.643945237     -0.53496626
 [4,]                                  1.848907622     -2.87716506
 [5,]                                  0.958743314     -0.36017530
 [6,]                                  0.758357143     -1.37396284
 [7,]                                  0.518621214     -0.84958998
 [8,]                                 -0.110644269     -0.84958998
 [9,]                                 -0.327894622     -0.60488264
[10,]                                 -0.606318971     -0.46504987
[11,]                                 -1.615193899     -0.63984083
[12,]                                 -0.474712213     -0.56992445
[13,]                                 -0.767686053      0.02436480
[14,]                                 -0.624175165     -0.18538435
[15,]                                  0.006412999      0.65361224
[16,]                                  0.396934562      0.37394671
[17,]                                 -0.256469849      0.12923937
[18,]                                  0.048738791      0.30403033
[19,]                                  0.690900413      0.30403033
[20,]                                  0.449180461      0.65361224
[21,]                                  1.220303480      0.09428118
[22,]                                  0.294096115      0.33898852
[23,]                                 -1.800038568     -0.88454817
[24,]                                 -1.551043871      0.05932299
[25,]                                 -0.482978969      0.54873767
[26,]                                  0.260367749      1.03815234
[27,]                                  1.190873828      1.42269244
[28,]                                  0.836064652      1.38773425
[29,]                                  1.222948842      1.17798510
[30,]                                  2.020856151      1.24790149
[31,]                                 -0.377825830      0.51377947
[32,]                                 -1.587086928      1.45765063
[33,]                                 -1.469368319      1.31781787
      Production (BU) Corn Price (USD)
 [1,]     -1.16525057      -0.71350030
 [2,]     -1.48586963      -0.74908576
 [3,]     -0.35479684      -0.79953258
 [4,]     -2.78592054      -0.80000978
 [5,]     -0.32736609      -0.72618017
 [6,]     -1.48729460      -0.51539426
 [7,]     -0.81185712       0.06992525
 [8,]     -0.97572908      -0.55745600
 [9,]     -0.67458466      -0.80832669
[10,]     -0.70023418      -0.98932172
[11,]     -0.77195786      -0.98938989
[12,]     -0.92300506      -0.99511628
[13,]     -0.28853556      -0.87056717
[14,]     -0.43875153      -0.83954919
[15,]      0.45446942      -0.70300190
[16,]      0.25996052      -0.99136686
[17,]     -0.00698453      -0.63851177
[18,]      0.76915109       0.13332463
[19,]      0.32242187       1.18275492
[20,]      0.84134975       0.12603030
[21,]      0.23799218       0.50444965
[22,]      0.72046449       2.20253065
[23,]     -0.41832691       2.28345009
[24,]      0.20699901       1.44576012
[25,]      0.74658901       0.40641920
[26,]      1.07480793       0.14757245
[27,]      1.63268509       0.02043282
[28,]      1.31277852       0.03393076
[29,]      1.05913322       0.09398975
[30,]      1.26076698       0.19631499
[31,]      0.54685521       0.04967835
[32,]      1.15603142       1.48795821
[33,]      1.01400905       2.30178819
attr(,"scaled:center")
                                        Year 
                                2.006000e+03 
                 Average Temperature (Deg F) 
                                4.655758e+01 
                      Precipitation (Inches) 
                                3.033030e+01 
Average Palmer Drought Severity Index (PDSI) 
                                1.209672e+00 
                             Yeild (BU/Acre) 
                                1.623030e+02 
                             Production (BU) 
                                2.053041e+09 
                            Corn Price (USD) 
                                3.566427e+00 
attr(,"scaled:scale")
                                        Year 
                                9.669540e+00 
                 Average Temperature (Deg F) 
                                1.800700e+00 
                      Precipitation (Inches) 
                                5.518781e+00 
Average Palmer Drought Severity Index (PDSI) 
                                2.520134e+00 
                             Yeild (BU/Acre) 
                                2.860560e+01 
                             Production (BU) 
                                4.210604e+08 
                            Corn Price (USD) 
                                1.466891e+00 
# Load required packages
library(ggplot2)


ggplot(Corn_Prod_Data, aes(x = Year)) +
  geom_line(aes(y = `Average Temperature (Deg F)`, color = "Average Temperature (Deg F)")) +
  geom_line(aes(y = `Precipitation (Inches)`, color = "Precipitation (Inches)")) +
  geom_line(aes(y =`Average Palmer Drought Severity Index (PDSI)`, color = "Average Palmer Drought Severity Index (PDSI)")) +
  labs(x = "Year", y = "Value", color = "Variable") +
  scale_color_manual(values = c("red", "blue", "green"))

library(ggplot2)

ggplot(data =Corn_Prod_Data, aes(x = Year, y = `Average Palmer Drought Severity Index (PDSI)`, group = 1)) +
  geom_line(aes(colour = ifelse(`Average Palmer Drought Severity Index (PDSI)` >= 0, "brown", "green"))) +
  scale_color_manual(values = c("green", "brown"), 
                     guide = guide_legend(title = "PDSI")) +
  labs(x = "Year", y = "Average PDSI", title = "Average Palmer Drought Severity Index (PDSI)", 
       subtitle = "The Palmer Drought Severity Index (PDSI)  is a standardized index that generally spans -10 (dry) to +10 (wet).") +
  theme_bw() +
  theme(plot.title = element_text(size = 14, face = "bold"),
        plot.subtitle = element_text(size = 12),
        legend.position = "bottom") +
  geom_hline(yintercept = 0, linetype = "dashed")

library(ggplot2)

# create scatter plot
ggplot(Corn_Prod_Data, aes(x = Year, y =`Average Temperature (Deg F)`)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) +
  labs(x = "Year", y ="Average Temperature (Deg F)", 
       title = "Average Temperature Trend")
`geom_smooth()` using formula = 'y ~ x'

# create scatter plot
ggplot(Corn_Prod_Data, aes(x = Year, y =`Precipitation (Inches)`)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) +
  labs(x = "Year", y ="Precipitation (Inches)", 
       title = "Precipitation Trend")
`geom_smooth()` using formula = 'y ~ x'

ggplot(Corn_Prod_Data, aes(x = Year, y = `Yeild (BU/Acre)`)) +
  geom_line() +
  ylab("Yield") +
  scale_y_continuous()

ggplot(Corn_Prod_Data, aes(x = Year, y = `Production (BU)`)) +
  geom_line() +
  ylab("Productions(Bu)") +
  scale_y_continuous()

ggplot(Corn_Prod_Data, aes( x=`Corn Price (USD)`, y = `Production (BU)`)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) +
  xlab("Production") +
  ylab("Price")
`geom_smooth()` using formula = 'y ~ x'

ggplot(Corn_Prod_Data, aes(x = `Corn Price (USD)`, y = `Yeild (BU/Acre)`)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE) +
  xlab("Yield") +
  ylab("Price")
`geom_smooth()` using formula = 'y ~ x'

# Fit the linear regression model
model <- lm(`Production (BU)` ~ `Average Palmer Drought Severity Index (PDSI)` + `Average Temperature (Deg F)` + `Precipitation (Inches)`, data =Corn_Prod_Data)

# Print the model summary
summary(model)

Call:
lm(formula = `Production (BU)` ~ `Average Palmer Drought Severity Index (PDSI)` + 
    `Average Temperature (Deg F)` + `Precipitation (Inches)`, 
    data = Corn_Prod_Data)

Residuals:
       Min         1Q     Median         3Q        Max 
-1.108e+09 -2.907e+08 -2.385e+07  3.215e+08  6.029e+08 

Coefficients:
                                                 Estimate Std. Error t value
(Intercept)                                    -1.072e+09  2.189e+09  -0.489
`Average Palmer Drought Severity Index (PDSI)`  2.311e+07  4.595e+07   0.503
`Average Temperature (Deg F)`                   6.357e+07  4.593e+07   1.384
`Precipitation (Inches)`                        4.515e+06  1.980e+07   0.228
                                               Pr(>|t|)
(Intercept)                                       0.628
`Average Palmer Drought Severity Index (PDSI)`    0.619
`Average Temperature (Deg F)`                     0.177
`Precipitation (Inches)`                          0.821

Residual standard error: 426600000 on 29 degrees of freedom
Multiple R-squared:  0.06988,   Adjusted R-squared:  -0.02634 
F-statistic: 0.7262 on 3 and 29 DF,  p-value: 0.5446
ggplot(Corn_Prod_Data, aes( x=`Precipitation (Inches)`, y = `Production (BU)`)) + 
  geom_point() + 
  geom_smooth(method = "loess")
`geom_smooth()` using formula = 'y ~ x'

ggplot(Corn_Prod_Data, aes( x=`Average Palmer Drought Severity Index (PDSI)`, y = `Production (BU)`)) + 
  geom_point() + 
  geom_smooth(method = "loess")
`geom_smooth()` using formula = 'y ~ x'

ggplot(Corn_Prod_Data, aes( x=`Average Temperature (Deg F)`, y = `Production (BU)`)) + 
  geom_point() + 
  geom_smooth(method = "loess")
`geom_smooth()` using formula = 'y ~ x'