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:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
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.
df = read.csv("D:\\TAM DAN NON-ORTHO\\06. Non ortho_OCCLUSION\\06.1 Non ortho_IOTN\\06.1 Non ortho_IOTN.csv")
library("lessR")
## Warning: package 'lessR' was built under R version 4.5.2
##
## lessR 4.5 feedback: gerbing@pdx.edu
## --------------------------------------------------------------
## > d <- Read("") Read data file, many formats available, e.g., Excel
## d is the default data frame, data= in analysis routines optional
##
## Many examples of reading, writing, and manipulating data, graphics,
## testing means and proportions, regression, factor analysis,
## customization, forecasting, and aggregation to pivot tables.
## Enter: browseVignettes("lessR")
##
## View lessR updates, now including modern time series forecasting
## and many, new Plotly interactive visualizations output. Most
## visualization functions are now reorganized to three functions:
## Chart(): type="bar", "pie", "radar", "bubble", "treemap", "icicle"
## X(): type="histogram", "density", "vbs" and more
## XY(): type="scatter" for a scatterplot, or "contour", "smooth"
## Most previous function calls still work, such as:
## BarChart(), Histogram, and Plot().
## Enter: news(package="lessR"), or ?Chart, ?X, or ?XY
## There is also Flows() for Sankey flow diagrams, see ?Flows
##
## Interactive data analysis for constructing visualizations.
## Enter: interact()
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:lessR':
##
## order_by, recode, rename
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(labelled)
## Warning: package 'labelled' was built under R version 4.5.3
# 1. MÃ HÓA VÀ GHI ĐÈ TRỰC TIẾP LÊN BIẾN GỐC
df <- df %>%
mutate(
# --- GENDER ---
Gender = factor(Gender, levels = c(0, 1), labels = c("Male", "Female")),
# --- CÁC BIẾN ĐO LƯỜNG ĐƠN LẺ ---
abQ8_Overjet = factor(abQ8_Overjet, levels = c(0, 1, 2, 3, 4),
labels = c("Overjet <0", "Overjet =0", "Overjet 0.5 - 2.5", "Overjet 3.0 - 4.0", "Overjet >4.0")),
bQ9 = factor(bQ9, levels = c(0, 1), labels = c("None", "Incompetence")),
cQ10 = factor(cQ10, levels = c(0, 1, 2, 3, 4, 5),
labels = c("None", "Front", "Posterior teeth on one side", "Posterior teeth on both sides",
"Front & Posterior teeth on one side", "Front & Posterior teeth on both sides")),
cQ11_Score = factor(cQ11_Score, levels = c(0, 1, 2, 3),
labels = c("0", "<1 mm", "1 - 2 mm", "2 mm+")),
fQ15 = factor(fQ15, levels = c(0, 1, 2),
labels = c("None", "Impinging, no periodontal", "Impinging, periodontal lesion")),
hQ16 = factor(hQ16, levels = c(0, 1, 2),
labels = c("none", "1 tooth per", ">1 tooth per")),
sQ21 = factor(sQ21, levels = c(0, 1), labels = c("None", "Have tooth....")),
# --- NHÓM KHOẢNG CÁCH (CROWDING, SPACING, OPEN BITE) ---
# Cả 3 biến này dùng chung thang đo từ 0 đến 4
across(
c(dQ12_CrowScore, dQ12_SpacScore, eQ13_Score),
~ factor(., levels = c(0, 1, 2, 3, 4),
labels = c("=0", "<1 mm", "1 - 2 mm", ">2 - 4 mm", ">4 mm"))
),
# --- NHÓM YES/NO (0 = None, 1 = Yes) ---
across(
c(iQ17, jQ18, pQ20, tQ22, xQ23),
~ factor(., levels = c(0, 1), labels = c("None", "Yes"))
),
# --- NHÓM NONE/HAVE (0 = None, 1 = Have) ---
across(
c(Prema_Contact, kQ19),
~ factor(., levels = c(0, 1), labels = c("None", "Have"))
)
)
# 2. GẮN NHÃN MÔ TẢ (LABELS) CHO CÁC BIẾN
df <- df %>%
set_variable_labels(
Gender = "Gender",
abQ8_Overjet = "Overjet",
bQ9 = "Lips incompetence",
cQ10 = "Lingual posterior crossbite",
cQ11_Score = "RCP - ICP",
dQ12_CrowScore = "Crowding",
dQ12_SpacScore = "Spacing",
eQ13_Score = "Open bite",
fQ15 = "Impinging",
hQ16 = "Missing teeth",
iQ17 = "Impeded eruption (except 3rd molars)",
jQ18 = "Buccal posterior crossbite",
Prema_Contact = "Premature contact",
kQ19 = "Dysfunction",
pQ20 = "Cleft lip & palate",
sQ21 = "Deciduous teeth",
tQ22 = "Partially erupted",
xQ23 = "Supplemental tooth"
)