오늘 내용은 최신 로컬 모델인 젬마 4 26B A4B와 Qwen 3.6 35B A3B의 연구 보조 R 코딩에 대한 짧은 소감입니다. 구체적인 벤치보다는 실제 연구 환경에서 겪을 수 있는 내용에 대해 적었습니다. 그런 만큼 그냥 참고로 봐주시면 감사하겠습니다. 다른 언어, 다른 조건에서 얼마든 다른 결과 나올 수 있습니다. Qwen을 어떻게 발음하는지 잘 몰라서 쿠엔 혹은 쿠원늘 내용은 최신 로컬 모델인 젬마 4 26B A4B와 Qwen 3.6 35B A3B의 연구 보조 R 코딩에 대한 짧은 소감입니다.
구체적인 벤치보다는 실제 연구 환경에서 겪을 수 있는 내용에 대해 적었습니다. 그런 만큼 그냥 참고로 봐주시면 감사하겠습니다. 다른 언어, 다른 조건에서 얼마든 다른 결과 나올 수 있습니다. Qwen을 어떻게 발음하는지 잘 몰라서 쿠엔 혹은 쿠원 식으로 말했는데, 정확하지 않을 수 있다는 점 (중국어 모름)도 말씀드립니다.
혹시 필요하신 분 위해 코드도 공개합니다.
1. 테이블 한 개 코드 (젬마 4 작성)
library(ggplot2)
library(gridExtra)
library(patchwork)
# [데이터 준비]
df_t2 <- data.frame(
Status = factor(c("Never", "Never", "Former", "Former", "Current", "Current"),
levels = c("Never", "Former", "Current")),
Model = rep(c("Unadjusted", "Adjusted"), times = 3),
HR = c(1.00, 1.00, 1.04, 1.08, 1.22, 1.24),
Lower = c(1.00, 1.00, 0.97, 1.01, 1.15, 1.16),
Upper = c(1.00, 1.00, 1.11, 1.15, 1.30, 1.32)
)
# [하단 테이블용 데이터: HR (95% CI) 형식]
table_t2 <- data.frame(
Status = c("Never", "Former", "Current"),
Unadjusted = c("1.00 (Ref)", "1.04 (0.97-1.11)", "1.22 (1.15-1.30)"),
Adjusted = c("1.00 (Ref)", "1.08 (1.01-1.15)", "1.24 (1.16-1.32)")
)
# [상단 그래프 생성]
p1 <- ggplot(df_t2, aes(x = Status, y = HR, fill = Model)) +
geom_bar(stat = "identity", position = position_dodge(width = 0.8), color = "black", width = 0.7) +
geom_errorbar(aes(ymin = Lower, ymax = Upper), position = position_dodge(width = 0.8), width = 0.25) +
geom_hline(yintercept = 1.0, linetype = "dashed", color = "black") + # 기준선 검은색
scale_fill_manual(values = c("gray85", "gray45")) +
theme_classic() +
labs(title = "Hazard Ratio by Smoking Status", y = "Hazard Ratio (9int 95% CI)", x = "") +
coord_cartesian(ylim = c(0.8, 1.5)) +
theme(plot.title = element_text(hjust = 0.5, face = "bold"), legend.position = "top")
# [하단 테이블 생성]
tt <- ttheme_default(core = list(fg_params = list(cex = 0.8)),
colhead = list(fg_params = list(fontface = "bold")))
p2 <- tableGrob(table_t2, rows = NULL, theme = tt)
# [결합]
final_plot_T2 <- p1 / p2 + plot_layout(heights = c(3, 1))
print(final_plot_T2)
2. Qwen 작성 코드 (테이블 3개 한 번에)
library(ggplot2)
library(ggpubr) # Assuming you are using ggarrange
# --- 1. DATA PREPARATION ---
# Table 2 Data: Smoking Status
t2_data <- data.frame(
Level = c("Never", "Former", "Current"),
Model = c(rep("Unadjusted", 3), rep("Adjusted", 3)),
HR = c(1.00, 1.04, 1.22, 1.00, 1.08, 1.24),
L = c(NA, 0.97, 1.15, NA, 1.01, 1.16),
U = c(NA, 1.11, 1.30, NA, 1.15, 1.32)
)
t2_data$Level <- factor(t2_data$Level, levels = c("Never", "Former", "Current"))
# *** CHANGE 1: Convert Model to factor to control bar order ***
t2_data$Model <- factor(t2_data$Model, levels = c("Unadjusted", "Adjusted"))
# Table 3 Data: Current Smoker (Pack-Year)
t3_data <- data.frame(
Level = c("Never", "< 10", "10 - < 20", ">= 20"),
Model = c(rep("Unadjusted", 4), rep("Adjusted", 4)),
HR = c(1.00, 1.22, 1.23, 1.24, 1.00, 1.18, 1.27, 1.38),
L = c(NA, 1.14, 1.14, 1.14, NA, 1.10, 1.18, 1.25),
U = c(NA, 1.31, 1.32, 1.36, NA, 1.27, 1.37, 1.52)
)
t3_data$Level <- factor(t3_data$Level, levels = c("Never", "< 10", "10 - < 20", ">= 20"))
# *** CHANGE 2: Convert Model to factor ***
t3_data$Model <- factor(t3_data$Model, levels = c("Unadjusted", "Adjusted"))
# Table 4 Data: Urinary Cotinine
t4_data <- data.frame(
Level = c("< 50", "Tertile 1", "Tertile 2", "Tertile 3"),
Model = c(rep("Unadjusted", 4), rep("Adjusted", 4)),
HR = c(1.00, 1.10, 1.18, 1.10, 1.00, 1.09, 1.17, 1.10),
L = c(NA, 1.03, 1.11, 1.03, NA, 1.02, 1.09, 1.00),
U = c(NA, 1.18, 1.26, 1.18, NA, 1.17, 1.25, 1.15)
)
t4_data$Level <- factor(t4_data$Level, levels = c("< 50", "Tertile 1", "Tertile 2", "Tertile 3"))
# *** CHANGE 3: Convert Model to factor ***
t4_data$Model <- factor(t4_data$Model, levels = c("Unadjusted", "Adjusted"))
# --- 2. PLOTTING FUNCTION ---
create_hr_plot <- function(data, title) {
ggplot(data, aes(x = Level, y = HR, fill = Model)) +
# Draw bars with uniform width
geom_col(position = position_dodge(width = 0.9), width = 0.45, color = "black") +
# Draw error bars (Confidence Intervals)
geom_errorbar(aes(ymin = L, ymax = U),
position = position_dodge(width = 0.9),
width = 0.2, size = 0.5) +
# Reference line at HR = 1
geom_hline(yintercept = 1, linetype = "dashed", color = "grey50") +
# Set specific colors (Light Grey and Dark Grey)
# Note: The names map to the factor levels, so colors stay correct
scale_fill_manual(values = c("Unadjusted" = "#BEBEBE", "Adjusted" = "#595959"),
name = "Model") +
# Use coord_cartesian to set limits without clipping data
coord_cartesian(ylim = c(0.8, 1.6)) +
# Set Y-axis ticks
scale_y_continuous(breaks = seq(0.8, 1.6, 0.2)) +
labs(title = title, x = NULL, y = "Hazard Ratio (95% CI)") +
theme_minimal() +
theme(
plot.title = element_text(hjust = 0.5, face = "bold", size = 12),
axis.text.x = element_text(angle = 0, hjust = 0.5),
axis.title.y = element_text(size = 10),
axis.text.y = element_text(size = 10),
legend.position = "top",
legend.justification = "center",
legend.box = "horizontal",
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank()
)
}
# --- 3. GENERATE AND ARRANGE PLOTS ---
p1 <- create_hr_plot(t2_data, "A. Smoking Status")
p2 <- create_hr_plot(t3_data, "B. Smoking Amount (Pack-Year)")
p3 <- create_hr_plot(t4_data, "C. Urinary Cotinine Levels")
# Arrange horizontally side-by-side
ggarrange(p1, p2, p3, nrow = 1, labels = c("A", "B", "C"), label_x = 0, label_y = 1.1)
댓글
댓글 쓰기