This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
# 1. Load necessary library
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
# 2. Load the dataset (Use the English variable version)
# Ensure 'law_data2.csv' is in your working directory
df_law <- read.csv("law_data/law_data2.csv")
# 3. Data Preprocessing
# We rename the specific 'q_' columns to meaningful English names based on the analysis.
# Mapping:
# - q_122 : Trial Experience (재판 관련 경험 여부)
# - q_184 : Gender (성별)
# - q_185 : Age Group (연령별)
# - q_188 : Monthly Income (월 평균가구소득별)
# - q_83 ~ q_87 : Trust in Judicial System (Questions 82-86 in original)
df_analysis <- df_law %>%
mutate(
# (1) Create Trial Experience Dummy Variable
# Assuming: 1 = Experience (Yes), 2 = No Experience (No)
# Result: 1 = Yes, 0 = No
Trial_Exp = ifelse(q_122 == 1, 1, 0),
# (2) Create Average Trust Score (using q_83 to q_87)
# These represent: Speed, Fairness, Bail Equality, Detention Equality, Wrongful Punishment
Trust_System_Avg = rowMeans(select(., q_83, q_84, q_85, q_86, q_87), na.rm = TRUE),
# (3) Rename demographic variables for clarity
Gender = q_184,
Age = q_185,
Income = q_188
)
# 4. Run Regression Analysis
# Hypothesis: Does Trial Experience affect Trust in the Judicial System?
model <- lm(Trust_System_Avg ~ Trial_Exp + Gender + Age + Income, data = df_analysis)
# 5. Print the Result
summary(model)
##
## Call:
## lm(formula = Trust_System_Avg ~ Trial_Exp + Gender + Age + Income,
## data = df_analysis)
##
## Residuals:
## Min 1Q Median 3Q Max
## -1.6862 -0.3072 -0.0491 0.3370 1.3844
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 2.531249 0.053425 47.379 <2e-16 ***
## Trial_Exp -0.061104 0.031203 -1.958 0.0503 .
## Gender 0.017000 0.018576 0.915 0.3602
## Age 0.021015 0.007515 2.796 0.0052 **
## Income 0.011571 0.006153 1.881 0.0601 .
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 0.5239 on 3395 degrees of freedom
## Multiple R-squared: 0.003892, Adjusted R-squared: 0.002718
## F-statistic: 3.316 on 4 and 3395 DF, p-value: 0.01015
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.