R Markdown

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

Including Plots

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.csv2("D:\\TAM DAN NON-ORTHO\\02. Non ortho_SLEEP CLINICAL RECORD\\02. Non ortho_SLEEP CLINICAL RECORD.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 CÓ/KHÔNG (0 = No, 1 = Yes) GỘP CHUNG ---
    # Bao gồm nhóm Nose, Palate, Overjet và Lip/Gingivitis
    across(
      c(SL1, SL2, SL3, SL4, SL5, SL10, SL11, Lip3, Lip.4, Lip.6),
      ~ factor(., levels = c(0, 1), labels = c("No", "Yes"))
    ),
    
    # --- EXAMINATION OF THE OROPHARYNX ---
    SL6 = factor(SL6, levels = c(1, 2, 3, 4), 
                 labels = c("Tonsils cover 0-25% or are removed", "cover 26-50%", "51-75%", "cover 76-100%")),
    FrdTI = factor(FrdTI, levels = c(1, 2, 3, 4), 
                   labels = c("Entire uvula & tonsils are visible (F1)", 
                              "Entire uvula but tonsils are not visible (F2)", 
                              "Soft palate is visible but uvula is not visible (F3)", 
                              "Only hard palate is visible (F4)")),
    SL7 = factor(SL7, levels = c(1, 2, 3, 4), 
                 labels = c("Complete view of uvula and tonsils, or anterior and posterior uvula pillars", 
                            "Complete view of uvula and palate view of pillars", 
                            "Partial view of soft palate, but not of distal part", 
                            "View only of hard palate")),
    FMaI = factor(FMaI, levels = c(1, 2, 3, 4), 
                  labels = c("Entire uvula & pillars/tonsils is visible (M1)", 
                             "Uvula visible, bit NOT the pillars. Tonsils (M2)", 
                             "Base of uvula and soft palate visible (M3)", 
                             "No uvula visible. Only hard palate is visible. (M4)")),
    
    # --- DENTAL EXAMINATION ---
    SL8 = factor(SL8, levels = c(1, 2, 3), 
                 labels = c("Angle I", "Angle II", "Angle III")),
    SL9 = factor(SL9, levels = c(0, 1, 2, 3), 
                 labels = c("normal", "Openbite", "Deepbite", "Crossbite")),
    
    # --- FACE SHAPE ASSESSMENT ---
    SL12.H = factor(SL12.H, levels = c(1, 2, 3, 4, 5, 6), 
                    labels = c("face 1", "face 2", "face 3", "face 4", "face 5", "face 6")),
    SL12.V = factor(SL12.V, levels = c(1, 2, 3), 
                    labels = c("Increased third of the face: inferior", "Normal", "Increased third of the face: Superior")),
    FA1 = factor(FA1, levels = c(1, 2, 3, 4), 
                 labels = c("pic 1 (closed)", "pic 2 (Half-open)", "pic 3 (open lips)", "pic 4 (open lips)")),
    FA2 = factor(FA2, levels = c(1, 2, 3, 4), 
                 labels = c("The lips are completely closed at rest without effort. No chin lines/grooves", 
                            "The lips do not close completely when resting, but they close easily without a line/groove on the chin", 
                            "Mouth open when resting. When the lips are closed, a slight line/groove appears on the chin", 
                            "Mouth open when resting. When the lips are closed, deep lines/grooves appear on the chin")),
    Faextra = factor(Faextra, levels = c(1, 2, 3, 4), 
                     labels = c("The entire tongue is pressed along the palate.", 
                                "The tip of the tongue often rests/touches the palate", 
                                "The tongue is usually placed between the teeth.", 
                                "The tongue is usually placed at the floor of the mouth.")),
    
    # --- LIPS & TEETH (Gộp chung đánh giá R11 và R21) ---
    # Teething condition
    across(
      c(Lip5..R11, Lip5..R21),
      ~ factor(., levels = c(1, 2, 3, 4, 5), 
               labels = c("Straight", "Outwardly misaligned", "Inwardly misaligned", "Tilted close", "Tilted far"))
    ),
    # Gingival index
    across(
      c(Lip7..R11, Lip7..R21),
      ~ factor(., levels = c(0, 1, 2, 3), 
               labels = c("Normal", "Mild", "Medium", "Heavy"))
    )
  )

# 2. GẮN NHÃN MÔ TẢ (LABELS) CHO CÁC BIẾN
df <- df %>%
  set_variable_labels(
    Gender = "Gender",
    SL1 = "Septum nose devation",
    SL2 = "Nasal cartilage hypotonia",
    SL3 = "Orbicular muscle hypotonia",
    SL4 = "Nasal passage ventilation",
    SL5 = "Frequent nasal congestion",
    
    SL6 = "Amygdale Brodsky dimensions",
    FrdTI = "Amygdale Freidman Dimensions",
    SL7 = "Tongue position according to Friedman_FTP",
    FMaI = "Tongue position according to Mallampati",
    
    SL8 = "Classification of bite according to Angle (face shape)",
    SL9 = "Anterior occlusion",
    SL10 = "Abnormal overjet",
    SL11 = "Narrow palate",
    
    SL12.S = "Score",
    SL12.H = "Horizontal dimension",
    SL12.V = "Vertical dimension",
    
    FA1 = "Image of incisors: SMILE LIGHTLY. Estimate the height of the upper central incisors.",
    FA2 = "Chin area: Mouth relax, and note the expression on the chin...",
    Faextra = "Tongue resting position",
    
    Lip3 = "Retraction of the labial frenum causes gum recession",
    Lip.4 = "Radiolucent V-shape image between R11,21",
    Lip5..R11 = "Teething condition R11",
    Lip5..R21 = "Teething condition R21",
    Lip.6 = "Gingivitis",
    Lip7..R11 = "Gingival index R11",
    Lip7..R21 = "Gingival index R21"
  )