Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem : R Programming Calculate the two-sample t-test for each numerical variable in the chol data frame (from the chol.txt file) by the sex variable
Problem : R Programming
Calculate the two-sample t-test for each numerical variable in the chol data frame (from the chol.txt file) by the sex variable by using the apply function. The result should be a matrix that contains five columns: F.mean (mean of the numerical variable for Female), M.mean (mean of the numerical variable for Male), t (for t-statistics), df (for degrees of freedom), and p (for p-value).
sex age chol tg ht wt sbp dbp vldl hdl ldl bmi id.2 M 60 137 50 68.25 111.75 110 70 10 53 74 2.399066135 id.3 M 26 154 202 82.75 184.75 88 64 34 31 92 2.698040361 id.4 M 33 198 108 64.25 147 120 80 22 34 132 3.560992596 id.5 F 27 154 47 63.25 129 110 76 9 57 88 3.224546548 id.6 M 36 212 79 67.5 176.25 130 100 16 37 159 3.868312757 id.7 F 31 197 90 64.5 121 122 78 18 58 111 2.908479058 id.8 M 28 178 163 66.5 167 118 68 19 30 135 3.776358189 id.9 F 28 146 60 63 104.75 120 80 12 46 88 2.63920383 id.11 F 25 231 165 64 126 130 72 23 70 137 3.076171875 id.12 M 22 163 30 68.75 173 112 70 6 50 107 3.660165289 id.13 F 21 188 84 62.3 110.25 120 68 17 40 81 2.840550436 id.15 M 48 158 89 67.25 168 100 70 18 34 116 3.714708199 id.16 F 51 335 64 67.25 167 100 70 14 66 258 3.692596841 id.18 M 18 148 46 72 158 90 70 9 48 91 3.047839506 id.19 M 17 255 81 70.25 164.3 120 80 20 48 186 3.329238485 id.20 F 15 294 81 63 116 120 80 19 40 243 2.922650542 id.22 F 7 309 80 52 60.5 90 56 14 51 245 2.237426036 id.23 M 41 153 47 69.13 149.25 128 82 9 41 103 3.123066458 id.24 F 39 172 77 63.25 110 122 82 15 47 110 2.749613336 id.25 M 16 108 36 66.8 146 140 90 7 31 70 3.271899315 id.26 M 13 134 32 63.75 117.25 120 80 6 34 94 2.885044214 id.27 F 11 123 41 58 75.25 110 66 8 37 78 2.236920333 id.28 M 9 130 57 52.13 70.25 124 88 11 39 80 2.585061495 id.29 F 9 140 46 40 49.25 86 48 9 35 96 3.078125 id.30 M 5 120 46 45 42.75 80 40 9 36 75 2.111111111 id.31 M 41 212 356 60.5 204 134 97 56 46 110 5.573389796 id.32 F 45 294 141 63.25 150 132 92 32 39 223 3.74947273 id.33 F 19 161 76 62.13 148.5 122 76 15 41 105 3.84701382 id.34 M 17 117 46 66.75 138.25 112 74 9 34 74 3.102862994 id.35 M 16 167 55 66.25 136.5 120 74 11 52 100 3.11000356 id.36 M 15 121 59 68.25 130.75 120 84 12 37 72 2.806961049 id.37 F 13 119 62 64 106.25 118 64 12 43 64 2.593994141 id.38 M 11 288 89 56 91.25 100 70 20 33 233 2.909757653 id.39 F 11 113 68 55.75 74 100 64 14 37 62 2.380904502 id.40 F 6 114 63 45.5 32.5 100 60 13 36 65 1.569858713 id.42 F 55 263 203 60.5 149 230 120 33 68 152 4.070760194 id.43 M 40 246 104 72.5 202 130 90 21 33 192 3.843043995 id.44 F 42 185 70 63 121.75 128 78 14 63 108 3.067523306 id.45 M 19 154 178 72.25 170.5 128 84 34 32 77 3.266244418 id.46 F 13 130 50 63 123 134 94 10 50 70 3.099017385 id.47 F 11 147 73 58.13 83 118 58 15 46 86 2.456277593 id.48 F 9 195 65 58 82 120 68 13 59 123 2.437574316 id.49 M 35 218 268 71.5 252 130 90 65 35 107 4.929336398 id.50 F 35 302 76 62.25 105 134 100 11 46 235 2.709633716 id.51 M 15 242 66 58.5 71.25 110 60 13 41 180 2.08196362 id.52 F 14 165 67 65.5 123.25 100 60 13 52 100 2.872792961 id.53 F 10 150 90 58 73.5 110 70 18 48 84 2.18489893 id.54 M 4 198 202 35.5 29.5 80 40 33 31 119 2.340805396 id.55 M 6 468 110 40 34.25 100 80 20 50 382 2.140625 id.56 F 3 150 63 32 22 94 50 15 47 88 2.1484375 id.57 M 37 331 91 66 144.5 128 82 13 36 272 3.317263545 id.58 F 35 230 70 66.25 126 110 68 14 61 155 2.870772517 id.59 M 12 283 70 64 116.5 136 78 13 40 221 2.844238281 id.60 F 8 348 82 52.25 58 118 88 14 41 271 2.124493487 id.61 F 6 280 53 46 43 90 50 8 40 235 2.032136106 id.62 F 5 374 45 45 39 90 60 4 54 311 1.925925926 id.63 M 43 191 58 74.25 215.25 134 90 12 48 131 3.9043635 id.64 F 43 214 82 64.5 111.5 112 72 16 54 144 2.680127396 id.65 M 14 164 81 67.25 137.5 120 78 16 44 104 3.04031177 id.66 F 13 134 58 62.5 108.25 117 75 12 50 72 2.7712 id.67 F 12 154 94 67 73.25 110 75 19 45 90 1.63176654 id.68 F 10 150 46 66 113.25 92 70 9 54 87 2.599862259 id.70 F 20 320 60 64 106 140 60 10 44 255 2.587890625 id.71 M 18 192 89 69.5 136 140 80 18 47 127 2.815589255 id.72 M 17 324 68 72.5 138.5 145 108 11 39 267 2.634958383 id.73 F 16 315 155 62.5 158.5 150 82 35 35 237 4.0576 id.74 F 14 178 103 60.25 122.5 130 78 21 39 118 3.374597545 id.75 M 13 155 40 67.5 129.25 120 67 8 48 99 2.836762689 id.76 M 48 268 174 69 182 120 70 34 32 198 3.822726318 id.77 F 49 289 152 59 114 142 82 33 40 206 3.274921 id.78 F 25 192 84 64 116 120 80 17 56 119 2.83203125 id.79 M 23 214 66 69 138 90 60 13 69 132 2.898550725 id.81 M 21 380 116 70 168 128 82 18 55 305 3.428571429 id.82 M 17 304 82 68 124 118 76 12 40 250 2.6816609 id.83 F 13 202 88 59.25 86.25 91 78 18 55 129 2.456871228 id.84 F 11 179 98 61 85.5 112 92 20 62 97 2.297769417 id.85 M 53 221 81 67.25 151 122 80 17 45 159 3.338815108 id.86 F 47 340 96 60.5 136 128 76 16 46 277 3.715593197 id.87 M 24 321 116 67 163 132 92 38 33 250 3.63109824 id.88 M 22 210 145 66.25 157 120 80 29 52 129 3.577073692 id.89 M 21 183 68 67 167.5 138 78 14 45 124 3.731343284 id.90 F 19 320 57 62 111 122 86 9 73 238 2.887617066 id.91 F 18 165 101 64 129.25 105 70 20 56 89 3.155517578 id.92 M 15 172 107 66.25 137.5 140 72 21 40 111 3.132787469 id.93 M 13 139 72 64.25 121.5 100 64 14 45 80 2.943269391 id.94 F 12 245 116 59.25 88.5 112 70 28 35 179 2.520963521 id.95 F 11 310 84 52 59.5 99 70 9 64 223 2.200443787 id.96 M 8 167 40 52.5 68.75 104 60 8 53 106 2.494331066 id.97 M 7 316 47 50 56 124 86 6 51 255 2.24 id.98 M 22 165 69 73 209 150 108 14 36 85 3.921936574 id.99 F 23 301 60 62 123 120 74 7 58 230 3.199791884 id.102 F 2 150 113 36.5 29.75 105 70 23 39 88 2.233064365 id.103 F 2 210 120 40 24.75 80 60 24 42 134 1.546875 id.104 F 3 190 65 38 31 78 50 13 54 123 2.146814404 id.105 F 5 162 56 36 41.25 80 56 11 51 100 3.18287037 id.106 M 66 178 220 65.5 175 112 84 44 39 94 4.079016374 id.107 F 57 328 120 62 170 154 78 19 68 237 4.422476587 id.108 M 34 335 113 71.25 203 158 108 25 36 270 3.998768852 id.109 F 29 144 141 63 211 140 70 28 41 75 5.316200554 id.110 M 34 269 51 70 159 130 80 9 47 211 3.244897959 id.111 F 30 182 163 66 168 130 90 31 42 106 3.856749311 id.112 F 7 128 52 51.25 52 82 50 10 47 71 1.979773944 id.113 F 6 154 84 47.5 51 88 50 17 41 96 2.260387812 id.114 M 5 266 63 43 44 76 50 10 35 206 2.379664684 id.115 F 58 324 151 66.75 203 190 95 39 36 238 4.556102625 id.116 M 30 262 110 66.5 195 135 70 20 43 215 4.409520041 id.117 M 25 201 78 74 154 130 86 16 51 134 2.812271731 id.118 M 21 NA NA 68.4 148 140 75 NA NA NA 3.163366506 id.119 F 29 NA NA 63.5 120 110 90 NA NA NA 2.976005952 id.120 F 20 159 62 61 107 101 74 12 52 95 2.875571083 id.121 F 17 199 38 61.25 124.75 104 84 8 55 136 3.325281133 id.122 F 3 364 91 37.5 30 80 58 13 32 205 2.133333333 id.123 M 1 144 145 30 24 800 60 22 22 84 2.666666667 id.124 F 35 181 77 64.75 119 107 70 15 54 112 2.838359595 id.125 M 37 177 152 69.5 175 130 62 37 44 94 3.62300088 id.126 M 5 166 84 42.5 36 106 60 11 50 117 1.993079585 id.127 M 8 132 124 51 65 90 70 12 44 109 2.499038831 id.128 M 10 177 59 58 98 90 70 26 56 62 2.913198573 id.129 M 12 171 55 60 99 130 90 17 53 99 2.75 id.130 F 45 185 57 67 150 112 74 11 76 98 3.341501448 id.134 M 8 143 57 51 71 124 82 11 45 87 2.729719339 id.135 F 45 215 98 70 111 126 86 20 50 145 2.265306122 id.136 F 31 173 153 63 162 130 78 8 52 111 4.081632653 id.137 M 34 170 43 68 151 124 74 9 63 98 3.265570934 id.138 F 8 209 41 51.25 57 108 68 8 74 127 2.170136823 id.139 M 7 161 32 49 50 110 70 6 72 84 2.082465639 id.140 F 45 185 112 65 204 130 80 23 36 127 4.828402367 id.141 M 17 119 64 70 164 116 52 13 32 71 3.346938776 id.142 F 15 137 53 65 145 116 72 11 46 80 3.431952663 id.143 F 40 187 98 63.25 146 128 78 20 48 119 3.649486791 id.144 M 44 223 92 70 201 120 80 18 40 165 4.102040816 id.145 M 16 129 56 57.5 162 124 84 11 43 65 4.899810964 id.146 F 14 138 38 62.5 123 100 70 8 50 80 3.1488 id.147 F 13 270 69 60 99 108 66 12 55 210 2.75 id.148 F 9 150 47 53.25 63 90 65 9 56 85 2.221781393 id.149 M 35 200 62 69 173 120 90 13 55 133 3.633690401 id.150 F 31 188 115 62 127 140 96 23 76 89 3.303850156 id.151 M 12 155 38 58 105 110 70 8 62 85 3.121284186 id.152 F 9 145 32 53 64 128 76 6 66 73 2.278390886 id.153 M 55 338 79 73 200 129 71 13 32 293 3.753049353 id.154 F 55 206 47 66 136 138 70 9 78 119 3.122130395 id.155 F 19 154 53 68 139.5 110 76 11 61 82 3.016868512 id.156 M 47 149 55 73 238 115 80 11 44 94 4.46612873 id.157 F 45 195 53 65.75 177 120 80 11 75 109 4.09431971 id.158 M 13 134 32 66 126 110 68 6 70 58 2.892561984 id.159 M 17 133 36 71 156 130 80 7 50 76 3.094624083 id.160 F 21 166 67 66 154 118 70 13 66 87 3.535353535 id.161 F 9 130 61 57.5 122 104 80 12 46 72 3.689981096 id.162 F 41 209 97 63 123 100 49 19 33 107 3.099017385 id.163 M 9 166 47 54.75 72 100 60 9 62 95 2.401951586 id.164 F 4 169 66 41.75 46 100 60 13 51 105 2.639033311 id.165 F 40 204 53 67 140 110 78 11 56 137 3.118734685 id.166 M 41 224 48 73.25 176 135 80 10 59 135 3.280177987 id.167 F 15 126 68 58 144 126 78 12 45 69 4.280618312 id.168 M 14 150 40 69.25 151 115 65 8 64 78 3.148744282 id.169 F 11 170 44 66 114 125 70 9 74 87 2.61707989 id.170 F 8 208 53 54 67 125 75 11 55 142 2.297668038 id.171 F 7 164 64 51.5 61 115 70 13 43 108 2.299934018 id.172 F 42 165 61 60.25 149 118 68 12 54 89 4.104612524 id.173 M 42 183 101 68 212 144 102 20 44 119 4.584775087 id.174 M 16 119 36 73 184 120 78 7 54 58 3.452805404 id.175 M 14 117 29 65 149 106 80 6 55 56 3.526627219 id.176 F 12 137 36 57.25 91 110 72 7 64 66 2.776453538 id.177 M 10 162 46 58 115 108 88 9 63 90 3.418549346 id.178 M 4 140 42 41.25 40 90 70 8 66 56 2.350780533 id.179 M 48 184 120 70 192 118 40 14 41 129 3.918367347 id.180 F 35 196 41 66.75 166 120 70 8 53 135 3.725679979 id.181 F 14 172 67 65 132 138 73 14 58 101 3.124260355 id.182 M 12 183 44 59 92 110 50 9 62 112 2.642918702 id.183 M 11 199 35 56 86 96 80 7 64 129 2.742346939 id.184 M 9 202 53 57.25 82 116 78 11 56 135 2.501859232 id.185 M 37 179 86 70 172 160 80 17 54 108 3.510204082 id.186 F 40 187 53 62.25 141 112 72 11 68 108 3.63865099 id.187 M 16 207 87 65 173.5 95 70 15 41 151 4.106508876 id.188 M 17 197 62 67.25 188 110 70 12 41 124 4.156935366 id.189 M 45 260 90 65 146 156 104 16 52 194 3.455621302 id.190 M 15 140 38 67 126 120 80 8 56 76 2.806861216 id.191 M 14 173 39 61 94 104 70 8 57 108 2.526202634 id.192 M 13 148 36 60 92 110 70 7 64 77 2.555555556 id.193 M 16 168 60 68 138 90 65 12 39 117 2.984429066 id.194 M 49 216 82 68 189 98 72 16 53 147 4.087370242 id.196 F 41 162 87 64.75 156 142 104 17 47 98 3.720874763 id.197 F 19 165 83 66.75 131 120 80 17 46 102 2.940145043 id.198 M 18 170 52 69 168 110 70 10 42 118 3.528670447 id.199 M 16 161 74 70 171 105 65 15 36 110 3.489795918 id.200 F 14 125 60 64.5 134 138 60 12 44 69 3.220960279 id.201 M 11 145 81 59.25 95 120 80 16 67 62 2.706119034 id.202 F 68 207 116 63 137 135 80 23 48 136 3.451751071 id.205 M 21 301 76 72 205 140 90 12 47 241 3.954475309 id.206 M 3 114 40 37.13 31.75 90 70 8 31 75 2.302999434 id.401 F 56 213 119 60.87 133 160 88 24 48 141 3.589591577 id.421 F 13 305 67 66 115 135 75 11 47 260 2.640036731
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started