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\\03. ENG_LINGUAL FRENULUM PROTOCOL\\03. Non Ortho_MARTINELLI.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")),
    
    # --- LIP POSTURE ---
    Lrest = factor(Lrest, levels = c(0, 1, 2), 
                   labels = c("close", "Half-open", "Open")),
    Lrest_S = factor(Lrest_S, levels = c(0, 1), 
                     labels = c("picture 1", "picture 2, 3")),
    
    # --- TONGUE POSITION & SHAPE ---
    TPOM = factor(TPOM, levels = c(0, 1, 2, 3), 
                  labels = c("Midline", "Elevated", "Midline with lateral elevation", "Apex of the tongue down with tongue lateral elevation")),
    TPOM_S = factor(TPOM_S, levels = c(0, 1), 
                    labels = c("pic 1 and 2", "pic 3 and 4")),
    STA = factor(STA, levels = c(0, 1, 2), 
                 labels = c("Round", "V-shaped", "Heart-shaped")),
    # Lưu ý: Các biến Score dưới đây bị khuyết số (ví dụ: 0, 2, 3 chứ không có 1), tôi đã giữ nguyên logic mức của bạn
    STA_S = factor(STA_S, levels = c(0, 2, 3), 
                   labels = c("pic 1", "pic 2", "pic 3")),
    
    # --- LINGUAL FRENULUM (Phanh lưỡi) ---
    FrenuL = factor(FrenuL, levels = c(0, 1, 2), 
                    labels = c("Visible", "Not visible", "Visible with maneuver")),
    FrenuT = factor(FrenuT, levels = c(0, 1), 
                    labels = c("Thin", "Thick")),
    FrenuT_S = factor(FrenuT_S, levels = c(0, 2), 
                      labels = c("pic 1", "pic 2")),
    FrenuAT = factor(FrenuAT, levels = c(0, 1, 2), 
                     labels = c("Midline", "Between midline and apex", "Apex")),
    FrenuAT_S = factor(FrenuAT_S, levels = c(0, 2, 3), 
                       labels = c("pic 1", "pic 2", "pic 3")),
    FrenuAF = factor(FrenuAF, levels = c(0, 1), 
                     labels = c("Visible from the sublingual caruncles", "Visible from the inferior alveolar crest")),
    FrenuAF_S = factor(FrenuAF_S, levels = c(0, 1), 
                       labels = c("pic 1", "pic 2")),
    
    # --- BIẾN TOTAL (Sử dụng case_when để phân loại theo khoảng) ---
    Total = case_when(
      Total == 0 ~ "No",
      Total >= 1 & Total <= 6 ~ "light",
      Total >= 7 & Total < 12 ~ "Movement restrictions",
      Total == 12 ~ "Heavy",
      TRUE ~ NA_character_  # Nếu có giá trị nào khác (ví dụ ô trống), trả về NA
    ),
    # Chuyển đổi Total thành dạng factor để R hiểu thứ tự các mức độ khi phân tích
    Total = factor(Total, levels = c("No", "light", "Movement restrictions", "Heavy"))
  )

# 2. GẮN NHÃN MÔ TẢ (LABELS) CHO CÁC BIẾN
df <- df %>%
  set_variable_labels(
    Gender = "Gender",
    Lrest = "Lip posture at rest",
    Lrest_S = "Score of Lip posture at rest",
    TPOM = "Tongue position during open mouth",
    TPOM_S = "Score of Tongue position during open mouth",
    STA = "Shape of the tongue apex when elevated during open mouth or elevation maneuver",
    STA_S = "Score of Shape of the tongue apex when elevated during open mouth or elevation maneuver",
    FrenuL = "Lingual Frenulum",
    FrenuT = "Frenulum thickness",
    FrenuT_S = "Score of Frenulum thickness",
    FrenuAT = "Frenulum attachment to the tongue",
    FrenuAT_S = "Score of Frenulum attachment to the tongue",
    FrenuAF = "Frenulum attachment to the floor of the mouth",
    FrenuAF_S = "Score of Frenulum attachment to the floor of the mouth",
    Total = "Total score"
  )