library(kableExtra) library(tidyverse)

ebsurvey <- read_csv(‘https://uoepsy.github.io/data/science-faith-attitude.csv’) head(ebsurvey)

##1

ebsurvey2 <- ebsurvey %>% select(kstot) ebsurvey2 <- ebsurvey2 %>% rename(science_score = kstot)

head(ebsurvey2,3)

dim(ebsurvey2)

anyNA(ebsurvey2)

ggplot(ebsurvey2, aes(x = science_score)) + geom_histogram(color = ‘white’, binwidth = 5, fill=‘steelblue’) + labs(x = ‘Age (years)’, y = ‘Frequency’)

library(kableExtra)

ebsurvey2 %>% summarise(Min = min(science_score), Median = quantile(science_score, 0.5), IQR = IQR(science_score), Mean = mean(science_score), SD = sd(science_score), Max = max(science_score)) %>% kable(digits = 2, caption = ‘Descriptive Statistics of Science Score’) %>% kable_styling(full_width = FALSE)

##misc ebsurvey0 <- ebsurvey %>% select(kstot, age, toomuchscience) ebsurvey0 <- ebsurvey0 %>% rename(science_score = kstot, attitude = toomuchscience) head(ebsurvey0,3) dim(ebsurvey0) anyNA(ebsurvey0) ebsurvey1 <- na.omit(ebsurvey0) dim(ebsurvey1)

library(plotly) library(GGally)

correlation_plot <- ggpairs(ebsurvey1, title = “Correlogram”) ggplotly(correlation_plot)

reg <- lm(attitude ~ science_score + age, data=ebsurvey1) summary(reg) par(mfrow = c(1,2)) plot(reg, which=c(1,2)) par(mfrow = c(1,1))

##2 ?? library(car)

boot_reg <- Boot(reg, R = 1000) summary(boot_reg)

Confint(boot_reg, level = 0.95, type = “perc”)

library(kableExtra) Confint(boot_reg, type = “perc”) %>% kable(digits = 3, caption = ‘Bootstrap 95% CIs’) %>% kable_styling(full_width = FALSE)

head(boot_reg$t)

boot_reg$t0

plot_data <- as_tibble(boot_reg$t) head(plot_data)

hist(boot_reg, ci = “perc”, legend = “separate”)

boot_reg %>% summarise(Min = min(‘(Intercept)’), Median = quantile(‘(Intercept)’, 0.5), IQR = IQR(‘(Intercept)’), Mean = mean(‘(Intercept)’), SD = sd(‘(Intercept)’), Max = max(‘(Intercept)’) %>% kable(digits = 2, caption = ‘Descriptive Statistics of Intercept’) %>% kable_styling(full_width = FALSE)

##3 ?? ggplot(boot_reg, aes(x = ‘(Intercept)’)) + geom_histogram(color = ‘white’, binwidth = 5, fill=‘steelblue’) + labs(x = ‘Age (years)’, y = ‘Scienece_Score’)