title: extracting p values from multiple linear regression (lm) inside of a ddply function using spatial data
body: <p>I have a set of spatial coordinate (x,y) data that has a response variable for each coordinate over the course of several years. The following code generates a similar data frame:</p>
  
  <pre><code>df &lt;- data.frame(
    id = rep(1:2, 2),
    x = rep(c(25, 30),10),
    y = rep(c(100, 200), 10),
    year = rep(1980:1989, 2),
    response = rnorm(20)
  )
  </code></pre>
  
  <p>The resulting data frame:</p>
  
  <pre><code>head(df)
  
   id  x   y year   response
  1  1 25 100 1980  0.1707431
  2  2 30 200 1981  1.3562263
  3  1 25 100 1982 -0.4590506
  4  2 30 200 1983  1.3238410
  5  1 25 100 1984  1.7765772
  6  2 30 200 1985 -0.6258069
  </code></pre>
  
  <p>I want to run a linear regression on each cell through time to get the change in response variable. To do this, I use plyr and the ddply command:</p>
  
  <pre><code>require(plyr)    
  lm.df &lt;- ddply(df, .(id), function(z)coef(lm(response ~ year, data = z)))
  </code></pre>
  
  <p>Then I recombine w/ the spatial data (the example here of the recombination is a bit simple, but works for the example.): </p>
  
  <pre><code>points &lt;- data.frame(
    id = c(1,2),
    x = c(25,30),
    y = c(100,200)
  )
  
  lm.stack &lt;-  merge(points, lm.df, by="id")
  colnames(lm.stack) &lt;- c("ID", "x", "y", "intercept", "slope")
  
  print(lm.stack)
  ID  x   y intercept       slope
  1  1 25 100  257.7291 -0.12985632
  2  2 30 200  173.3676 -0.08708068
  </code></pre>
  
  <p>This works great. But what I want, is to be able to extract the adj r squared value of each lm model to be able to denote significant trends by coordinate cell w/ the ultimate goal of projecting a map of cells colored by significance value. This is where I need help and am greatly appreciative. Thanks!</p>