0% found this document useful (0 votes)
15 views33 pages

Eesh Ass8

Uploaded by

eeshnaugraiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views33 pages

Eesh Ass8

Uploaded by

eeshnaugraiya
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Assignment_8

Eesh Naugraiya (210368)

Q 1.1
library(brms)

## Loading required package: Rcpp

## Loading 'brms' package (version 2.21.0). Useful instructions


## can be found by typing help('brms'). A more detailed introduction
## to the package is available through vignette('brms_overview').

##
## Attaching package: 'brms'

## The following object is masked from 'package:stats':


##
## ar

library(dplyr)

##
## Attaching package: 'dplyr'

## The following objects are masked from 'package:stats':


##
## filter, lag

## The following objects are masked from 'package:base':


##
## intersect, setdiff, setequal, union

library(ggplot2)
#1.1

# Function to calculate number of crossing dependencies


crossing_dependencies <- function(sentence_length, alpha, beta) {
# Calculate the expected rate of crossing dependencies
lambda_i <- exp(alpha + beta * sentence_length)
# Generate number of crossing dependencies from Poisson distribution
num_crossings <- rpois(1, lambda_i)

return(num_crossings)
}

# Example usage:
alpha <- 1.5
beta <- 0.1
sentence_length <- 12

num_crossings <- crossing_dependencies(sentence_length, alpha, beta)


print(paste("Number of crossing dependencies:", num_crossings))

## [1] "Number of crossing dependencies: 11"

Q1.2
generate_prior_prediction <- function(sentence_length, alpha_mean,
alpha_sd,
beta_mean, beta_sd) {
alpha <- rnorm(1, alpha_mean, alpha_sd)
beta <- rnorm(1, beta_mean, beta_sd)
lambda_i <- exp(alpha + beta * sentence_length)
return(lambda_i)
}

alpha_mean <- 0.15


alpha_sd <- 0.1
beta_mean <- 0.25
beta_sd <- 0.05

sentence_length <- 4
prior_crossings <- generate_prior_prediction(sentence_length,
alpha_mean, alpha_sd,
beta_mean, beta_sd)

cat("Prior predictions for sentences of length", sentence_length, ":


\n")

## Prior predictions for sentences of length 4 :


cat("Mean:", prior_crossings, "\n")

## Mean: 4.043474

Q1.3
# Load data
data <- read.csv("/Users/eeshnaugraiya/Downloads/
60b40413715a5448bab29ed0d032df29500a86aa794c9ef4e8876bea07cc4188_cross
ings.csv")
head(data)

## Language s.id s.length nCross


## 1 German 1 2 0
## 2 German 2 2 1
## 3 German 3 2 0
## 4 German 4 2 0
## 5 German 5 2 2
## 6 German 6 2 1

# Fit Model M1

fit_m1 <- brm(nCross ~ s.length + (1|Language),


data = data,
family = poisson(link = "log"),
prior = c(prior(normal(0.15, 0.1), class = Intercept),
prior(normal(0, 0.15), class = b)),
chains = 4)

## Compiling Stan program...

## Trying to compile a simple C file

## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB


foo.c
## using C compiler: ‘Apple clang version 15.0.0 (clang-1500.3.9.4)’
## using SDK: ‘MacOSX14.4.sdk’
## clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/
include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/Rcpp/include/" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/RcppEigen/include/"
-I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/unsupported" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/BH/include" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/
Versions/4.3-arm64/Resources/library/StanHeaders/include/" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/
4.3-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG
-DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP
-DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS
-DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_HAS_AUTO_PTR_ETC=0
-include '/Library/Frameworks/R.framework/Versions/4.3-arm64/
Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'
-D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/opt/R/arm64/include
-fPIC -falign-functions=64 -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/
Eigen.hpp:22:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Core:19:
## /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal
error: 'cmath' file not found
## #include <cmath>
## ^~~~~~~
## 1 error generated.
## make: *** [foo.o] Error 1

## Start sampling

##
## SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 1).
## Chain 1:
## Chain 1: Gradient evaluation took 0.000168 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition
would take 1.68 seconds.
## Chain 1: Adjust your expectations accordingly!
## Chain 1:
## Chain 1:
## Chain 1: Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 1: Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 1: Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 1: Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 1: Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 1: Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 1: Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 1: Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 1: Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 1: Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 1: Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 1: Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 1:
## Chain 1: Elapsed Time: 3.105 seconds (Warm-up)
## Chain 1: 2.141 seconds (Sampling)
## Chain 1: 5.246 seconds (Total)
## Chain 1:
##
## SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 2).
## Chain 2:
## Chain 2: Gradient evaluation took 7.5e-05 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition
would take 0.75 seconds.
## Chain 2: Adjust your expectations accordingly!
## Chain 2:
## Chain 2:
## Chain 2: Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 2: Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 2: Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 2: Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 2: Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 2: Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 2: Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 2: Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 2: Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 2: Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 2: Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 2: Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 2:
## Chain 2: Elapsed Time: 3.244 seconds (Warm-up)
## Chain 2: 2.681 seconds (Sampling)
## Chain 2: 5.925 seconds (Total)
## Chain 2:
##
## SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 3).
## Chain 3:
## Chain 3: Gradient evaluation took 7e-05 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition
would take 0.7 seconds.
## Chain 3: Adjust your expectations accordingly!
## Chain 3:
## Chain 3:
## Chain 3: Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 3: Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 3: Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 3: Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 3: Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 3: Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 3: Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 3: Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 3: Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 3: Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 3: Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 3: Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 3:
## Chain 3: Elapsed Time: 3.277 seconds (Warm-up)
## Chain 3: 3.437 seconds (Sampling)
## Chain 3: 6.714 seconds (Total)
## Chain 3:
##
## SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 4).
## Chain 4:
## Chain 4: Gradient evaluation took 7.3e-05 seconds
## Chain 4: 1000 transitions using 10 leapfrog steps per transition
would take 0.73 seconds.
## Chain 4: Adjust your expectations accordingly!
## Chain 4:
## Chain 4:
## Chain 4: Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 4: Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 4: Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 4: Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 4: Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 4: Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 4: Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 4: Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 4: Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 4: Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 4: Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 4: Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 4:
## Chain 4: Elapsed Time: 3.185 seconds (Warm-up)
## Chain 4: 1.759 seconds (Sampling)
## Chain 4: 4.944 seconds (Total)
## Chain 4:

## Warning: There were 88 divergent transitions after warmup. See


## https://mc-stan.org/misc/warnings.html#divergent-transitions-after-
warmup
## to find out why this is a problem and how to eliminate them.

## Warning: Examine the pairs() plot to diagnose sampling problems

## Warning: Bulk Effective Samples Size (ESS) is too low, indicating


posterior means and medians may be unreliable.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#bulk-ess

## Warning: Tail Effective Samples Size (ESS) is too low, indicating


posterior variances and tail quantiles may be unreliable.
## Running the chains for more iterations may help. See
## https://mc-stan.org/misc/warnings.html#tail-ess

# Fit Model M2

fit_m2 <- brm(nCross ~ s.length + Language + s.length:Language,


data = data,
family = poisson(link = "log"))

## Compiling Stan program...


## Trying to compile a simple C file

## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB


foo.c
## using C compiler: ‘Apple clang version 15.0.0 (clang-1500.3.9.4)’
## using SDK: ‘MacOSX14.4.sdk’
## clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/
include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/Rcpp/include/" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/RcppEigen/include/"
-I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/unsupported" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/BH/include" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/
Versions/4.3-arm64/Resources/library/StanHeaders/include/" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/
4.3-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG
-DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP
-DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS
-DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_HAS_AUTO_PTR_ETC=0
-include '/Library/Frameworks/R.framework/Versions/4.3-arm64/
Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'
-D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/opt/R/arm64/include
-fPIC -falign-functions=64 -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/
Eigen.hpp:22:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Core:19:
## /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal
error: 'cmath' file not found
## #include <cmath>
## ^~~~~~~
## 1 error generated.
## make: *** [foo.o] Error 1

## Start sampling

##
## SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 1).
## Chain 1:
## Chain 1: Gradient evaluation took 5.2e-05 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition
would take 0.52 seconds.
## Chain 1: Adjust your expectations accordingly!
## Chain 1:
## Chain 1:
## Chain 1: Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 1: Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 1: Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 1: Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 1: Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 1: Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 1: Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 1: Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 1: Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 1: Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 1: Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 1: Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 1:
## Chain 1: Elapsed Time: 0.596 seconds (Warm-up)
## Chain 1: 0.496 seconds (Sampling)
## Chain 1: 1.092 seconds (Total)
## Chain 1:
##
## SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 2).
## Chain 2:
## Chain 2: Gradient evaluation took 3e-05 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition
would take 0.3 seconds.
## Chain 2: Adjust your expectations accordingly!
## Chain 2:
## Chain 2:
## Chain 2: Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 2: Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 2: Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 2: Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 2: Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 2: Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 2: Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 2: Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 2: Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 2: Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 2: Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 2: Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 2:
## Chain 2: Elapsed Time: 0.535 seconds (Warm-up)
## Chain 2: 0.546 seconds (Sampling)
## Chain 2: 1.081 seconds (Total)
## Chain 2:
##
## SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 3).
## Chain 3:
## Chain 3: Gradient evaluation took 3e-05 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition
would take 0.3 seconds.
## Chain 3: Adjust your expectations accordingly!
## Chain 3:
## Chain 3:
## Chain 3: Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 3: Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 3: Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 3: Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 3: Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 3: Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 3: Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 3: Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 3: Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 3: Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 3: Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 3: Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 3:
## Chain 3: Elapsed Time: 0.53 seconds (Warm-up)
## Chain 3: 0.568 seconds (Sampling)
## Chain 3: 1.098 seconds (Total)
## Chain 3:
##
## SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 4).
## Chain 4:
## Chain 4: Gradient evaluation took 2.9e-05 seconds
## Chain 4: 1000 transitions using 10 leapfrog steps per transition
would take 0.29 seconds.
## Chain 4: Adjust your expectations accordingly!
## Chain 4:
## Chain 4:
## Chain 4: Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 4: Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 4: Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 4: Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 4: Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 4: Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 4: Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 4: Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 4: Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 4: Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 4: Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 4: Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 4:
## Chain 4: Elapsed Time: 0.508 seconds (Warm-up)
## Chain 4: 0.554 seconds (Sampling)
## Chain 4: 1.062 seconds (Total)
## Chain 4:

# Extracting parameter names


parameter_names <- colnames(as.data.frame(summary(fit_m2)$coefs))
parameter_language <- paste0("b_", grep("Language", parameter_names,
value = TRUE))
parameter_interaction <- paste0("b_", grep("s.length:Language",
parameter_names, value = TRUE))

# Specify priors using the actual parameter names


priors <- c(
set_prior("normal(0.15, 0.1)", class = "Intercept"),
set_prior("normal(0, 0.15)", class = "b", coef = "s.length"),
set_prior("normal(0, 0.15)", class = "b", coef =
parameter_language),
set_prior("normal(0, 0.15)", class = "b", coef =
parameter_interaction)
)

# Update Model M2 with new priors


fit_m2 <- update(fit_m2, prior = priors)
## The desired updates require recompiling the model

## Compiling Stan program...

## Trying to compile a simple C file

## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB


foo.c
## using C compiler: ‘Apple clang version 15.0.0 (clang-1500.3.9.4)’
## using SDK: ‘MacOSX14.4.sdk’
## clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/
include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/Rcpp/include/" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/RcppEigen/include/"
-I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/unsupported" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/BH/include" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/
Versions/4.3-arm64/Resources/library/StanHeaders/include/" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/
4.3-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG
-DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP
-DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS
-DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_HAS_AUTO_PTR_ETC=0
-include '/Library/Frameworks/R.framework/Versions/4.3-arm64/
Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'
-D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/opt/R/arm64/include
-fPIC -falign-functions=64 -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/
Eigen.hpp:22:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Core:19:
## /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal
error: 'cmath' file not found
## #include <cmath>
## ^~~~~~~
## 1 error generated.
## make: *** [foo.o] Error 1

## Start sampling

##
## SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 1).
## Chain 1:
## Chain 1: Gradient evaluation took 6.9e-05 seconds
## Chain 1: 1000 transitions using 10 leapfrog steps per transition
would take 0.69 seconds.
## Chain 1: Adjust your expectations accordingly!
## Chain 1:
## Chain 1:
## Chain 1: Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 1: Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 1: Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 1: Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 1: Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 1: Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 1: Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 1: Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 1: Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 1: Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 1: Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 1: Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 1:
## Chain 1: Elapsed Time: 0.577 seconds (Warm-up)
## Chain 1: 0.557 seconds (Sampling)
## Chain 1: 1.134 seconds (Total)
## Chain 1:
##
## SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 2).
## Chain 2:
## Chain 2: Gradient evaluation took 3.1e-05 seconds
## Chain 2: 1000 transitions using 10 leapfrog steps per transition
would take 0.31 seconds.
## Chain 2: Adjust your expectations accordingly!
## Chain 2:
## Chain 2:
## Chain 2: Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 2: Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 2: Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 2: Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 2: Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 2: Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 2: Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 2: Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 2: Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 2: Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 2: Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 2: Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 2:
## Chain 2: Elapsed Time: 0.539 seconds (Warm-up)
## Chain 2: 0.54 seconds (Sampling)
## Chain 2: 1.079 seconds (Total)
## Chain 2:
##
## SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 3).
## Chain 3:
## Chain 3: Gradient evaluation took 3.1e-05 seconds
## Chain 3: 1000 transitions using 10 leapfrog steps per transition
would take 0.31 seconds.
## Chain 3: Adjust your expectations accordingly!
## Chain 3:
## Chain 3:
## Chain 3: Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 3: Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 3: Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 3: Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 3: Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 3: Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 3: Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 3: Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 3: Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 3: Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 3: Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 3: Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 3:
## Chain 3: Elapsed Time: 0.523 seconds (Warm-up)
## Chain 3: 0.469 seconds (Sampling)
## Chain 3: 0.992 seconds (Total)
## Chain 3:
##
## SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 4).
## Chain 4:
## Chain 4: Gradient evaluation took 3e-05 seconds
## Chain 4: 1000 transitions using 10 leapfrog steps per transition
would take 0.3 seconds.
## Chain 4: Adjust your expectations accordingly!
## Chain 4:
## Chain 4:
## Chain 4: Iteration: 1 / 2000 [ 0%] (Warmup)
## Chain 4: Iteration: 200 / 2000 [ 10%] (Warmup)
## Chain 4: Iteration: 400 / 2000 [ 20%] (Warmup)
## Chain 4: Iteration: 600 / 2000 [ 30%] (Warmup)
## Chain 4: Iteration: 800 / 2000 [ 40%] (Warmup)
## Chain 4: Iteration: 1000 / 2000 [ 50%] (Warmup)
## Chain 4: Iteration: 1001 / 2000 [ 50%] (Sampling)
## Chain 4: Iteration: 1200 / 2000 [ 60%] (Sampling)
## Chain 4: Iteration: 1400 / 2000 [ 70%] (Sampling)
## Chain 4: Iteration: 1600 / 2000 [ 80%] (Sampling)
## Chain 4: Iteration: 1800 / 2000 [ 90%] (Sampling)
## Chain 4: Iteration: 2000 / 2000 [100%] (Sampling)
## Chain 4:
## Chain 4: Elapsed Time: 0.582 seconds (Warm-up)
## Chain 4: 0.524 seconds (Sampling)
## Chain 4: 1.106 seconds (Total)
## Chain 4:

# Display summary of Model M1


summary(fit_m1)

## Warning: There were 88 divergent transitions after warmup.


Increasing
## adapt_delta above 0.8 may help. See
## http://mc-stan.org/misc/warnings.html#divergent-transitions-after-
warmup

## Family: poisson
## Links: mu = log
## Formula: nCross ~ s.length + (1 | Language)
## Data: data (Number of observations: 1900)
## Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
## total post-warmup draws = 4000
##
## Multilevel Hyperparameters:
## ~Language (Number of levels: 2)
## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
Tail_ESS
## sd(Intercept) 0.45 0.29 0.13 1.23 1.02 280
157
##
## Regression Coefficients:
## Estimate Est.Error l-95% CI u-95% CI Rhat Bulk_ESS
Tail_ESS
## Intercept -1.48 0.10 -1.67 -1.29 1.00 1083
1681
## s.length 0.15 0.00 0.14 0.16 1.01 1500
1671
##
## Draws were sampled using sampling(NUTS). For each parameter,
Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the
potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

# Display summary of Model M2


summary(fit_m2)

## Family: poisson
## Links: mu = log
## Formula: nCross ~ s.length + Language + s.length:Language
## Data: data (Number of observations: 1900)
## Draws: 4 chains, each with iter = 2000; warmup = 1000; thin = 1;
## total post-warmup draws = 4000
##
## Regression Coefficients:
## Estimate Est.Error l-95% CI u-95% CI Rhat
Bulk_ESS
## Intercept -0.91 0.08 -1.06 -0.75 1.00
1663
## s.length 0.10 0.01 0.09 0.11 1.00
1737
## LanguageGerman -1.02 0.12 -1.27 -0.78 1.00
1497
## s.length:LanguageGerman 0.10 0.01 0.08 0.11 1.00
1441
## Tail_ESS
## Intercept 1655
## s.length 1808
## LanguageGerman 1546
## s.length:LanguageGerman 1333
##
## Draws were sampled using sampling(NUTS). For each parameter,
Bulk_ESS
## and Tail_ESS are effective sample size measures, and Rhat is the
potential
## scale reduction factor on split chains (at convergence, Rhat = 1).

plot(fit_m1)
plot(fit_m2)
Q1.4
observed <- read.table("/Users/eeshnaugraiya/Downloads/
60b40413715a5448bab29ed0d032df29500a86aa794c9ef4e8876bea07cc4188_cross
ings.csv", sep = ",", header = TRUE)
observed %>%
group_by(Language, s.length) %>%
summarise(mean.crossings = mean(nCross)) %>%
ggplot(aes(x = s.length, y = mean.crossings, group = Language, color
= Language)) +
geom_point() + geom_line()

## `summarise()` has grouped output by 'Language'. You can override


using the
## `.groups` argument.
observed$s.length <- observed$s.length - mean(observed$s.length)
observed$lang <- ifelse(observed$Language == "German", 1, 0)

lpds.m1 <- c()


lpds.m2 <- c()
untested <- observed

for (k in 1:5) {
# Prepare test data and training data
ytest <- sample_n(untested, size = nrow(observed) / 5)
ytrain <- setdiff(observed, ytest)
untested <- setdiff(untested, ytest)

# Fit Model M1 on training data


fit.m1 <- brm(nCross ~ 1 + s.length, data = ytrain,
family = poisson(link = "log"),
prior = c(prior(normal(0.15, 0.1), class = Intercept),
prior(normal(0, 0.15), class = b)),
cores = 4)

# Fit Model M2 on training data


fit.m2 <- brm(nCross ~ 1 + s.length + lang + s.length * lang,
data = ytrain,
family = poisson(link = "log"),
prior = c(prior(normal(0.15, 0.1), class = Intercept),
prior(normal(0, 0.15), class = b)),
cores = 4)

# Retrieve posterior samples


post.m1 <- posterior_samples(fit.m1)
post.m2 <- posterior_samples(fit.m2)

# Calculate log pointwise predictive density using test data


lppd.m1 <- 0
lppd.m2 <- 0

for (i in 1:nrow(ytest)) {
lpd_im1 <- log(mean(dpois(ytest[i,]$nCross,
lambda = exp(post.m1[,1] + post.m1[,2]
* ytest[i,]$s.length))))
lppd.m1 <- lppd.m1 + lpd_im1

lpd_im2 <- log(mean(dpois(ytest[i,]$nCross,


lambda = exp(post.m2[,1] + post.m2[,2]
* ytest[i,]$s.length +
post.m2[,3] * ytest[i,]
$lang +
post.m2[,4] * ytest[i,]
$s.length * ytest[i,]$lang))))
lppd.m2 <- lppd.m2 + lpd_im2
}

lpds.m1 <- c(lpds.m1, lppd.m1)


lpds.m2 <- c(lpds.m2, lppd.m2)
}
## Compiling Stan program...
## Trying to compile a simple C file

## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB


foo.c
## using C compiler: ‘Apple clang version 15.0.0 (clang-1500.3.9.4)’
## using SDK: ‘MacOSX14.4.sdk’
## clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/
include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/Rcpp/include/" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/RcppEigen/include/"
-I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/unsupported" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/BH/include" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/
Versions/4.3-arm64/Resources/library/StanHeaders/include/" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/
4.3-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG
-DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP
-DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS
-DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_HAS_AUTO_PTR_ETC=0
-include '/Library/Frameworks/R.framework/Versions/4.3-arm64/
Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'
-D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/opt/R/arm64/include
-fPIC -falign-functions=64 -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/
Eigen.hpp:22:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Core:19:
## /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal
error: 'cmath' file not found
## #include <cmath>
## ^~~~~~~
## 1 error generated.
## make: *** [foo.o] Error 1
## Start sampling
## Compiling Stan program...
## Trying to compile a simple C file

## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB


foo.c
## using C compiler: ‘Apple clang version 15.0.0 (clang-1500.3.9.4)’
## using SDK: ‘MacOSX14.4.sdk’
## clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/
include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/Rcpp/include/" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/RcppEigen/include/"
-I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/unsupported" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/BH/include" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/
Versions/4.3-arm64/Resources/library/StanHeaders/include/" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/
4.3-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG
-DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP
-DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS
-DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_HAS_AUTO_PTR_ETC=0
-include '/Library/Frameworks/R.framework/Versions/4.3-arm64/
Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'
-D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/opt/R/arm64/include
-fPIC -falign-functions=64 -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/
Eigen.hpp:22:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Core:19:
## /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal
error: 'cmath' file not found
## #include <cmath>
## ^~~~~~~
## 1 error generated.
## make: *** [foo.o] Error 1

## Start sampling

## Warning: Method 'posterior_samples' is deprecated. Please see ?


as_draws for
## recommended alternatives.

## Warning: Method 'posterior_samples' is deprecated. Please see ?


as_draws for
## recommended alternatives.

## Compiling Stan program...


## Trying to compile a simple C file

## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB


foo.c
## using C compiler: ‘Apple clang version 15.0.0 (clang-1500.3.9.4)’
## using SDK: ‘MacOSX14.4.sdk’
## clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/
include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/Rcpp/include/" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/RcppEigen/include/"
-I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/unsupported" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/BH/include" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/
Versions/4.3-arm64/Resources/library/StanHeaders/include/" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/
4.3-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG
-DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP
-DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS
-DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_HAS_AUTO_PTR_ETC=0
-include '/Library/Frameworks/R.framework/Versions/4.3-arm64/
Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'
-D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/opt/R/arm64/include
-fPIC -falign-functions=64 -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/
Eigen.hpp:22:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Core:19:
## /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal
error: 'cmath' file not found
## #include <cmath>
## ^~~~~~~
## 1 error generated.
## make: *** [foo.o] Error 1

## Start sampling
## Compiling Stan program...
## Trying to compile a simple C file

## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB


foo.c
## using C compiler: ‘Apple clang version 15.0.0 (clang-1500.3.9.4)’
## using SDK: ‘MacOSX14.4.sdk’
## clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/
include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/Rcpp/include/" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/RcppEigen/include/"
-I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/unsupported" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/BH/include" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/
Versions/4.3-arm64/Resources/library/StanHeaders/include/" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/
4.3-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG
-DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP
-DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS
-DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_HAS_AUTO_PTR_ETC=0
-include '/Library/Frameworks/R.framework/Versions/4.3-arm64/
Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'
-D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/opt/R/arm64/include
-fPIC -falign-functions=64 -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/
Eigen.hpp:22:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Core:19:
## /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal
error: 'cmath' file not found
## #include <cmath>
## ^~~~~~~
## 1 error generated.
## make: *** [foo.o] Error 1

## Start sampling

## Warning: Method 'posterior_samples' is deprecated. Please see ?


as_draws for
## recommended alternatives.

## Warning: Method 'posterior_samples' is deprecated. Please see ?


as_draws for
## recommended alternatives.

## Compiling Stan program...


## Trying to compile a simple C file

## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB


foo.c
## using C compiler: ‘Apple clang version 15.0.0 (clang-1500.3.9.4)’
## using SDK: ‘MacOSX14.4.sdk’
## clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/
include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/Rcpp/include/" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/RcppEigen/include/"
-I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/unsupported" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/BH/include" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/
Versions/4.3-arm64/Resources/library/StanHeaders/include/" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/
4.3-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG
-DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP
-DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS
-DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_HAS_AUTO_PTR_ETC=0
-include '/Library/Frameworks/R.framework/Versions/4.3-arm64/
Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'
-D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/opt/R/arm64/include
-fPIC -falign-functions=64 -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/
Eigen.hpp:22:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Core:19:
## /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal
error: 'cmath' file not found
## #include <cmath>
## ^~~~~~~
## 1 error generated.
## make: *** [foo.o] Error 1

## Start sampling
## Compiling Stan program...
## Trying to compile a simple C file

## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB


foo.c
## using C compiler: ‘Apple clang version 15.0.0 (clang-1500.3.9.4)’
## using SDK: ‘MacOSX14.4.sdk’
## clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/
include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/Rcpp/include/" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/RcppEigen/include/"
-I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/unsupported" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/BH/include" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/
Versions/4.3-arm64/Resources/library/StanHeaders/include/" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/
4.3-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG
-DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP
-DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS
-DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_HAS_AUTO_PTR_ETC=0
-include '/Library/Frameworks/R.framework/Versions/4.3-arm64/
Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'
-D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/opt/R/arm64/include
-fPIC -falign-functions=64 -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/
Eigen.hpp:22:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Core:19:
## /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal
error: 'cmath' file not found
## #include <cmath>
## ^~~~~~~
## 1 error generated.
## make: *** [foo.o] Error 1

## Start sampling

## Warning: Method 'posterior_samples' is deprecated. Please see ?


as_draws for
## recommended alternatives.

## Warning: Method 'posterior_samples' is deprecated. Please see ?


as_draws for
## recommended alternatives.

## Compiling Stan program...


## Trying to compile a simple C file

## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB


foo.c
## using C compiler: ‘Apple clang version 15.0.0 (clang-1500.3.9.4)’
## using SDK: ‘MacOSX14.4.sdk’
## clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/
include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/Rcpp/include/" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/RcppEigen/include/"
-I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/unsupported" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/BH/include" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/
Versions/4.3-arm64/Resources/library/StanHeaders/include/" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/
4.3-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG
-DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP
-DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS
-DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_HAS_AUTO_PTR_ETC=0
-include '/Library/Frameworks/R.framework/Versions/4.3-arm64/
Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'
-D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/opt/R/arm64/include
-fPIC -falign-functions=64 -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/
Eigen.hpp:22:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Core:19:
## /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal
error: 'cmath' file not found
## #include <cmath>
## ^~~~~~~
## 1 error generated.
## make: *** [foo.o] Error 1

## Start sampling
## Compiling Stan program...
## Trying to compile a simple C file

## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB


foo.c
## using C compiler: ‘Apple clang version 15.0.0 (clang-1500.3.9.4)’
## using SDK: ‘MacOSX14.4.sdk’
## clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/
include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/Rcpp/include/" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/RcppEigen/include/"
-I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/unsupported" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/BH/include" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/
Versions/4.3-arm64/Resources/library/StanHeaders/include/" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/
4.3-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG
-DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP
-DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS
-DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_HAS_AUTO_PTR_ETC=0
-include '/Library/Frameworks/R.framework/Versions/4.3-arm64/
Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'
-D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/opt/R/arm64/include
-fPIC -falign-functions=64 -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/
Eigen.hpp:22:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Core:19:
## /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal
error: 'cmath' file not found
## #include <cmath>
## ^~~~~~~
## 1 error generated.
## make: *** [foo.o] Error 1

## Start sampling

## Warning: Method 'posterior_samples' is deprecated. Please see ?


as_draws for
## recommended alternatives.

## Warning: Method 'posterior_samples' is deprecated. Please see ?


as_draws for
## recommended alternatives.

## Compiling Stan program...


## Trying to compile a simple C file

## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB


foo.c
## using C compiler: ‘Apple clang version 15.0.0 (clang-1500.3.9.4)’
## using SDK: ‘MacOSX14.4.sdk’
## clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/
include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/Rcpp/include/" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/RcppEigen/include/"
-I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/unsupported" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/BH/include" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/
Versions/4.3-arm64/Resources/library/StanHeaders/include/" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/
4.3-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG
-DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP
-DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS
-DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_HAS_AUTO_PTR_ETC=0
-include '/Library/Frameworks/R.framework/Versions/4.3-arm64/
Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'
-D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/opt/R/arm64/include
-fPIC -falign-functions=64 -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/
Eigen.hpp:22:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Core:19:
## /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal
error: 'cmath' file not found
## #include <cmath>
## ^~~~~~~
## 1 error generated.
## make: *** [foo.o] Error 1

## Start sampling
## Compiling Stan program...
## Trying to compile a simple C file

## Running /Library/Frameworks/R.framework/Resources/bin/R CMD SHLIB


foo.c
## using C compiler: ‘Apple clang version 15.0.0 (clang-1500.3.9.4)’
## using SDK: ‘MacOSX14.4.sdk’
## clang -arch arm64 -I"/Library/Frameworks/R.framework/Resources/
include" -DNDEBUG -I"/Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/Rcpp/include/" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/RcppEigen/include/"
-I"/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/unsupported" -I"/Library/Frameworks/
R.framework/Versions/4.3-arm64/Resources/library/BH/include" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
StanHeaders/include/src/" -I"/Library/Frameworks/R.framework/
Versions/4.3-arm64/Resources/library/StanHeaders/include/" -I"/
Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/library/
RcppParallel/include/" -I"/Library/Frameworks/R.framework/Versions/
4.3-arm64/Resources/library/rstan/include" -DEIGEN_NO_DEBUG
-DBOOST_DISABLE_ASSERTS -DBOOST_PENDING_INTEGER_LOG2_HPP
-DSTAN_THREADS -DUSE_STANC3 -DSTRICT_R_HEADERS
-DBOOST_PHOENIX_NO_VARIADIC_EXPRESSION -D_HAS_AUTO_PTR_ETC=0
-include '/Library/Frameworks/R.framework/Versions/4.3-arm64/
Resources/library/StanHeaders/include/stan/math/prim/fun/Eigen.hpp'
-D_REENTRANT -DRCPP_PARALLEL_USE_TBB=1 -I/opt/R/arm64/include
-fPIC -falign-functions=64 -Wall -g -O2 -c foo.c -o foo.o
## In file included from <built-in>:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/StanHeaders/include/stan/math/prim/fun/
Eigen.hpp:22:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Dense:1:
## In file included from /Library/Frameworks/R.framework/Versions/4.3-
arm64/Resources/library/RcppEigen/include/Eigen/Core:19:
## /Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/
library/RcppEigen/include/Eigen/src/Core/util/Macros.h:679:10: fatal
error: 'cmath' file not found
## #include <cmath>
## ^~~~~~~
## 1 error generated.
## make: *** [foo.o] Error 1

## Start sampling

## Warning: Method 'posterior_samples' is deprecated. Please see ?


as_draws for
## recommended alternatives.

## Warning: Method 'posterior_samples' is deprecated. Please see ?


as_draws for
## recommended alternatives.

elpd.m1 <- sum(lpds.m1)


elpd.m2 <- sum(lpds.m2)
difference_elpd <- elpd.m2 - elpd.m1
# Calculate Bayes Factor
bayes_factor <- exp(difference_elpd)
#print("bayes factor:", bayes_factor)
print(elpd.m1)

## [1] -2815.463

print(elpd.m2)

## [1] -2682.351

print(difference_elpd)

## [1] 133.112

print(bayes_factor)

## [1] 6.456081e+57

You might also like