title: How to create rate on R
body: <p>I want to change my data so that it gives me the rate of pedestrians to that states population. I am using a linear model and my summary values look like this:
  Coefficients:</p>
  <pre><code>             Estimate Std. Error t value Pr(&gt;|t|)   
  (Intercept)  0.087061   0.029876   2.914  0.00438 **
  intersection 0.009192   0.003086   2.978  0.00362 ** 
  </code></pre>
  <p>Here, my beta value intersection is .009192 and that is not meaningful because compared to a state that has a smaller population, this value might be nothing in comparison.</p>
  <p>Below is a condensed version of my data without all the columns I use, but here is the link of the csv incase someone wants to download it from <a href="https://www.nhtsa.gov/content/nhtsa-ftp/280561" rel="nofollow noreferrer">there</a>.</p>
  <pre><code>&gt; head(c)
  # A tibble: 6 x 15
    STATE STATENAME  PEDS PERSONS PERMVIT PERNOTMVIT COUNTY COUNTYNAME     CITY   DAY MONTH  YEAR LATITUDE LONGITUD
    &lt;dbl&gt; &lt;chr&gt;     &lt;dbl&gt;   &lt;dbl&gt;   &lt;dbl&gt;      &lt;dbl&gt;  &lt;dbl&gt; &lt;chr&gt;         &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt; &lt;dbl&gt;    &lt;dbl&gt;    &lt;dbl&gt;
  1     1 Alabama       0       3       3          0     81 LEE (81)       2340     7     2  2019     32.7    -85.3
  2     1 Alabama       0       2       2          0     55 ETOWAH (55)    1280    23     1  2019     34.0    -86.1
  3     1 Alabama       0       4       4          0     29 CLEBURNE (29)     0    22     1  2019     33.7    -85.4
  4     1 Alabama       1       1       1          1     55 ETOWAH (55)    2562    22     1  2019     34.0    -86.1
  5     1 Alabama       0       1       1          0      3 BALDWIN (3)       0    18     1  2019     30.7    -87.8
  6     1 Alabama       0       2       2          0     85 LOWNDES (85)      0     7     1  2019     32.2    -86.4
  # … with 1 more variable: FATALS &lt;dbl&gt;
  </code></pre>
  <p>Here is the code I have that runs through the process I am doing. I don't see how I can change it so that each value is a rate (values like peds or type_int)</p>
  <pre><code>#Libraries
  rm(list=ls()) # this is to clear anything  in memory
  library(leaflet)
  library(tidyverse)
  library(ggmap)
  library(leaflet.extras)
  library(htmltools)
  library(ggplot2)
  library(maps)
  library(mapproj)
  library(mapdata)
  library(zoo)
  library(tsibble)
  
  setwd(&quot;~/Desktop/Statistics790/DataSets/FARS2019NationalCSV&quot;)
  df &lt;- read.csv(&quot;accident.csv&quot;)
  
  state &lt;- unique(df$STATE)
  for(i in state){
    df1&lt;- df %&gt;%
      filter(STATE==i) %&gt;%
      dplyr::select(c(STATE,PEDS,DAY,MONTH,YEAR,TYP_INT)) %&gt;%
      mutate(date = as.Date(as.character(paste(YEAR, MONTH, DAY, sep = &quot;-&quot;),&quot;%Y-%m-%d&quot;))) %&gt;% # create a date
      group_by(date) %&gt;% # Group by State id and date
      # summarise_at(.vars = vars(PEDS), sum)
      summarise(pedday=sum(PEDS),intersection=mean(TYP_INT))
  #ts1&lt;-ts(df,start=c(2019,1,1), frequency=365) 
  setwd(&quot;~/Desktop/Statistics790/States_ts/figures&quot;)
  plots&lt;-df1 %&gt;% 
      ggplot()+
      geom_line(aes(x=date,y=pedday))+ylim(0,13)+
      theme_bw()
      ggsave(paste0(&quot;state_&quot;,i,&quot;.png&quot;),width=8,height=6, )
    ts1&lt;-ts(df1,start=c(2019,1,1), frequency=365)
    setwd(&quot;~/Desktop/Statistics790/States_ts&quot;)
    ts1 %&gt;% write.csv(paste0(&quot;state_&quot;,i,&quot;.csv&quot;),row.names = F)
  #Plots
  }
  #date1&lt;- as.character(df$date)
  #df1&lt;- df%&gt;% filter(STATE==&quot;1&quot;)
  #ts2&lt;-xts(df,order.by = as.Date(df$date,&quot;%Y-%m-%d&quot;))
  setwd(&quot;~/Desktop/Statistics790/States_ts&quot;)
  cat(&quot;\f&quot;)
  #df &lt;- read.csv(paste0(&quot;state_1.csv&quot;))
  #print(&quot;------Linear Model------&quot;)
  #summary(lm(pedday~weather,data=df))
  
  for(i in state){
    print(paste0(&quot;-------------------------Analysis for State: &quot;,i,&quot; -------------------------------&quot;))
    df &lt;- read.csv(paste0(&quot;state_&quot;,i,&quot;.csv&quot;))
    print(&quot;------Linear Model------&quot;)
    print(summary(lm(pedday~intersection,data=df)))
  }
  </code></pre>