An official website of the United States government.

This is not the current EPA website. To navigate to the current EPA website, please go to www.epa.gov. This website is historical material reflecting the EPA website as it existed on January 19, 2021. This website is no longer updated and links to external websites and some internal pages may not work. More information »

CADDIS Volume 4

R Script: Calculate Weighted Average Inferences

# Calculate Weighted Average Inferences  
#Only select taxa for which tolerance values
#   have been computed.

df1 <- merge(site.species.or, env.data.or, by = "SITE.ID")
mat1 <- as.matrix(df1[, names.match])                      

# First get total abundance

tot.abn <- apply(mat1, 1, sum)                           

# Use matrix multiplication to compute the sum of all
# observed tolerance values, and then divide by total
# abundance to get the mean tolerance value.

mean.tv <- (mat1 %*% WA[names.match])/tot.abn       
plot(df1$temp, mean.tv, xlab = "Temperature",
     ylab = "Mean weighted average")