1. Trang chủ
  2. » Thể loại khác

Các câu lệnh trong R

35 86 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 35
Dung lượng 132 KB
File đính kèm lenh_nhap_truc_tiep.rar (25 KB)

Nội dung

1) Cài đặt - Cài đặt R: R-2.9.0-win32.exe - Cài đặt số liệu: Stata Data Installation.exe - Sau cài đặt R, khởi động R vào vào menu: Packages :: Install packages from local zip file để cài đặt thư viện Hmisc Epicalc 2) Đọc tập tin R stata.get("tên tập tin") - Đọc tập tin R gán vào số liệu tên ivf ivf zap() > use(Oswego) Error in use(Oswego) : object 'Oswego' not found > data(Oswego) > use(Oswego) > des() No of observations = 75 Variable Class Description age numeric sex AsIs timesupper numeric ill logical onsetdate AsIs onsettime numeric bakedham logical spinach logical mashedpota logical 10 cabbagesal logical 11 jello logical 12 rolls logical 13 brownbread logical 14 milk logical 15 coffee logical 16 water logical 17 cakes logical 18 vanilla logical 19 chocolate logical 20 fruitsalad logical > tableStack(vars=c(age,sex),by=ill) Error in rbind(table2, label.row, table0, blank.row) : number of columns of matrices must match (see arg 3) > tableStack(vars=c(age,sex),by="ill") Total age mean(SD) 36.8 (21.5) sex mean(SD) 36.8 (21.5) > describe(age) age n missing unique Mean 05 10 25 50 75 90 95 75 45 36.81 8.0 11.0 16.5 36.0 57.5 65.0 69.3 lowest : 10, highest: 69 70 72 74 77 > describe(sex) sex n missing unique 75 F (44, 59%), M (31, 41%) > data$sex=factor(.data$sex) > tableStack(vars=c(age,sex),by="ill") Total age mean(SD) 36.8 (21.5) sex F M 44 (58.7) 31 (41.3) > tableStack(vars=c(age,sex),by=ill) FALSE TRUE Test stat age Ranksum test median(IQR) 35 (14,50) 38.5 (17.2,58.8) sex F M P value 0.284 Chisq (1 df) = 1.46 0.226 14 (48.3) 30 (65.2) 15 (51.7) 16 (34.8) > des() No of observations = 75 Variable Class Description age numeric sex factor timesupper numeric ill logical onsetdate AsIs onsettime numeric bakedham logical spinach logical mashedpota logical 10 cabbagesal logical 11 jello logical 12 rolls logical 13 brownbread logical 14 milk logical 15 coffee logical 16 water logical 17 cakes logical 18 vanilla logical 19 chocolate logical 20 fruitsalad logical > tableStack(vars=c(bakedham,spinach,mashedpota,cabbagesal,jello,rolls ,brownbread, milk, coffee, water, cakes,vanilla,chocolate,fruitsalad),by=ill) FALSE TRUE Test stat P value bakedham Chisq (1 df) = 0.02 0.889 FALSE 12 (41.4) 17 (37) TRUE 17 (58.6) 29 (63) spinach Chisq (1 df) = FALSE 12 (41.4) 20 (43.5) TRUE 17 (58.6) 26 (56.5) 0.952 mashedpota Chisq (1 df) = 0.06 0.811 FALSE 14 (50) 23 (50) TRUE 14 (50) 23 (50) cabbagesal Chisq (1 df) = 0.03 0.873 FALSE 19 (65.5) 28 (60.9) TRUE 10 (34.5) 18 (39.1) jello Chisq (1 df) = 0.51 0.474 FALSE 22 (75.9) 30 (65.2) TRUE (24.1) 16 (34.8) rolls Chisq (1 df) = 0.32 0.571 FALSE 13 (44.8) 25 (54.3) TRUE 16 (55.2) 21 (45.7) brownbread Chisq (1 df) = 0.22 0.642 FALSE 20 (69) 28 (60.9) TRUE (31) 18 (39.1) milk Fisher's exact test 0.638 FALSE 27 (93.1) 44 (95.7) TRUE (6.9) (4.3) coffee Chisq (1 df) = 0.05 0.815 FALSE 17 (58.6) 27 (58.7) TRUE 12 (41.4) 19 (41.3) water Chisq (1 df) = 0.38 0.535 FALSE 18 (62.1) 33 (71.7) TRUE 11 (37.9) 13 (28.3) cakes Chisq (1 df) = 0.87 0.35 FALSE 16 (55.2) 19 (41.3) TRUE 13 (44.8) 27 (58.7) vanilla Chisq (1 df) = 24.54 < 0.001 FALSE 18 (62.1) (6.5) TRUE 11 (37.9) 43 (93.5) chocolate Chisq (1 df) = 2.32 0.127 FALSE (24.1) 20 (44.4) TRUE 22 (75.9) 25 (55.6) fruitsalad Fisher's exact test No 27 (93.1) 42 (91.3) Yes (6.9) (8.7) > hqoswego hqoswego Call: glm(formula = ill ~ bakedham + spinach + mashedpota + cabbagesal + jello + rolls + brownbread + milk + coffee + water + cakes + vanilla + chocolate + fruitsalad, family = "binomial") Coefficients: (Intercept) bakedhamTRUE spinachTRUE mashedpotaTRUE cabbagesalTRUE jelloTRUE rollsTRUE brownbreadTRUE milkTRUE -2.1486 0.9605 -0.4917 -0.3472 0.1143 -0.3085 -0.2051 0.7349 -1.9674 coffeeTRUE waterTRUE cakesTRUE vanillaTRUE chocolateTRUE fruitsaladTRUE -0.5125 0.1614 0.8512 3.2256 -0.1184 -0.3998 Degrees of Freedom: 72 Total (i.e Null); 58 Residual (2 observations deleted due to missingness) Null Deviance: 97.2 Residual Deviance: 66.36 AIC: 96.36 > logistic.display(hqoswego) Logistic regression predicting ill crude OR(95%CI) adj OR(95%CI) P(Wald's test) P(LR- test) bakedham 1.24 (0.47,3.23) 2.61 (0.14,48.64) 0.52 spinach 0.94 (0.36,2.43) mashedpota 0.96 (0.37,2.46) cabbagesal 1.41 (0.52,3.8) 0.61 (0.05,8) 0.708 0.71 (0.12,4.26) 1.12 (0.19,6.49) 0.705 0.898 0.516 0.702 0.704 0.898 jello 1.66 (0.58,4.73) 0.73 (0.1,5.48) 0.764 0.763 rolls 0.76 (0.29,1.95) 0.81 (0.08,8.37) 0.863 0.862 brownbread 1.28 (0.47,3.47) 2.09 (0.32,13.76) 0.445 0.14 (0.01,3.47) 0.23 0.439 milk 0.3 (0.03,3.42) coffee 0.89 (0.34,2.31) 0.6 (0.06,5.74) 0.657 0.654 water 0.73 (0.27,2) 0.866 0.866 cakes 1.73 (0.67,4.49) vanilla 21.64 (5.36,87.34) 25.17 (4.74,133.6) < 0.001 1.18 (0.18,7.64) 2.34 (0.57,9.55) 0.235 chocolate 0.42 (0.15,1.18) 0.89 (0.21,3.79) 0.873 fruitsalad 0.93 (0.15,5.93) 0.67 (0.07,6.61) 0.732 0.227 0.228 < 0.001 0.873 0.734 Log-likelihood = -33.1825 No of observations = 73 AIC value = 96.3649 > local({fn save.image("C:\\Documents and Settings\\Admin\\Desktop\\gjhgj") ... vanilla + chocolate + fruitsalad, family = "binomial") Coefficients: (Intercept) bakedhamTRUE spinachTRUE mashedpotaTRUE cabbagesalTRUE jelloTRUE rollsTRUE brownbreadTRUE milkTRUE -2.1486 0.9605... logical 20 fruitsalad logical > tableStack(vars=c(age,sex),by=ill) Error in rbind(table2, label.row, table0, blank.row) : number of columns of matrices must match (see arg 3) > tableStack(vars=c(age,sex),by="ill")... -1.9674 coffeeTRUE waterTRUE cakesTRUE vanillaTRUE chocolateTRUE fruitsaladTRUE -0.5125 0.1614 0.8512 3.2256 -0.1184 -0.3998 Degrees of Freedom: 72 Total (i.e Null); 58 Residual (2 observations deleted

Ngày đăng: 26/08/2021, 11:33

TỪ KHÓA LIÊN QUAN

w