In [1]:
setwd('/Users/erinlarson/Dropbox/Documents/GIT/DDESSS_Stream_Dream_Team')
data<-read.csv('WorkingDataSet.csv')
head(data)
library("dplyr")
In [7]:
TotalP<-subset(data, ResultSampleFractionText=="Total" )
Total<-group_by(TotalP, MonitoringLocationIdentifier) %>%
summarise(AvgTotal_P = mean(ResultMeasure2, na.rm = TRUE),
SDTotal_P = sd(ResultMeasure2, na.rm = TRUE),
PFOR2 = mean(PFOR2, na.rm = TRUE),
PWETL2 = mean(PWETL2, na.rm = TRUE),
PURB2 = mean(PURB2, na.rm = TRUE),
PAGT2 = mean(PAGT2, na.rm = TRUE),
Lat = mean(LatitudeMeasure, na.rm = TRUE),
Long = mean(LongitudeMeasure, na.rm=TRUE)
)
TD.P<-subset(data, ResultSampleFractionText=="Dissolved" )
TDP<-group_by(TD.P, MonitoringLocationIdentifier) %>%
summarise(AvgTDP = mean(ResultMeasure2, na.rm = TRUE),
SDTotal_P = sd(ResultMeasure2, na.rm = TRUE),
PFOR2 = mean(PFOR2, na.rm = TRUE),
PWETL2 = mean(PWETL2, na.rm = TRUE),
PURB2 = mean(PURB2, na.rm = TRUE),
PAGT2 = mean(PAGT2, na.rm = TRUE),
Lat = mean(LatitudeMeasure, na.rm = TRUE),
Long = mean(LongitudeMeasure, na.rm=TRUE)
)
do multiple linear regression: fit <- lm(y ~ x1 + x2 + x3, data=mydata) summary(fit) # show results
In [4]:
total.fit<-lm(AvgTotal_P~ PFOR2+PWETL2+PURB2+PAGT2, data=Total)
summary(total.fit)
In [5]:
step(total.fit)
In [6]:
total.fit<-lm(AvgTotal_P~ PFOR2, data=Total)
summary(total.fit)
In [8]:
TDP.fit<-lm(AvgTDP~ PFOR2+PWETL2+PURB2+PAGT2, data=TDP)
summary(TDP.fit)
In [9]:
step(TDP.fit)
In [10]:
par(mfrow=c(2,2))
plot(TDP$PFOR2, TDP$AvgTDP, ylab="TDP", xlab="% Forest")
plot(TDP$PWETL2, TDP$AvgTDP, ylab="TDP", xlab="% Wetland")
plot(TDP$PURB2, TDP$AvgTDP, ylab="TDP", xlab="% Urban")
plot(TDP$PAGT2, TDP$AvgTDP, ylab="TDP", xlab="% Agriculture")
In [ ]:
In [11]:
par(mfrow=c(2,2))
plot(Total$PFOR2, Total$AvgTotal_P, ylab="Total P", xlab="% Forest")
plot(Total$PWETL2, Total$AvgTotal_P, ylab="Total P", xlab="% Wetland")
plot(Total$PURB2, Total$AvgTotal_P, ylab="Total P", xlab="% Urban")
plot(Total$PAGT2, Total$AvgTotal_P, ylab="Total P", xlab="% Agriculture")
In [ ]: