Skip to content

Commit

Permalink
added some data massaging that was in the .rmd doc that should have b…
Browse files Browse the repository at this point in the history
…een in a script. now it is
  • Loading branch information
elisehellwig committed Jan 16, 2018
1 parent bd40568 commit 7d91cfb
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion 9_parameter_post_analysis.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ options(stringsAsFactors = FALSE)
library(rstan)
library(ggplot2)
library(rethinking)
library(reshape2)
source('functions.R')

av <- read.csv(file.path(datapath, 'allvars.csv'))
Afp <- readRDS(file.path(datapath, 'models/AlphaFixedPost.RDS'))
Bfp <- readRDS(file.path(datapath, 'models/BetaFixedPost.RDS'))
Expand All @@ -13,7 +16,20 @@ Bmod <- readRDS(file.path(datapath, 'models/BetaFixedModel.RDS'))
DPmod <- readRDS(file.path(datapath, 'models/DeclinePFixedModel.RDS'))


source('functions.R')
Afit <- modfit(Amod)
Bfit <- modfit(Bmod)
DPfit <- modfit(DPmod)


####



respvars <- c('alpha','beta','declineP')
char <- c('PopSize', 'PopTrend','DeclineProb')




###########################################################################
###########################################################################
Expand Down Expand Up @@ -54,4 +70,29 @@ ResidDF <- merge(av[,avars], modres, by.x='latitude', by.y='lat')

write.csv(ResidDF, file.path(datapath, 'Residuals.csv'), row.names = FALSE)

#######################################################
#37.7-38.3 centered: 37.98501, scaled:0.10711

brvars <- c('declineP','alpha','beta','Latitude','latitude')

avr <- av[,brvars]
avr$type <- 'obs'

LatX <- seq(37.8, 38.22, by=0.1)
latX <- (LatX - 37.98501)/0.10711

avfit <- data.frame(Latitude=LatX,
latitude=latX,
type='fit',
alpha=Afit(latX),
beta=Bfit(latX),
declineP=DPfit(latX))

AV <- rbind(avr, avfit)
avm <- melt(AV, id.vars=c('Latitude','latitude','type'),
variable.name = 'response', value.name = 'value')

write.csv(avm, file.path(datapath, 'LatitudeModelResults.csv'),
row.names = FALSE)


0 comments on commit 7d91cfb

Please sign in to comment.