-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscore_confint.R
49 lines (42 loc) · 1.53 KB
/
score_confint.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Uncomment and run if not already installed.
#install.packages('jsonlite', dependencies=TRUE, repos='http://cran.rstudio.com/')
#install.packages('RPostgreSQL')
#install.packages('RPostgres')
#install.packages('DBI')
#install.packages('dotenv')
#install.packages('ciTools')
#install.packages('ggplot2')
library(RPostgreSQL)
library(RPostgres)
library(DBI)
library(dotenv)
library(ciTools)
library(ggplot2)
library(ggfortify)
# Connect to database
#getwd() # to check working directory
setwd("~/Desktop/eit/dansende-fugl") # set to your project path
load_dot_env(file = ".env")
db <- Sys.getenv("POSTGRES_DB")
host_db <- Sys.getenv("HOST")
db_user <- Sys.getenv("DB_USER")
db_password <- Sys.getenv("DB_PASSWORD")
con <- dbConnect(RPostgres::Postgres(), dbname = db, host=host_db, user=db_user, password=db_password)
# Load data
db <- dbGetQuery(con, "SELECT mbti, score, word_count_quoteless FROM unique_no_comments")
################ SCORE ###########################
score.lm <- lm(score ~ mbti, data=db)
summary(score.lm)
d = data.frame("mbti"= unique(db$mbti))
d$fit = (predict(score.lm, newdata=d,se.fit = T))$fit
d$se.fit = (predict(score.lm, newdata=d,se.fit = T))$se.fit
d$lci = d$fit-1.96*d$se.fit
d$uci = d$fit+1.96*d$se.fit
ggplot(d,aes(y=fit,x=mbti,ymin=lci,ymax=uci,label=round(fit,digits=2)))+
geom_point()+
geom_errorbar()+
ylab("Gjennomsnittlig score")+
xlab("MBTI personlighetstype")+
geom_text(hjust=1.2,size=4)+
theme(axis.text = element_text(size = 12), axis.title=element_text(size = 14))+
coord_cartesian(clip='off')