diff --git a/.RData b/.RData index f9c4142..0d1a132 100644 Binary files a/.RData and b/.RData differ diff --git a/.Rhistory b/.Rhistory index 6ab6247..2c5941f 100644 --- a/.Rhistory +++ b/.Rhistory @@ -1,493 +1,512 @@ -# definegrid -p_grid <-seq(from=0,to=1,length.out=20) -# defineprior -#prior <-rep(1,20) -prior <-ifelse(p_grid<0.5,0,1) -# computelikelihoodateachvalueingrid -likelihood <-dbinom(6,size=9,prob=p_grid) -# computeproductoflikelihoodandprior -unstd.posterior <-likelihood*prior -# standardizetheposterior,soitsumsto1 -posterior <-unstd.posterior/sum(unstd.posterior) -# definegrid -p_grid <-seq(from=0,to=1,length.out=20) -# defineprior -#prior <-rep(1,20) -prior <-ifelse(p_grid<0.5,0,1) -# computelikelihoodateachvalueingrid -likelihood <-dbinom(6,size=9,prob=p_grid) -# computeproductoflikelihoodandprior -unstd.posterior <-likelihood*prior -# standardizetheposterior,soitsumsto1 -posterior <-unstd.posterior/sum(unstd.posterior) -plot( p_grid,posterior,type="b", -xlab="probability ofwater",ylab="posteriorprobability") -mtext( "20points") -# 2.7 analyticalcalculation -W <-6 -L <-3 -curve( dbeta(x,W+1,L+1),from=0,to=1) -# quadraticapproximation -curve( dnorm(x,0.67,0.16),lty=2,add=TRUE) +#dev.off() +var = (1/20)*(theta_hat^2*(1+theta_hat)^2)/(theta_hat^2+(theta_hat+1)^2) +post_approx = dnorm(theta_vec, theta_hat,sqrt(var)) +#pdf(file = "~/Dropbox/pubh8442/2015/Asymptotic_Posterior_Approximation_NormApp##.pdf", width = 7, height=4) +plot(theta_vec,post_approx,xlim = c(0,6), ylab = "Density", xlab = "theta", type = 'l', lwd = 2, main = "") +abline(v=theta_hat, col = 'red') +#dev.off() library(rethinking) -f <- alist( -y ~ dnorm( mu , sigma ), -mu ~ dnorm( 0 , 10 ), -sigma ~ dexp( 1 ) -) -fit <- quap( -f , -data=list(y=c(-1,1)) , -start=list(mu=0,sigma=1) -) -# definegrid -p_grid <-seq(from=0,to=1,length.out=20) -# defineprior -#prior <-rep(1,20) -prior <-ifelse(p_grid<0.5,0,1) -# computelikelihoodateachvalueingrid -likelihood <-dbinom(6,size=9,prob=p_grid) -# computeproductoflikelihoodandprior -unstd.posterior <-likelihood*prior -# standardizetheposterior,soitsumsto1 -posterior <-unstd.posterior/sum(unstd.posterior) -plot( p_grid,posterior,type="b", -xlab="probability ofwater",ylab="posteriorprobability") -mtext( "20points") -# 2.7 analyticalcalculation -W <-6 -L <-3 -curve( dbeta(x,W+1,L+1),from=0,to=1) -# quadraticapproximation -curve( dnorm(x,0.67,0.16),lty=2,add=TRUE) -p <- c(0, .25, .5, .75, 1) -model <- sapply(p, function (p, W, L) return (4*p)^W*(4-4*p)^L) -print(model) -n_samples <-1000 -p <-rep(NA,n_samples) -p[1] <-0.5 -W <-6 -L <-3 -for (i in 2:n_samples){ -p_new <-rnorm(1,p[i-1],0.1) -if (p_new < 0) p_new <- abs(p_new) -if (p_new > 1) p_new <- 2-p_new -q0 <-dbinom(W,W+L,p[i-1]) -q1 <-dbinom(W,W+L,p_new) -p[i] <-ifelse(runif(1) 1) p_new <- 2-p_new -q0 <-dbinom(W,W+L,p[i-1]) -q1 <-dbinom(W,W+L,p_new) -p[i] <-ifelse(runif(1)=18,] library(rethinking) +library(tidyverse) +library(dplyr) data(Howell1) d <-Howell1[Howell1$age>=18,] -#Similate a sample of 10 people -set.seed(93) -H <- runif(10,130,170) -W <- sim_weight(H,b=0.5, sd=5) -#Run Model -m3.1 <- quap( +Howell |> +plot(H, W) +Howell1 |> +ggplot(aes(x=height, y=weight))+ +geom_point() +Howell1 |> +ggplot(aes(x=height, y=weight))+ +geom_point(color=sex)+ +plot(H, W) +Howell1 |> +ggplot(aes(x=height, y=weight))+ +geom_point(color=sex) +Howell1 |> +ggplot(aes(x=height, y=weight))+ +geom_point(color=sex) +View(Howell1) +Howell1 |> +ggplot(aes(x=height, y=weight))+ +geom_point(color=male) +Howell1 |> +ggplot(aes(x=height, y=weight, color=male))+ +geom_point() +Howell1 |> +ggplot(aes(x=weight, y=height, color=male))+ +geom_point() +Howell1 |> +ggplot(aes(x=weight, y=height, color=factor(male)))+ +geom_point() +Howell1 |> +ggplot(aes(x=hight, y=weight, color=factor(male)))+ +geom_point() +Howell1 |> +ggplot(aes(x=height, y=weight, color=factor(male)))+ +geom_point() +d |> +ggplot(aes(x=height, y=weight, color=factor(male)))+ +geom_point() +plot(H, W) +5/24 +d |> +ggplot(aes(x=height, y=weight, color=factor(male)))+ +geom_point() +d |> +ggplot(aes(x=height, y=weight, color=factor(male)))+ +geom_point() +d |> +ggplot(aes(x=height, y=weight, color=factor(male)))+ +geom_density() +d |> +ggplot(aes(x=height, color=factor(male)))+ +geom_density(aes(y=weight)) +d |> +ggplot(aes(x=weight))+ +geom_density(aes(color=factor(male))) +d |> +ggplot(aes(x=height, y=weight, color=factor(male)))+ +geom_point()+ +theme_bw() +d |> +ggplot(aes(x=weight))+ +geom_density(aes(color=factor(male)))+ +theme_bw() +d |> +ggplot(aes(x=height, y=weight, color=factor(male)))+ +geom_point()+ +theme_bw() +d |> +ggplot(aes(x=weight))+ +geom_density(aes(color=factor(male)))+ +theme_bw() +d |> +ggplot(aes(x=hight))+ +geom_density(aes(color=factor(male)))+ +theme_bw() +d |> +ggplot(aes(x=height, y=weight, color=factor(male)))+ +geom_point()+ +theme_bw() +d |> +ggplot(aes(x=weight))+ +geom_density(aes(color=factor(male)))+ +theme_bw() +d |> +ggplot(aes(x=height))+ +geom_density(aes(color=factor(male)))+ +theme_bw() +# S = 1: female, S=2: male +sim_HW <- function(S, b, a) { +N <- length(S) +H <- ifelse(S==1,150,160)+rnorm(N,0,5) +data.frame(S,H,W) +} +W <- a[S] + b[S]*H + rnorm(N, 0, 5) +# S = 1: female, S=2: male +sim_HW <- function(S, b, a) { +N <- length(S) +H <- ifelse(S==1,150,160)+rnorm(N,0,5) +W <- a[S] + b[S]*H + rnorm(N, 0, 5) +data.frame(S,H,W) +} +S <- rbern(100)+1 +dat <- sim_HW(S, b=c(.5,.6), a=c(0,0)) +head(dat) +dat |> +ggplot(aes(x=H, y=W, color=factor(S)))+ +geom_point()+ +theme_bw() +# female sample +S <- rep(1,100) +simF <- sim_HW(S, b=c(.5,.6), a=c(0,0)) +# male sample +S <- rep(2,100) +simM <- sim_HW(S, b=c(.5,.6), a=c(0,0)) +# effect of sex (male-female) +mean(simM$W-simF$W) +S <- rbern(100)+1 +dat <- sim_HW(S, b=c(.5,.6), a=c(0,0)) +# estimate posterior +m_SW <- quap( +alist( +W~dnorm(mu,sigma), +mu <- a[S], +a[S] ~ dnorm(60,10), +sigma ~ dunif(0,10) +), data=dat +) +precis(m_SW,depth=2) +# recoding +dat <- list( +W = d$weight, +S = d$male+1 +) +# estimate posterior +m_SW <- quap( +alist( +W~dnorm(mu,sigma), +mu <- a[S], +a[S] ~ dnorm(60,10), +sigma ~ dunif(0,10) +), data=dat +) +precis(m_SW,depth=2) +View(dat) +post <- extract.samples(m_SW) +dens(post$a[,1],xlim=c(35, 55),lwd=3,col=2,xlab="posterior mean weight(kg") +dens(post$a[,2], lwd=3,col=4,add=TRUE) +W1 <- rnorm(1000,post$a[,1], post$sigma) +W2 <- rnorm(1000,post$a[,2], post$sigma) +dens(W1,xlim=c(20,70),ylim(0,.085),lwd=3, col=2) +W1 <- rnorm(1000,post$a[,1], post$sigma) +W2 <- rnorm(1000,post$a[,2], post$sigma) +dens(W1,xlim=c(20,70),ylim=c(0,.085),lwd=3, col=2) +dens(W2,lwd=3, col=4, add=TRUE) +W1 +post +mu_contrast <- post$a[,2]-post$a[,1] +dens(mu_contrast,xlim=c(3,10),lwd=3, col=1,xlab="posterior mean weight contrast(kg)") +W1 <- rnorm(1000,post$a[,1], post$sigma) +W2 <- rnorm(1000,post$a[,2], post$sigma) +# conntrast +W_contrast <- W2 - W1 +dens(W_contrast,xlim=c(-25,35),lwd=3, col=1, +xlab="posterior weight contrast (kg)") +W1 <- rnorm(1000,post$a[,1], post$sigma) +W2 <- rnorm(1000,post$a[,2], post$sigma) +# conntrast +W_contrast <- W2 - W1 +dens(W_contrast,xlim=c(-25,35),lwd=3, col=1, +xlab="posterior weight contrast (kg)") +sum(W_contrast>0)/1000 +sum(W_contrast<0)/1000 +df <- data.frame ( +W1 = W1, +W2 = W2, +W_contrast = W_contrast +) +View(df) +ggplot(df, aes(x=W_contrast, fill=W_contrast)) +ggplot(df, aes(x=W_contrast)) +ggplot(df, aes(x=W_contrast))+ +geom_area() +ggplot(df, aes(x=W_contrast,fill=W_contrast))+ +geom_area() +df <- data.frame ( +W1 = W1, +W2 = W2, +W_contrast = W_contrast, +W_up = (W_contrast>0), +W_down = !(W_up) +) +df <- data.frame ( +W1 = W1, +W2 = W2, +W_contrast = W_contrast, +W_up = (W_contrast>0), +W_down = (W_contrast<0) +) +ggplot(df, aes(x=W_contrast,fill=W_up))+ +geom_area() +View(df) +df <- data.frame ( +W1 = W1, +W2 = W2, +W_contrast = W_contrast, +W_up = factor(W_contrast>0), +W_down = factor(W_contrast<0) +) +View(df) +ggplot(df, aes(x=W_contrast,fill=W_up))+ +geom_area() +ggplot(df, aes(y=W_contrast,fill=W_up))+ +geom_area() +ggplot(df, aes(y=W_contrast))+ +geom_area() +View(post) +df <- data.frame ( +W1 = W1, +W2 = W2, +W_contrast = W_contrast, +W_up = factor(W_contrast>0), +W_down = factor(W_contrast<0) +) +ggplot(df, aes(y=W_contrast))+ +geom_density() +ggplot(df, aes(x=W_contrast))+ +geom_density() +ggplot(df, aes(x=W_contrast))+ +geom_density()+ +theme_bw() +ggplot(df, aes(x=W_contrast, fill=W_up))+ +geom_density()+ +theme_bw() +ggplot(df, aes(x=W_contrast, fill=W_up))+ +geom_area()+ +theme_bw() +ggplot(df, aes(x=W_contrast), fill=W_up))+ +ggplot(df, aes(x=W_contrast), fill=W_up))+ +ggplot(df, aes(x=W_contrast), fill=W_up)+ +geom_area()+ +theme_bw() +ggplot(df, aes(x=W_contrast, y=W_contrastfill=W_up))+ +ggplot(df, aes(x=W_contrast, y=W_contrast,fill=W_up))+ +geom_area()+ +theme_bw() +ggplot(df, aes(x=W_contrast, y=W1,fill=W_up))+ +geom_area()+ +theme_bw() +df <- data.frame ( +W1 = W1, +W2 = W2, +W_contrast = W_contrast, +W_flag = factor(W_contrast>W_up) +) +W_up <- sum(W_contrast>0)/1000 +W_down <- sum(W_contrast<0)/1000 +df <- data.frame ( +W1 = W1, +W2 = W2, +W_contrast = W_contrast, +W_flag = factor(W_contrast>W_up) +) +View(df) +ggplot(df, aes(x=W_contrast,fill=W_flag))+ +geom_area()+ +theme_bw() +ggplot(df, aes(x=W_contrast,fill=W_flag))+ +geom_areadensity()+ +theme_bw() +ggplot(df, aes(x=W_contrast,fill=W_flag))+ +geom_density()+ +theme_bw() +W1 <- rnorm(1000,post$a[,1], post$sigma) +W2 <- rnorm(1000,post$a[,2], post$sigma) +# conntrast +W_contrast <- W2 - W1 +dens(W_contrast,xlim=c(-25,35),lwd=3, col=1, +xlab="posterior weight contrast (kg)") +W_up <- sum(W_contrast>0)/1000 +W_down <- sum(W_contrast<0)/1000 +cat("W_up:",W_up," and W_down:",W_down) +df <- data.frame ( +W1 = W1, +W2 = W2, +W_contrast = W_contrast, +W_flag = factor(W_contrast>W_up) +) +ggplot(df, aes(x=W_contrast,fill=W_flag))+ +geom_density()+ +theme_bw() +S <- rbern(100)+1 +dat <- sim_HW(S, b=c(.5,.5), a=c(0,10)) +# Indirect effect (b) is the same for men and women +# Indirect effect (b) is the same for men and women +dat |> +ggplot(aes(x=H, y=W, color=factor(S)))+ +geom_point()+ +theme_bw() +# Indirect effect (b) is the same for men and women +dat |> +ggplot(aes(x=H, y=W, color=factor(S)))+ +geom_point()+ +geom_smooth(method = lm)+ +theme_bw() +# Indirect effect (b) is the same for men and women +dat |> +ggplot(aes(x=H, y=W, color=factor(S)))+ +geom_point()+ +geom_smooth(method = lm)+ +facet_wrap(~S)+ +theme_bw() +```{r, warning=FALSE} +S <- rbern(100)+1 +dat <- sim_HW(S, b=c(.5,.5), a=c(0,10)) +# Indirect effect (b) is the same for men and women +dat |> +ggplot(aes(x=H, y=W, color=factor(S)))+ +geom_point()+ +geom_smooth(method = lm)+ +facet_wrap(~S)+ +theme_bw() +S <- rbern(100)+1 +dat <- sim_HW(S, b=c(.5,.5), a=c(0,10)) +# Indirect effect (b) is the same for men and women +dat |> +ggplot(aes(x=H, y=W, color=factor(S)))+ +geom_point()+ +geom_smooth(method = lm)+ +facet_wrap(~S)+ +theme_bw() +S <- rbern(100)+1 +dat <- sim_HW(S, b=c(.5,.5), a=c(0,10)) +# Indirect effect (b) is the same for men and women +dat |> +ggplot(aes(x=H, y=W, color=factor(S)))+ +geom_point()+ +geom_smooth(method = lm)+ +# facet_wrap(~S)+ +theme_bw() +dat <- list( +W = d$weight, +H = d$height, +Hbar = mean(d$height), +S = d$male+1 ) +m_SHW <- quap( alist( W ~ dnorm(mu,sigma), -mu <- a + b*H, -a ~ dnorm(0,10), -b ~ dunif(0,1), -sigma~dunif(0,10) -),data=list(W=W, H=H)) -#Summary -precis(m3.1) -n <- 1e3 -a <- rnorm(n,0,10) -b <- runif(n,0,1) -plot(NULL,xlim=c(130,170),ylim=c(50,90), -xlab="height(cm)", ylab="weight(kg)",) -for (j in 1:50 ) abline(a=a[j], b=b[j], lwd=2, col=2) -dat <- list(W=d$weight, H=d$height) -#k <- 10 -#dat <- list(W=d$weight[1:k], H=d$height[1:k]) -#Run Model -m3.2 <- quap( +mu <- a[S]+b[S]*(H-Hbar), +a[S] ~ dnorm(60,10), +b[S] ~ dunif(0,1), +sigma ~ dunif(0,10) +), data=dat +) +dat <- list( +W = d$weight, +H = d$height, +Hbar = mean(d$height), +S = d$male+1 ) +m_SHW <- quap( alist( W ~ dnorm(mu,sigma), -mu <- a + b*H, -a ~ dnorm(0,10), -b ~ dunif(0,1), -sigma~dunif(0,10) -),data=dat) -precis(m3.2) -post <- extract.samples(m3.2) -plot(dat$H,dat$W,col=2,lwd=3, -xlim=c(min(dat$H),max(dat$H)), ylim=c(min(30,dat$w),max(dat$W)), -xlab="height(cm)", ylab="weight(kg)") -for (j in 1:20) -abline(a=post$a[j],b=post$b[j], lty=1) -post <- extract.samples(m3.2) -pairs(post) -head(post) -plot(d$height,d$weight,col=2,lwd=3, -xlab="height(cm)", ylab="weight(kg)") -for (j in 1:20) -abline(a=post$a[j],b=post$b[j], lty=1) -height_seq <- seq(130,190,len=20) -W_postpred <- sim(m3.2,data=list(H=height_seq)) -W_PI <- apply(W_postpred,2,PI) -lines(height_seq,W_PI[1,],lty=2,lwd=2) -lines(height_seq,W_PI[2,],lty=2,lwd=2) -# definegrid -p_grid <-seq(from=0,to=1,length.out=20) -# defineprior -#prior <-rep(1,20) -prior <-ifelse(p_grid<0.5,0,1) -# computelikelihoodateachvalueingrid -likelihood <-dbinom(6,size=9,prob=p_grid) -# computeproductoflikelihoodandprior -unstd.posterior <-likelihood*prior -# standardizetheposterior,soitsumsto1 -posterior <-unstd.posterior/sum(unstd.posterior) -plot( p_grid,posterior,type="b", -xlab="probability ofwater",ylab="posteriorprobability") -mtext( "20points") -# 2.7 analyticalcalculation -W <-6 -L <-3 -curve( dbeta(x,W+1,L+1),from=0,to=1) -# quadraticapproximation -curve( dnorm(x,0.67,0.16),lty=2,add=TRUE) -# definegrid -p_grid <-seq(from=0,to=1,length.out=20) -# defineprior -#prior <-rep(1,20) -prior <-ifelse(p_grid<0.5,0,1) -# computelikelihoodateachvalueingrid -likelihood <-dbinom(6,size=9,prob=p_grid) -# computeproductoflikelihoodandprior -unstd.posterior <-likelihood*prior -# standardizetheposterior,soitsumsto1 -posterior <-unstd.posterior/sum(unstd.posterior) -plot( p_grid,posterior,type="b", -xlab="probability ofwater",ylab="posteriorprobability") -mtext( "20points") -# 2.7 analyticalcalculation -W <-6 -L <-3 -curve( dbeta(x,W+1,L+1),from=0,to=1) -# quadraticapproximation -curve( dnorm(x,0.67,0.16),lty=2,add=TRUE) -p <- c(0, .25, .5, .75, 1) -model <- sapply(p, function (p, W, L) return (4*p)^W*(4-4*p)^L) -print(model) -n_samples <-1000 -p <-rep(NA,n_samples) -p[1] <-0.5 -W <-6 -L <-3 -for (i in 2:n_samples){ -p_new <-rnorm(1,p[i-1],0.1) -if (p_new < 0) p_new <- abs(p_new) -if (p_new > 1) p_new <- 2-p_new -q0 <-dbinom(W,W+L,p[i-1]) -q1 <-dbinom(W,W+L,p_new) -p[i] <-ifelse(runif(1)=18,] -#Similate a sample of 10 people -set.seed(93) -H <- runif(10,130,170) -W <- sim_weight(H,b=0.5, sd=5) -#Run Model -m3.1 <- quap( +mu <- a[S]+b[S]*(H-Hbar), +a[S] ~ dnorm(60,10), +b[S] ~ dunif(0,1), +sigma ~ dunif(0,10) +), data=dat +) +precis(m_SHW,depth=2) +post <- extract.samples(m_SHW) +dens(post$a[,1],xlim=c(35, 55),lwd=3,col=2,xlab="posterior mean weight(kg") +dens(post$a[,2], lwd=3,col=4,add=TRUE) +post <- extract.samples(m_SHW) +dens(post$b[,1],xlim=c(35, 55),lwd=3,col=2,xlab="posterior mean weight(kg") +dens(post$b[,2], lwd=3,col=4,add=TRUE) +post <- extract.samples(m_SHW) +dens(post$b[,1],lwd=3,col=2,xlab="posterior mean weight(kg") +dens(post$b[,2],lwd=3,col=4,add=TRUE) +post <- extract.samples(m_SHW) +dens(post$b[,1],xlim=c(.3, .9),lwd=3,col=2,xlab="posterior mean weight(kg") +dens(post$b[,2],lwd=3,col=4,add=TRUE) +post <- extract.samples(m_SHW) +dens(post$b[,1],xlim=c(.3, .9),ylim=c(0,8), +lwd=3,col=2,xlab="posterior mean weight(kg") +dens(post$b[,2],lwd=3,col=4,add=TRUE) +dat <- list( +W = d$weight, +H = d$height, +Hbar = mean(d$height), +S = d$male+1 ) +m_SHW <- quap( alist( W ~ dnorm(mu,sigma), -mu <- a + b*H, -a ~ dnorm(0,10), -b ~ dunif(0,1), -sigma~dunif(0,10) -),data=list(W=W, H=H)) -#Summary -precis(m3.1) -n <- 1e3 -a <- rnorm(n,0,10) -b <- runif(n,0,1) -plot(NULL,xlim=c(130,170),ylim=c(50,90), -xlab="height(cm)", ylab="weight(kg)",) -for (j in 1:50 ) abline(a=a[j], b=b[j], lwd=2, col=2) -dat <- list(W=d$weight, H=d$height) -#k <- 10 -#dat <- list(W=d$weight[1:k], H=d$height[1:k]) -#Run Model -m3.2 <- quap( +mu <- a[S]+b[S]*(H-Hbar), +a[S] ~ dnorm(60,10), +b[S] ~ dunif(0,1), +sigma ~ dunif(0,10) +), data=dat +) +dat |> +ggplot(aes(x=H, y=W, color=factor(S)))+ +geom_point()+ +geom_smooth(method = lm)+ +# facet_wrap(~S)+ +theme_bw() +data.frame(dat) |> +ggplot(aes(x=H, y=W, color=factor(S)))+ +geom_point()+ +geom_smooth(method = lm)+ +# facet_wrap(~S)+ +theme_bw() +```{r, message=FALSE} +dat <- list( +W = d$weight, +H = d$height, +Hbar = mean(d$height), +S = d$male+1 ) +m_SHW <- quap( alist( W ~ dnorm(mu,sigma), -mu <- a + b*H, -a ~ dnorm(0,10), -b ~ dunif(0,1), -sigma~dunif(0,10) -),data=dat) -precis(m3.2) -post <- extract.samples(m3.2) -plot(dat$H,dat$W,col=2,lwd=3, -xlim=c(min(dat$H),max(dat$H)), ylim=c(min(30,dat$w),max(dat$W)), -xlab="height(cm)", ylab="weight(kg)") -for (j in 1:20) -abline(a=post$a[j],b=post$b[j], lty=1) -post <- extract.samples(m3.2) -pairs(post) -head(post) -plot(d$height,d$weight,col=2,lwd=3, -xlab="height(cm)", ylab="weight(kg)") -for (j in 1:20) -abline(a=post$a[j],b=post$b[j], lty=1) -height_seq <- seq(130,190,len=20) -W_postpred <- sim(m3.2,data=list(H=height_seq)) -W_PI <- apply(W_postpred,2,PI) -lines(height_seq,W_PI[1,],lty=2,lwd=2) -lines(height_seq,W_PI[2,],lty=2,lwd=2) -pos_true <- .95 -pos <- .01 -true_pos <- (pos_true*pos)/(pos_true*pos+(1-pos_true)*(1-pos)) -true_pos -true_pos <- sapply(seq(from=.01, to=.95, by=0.01), function (pos) return (pos_true*pos)/(pos_true*pos+(1-pos_true)*(1-pos))) -plot(true_pos, col=2, lwd=2) -true_pos <- sapply(pos=seq(from=.01, to=.95, by=0.01), function (pos) return (pos_true*pos)/(pos_true*pos+(1-pos_true)*(1-pos))) -true_pos <- sapply(c(.01), function (pos) return (pos_true*pos)/(pos_true*pos+(1-pos_true)*(1-pos))) -plot(true_pos, col=2, lwd=2) -true_pos <- sapply(c(.01), function (p) return (pos_true*p)/(pos_true*p+(1-pos_true)*(1-p))) -true_pos <- sapply(c(.01), function (p, pt) return (pt*p)/(pt*p+(1-pt)*(1-p))) -pt <- pos_true -true_pos <- sapply(c(.01), function (p, pt) return (pt*p)/(pt*p+(1-pt)*(1-p))) -pt <- pos_true -true_pos <- sapply(c(.01), function (p, pt) return (pt*p)/(pt*p+(1-pt)*(1-p))) -seq(from=.01, to=.95, by=0.01) -seq(from=.01, to=1, by=0.01) -x <- list(p = seq(from=.01, to=1, by=0.01), pt=rep(.95, 100)) -x <- list(p = seq(from=.01, to=1, by=0.01), pt=rep(.95, 100)) -View(x) -true_pos <- sapply(x, function (p, pt) return (pt*p)/(pt*p+(1-pt)*(1-p))) -true_pos <- sapply(x, function (p) return (pt*p)/(pt*p+(1-pt)*(1-p))) -true_pos <- sapply(x, function (p) return (pt*p)/(pt*p+(1-pt)*(1-p))) -plot(true_pos, col=2, lwd=2) -pos_true <- .95 # likelihood -pos <- .01 # prior -true_pos <- (pos_true*pos)/(pos_true*pos+(1-pos_true)*(1-pos)) -true_pos # posterior -x[1] -x[,1] -x[1] -x[2] -p <- c(0, .25, .5, .75, 1) -model <- sapply(p, function (p, W, L) return (4*p)^W*(4-4*p)^L) -print(model) -x <- list(p = seq(from=.01, to=1, by=0.01), pt=rep(.95, 100)) -true_pos <- sapply(x, function (p=p, pt=pt) return (pt*p)/(pt*p+(1-pt)*(1-p))) -x <- list(p = seq(from=.01, to=1, by=0.01), ptr=rep(.95, 100)) -true_pos <- sapply(x, function (p,ptr) return (ptr*p)/(ptr*p+(1-ptr)*(1-p))) -View(x) -true_pos <- sapply(x$p, x$ptr, function (p,ptr) return (ptr*p)/(ptr*p+(1-ptr)*(1-p))) -ptr <- .95 -true_pos <- sapply(x$p, function (p,ptr) return (ptr*p)/(ptr*p+(1-ptr)*(1-p))) -p <- seq(from=.01, to=1, by=0.01) -true_pos <- sapply(p, function (p) return (ptr*p)/(ptr*p+(1-ptr)*(1-p))) -plot(true_pos, col=2, lwd=2) -(ptr*p)/(ptr*p+(1-ptr)*(1-p)) -true_pos <- apply(p, function (p) return (ptr*p)/(ptr*p+(1-ptr)*(1-p))) -plot(true_pos, col=2, lwd=2) -true_pos <- lapply(p, function (p) return (ptr*p)/(ptr*p+(1-ptr)*(1-p))) -plot(true_pos, col=2, lwd=2) -View(true_pos) -true_pos <- sapply(p, function (p) return (ptr*p)/(ptr*p+(1-ptr)*(1-p))) -(ptr*p[1])/(ptr*p[1]+(1-ptr)*(1-p[1])) -sample <- c('W','L','W','W','W','L','W','L','W') -W <- sum(sample=='W') # No. of W observed -L <- sum(sample=='L') # No. of L observed -p <- c(0,.25,.5,.75,1) # Proportions W -ways <- sapply(p, function (q) (q*4)^W*((1-q)*4)^L) -prob <- ways/sum(ways) -cbind(p, ways, prob) -(q*4)^W*((1-q)*4)^L -true_pos <- sapply(p, function (q) return (ptr*q)/(ptr*q+(1-ptr)*(1-q))) -p <- seq(from=.01, to=1, by=0.01) -ptr <- .95 -true_pos <- sapply(p, function (q) return (ptr*q)/(ptr*q+(1-ptr)*(1-q))) -sapply(p, function (q) return (ptr*q)/(ptr*q+(1-ptr)*(1-q))) -sapply(p, function (q) (q*4)^W*((1-q)*4)^L) -ways <- sapply(p, function (q) (q*4)^W*((1-q)*4)^L) -p <- c(0,.25,.5,.75,1) # Proportions W -ways <- sapply(p, function (q) (q*4)^W*((1-q)*4)^L) -p <- seq(from=.01, to=1, by=0.01) -ptr <- .95 -true_pos <- sapply(p, function (q) (ptr*q)/(ptr*q+(1-ptr)*(1-q))) -plot(true_pos, col=2, lwd=2) -plot(true_pos, p, col=2, lwd=2) -plot(true_pos, p, col=2, lwd=3, lty="l") -plot(true_pos, p, col=2, lwd=3, lty=3) -p <- seq(from=.01, to=1, by=0.01); ptr <- .95 -true_pos <- sapply(p, function (q) (ptr*q)/(ptr*q+(1-ptr)*(1-q))) -plot(true_pos, p, col=2, lwd=3, lty=3) -p <- seq(from=.01, to=1, by=0.01); ptr <- .95 -true_pos <- sapply(p, function (q) (ptr*q)/(ptr*q+(1-ptr)*(1-q))) -plot(true_pos, p, col=2, lwd=3) +mu <- a[S]+b[S]*(H-Hbar), +a[S] ~ dnorm(60,10), +b[S] ~ dunif(0,1), +sigma ~ dunif(0,10) +), data=dat +) +dat <- list( +W = d$weight, +H = d$height, +Hbar = mean(d$height), +S = d$male+1 ) +m_SHW <- quap( +alist( +W ~ dnorm(mu,sigma), +mu <- a[S]+b[S]*(H-Hbar), +a[S] ~ dnorm(60,10), +b[S] ~ dunif(0,1), +sigma ~ dunif(0,10) +), data=dat +) +dat <- list( +W = d$weight, +H = d$height, +Hbar = mean(d$height), +S = d$male+1 ) +m_SHW <- quap( +alist( +W ~ dnorm(mu,sigma), +mu <- a[S]+b[S]*(H-Hbar), +a[S] ~ dnorm(60,10), +b[S] ~ dunif(0,1), +sigma ~ dunif(0,10) +), data=dat +) +data.frame(dat) |> +ggplot(aes(x=H, y=W, color=factor(S)))+ +geom_point()+ +geom_smooth(method = lm)+ +# facet_wrap(~S)+ +theme_bw() +precis(m_SHW,depth=2) +dat <- list( +W = d$weight, +H = d$height, +Hbar = mean(d$height), +S = d$male+1 ) +m_SHW <- quap( +alist( +W ~ dnorm(mu,sigma), +mu <- a[S]+b[S]*(H-Hbar), +a[S] ~ dnorm(60,10), +b[S] ~ dunif(0,1), +sigma ~ dunif(0,10) +), data=dat +) +dat <- list( +W = d$weight, +H = d$height, +Hbar = mean(d$height), +S = d$male+1 ) +m_SHW <- quap( +alist( +W ~ dnorm(mu,sigma), +mu <- a[S]+b[S]*(H-Hbar), +a[S] ~ dnorm(60,10), +b[S] ~ dunif(0,1), +sigma ~ dunif(0,10) +), data=dat +) +data.frame(dat) |> +ggplot(aes(x=H, y=W, color=factor(S)))+ +geom_point()+ +geom_smooth(method = lm)+ +# facet_wrap(~S)+ +theme_bw() +precis(m_SHW,depth=2) +xseq <- seq(from=130,to=190, len=50) +muF <- +link(m_adults2, data=list(S=rep(1,50),H=xseq,Hbar=mean(d$height))) diff --git a/.Rproj.user/B584AE7E/pcs/windowlayoutstate.pper b/.Rproj.user/B584AE7E/pcs/windowlayoutstate.pper index abd43e2..6065b0a 100644 --- a/.Rproj.user/B584AE7E/pcs/windowlayoutstate.pper +++ b/.Rproj.user/B584AE7E/pcs/windowlayoutstate.pper @@ -1,6 +1,6 @@ { "left": { - "splitterpos": 401, + "splitterpos": 155, "topwindowstate": "NORMAL", "panelheight": 959, "windowheight": 997 diff --git a/.Rproj.user/B584AE7E/sources/session-605e3cd7/77F68D30 b/.Rproj.user/B584AE7E/sources/per/t/77F68D30 similarity index 80% rename from .Rproj.user/B584AE7E/sources/session-605e3cd7/77F68D30 rename to .Rproj.user/B584AE7E/sources/per/t/77F68D30 index 1f97a83..f1f442a 100644 --- a/.Rproj.user/B584AE7E/sources/session-605e3cd7/77F68D30 +++ b/.Rproj.user/B584AE7E/sources/per/t/77F68D30 @@ -3,7 +3,7 @@ "path": "C:/Users/lacor/OneDrive/100. Personal/SelfDevelopment/25. Project 2022/Statistical-Thinking-2023/Statistical Thinking 2023_v2.qmd", "project_path": "Statistical Thinking 2023_v2.qmd", "type": "quarto_markdown", - "hash": "1895704522", + "hash": "799310168", "contents": "", "dirty": false, "created": 1673908998203.0, @@ -16,16 +16,16 @@ "Source": "Source", "docOutlineVisible": "1", "rmdVisualCollapsedChunks": "", - "rmdVisualModeLocation": "10046:19198", - "cursorPosition": "527,0", + "rmdVisualModeLocation": "11232:22202", + "cursorPosition": "602,0", "scrollLine": "0" }, "folds": "", - "lastKnownWriteTime": 1674170667, + "lastKnownWriteTime": 1674187233, "encoding": "UTF-8", "collab_server": "", "source_window": "", - "last_content_update": 1674170667303, + "last_content_update": 1674187233984, "read_only": false, "read_only_alternatives": [] } \ No newline at end of file diff --git a/.Rproj.user/B584AE7E/sources/session-605e3cd7/77F68D30-contents b/.Rproj.user/B584AE7E/sources/per/t/77F68D30-contents similarity index 91% rename from .Rproj.user/B584AE7E/sources/session-605e3cd7/77F68D30-contents rename to .Rproj.user/B584AE7E/sources/per/t/77F68D30-contents index 70a56f8..e67ef4b 100644 --- a/.Rproj.user/B584AE7E/sources/session-605e3cd7/77F68D30-contents +++ b/.Rproj.user/B584AE7E/sources/per/t/77F68D30-contents @@ -549,3 +549,57 @@ ggplot(df, aes(x=W_contrast,fill=W_flag))+ geom_density()+ theme_bw() ``` + +Now, what is the direct effect of sex over weight? + +```{r, message=FALSE} +S <- rbern(100)+1 +dat <- sim_HW(S, b=c(.5,.5), a=c(0,10)) + +# Indirect effect (b) is the same for men and women +dat |> + ggplot(aes(x=H, y=W, color=factor(S)))+ + geom_point()+ + geom_smooth(method = lm)+ + # facet_wrap(~S)+ + theme_bw() +``` + +```{r, message=FALSE} +dat <- list( + W = d$weight, + H = d$height, + Hbar = mean(d$height), + S = d$male+1 ) + +m_SHW <- quap( + alist( + W ~ dnorm(mu,sigma), + mu <- a[S]+b[S]*(H-Hbar), + a[S] ~ dnorm(60,10), + b[S] ~ dunif(0,1), + sigma ~ dunif(0,10) + ), data=dat +) +data.frame(dat) |> + ggplot(aes(x=H, y=W, color=factor(S)))+ + geom_point()+ + geom_smooth(method = lm)+ + # facet_wrap(~S)+ + theme_bw() + +precis(m_SHW,depth=2) +``` + +Note that regression line's slopes are almost the same for both male and female. + +```{r} +post <- extract.samples(m_SHW) +dens(post$b[,1],xlim=c(.3, .9),ylim=c(0,8), + lwd=3,col=2,xlab="posterior mean weight(kg)") +dens(post$b[,2],lwd=3,col=4,add=TRUE) +``` + +```{r} + +``` diff --git a/.Rproj.user/B584AE7E/sources/session-605e3cd7/884F836F b/.Rproj.user/B584AE7E/sources/per/t/884F836F similarity index 100% rename from .Rproj.user/B584AE7E/sources/session-605e3cd7/884F836F rename to .Rproj.user/B584AE7E/sources/per/t/884F836F diff --git a/.Rproj.user/B584AE7E/sources/session-605e3cd7/884F836F-contents b/.Rproj.user/B584AE7E/sources/per/t/884F836F-contents similarity index 100% rename from .Rproj.user/B584AE7E/sources/session-605e3cd7/884F836F-contents rename to .Rproj.user/B584AE7E/sources/per/t/884F836F-contents diff --git a/.Rproj.user/B584AE7E/sources/session-605e3cd7/9F66EA64 b/.Rproj.user/B584AE7E/sources/per/t/9F66EA64 similarity index 100% rename from .Rproj.user/B584AE7E/sources/session-605e3cd7/9F66EA64 rename to .Rproj.user/B584AE7E/sources/per/t/9F66EA64 diff --git a/.Rproj.user/B584AE7E/sources/session-605e3cd7/9F66EA64-contents b/.Rproj.user/B584AE7E/sources/per/t/9F66EA64-contents similarity index 100% rename from .Rproj.user/B584AE7E/sources/session-605e3cd7/9F66EA64-contents rename to .Rproj.user/B584AE7E/sources/per/t/9F66EA64-contents diff --git a/.Rproj.user/B584AE7E/sources/session-605e3cd7/E0A14F48 b/.Rproj.user/B584AE7E/sources/per/t/E0A14F48 similarity index 96% rename from .Rproj.user/B584AE7E/sources/session-605e3cd7/E0A14F48 rename to .Rproj.user/B584AE7E/sources/per/t/E0A14F48 index e870a96..7983484 100644 --- a/.Rproj.user/B584AE7E/sources/session-605e3cd7/E0A14F48 +++ b/.Rproj.user/B584AE7E/sources/per/t/E0A14F48 @@ -3,7 +3,7 @@ "path": "C:/Users/lacor/OneDrive/100. Personal/SelfDevelopment/20. Project 2019/StockMarket/Asset_Analysis_v23.Rmd", "project_path": null, "type": "r_markdown", - "hash": "0", + "hash": "1870848255", "contents": "", "dirty": false, "created": 1674164268355.0, diff --git a/.Rproj.user/B584AE7E/sources/session-605e3cd7/E0A14F48-contents b/.Rproj.user/B584AE7E/sources/per/t/E0A14F48-contents similarity index 100% rename from .Rproj.user/B584AE7E/sources/session-605e3cd7/E0A14F48-contents rename to .Rproj.user/B584AE7E/sources/per/t/E0A14F48-contents diff --git a/.Rproj.user/B584AE7E/sources/prop/EA93BB00 b/.Rproj.user/B584AE7E/sources/prop/EA93BB00 index a71d353..f21c38d 100644 --- a/.Rproj.user/B584AE7E/sources/prop/EA93BB00 +++ b/.Rproj.user/B584AE7E/sources/prop/EA93BB00 @@ -5,7 +5,7 @@ "Source": "Source", "docOutlineVisible": "1", "rmdVisualCollapsedChunks": "", - "rmdVisualModeLocation": "10046:19198", - "cursorPosition": "527,0", + "rmdVisualModeLocation": "11232:22202", + "cursorPosition": "602,0", "scrollLine": "0" } \ No newline at end of file diff --git a/.Rproj.user/B584AE7E/sources/session-605e3cd7/231C5E6B-contents b/.Rproj.user/B584AE7E/sources/session-605e3cd7/231C5E6B-contents deleted file mode 100644 index e69de29..0000000 diff --git a/.Rproj.user/B584AE7E/sources/session-605e3cd7/388DADFE-contents b/.Rproj.user/B584AE7E/sources/session-605e3cd7/388DADFE-contents deleted file mode 100644 index e69de29..0000000 diff --git a/.Rproj.user/B584AE7E/sources/session-605e3cd7/lock_file b/.Rproj.user/B584AE7E/sources/session-605e3cd7/lock_file deleted file mode 100644 index e69de29..0000000 diff --git a/.Rproj.user/B584AE7E/viewer-cache/993CD89E.Rdata b/.Rproj.user/B584AE7E/viewer-cache/993CD89E.Rdata new file mode 100644 index 0000000..3d0653e Binary files /dev/null and b/.Rproj.user/B584AE7E/viewer-cache/993CD89E.Rdata differ diff --git a/.Rproj.user/B584AE7E/viewer-cache/FBB44727.Rdata b/.Rproj.user/B584AE7E/viewer-cache/FBB44727.Rdata new file mode 100644 index 0000000..109d1f0 Binary files /dev/null and b/.Rproj.user/B584AE7E/viewer-cache/FBB44727.Rdata differ diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/B584AE7E605e3cd7/chunks.json b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/B584AE7E605e3cd7/chunks.json index 6ebb033..eefcdce 100644 --- a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/B584AE7E605e3cd7/chunks.json +++ b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/B584AE7E605e3cd7/chunks.json @@ -1 +1 @@ -{"chunk_definitions":[{"row":47,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-40"},"document_id":"77F68D30","chunk_id":"c0jrftmj331il","chunk_label":"unnamed-chunk-1"},{"row":53,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-41"},"document_id":"77F68D30","chunk_id":"cnq8c446n0wtz","chunk_label":"unnamed-chunk-2"},{"row":67,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-42"},"document_id":"77F68D30","chunk_id":"c3qooae84c4xs","chunk_label":"unnamed-chunk-3"},{"row":87,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-43"},"document_id":"77F68D30","chunk_id":"c8k36ylh3ik2z","chunk_label":"unnamed-chunk-4"},{"row":93,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-44"},"document_id":"77F68D30","chunk_id":"cff5zae4b4ix2","chunk_label":"unnamed-chunk-5"},{"row":107,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-45"},"document_id":"77F68D30","chunk_id":"cuj4f1k7oy0f9","chunk_label":"unnamed-chunk-6"},{"row":113,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-25"},"document_id":"77F68D30","chunk_id":"c3b4hkzi6i1gq","chunk_label":"unnamed-chunk-7"},{"row":129,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-47"},"document_id":"77F68D30","chunk_id":"cryc9nwjktom8","chunk_label":"unnamed-chunk-8"},{"row":134,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-48"},"document_id":"77F68D30","chunk_id":"c11kjcel8rada","chunk_label":"unnamed-chunk-9"},{"row":144,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-52"},"document_id":"77F68D30","chunk_id":"cu5f4f0k460vm","chunk_label":"unnamed-chunk-10"},{"row":151,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-50"},"document_id":"77F68D30","chunk_id":"cr9sbhfkl0l7m","chunk_label":"unnamed-chunk-11"},{"row":155,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-51"},"document_id":"77F68D30","chunk_id":"c67fek8fh1vdj","chunk_label":"unnamed-chunk-12"},{"row":159,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-52"},"document_id":"77F68D30","chunk_id":"c0qzt99s3uz17","chunk_label":"unnamed-chunk-13"},{"row":175,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-53"},"document_id":"77F68D30","chunk_id":"cf9t8qccs9es8","chunk_label":"unnamed-chunk-14"},{"row":203,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-57"},"document_id":"77F68D30","chunk_id":"cy1yzqk9v6smc","chunk_label":"unnamed-chunk-18"},{"row":237,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-59"},"document_id":"77F68D30","chunk_id":"c85mkxl3u2xgh","chunk_label":"unnamed-chunk-20"},{"row":231,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-58"},"document_id":"77F68D30","chunk_id":"c2fn3g4qdmzyy","chunk_label":"unnamed-chunk-19"},{"row":279,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-60"},"document_id":"77F68D30","chunk_id":"c2jly3c97ig8i","chunk_label":"unnamed-chunk-21"},{"row":299,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-61"},"document_id":"77F68D30","chunk_id":"cefh5ihzkcqbl","chunk_label":"unnamed-chunk-22"},{"row":308,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-62"},"document_id":"77F68D30","chunk_id":"cilpuhvqdmpej","chunk_label":"unnamed-chunk-23"},{"row":356,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-20"},"document_id":"77F68D30","chunk_id":"c1tfzdz2b80hy","chunk_label":"unnamed-chunk-26"},{"row":347,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-64"},"document_id":"77F68D30","chunk_id":"c63m2qhze3u2y","chunk_label":"unnamed-chunk-25"},{"row":331,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-63"},"document_id":"77F68D30","chunk_id":"czxt33feq8xzf","chunk_label":"unnamed-chunk-24"},{"row":363,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-61"},"document_id":"77F68D30","chunk_id":"c211ibf7ouri8","chunk_label":"unnamed-chunk-27"},{"row":195,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-56"},"document_id":"77F68D30","chunk_id":"cuafhnftbidp9","chunk_label":"unnamed-chunk-17"},{"row":190,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-55"},"document_id":"77F68D30","chunk_id":"cra8e128kr9o9","chunk_label":"unnamed-chunk-16"},{"row":183,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-54"},"document_id":"77F68D30","chunk_id":"c9ajju6cf9cv8","chunk_label":"unnamed-chunk-15"},{"row":393,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-2"},"document_id":"77F68D30","chunk_id":"cwqxet0zexx43","chunk_label":"unnamed-chunk-28"},{"row":406,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-4"},"document_id":"77F68D30","chunk_id":"cp6949hwjcirq","chunk_label":"unnamed-chunk-29"},{"row":423,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-23"},"document_id":"77F68D30","chunk_id":"c52kj3limvhya","chunk_label":"unnamed-chunk-30"},{"row":433,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-26"},"document_id":"77F68D30","chunk_id":"c4d2y4qjjl0e3","chunk_label":"unnamed-chunk-31"},{"row":446,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-28"},"document_id":"77F68D30","chunk_id":"cfk35uawz2hsn","chunk_label":"unnamed-chunk-32"},{"row":462,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-29"},"document_id":"77F68D30","chunk_id":"czw0rd1u0m33e","chunk_label":"unnamed-chunk-33"},{"row":480,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-30"},"document_id":"77F68D30","chunk_id":"cowzykbnv5xxz","chunk_label":"unnamed-chunk-34"},{"row":500,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-31"},"document_id":"77F68D30","chunk_id":"cct9s4x1m0a0t","chunk_label":"unnamed-chunk-35"},{"row":506,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-32"},"document_id":"77F68D30","chunk_id":"cozvs9s6hxsfi","chunk_label":"unnamed-chunk-36"},{"row":516,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-34"},"document_id":"77F68D30","chunk_id":"cwztp6gqf9w0s","chunk_label":"unnamed-chunk-37"},{"row":525,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-35"},"document_id":"77F68D30","chunk_id":"csmeeql20tusx","chunk_label":"unnamed-chunk-38"},{"row":550,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-68"},"document_id":"77F68D30","chunk_id":"cqa1e485jcrzr","chunk_label":"unnamed-chunk-39"}],"doc_write_time":1674158939,"chunk_rendered_width":661} \ No newline at end of file +{"chunk_definitions":[{"row":47,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-40"},"document_id":"77F68D30","chunk_id":"c0jrftmj331il","chunk_label":"unnamed-chunk-1"},{"row":53,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-41"},"document_id":"77F68D30","chunk_id":"cnq8c446n0wtz","chunk_label":"unnamed-chunk-2"},{"row":67,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-42"},"document_id":"77F68D30","chunk_id":"c3qooae84c4xs","chunk_label":"unnamed-chunk-3"},{"row":87,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-43"},"document_id":"77F68D30","chunk_id":"c8k36ylh3ik2z","chunk_label":"unnamed-chunk-4"},{"row":93,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-44"},"document_id":"77F68D30","chunk_id":"cff5zae4b4ix2","chunk_label":"unnamed-chunk-5"},{"row":107,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-45"},"document_id":"77F68D30","chunk_id":"cuj4f1k7oy0f9","chunk_label":"unnamed-chunk-6"},{"row":113,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-25"},"document_id":"77F68D30","chunk_id":"c3b4hkzi6i1gq","chunk_label":"unnamed-chunk-7"},{"row":129,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-47"},"document_id":"77F68D30","chunk_id":"cryc9nwjktom8","chunk_label":"unnamed-chunk-8"},{"row":134,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-48"},"document_id":"77F68D30","chunk_id":"c11kjcel8rada","chunk_label":"unnamed-chunk-9"},{"row":144,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-52"},"document_id":"77F68D30","chunk_id":"cu5f4f0k460vm","chunk_label":"unnamed-chunk-10"},{"row":151,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-50"},"document_id":"77F68D30","chunk_id":"cr9sbhfkl0l7m","chunk_label":"unnamed-chunk-11"},{"row":155,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-51"},"document_id":"77F68D30","chunk_id":"c67fek8fh1vdj","chunk_label":"unnamed-chunk-12"},{"row":159,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-52"},"document_id":"77F68D30","chunk_id":"c0qzt99s3uz17","chunk_label":"unnamed-chunk-13"},{"row":175,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-53"},"document_id":"77F68D30","chunk_id":"cf9t8qccs9es8","chunk_label":"unnamed-chunk-14"},{"row":203,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-57"},"document_id":"77F68D30","chunk_id":"cy1yzqk9v6smc","chunk_label":"unnamed-chunk-18"},{"row":237,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-59"},"document_id":"77F68D30","chunk_id":"c85mkxl3u2xgh","chunk_label":"unnamed-chunk-20"},{"row":231,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-58"},"document_id":"77F68D30","chunk_id":"c2fn3g4qdmzyy","chunk_label":"unnamed-chunk-19"},{"row":279,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-60"},"document_id":"77F68D30","chunk_id":"c2jly3c97ig8i","chunk_label":"unnamed-chunk-21"},{"row":299,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-61"},"document_id":"77F68D30","chunk_id":"cefh5ihzkcqbl","chunk_label":"unnamed-chunk-22"},{"row":308,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-62"},"document_id":"77F68D30","chunk_id":"cilpuhvqdmpej","chunk_label":"unnamed-chunk-23"},{"row":356,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-20"},"document_id":"77F68D30","chunk_id":"c1tfzdz2b80hy","chunk_label":"unnamed-chunk-26"},{"row":347,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-64"},"document_id":"77F68D30","chunk_id":"c63m2qhze3u2y","chunk_label":"unnamed-chunk-25"},{"row":331,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-63"},"document_id":"77F68D30","chunk_id":"czxt33feq8xzf","chunk_label":"unnamed-chunk-24"},{"row":363,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-61"},"document_id":"77F68D30","chunk_id":"c211ibf7ouri8","chunk_label":"unnamed-chunk-27"},{"row":195,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-56"},"document_id":"77F68D30","chunk_id":"cuafhnftbidp9","chunk_label":"unnamed-chunk-17"},{"row":190,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-55"},"document_id":"77F68D30","chunk_id":"cra8e128kr9o9","chunk_label":"unnamed-chunk-16"},{"row":183,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-54"},"document_id":"77F68D30","chunk_id":"c9ajju6cf9cv8","chunk_label":"unnamed-chunk-15"},{"row":393,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-2"},"document_id":"77F68D30","chunk_id":"cwqxet0zexx43","chunk_label":"unnamed-chunk-28"},{"row":406,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-4"},"document_id":"77F68D30","chunk_id":"cp6949hwjcirq","chunk_label":"unnamed-chunk-29"},{"row":423,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-23"},"document_id":"77F68D30","chunk_id":"c52kj3limvhya","chunk_label":"unnamed-chunk-30"},{"row":433,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-26"},"document_id":"77F68D30","chunk_id":"c4d2y4qjjl0e3","chunk_label":"unnamed-chunk-31"},{"row":446,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-28"},"document_id":"77F68D30","chunk_id":"cfk35uawz2hsn","chunk_label":"unnamed-chunk-32"},{"row":462,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-29"},"document_id":"77F68D30","chunk_id":"czw0rd1u0m33e","chunk_label":"unnamed-chunk-33"},{"row":480,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-30"},"document_id":"77F68D30","chunk_id":"cowzykbnv5xxz","chunk_label":"unnamed-chunk-34"},{"row":500,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-31"},"document_id":"77F68D30","chunk_id":"cct9s4x1m0a0t","chunk_label":"unnamed-chunk-35"},{"row":506,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-32"},"document_id":"77F68D30","chunk_id":"cozvs9s6hxsfi","chunk_label":"unnamed-chunk-36"},{"row":516,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-34"},"document_id":"77F68D30","chunk_id":"cwztp6gqf9w0s","chunk_label":"unnamed-chunk-37"},{"row":525,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-35"},"document_id":"77F68D30","chunk_id":"csmeeql20tusx","chunk_label":"unnamed-chunk-38"},{"row":550,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-68"},"document_id":"77F68D30","chunk_id":"cqa1e485jcrzr","chunk_label":"unnamed-chunk-39"},{"row":565,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"label":"unnamed-chunk-76"},"document_id":"77F68D30","chunk_id":"c6t5kj9r0xqzx","chunk_label":"unnamed-chunk-40"},{"row":591,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"label":"unnamed-chunk-94"},"document_id":"77F68D30","chunk_id":"cgq5kq1n6i5pg","chunk_label":"unnamed-chunk-41"},{"row":600,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-83"},"document_id":"77F68D30","chunk_id":"cuugb0843jsqr","chunk_label":"unnamed-chunk-42"},{"row":604,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-95"},"document_id":"77F68D30","chunk_id":"cnh2brq8uipgl","chunk_label":"unnamed-chunk-43"}],"doc_write_time":1674186864,"chunk_rendered_width":661} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/c6t5kj9r0xqzx/000019.csv b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/c6t5kj9r0xqzx/000019.csv new file mode 100644 index 0000000..8f91174 --- /dev/null +++ b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/c6t5kj9r0xqzx/000019.csv @@ -0,0 +1,10 @@ +"0","S <- rbern(100)+1" +"0","dat <- sim_HW(S, b=c(.5,.5), a=c(0,10))" +"0","" +"0","# Indirect effect (b) is the same for men and women" +"0","dat |> " +"0"," ggplot(aes(x=H, y=W, color=factor(S)))+" +"0"," geom_point()+" +"0"," geom_smooth(method = lm)+" +"0"," # facet_wrap(~S)+" +"0"," theme_bw()" diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/c6t5kj9r0xqzx/00001a.metadata b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/c6t5kj9r0xqzx/00001a.metadata new file mode 100644 index 0000000..6399179 --- /dev/null +++ b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/c6t5kj9r0xqzx/00001a.metadata @@ -0,0 +1 @@ +{"height":408.5290482076638,"width":661.0,"size_behavior":0,"conditions":[]} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/c6t5kj9r0xqzx/00001a.png b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/c6t5kj9r0xqzx/00001a.png new file mode 100644 index 0000000..c9d9347 Binary files /dev/null and b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/c6t5kj9r0xqzx/00001a.png differ diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/c6t5kj9r0xqzx/00001a.snapshot b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/c6t5kj9r0xqzx/00001a.snapshot new file mode 100644 index 0000000..802e2e4 Binary files /dev/null and b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/c6t5kj9r0xqzx/00001a.snapshot differ diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/00001e.csv b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/00001e.csv new file mode 100644 index 0000000..43c755f --- /dev/null +++ b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/00001e.csv @@ -0,0 +1,21 @@ +"0","dat <- list(" +"0"," W = d$weight," +"0"," H = d$height," +"0"," Hbar = mean(d$height)," +"0"," S = d$male+1 )" +"0","" +"0","m_SHW <- quap(" +"0"," alist(" +"0"," W ~ dnorm(mu,sigma)," +"0"," mu <- a[S]+b[S]*(H-Hbar)," +"0"," a[S] ~ dnorm(60,10)," +"0"," b[S] ~ dunif(0,1)," +"0"," sigma ~ dunif(0,10)" +"0"," ), data=dat" +"0",")" +"0","data.frame(dat) |> " +"0"," ggplot(aes(x=H, y=W, color=factor(S)))+" +"0"," geom_point()+" +"0"," geom_smooth(method = lm)+" +"0"," # facet_wrap(~S)+" +"0"," theme_bw()" diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/00001f.metadata b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/00001f.metadata new file mode 100644 index 0000000..6399179 --- /dev/null +++ b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/00001f.metadata @@ -0,0 +1 @@ +{"height":408.5290482076638,"width":661.0,"size_behavior":0,"conditions":[]} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/00001f.png b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/00001f.png new file mode 100644 index 0000000..bfd6775 Binary files /dev/null and b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/00001f.png differ diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/00001f.snapshot b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/00001f.snapshot new file mode 100644 index 0000000..4bd6fe9 Binary files /dev/null and b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/00001f.snapshot differ diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/000020.csv b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/000020.csv new file mode 100644 index 0000000..73066c3 --- /dev/null +++ b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/000020.csv @@ -0,0 +1,2 @@ +"0","" +"0","precis(m_SHW,depth=2)" diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/000021.metadata b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/000021.metadata new file mode 100644 index 0000000..723792d --- /dev/null +++ b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/000021.metadata @@ -0,0 +1 @@ +{"classes":["data.frame"],"nrow":5,"ncol":4,"summary":{"Description":["df [5 × 4]"]}} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/000021.rdf b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/000021.rdf new file mode 100644 index 0000000..986ebb1 Binary files /dev/null and b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cgq5kq1n6i5pg/000021.rdf differ diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/chunks.json b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/chunks.json index 6ebb033..eefcdce 100644 --- a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/chunks.json +++ b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/chunks.json @@ -1 +1 @@ -{"chunk_definitions":[{"row":47,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-40"},"document_id":"77F68D30","chunk_id":"c0jrftmj331il","chunk_label":"unnamed-chunk-1"},{"row":53,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-41"},"document_id":"77F68D30","chunk_id":"cnq8c446n0wtz","chunk_label":"unnamed-chunk-2"},{"row":67,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-42"},"document_id":"77F68D30","chunk_id":"c3qooae84c4xs","chunk_label":"unnamed-chunk-3"},{"row":87,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-43"},"document_id":"77F68D30","chunk_id":"c8k36ylh3ik2z","chunk_label":"unnamed-chunk-4"},{"row":93,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-44"},"document_id":"77F68D30","chunk_id":"cff5zae4b4ix2","chunk_label":"unnamed-chunk-5"},{"row":107,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-45"},"document_id":"77F68D30","chunk_id":"cuj4f1k7oy0f9","chunk_label":"unnamed-chunk-6"},{"row":113,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-25"},"document_id":"77F68D30","chunk_id":"c3b4hkzi6i1gq","chunk_label":"unnamed-chunk-7"},{"row":129,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-47"},"document_id":"77F68D30","chunk_id":"cryc9nwjktom8","chunk_label":"unnamed-chunk-8"},{"row":134,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-48"},"document_id":"77F68D30","chunk_id":"c11kjcel8rada","chunk_label":"unnamed-chunk-9"},{"row":144,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-52"},"document_id":"77F68D30","chunk_id":"cu5f4f0k460vm","chunk_label":"unnamed-chunk-10"},{"row":151,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-50"},"document_id":"77F68D30","chunk_id":"cr9sbhfkl0l7m","chunk_label":"unnamed-chunk-11"},{"row":155,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-51"},"document_id":"77F68D30","chunk_id":"c67fek8fh1vdj","chunk_label":"unnamed-chunk-12"},{"row":159,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-52"},"document_id":"77F68D30","chunk_id":"c0qzt99s3uz17","chunk_label":"unnamed-chunk-13"},{"row":175,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-53"},"document_id":"77F68D30","chunk_id":"cf9t8qccs9es8","chunk_label":"unnamed-chunk-14"},{"row":203,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-57"},"document_id":"77F68D30","chunk_id":"cy1yzqk9v6smc","chunk_label":"unnamed-chunk-18"},{"row":237,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-59"},"document_id":"77F68D30","chunk_id":"c85mkxl3u2xgh","chunk_label":"unnamed-chunk-20"},{"row":231,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-58"},"document_id":"77F68D30","chunk_id":"c2fn3g4qdmzyy","chunk_label":"unnamed-chunk-19"},{"row":279,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-60"},"document_id":"77F68D30","chunk_id":"c2jly3c97ig8i","chunk_label":"unnamed-chunk-21"},{"row":299,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-61"},"document_id":"77F68D30","chunk_id":"cefh5ihzkcqbl","chunk_label":"unnamed-chunk-22"},{"row":308,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-62"},"document_id":"77F68D30","chunk_id":"cilpuhvqdmpej","chunk_label":"unnamed-chunk-23"},{"row":356,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-20"},"document_id":"77F68D30","chunk_id":"c1tfzdz2b80hy","chunk_label":"unnamed-chunk-26"},{"row":347,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-64"},"document_id":"77F68D30","chunk_id":"c63m2qhze3u2y","chunk_label":"unnamed-chunk-25"},{"row":331,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-63"},"document_id":"77F68D30","chunk_id":"czxt33feq8xzf","chunk_label":"unnamed-chunk-24"},{"row":363,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-61"},"document_id":"77F68D30","chunk_id":"c211ibf7ouri8","chunk_label":"unnamed-chunk-27"},{"row":195,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-56"},"document_id":"77F68D30","chunk_id":"cuafhnftbidp9","chunk_label":"unnamed-chunk-17"},{"row":190,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-55"},"document_id":"77F68D30","chunk_id":"cra8e128kr9o9","chunk_label":"unnamed-chunk-16"},{"row":183,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-54"},"document_id":"77F68D30","chunk_id":"c9ajju6cf9cv8","chunk_label":"unnamed-chunk-15"},{"row":393,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-2"},"document_id":"77F68D30","chunk_id":"cwqxet0zexx43","chunk_label":"unnamed-chunk-28"},{"row":406,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-4"},"document_id":"77F68D30","chunk_id":"cp6949hwjcirq","chunk_label":"unnamed-chunk-29"},{"row":423,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-23"},"document_id":"77F68D30","chunk_id":"c52kj3limvhya","chunk_label":"unnamed-chunk-30"},{"row":433,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-26"},"document_id":"77F68D30","chunk_id":"c4d2y4qjjl0e3","chunk_label":"unnamed-chunk-31"},{"row":446,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-28"},"document_id":"77F68D30","chunk_id":"cfk35uawz2hsn","chunk_label":"unnamed-chunk-32"},{"row":462,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-29"},"document_id":"77F68D30","chunk_id":"czw0rd1u0m33e","chunk_label":"unnamed-chunk-33"},{"row":480,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-30"},"document_id":"77F68D30","chunk_id":"cowzykbnv5xxz","chunk_label":"unnamed-chunk-34"},{"row":500,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-31"},"document_id":"77F68D30","chunk_id":"cct9s4x1m0a0t","chunk_label":"unnamed-chunk-35"},{"row":506,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-32"},"document_id":"77F68D30","chunk_id":"cozvs9s6hxsfi","chunk_label":"unnamed-chunk-36"},{"row":516,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-34"},"document_id":"77F68D30","chunk_id":"cwztp6gqf9w0s","chunk_label":"unnamed-chunk-37"},{"row":525,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-35"},"document_id":"77F68D30","chunk_id":"csmeeql20tusx","chunk_label":"unnamed-chunk-38"},{"row":550,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-68"},"document_id":"77F68D30","chunk_id":"cqa1e485jcrzr","chunk_label":"unnamed-chunk-39"}],"doc_write_time":1674158939,"chunk_rendered_width":661} \ No newline at end of file +{"chunk_definitions":[{"row":47,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-40"},"document_id":"77F68D30","chunk_id":"c0jrftmj331il","chunk_label":"unnamed-chunk-1"},{"row":53,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-41"},"document_id":"77F68D30","chunk_id":"cnq8c446n0wtz","chunk_label":"unnamed-chunk-2"},{"row":67,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-42"},"document_id":"77F68D30","chunk_id":"c3qooae84c4xs","chunk_label":"unnamed-chunk-3"},{"row":87,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-43"},"document_id":"77F68D30","chunk_id":"c8k36ylh3ik2z","chunk_label":"unnamed-chunk-4"},{"row":93,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-44"},"document_id":"77F68D30","chunk_id":"cff5zae4b4ix2","chunk_label":"unnamed-chunk-5"},{"row":107,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-45"},"document_id":"77F68D30","chunk_id":"cuj4f1k7oy0f9","chunk_label":"unnamed-chunk-6"},{"row":113,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-25"},"document_id":"77F68D30","chunk_id":"c3b4hkzi6i1gq","chunk_label":"unnamed-chunk-7"},{"row":129,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-47"},"document_id":"77F68D30","chunk_id":"cryc9nwjktom8","chunk_label":"unnamed-chunk-8"},{"row":134,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-48"},"document_id":"77F68D30","chunk_id":"c11kjcel8rada","chunk_label":"unnamed-chunk-9"},{"row":144,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-52"},"document_id":"77F68D30","chunk_id":"cu5f4f0k460vm","chunk_label":"unnamed-chunk-10"},{"row":151,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-50"},"document_id":"77F68D30","chunk_id":"cr9sbhfkl0l7m","chunk_label":"unnamed-chunk-11"},{"row":155,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-51"},"document_id":"77F68D30","chunk_id":"c67fek8fh1vdj","chunk_label":"unnamed-chunk-12"},{"row":159,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-52"},"document_id":"77F68D30","chunk_id":"c0qzt99s3uz17","chunk_label":"unnamed-chunk-13"},{"row":175,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-53"},"document_id":"77F68D30","chunk_id":"cf9t8qccs9es8","chunk_label":"unnamed-chunk-14"},{"row":203,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-57"},"document_id":"77F68D30","chunk_id":"cy1yzqk9v6smc","chunk_label":"unnamed-chunk-18"},{"row":237,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-59"},"document_id":"77F68D30","chunk_id":"c85mkxl3u2xgh","chunk_label":"unnamed-chunk-20"},{"row":231,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-58"},"document_id":"77F68D30","chunk_id":"c2fn3g4qdmzyy","chunk_label":"unnamed-chunk-19"},{"row":279,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-60"},"document_id":"77F68D30","chunk_id":"c2jly3c97ig8i","chunk_label":"unnamed-chunk-21"},{"row":299,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-61"},"document_id":"77F68D30","chunk_id":"cefh5ihzkcqbl","chunk_label":"unnamed-chunk-22"},{"row":308,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-62"},"document_id":"77F68D30","chunk_id":"cilpuhvqdmpej","chunk_label":"unnamed-chunk-23"},{"row":356,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-20"},"document_id":"77F68D30","chunk_id":"c1tfzdz2b80hy","chunk_label":"unnamed-chunk-26"},{"row":347,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-64"},"document_id":"77F68D30","chunk_id":"c63m2qhze3u2y","chunk_label":"unnamed-chunk-25"},{"row":331,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-63"},"document_id":"77F68D30","chunk_id":"czxt33feq8xzf","chunk_label":"unnamed-chunk-24"},{"row":363,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-61"},"document_id":"77F68D30","chunk_id":"c211ibf7ouri8","chunk_label":"unnamed-chunk-27"},{"row":195,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-56"},"document_id":"77F68D30","chunk_id":"cuafhnftbidp9","chunk_label":"unnamed-chunk-17"},{"row":190,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-55"},"document_id":"77F68D30","chunk_id":"cra8e128kr9o9","chunk_label":"unnamed-chunk-16"},{"row":183,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-54"},"document_id":"77F68D30","chunk_id":"c9ajju6cf9cv8","chunk_label":"unnamed-chunk-15"},{"row":393,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-2"},"document_id":"77F68D30","chunk_id":"cwqxet0zexx43","chunk_label":"unnamed-chunk-28"},{"row":406,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-4"},"document_id":"77F68D30","chunk_id":"cp6949hwjcirq","chunk_label":"unnamed-chunk-29"},{"row":423,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-23"},"document_id":"77F68D30","chunk_id":"c52kj3limvhya","chunk_label":"unnamed-chunk-30"},{"row":433,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-26"},"document_id":"77F68D30","chunk_id":"c4d2y4qjjl0e3","chunk_label":"unnamed-chunk-31"},{"row":446,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-28"},"document_id":"77F68D30","chunk_id":"cfk35uawz2hsn","chunk_label":"unnamed-chunk-32"},{"row":462,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-29"},"document_id":"77F68D30","chunk_id":"czw0rd1u0m33e","chunk_label":"unnamed-chunk-33"},{"row":480,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-30"},"document_id":"77F68D30","chunk_id":"cowzykbnv5xxz","chunk_label":"unnamed-chunk-34"},{"row":500,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-31"},"document_id":"77F68D30","chunk_id":"cct9s4x1m0a0t","chunk_label":"unnamed-chunk-35"},{"row":506,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-32"},"document_id":"77F68D30","chunk_id":"cozvs9s6hxsfi","chunk_label":"unnamed-chunk-36"},{"row":516,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-34"},"document_id":"77F68D30","chunk_id":"cwztp6gqf9w0s","chunk_label":"unnamed-chunk-37"},{"row":525,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-35"},"document_id":"77F68D30","chunk_id":"csmeeql20tusx","chunk_label":"unnamed-chunk-38"},{"row":550,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-68"},"document_id":"77F68D30","chunk_id":"cqa1e485jcrzr","chunk_label":"unnamed-chunk-39"},{"row":565,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"label":"unnamed-chunk-76"},"document_id":"77F68D30","chunk_id":"c6t5kj9r0xqzx","chunk_label":"unnamed-chunk-40"},{"row":591,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","message":false,"label":"unnamed-chunk-94"},"document_id":"77F68D30","chunk_id":"cgq5kq1n6i5pg","chunk_label":"unnamed-chunk-41"},{"row":600,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-83"},"document_id":"77F68D30","chunk_id":"cuugb0843jsqr","chunk_label":"unnamed-chunk-42"},{"row":604,"row_count":1,"visible":true,"expansion_state":0,"options":{"engine":"r","label":"unnamed-chunk-95"},"document_id":"77F68D30","chunk_id":"cnh2brq8uipgl","chunk_label":"unnamed-chunk-43"}],"doc_write_time":1674186864,"chunk_rendered_width":661} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cnh2brq8uipgl/00000f.csv b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cnh2brq8uipgl/00000f.csv new file mode 100644 index 0000000..9eddef6 --- /dev/null +++ b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cnh2brq8uipgl/00000f.csv @@ -0,0 +1,6 @@ +"0","xseq <- seq(from=130,to=190, len=50)" +"0","muF <- " +"0"," link(m_adults2, data=list(S=rep(1,50),H=xseq,Hbar=mean(d$height)))" +"2","Error in h(simpleError(msg, call)) : + error in evaluating the argument 'fit' in selecting a method for function 'link': object 'm_adults2' not found +" diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cnh2brq8uipgl/000010.error b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cnh2brq8uipgl/000010.error new file mode 100644 index 0000000..bee1728 --- /dev/null +++ b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cnh2brq8uipgl/000010.error @@ -0,0 +1 @@ +{"frames":[{"func":"link(m_adults2, data = list(S = rep(1, 50), H = xseq, Hbar = mean(d$height)))","file":"","line_number":0,"end_line_number":0,"character_number":0,"end_character_number":0},{"func":".handleSimpleError(function (cond) \n.Internal(C_tryCatchHelper(addr, 1L, cond)), \"object 'm_adults2' not found\", \n base::quote(link(m_adults2, data = list(S = rep(1, 50), H = xseq, \n Hbar = mean(d$height)))))","file":"","line_number":0,"end_line_number":0,"character_number":0,"end_character_number":0},{"func":"h(simpleError(msg, call))","file":"","line_number":0,"end_line_number":0,"character_number":0,"end_character_number":0}],"message":"Error in h(simpleError(msg, call)) : \n error in evaluating the argument 'fit' in selecting a method for function 'link': object 'm_adults2' not found\n"} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cuugb0843jsqr/00001f.csv b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cuugb0843jsqr/00001f.csv new file mode 100644 index 0000000..8510ab8 --- /dev/null +++ b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cuugb0843jsqr/00001f.csv @@ -0,0 +1,3 @@ +"0","post <- extract.samples(m_SHW)" +"0","dens(post$b[,1],xlim=c(.3, .9),ylim=c(0,8)," +"0"," lwd=3,col=2,xlab=""posterior mean weight(kg"")" diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cuugb0843jsqr/000021.csv b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cuugb0843jsqr/000021.csv new file mode 100644 index 0000000..26bdb3c --- /dev/null +++ b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cuugb0843jsqr/000021.csv @@ -0,0 +1 @@ +"0","dens(post$b[,2],lwd=3,col=4,add=TRUE)" diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cuugb0843jsqr/000022.metadata b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cuugb0843jsqr/000022.metadata new file mode 100644 index 0000000..6399179 --- /dev/null +++ b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cuugb0843jsqr/000022.metadata @@ -0,0 +1 @@ +{"height":408.5290482076638,"width":661.0,"size_behavior":0,"conditions":[]} \ No newline at end of file diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cuugb0843jsqr/000022.png b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cuugb0843jsqr/000022.png new file mode 100644 index 0000000..571f620 Binary files /dev/null and b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cuugb0843jsqr/000022.png differ diff --git a/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cuugb0843jsqr/000022.snapshot b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cuugb0843jsqr/000022.snapshot new file mode 100644 index 0000000..5c15f70 Binary files /dev/null and b/.Rproj.user/shared/notebooks/39C21CC9-Statistical Thinking 2023_v2/1/s/cuugb0843jsqr/000022.snapshot differ diff --git a/Articles/Quadractic Approximation (1988).pdf b/Articles/Quadractic Approximation (1988).pdf new file mode 100644 index 0000000..a3dfa5e Binary files /dev/null and b/Articles/Quadractic Approximation (1988).pdf differ diff --git a/Statistical Thinking 2023_v2.qmd b/Statistical Thinking 2023_v2.qmd index 70a56f8..e67ef4b 100644 --- a/Statistical Thinking 2023_v2.qmd +++ b/Statistical Thinking 2023_v2.qmd @@ -549,3 +549,57 @@ ggplot(df, aes(x=W_contrast,fill=W_flag))+ geom_density()+ theme_bw() ``` + +Now, what is the direct effect of sex over weight? + +```{r, message=FALSE} +S <- rbern(100)+1 +dat <- sim_HW(S, b=c(.5,.5), a=c(0,10)) + +# Indirect effect (b) is the same for men and women +dat |> + ggplot(aes(x=H, y=W, color=factor(S)))+ + geom_point()+ + geom_smooth(method = lm)+ + # facet_wrap(~S)+ + theme_bw() +``` + +```{r, message=FALSE} +dat <- list( + W = d$weight, + H = d$height, + Hbar = mean(d$height), + S = d$male+1 ) + +m_SHW <- quap( + alist( + W ~ dnorm(mu,sigma), + mu <- a[S]+b[S]*(H-Hbar), + a[S] ~ dnorm(60,10), + b[S] ~ dunif(0,1), + sigma ~ dunif(0,10) + ), data=dat +) +data.frame(dat) |> + ggplot(aes(x=H, y=W, color=factor(S)))+ + geom_point()+ + geom_smooth(method = lm)+ + # facet_wrap(~S)+ + theme_bw() + +precis(m_SHW,depth=2) +``` + +Note that regression line's slopes are almost the same for both male and female. + +```{r} +post <- extract.samples(m_SHW) +dens(post$b[,1],xlim=c(.3, .9),ylim=c(0,8), + lwd=3,col=2,xlab="posterior mean weight(kg)") +dens(post$b[,2],lwd=3,col=4,add=TRUE) +``` + +```{r} + +```