library(ggplot2)
library(pander)
library(kableExtra)
library(CodebookGenerator)
library(DT)
codebookDF <- gss

Data Frame Summary

kable(CodebookGenerator::summarizeDataFrame(codebookDF), digits=1) %>%
kable_styling(bootstrap_options = c("striped", "hover","condensed"),full_width = F)

Variable Summary

datatable(CodebookGenerator::summarizeVariables(codebookDF), escape=F, rownames=F, fillContainer=F, style="bootstrap")

year

Categorical
wzxhzdk:4
wzxhzdk:5
wzxhzdk:6

id

Identifier
wzxhzdk:7
wzxhzdk:8
wzxhzdk:9

age

age of respondent

Unclassified

tab <- variableOverview(codebookDF[["age"]])
 kable(tab, digits=1) %>%
  kable_styling(bootstrap_options = c("striped", "hover","condensed")) 

tab <- summarizeVariable(codebookDF[["age"]], "Unclassified")
 kable(tab, digits=1) %>%
  kable_styling(bootstrap_options = c("striped", "hover","condensed"))

var <- codebookDF[['age']]
bw=(max(var, na.rm=T)-min(var, na.rm=T))/30
m <- mean(var, na.rm=T)
sd <- sd(var, na.rm=T)
n <- length(!is.na(var))


                  class(codebookDF[['age']]) <- NULL
                  ggplot(data=codebookDF)+
                   geom_histogram(aes(age),color='black',bins=30)+
                   theme_minimal()+
                         stat_function(fun = function(x, mean, sd, n, bw){
                   dnorm(x = x, mean = mean, sd = sd) * bw * n},
                   args = c(mean = m, sd = sd, n = n, bw = bw), color='red')


race

race of respondent

Categorical

tab <- variableOverview(codebookDF[["race"]])
 kable(tab, digits=1) %>%
  kable_styling(bootstrap_options = c("striped", "hover","condensed")) 

tab <- summarizeVariable(codebookDF[["race"]], "Categorical")
 kable(tab, digits=1) %>%
  kable_styling(bootstrap_options = c("striped", "hover","condensed"))

codebookDF['race_new']<-factor(codebookDF[['race']])

                  ggplot(data=codebookDF)+
                   geom_bar(aes(race_new))+
                   theme_minimal()


generation

Categorical
wzxhzdk:16
wzxhzdk:17
wzxhzdk:18

hrs1

number of hours worked last week

Unclassified

tab <- variableOverview(codebookDF[["hrs1"]])
 kable(tab, digits=1) %>%
  kable_styling(bootstrap_options = c("striped", "hover","condensed")) 

tab <- summarizeVariable(codebookDF[["hrs1"]], "Unclassified")
 kable(tab, digits=1) %>%
  kable_styling(bootstrap_options = c("striped", "hover","condensed"))

var <- codebookDF[['hrs1']]
bw=(max(var, na.rm=T)-min(var, na.rm=T))/30
m <- mean(var, na.rm=T)
sd <- sd(var, na.rm=T)
n <- length(!is.na(var))


                  class(codebookDF[['hrs1']]) <- NULL
                  ggplot(data=codebookDF)+
                   geom_histogram(aes(hrs1),color='black',bins=30)+
                   theme_minimal()+
                         stat_function(fun = function(x, mean, sd, n, bw){
                   dnorm(x = x, mean = mean, sd = sd) * bw * n},
                   args = c(mean = m, sd = sd, n = n, bw = bw), color='red')


divorce

ever been divorced or separated

Categorical

tab <- variableOverview(codebookDF[["divorce"]])
 kable(tab, digits=1) %>%
  kable_styling(bootstrap_options = c("striped", "hover","condensed")) 

tab <- summarizeVariable(codebookDF[["divorce"]], "Categorical")
 kable(tab, digits=1) %>%
  kable_styling(bootstrap_options = c("striped", "hover","condensed"))

codebookDF['divorce_new']<-factor(codebookDF[['divorce']])

                  ggplot(data=codebookDF)+
                   geom_bar(aes(divorce_new))+
                   theme_minimal()


martype

marital type

Categorical

tab <- variableOverview(codebookDF[["martype"]])
 kable(tab, digits=1) %>%
  kable_styling(bootstrap_options = c("striped", "hover","condensed")) 

tab <- summarizeVariable(codebookDF[["martype"]], "Categorical")
 kable(tab, digits=1) %>%
  kable_styling(bootstrap_options = c("striped", "hover","condensed"))

codebookDF['martype_new']<-factor(codebookDF[['martype']])

                  ggplot(data=codebookDF)+
                   geom_bar(aes(martype_new))+
                   theme_minimal()


marital

marital status

Categorical

tab <- variableOverview(codebookDF[["marital"]])
 kable(tab, digits=1) %>%
  kable_styling(bootstrap_options = c("striped", "hover","condensed")) 

tab <- summarizeVariable(codebookDF[["marital"]], "Categorical")
 kable(tab, digits=1) %>%
  kable_styling(bootstrap_options = c("striped", "hover","condensed"))

codebookDF['marital_new']<-factor(codebookDF[['marital']])

                  ggplot(data=codebookDF)+
                   geom_bar(aes(marital_new))+
                   theme_minimal()




MartinLBarron/CodebookGenerator documentation built on May 25, 2019, 12:23 p.m.