seWithin is used to compute the standard error(s) for one or more variables, for one or more groups in a dataframe, handling within-subjects variables by removing inter-subject variability

seWithin(data = NULL, measurevar, betweenvars = NULL, withinvars = NULL,
idvar = NULL, na.rm = TRUE, conf.interval = 0.95, shownormed = FALSE)

Arguments

data

a dataframe

measurevar

the name(s) of column(s) that contain the variable to be summariezed

betweenvars

a vector containing names of columns that are between-subjects variables

withinvars

a vector containing names of columns that are within-subjects variables

idvar

the name of the column that identifies each subject

na.rm

boolean that indicates whether to ignore NA's

conf.interval

confidence interval range

shownormed

whether to show noramlized results

Value

A data.table

Note

Code adapted from R cookbook (see references).

References

http://www.cookbook-r.com/Graphs/Plotting_means_and_error_bars_(ggplot2)/

See also

Examples

result <- seWithin(data = ChickWeight, measurevar = "weight", betweenvars = "Diet", withinvars = "Time", idvar = "Chick")
#> Automatically converting the following non-factors to factors: Time
#> Joining, by = c("Chick", "Diet")
#> Joining, by = c("Diet", "Time", "N")
#> Factors have been converted to characters.
#> Confidence intervals: 0.95
#>
#> Diet Time N weight sd se ci #> 1: 1 0 20 41.40000 32.196088 7.199264 15.068233 #> 2: 1 2 20 47.25000 31.222053 6.981463 14.612371 #> 3: 1 4 19 56.47368 28.049332 6.434958 13.519345 #> 4: 1 6 19 66.78947 24.955540 5.725194 12.028185 #> 5: 1 8 19 79.68421 21.023526 4.823128 10.133015 #> 6: 1 10 19 93.05263 14.874487 3.412441 7.169273 #> 7: 1 12 19 108.52632 11.572480 2.654909 5.577757 #> 8: 1 14 18 123.38889 13.870327 3.269267 6.897551 #> 9: 1 16 17 144.64706 21.984518 5.332029 11.303396 #> 10: 1 18 17 158.94118 26.584912 6.447788 13.668700 #> 11: 1 20 17 170.41176 34.320498 8.323943 17.645972 #> 12: 1 21 16 177.75000 38.237769 9.559442 20.375469 #> 13: 2 0 10 40.70000 33.604854 10.626788 24.039464 #> 14: 2 2 10 49.40000 33.861652 10.707994 24.223166 #> 15: 2 4 10 59.80000 32.265022 10.203096 23.081006 #> 16: 2 6 10 75.40000 29.958647 9.473756 21.431125 #> 17: 2 8 10 91.70000 19.417095 6.140224 13.890153 #> 18: 2 10 10 108.50000 10.777143 3.408032 7.709503 #> 19: 2 12 10 131.30000 11.275312 3.565567 8.065872 #> 20: 2 14 10 141.90000 15.284023 4.833232 10.933531 #> 21: 2 16 10 164.70000 22.990849 7.270345 16.446662 #> 22: 2 18 10 187.70000 33.389549 10.558702 23.885444 #> 23: 2 20 10 205.60000 41.917684 13.255536 29.986105 #> 24: 2 21 10 214.70000 50.885426 16.091385 36.401241 #> 25: 3 0 10 40.80000 28.276080 8.941682 20.227489 #> 26: 3 2 10 50.40000 27.594930 8.726283 19.740223 #> 27: 3 4 10 62.20000 26.660100 8.430664 19.071487 #> 28: 3 6 10 77.90000 23.431511 7.409694 16.761893 #> 29: 3 8 10 98.40000 17.857046 5.646894 12.774161 #> 30: 3 10 10 117.10000 12.021922 3.801665 8.599965 #> 31: 3 12 10 144.40000 11.947923 3.778265 8.547029 #> 32: 3 14 10 164.50000 12.590895 3.981591 9.006984 #> 33: 3 16 10 197.40000 19.229222 6.080814 13.755756 #> 34: 3 18 10 233.10000 32.170338 10.173154 23.013273 #> 35: 3 20 10 258.90000 40.861992 12.921696 29.230908 #> 36: 3 21 10 270.30000 48.717298 15.405762 34.850255 #> 37: 4 0 10 41.00000 17.382195 5.496733 12.434473 #> 38: 4 2 10 51.80000 16.818054 5.318336 12.030911 #> 39: 4 4 10 64.50000 17.046321 5.390520 12.194203 #> 40: 4 6 10 83.90000 17.247248 5.454059 12.337938 #> 41: 4 8 10 105.60000 16.883489 5.339028 12.077720 #> 42: 4 10 10 126.00000 16.639228 5.261786 11.902987 #> 43: 4 12 10 151.40000 12.808176 4.050301 9.162417 #> 44: 4 14 10 161.80000 9.155805 2.895320 6.549668 #> 45: 4 16 10 182.00000 11.204764 3.543258 8.015406 #> 46: 4 18 10 202.90000 19.553833 6.183465 13.987970 #> 47: 4 20 9 233.88889 29.101735 9.700578 22.369574 #> 48: 4 21 9 238.55556 34.977292 11.659097 26.885927 #> Diet Time N weight sd se ci
# multiple outcome variables ChickWeight2 <- ChickWeight ChickWeight2$weight2 <- ChickWeight2$weight * 100 # create a new outcome variable result <- seWithin(data = ChickWeight2, measurevar = c("weight", "weight2"), betweenvars = "Diet", withinvars = "Time", idvar = "Chick")
#> Automatically converting the following non-factors to factors: Time
#> Joining, by = c("Chick", "Diet")
#> Joining, by = c("Diet", "Time", "N")
#> Factors have been converted to characters.
#> Confidence intervals: 0.95
#>
#> Joining, by = c("Chick", "Diet")
#> Joining, by = c("Diet", "Time", "N")
#> Factors have been converted to characters.
#> Confidence intervals: 0.95
#>
#> $weight #> Diet Time N weight sd se ci #> 1: 1 0 20 41.40000 32.196088 7.199264 15.068233 #> 2: 1 2 20 47.25000 31.222053 6.981463 14.612371 #> 3: 1 4 19 56.47368 28.049332 6.434958 13.519345 #> 4: 1 6 19 66.78947 24.955540 5.725194 12.028185 #> 5: 1 8 19 79.68421 21.023526 4.823128 10.133015 #> 6: 1 10 19 93.05263 14.874487 3.412441 7.169273 #> 7: 1 12 19 108.52632 11.572480 2.654909 5.577757 #> 8: 1 14 18 123.38889 13.870327 3.269267 6.897551 #> 9: 1 16 17 144.64706 21.984518 5.332029 11.303396 #> 10: 1 18 17 158.94118 26.584912 6.447788 13.668700 #> 11: 1 20 17 170.41176 34.320498 8.323943 17.645972 #> 12: 1 21 16 177.75000 38.237769 9.559442 20.375469 #> 13: 2 0 10 40.70000 33.604854 10.626788 24.039464 #> 14: 2 2 10 49.40000 33.861652 10.707994 24.223166 #> 15: 2 4 10 59.80000 32.265022 10.203096 23.081006 #> 16: 2 6 10 75.40000 29.958647 9.473756 21.431125 #> 17: 2 8 10 91.70000 19.417095 6.140224 13.890153 #> 18: 2 10 10 108.50000 10.777143 3.408032 7.709503 #> 19: 2 12 10 131.30000 11.275312 3.565567 8.065872 #> 20: 2 14 10 141.90000 15.284023 4.833232 10.933531 #> 21: 2 16 10 164.70000 22.990849 7.270345 16.446662 #> 22: 2 18 10 187.70000 33.389549 10.558702 23.885444 #> 23: 2 20 10 205.60000 41.917684 13.255536 29.986105 #> 24: 2 21 10 214.70000 50.885426 16.091385 36.401241 #> 25: 3 0 10 40.80000 28.276080 8.941682 20.227489 #> 26: 3 2 10 50.40000 27.594930 8.726283 19.740223 #> 27: 3 4 10 62.20000 26.660100 8.430664 19.071487 #> 28: 3 6 10 77.90000 23.431511 7.409694 16.761893 #> 29: 3 8 10 98.40000 17.857046 5.646894 12.774161 #> 30: 3 10 10 117.10000 12.021922 3.801665 8.599965 #> 31: 3 12 10 144.40000 11.947923 3.778265 8.547029 #> 32: 3 14 10 164.50000 12.590895 3.981591 9.006984 #> 33: 3 16 10 197.40000 19.229222 6.080814 13.755756 #> 34: 3 18 10 233.10000 32.170338 10.173154 23.013273 #> 35: 3 20 10 258.90000 40.861992 12.921696 29.230908 #> 36: 3 21 10 270.30000 48.717298 15.405762 34.850255 #> 37: 4 0 10 41.00000 17.382195 5.496733 12.434473 #> 38: 4 2 10 51.80000 16.818054 5.318336 12.030911 #> 39: 4 4 10 64.50000 17.046321 5.390520 12.194203 #> 40: 4 6 10 83.90000 17.247248 5.454059 12.337938 #> 41: 4 8 10 105.60000 16.883489 5.339028 12.077720 #> 42: 4 10 10 126.00000 16.639228 5.261786 11.902987 #> 43: 4 12 10 151.40000 12.808176 4.050301 9.162417 #> 44: 4 14 10 161.80000 9.155805 2.895320 6.549668 #> 45: 4 16 10 182.00000 11.204764 3.543258 8.015406 #> 46: 4 18 10 202.90000 19.553833 6.183465 13.987970 #> 47: 4 20 9 233.88889 29.101735 9.700578 22.369574 #> 48: 4 21 9 238.55556 34.977292 11.659097 26.885927 #> Diet Time N weight sd se ci #> #> $weight2 #> Diet Time N weight2 sd se ci #> 1: 1 0 20 4140.000 3219.6088 719.9264 1506.8233 #> 2: 1 2 20 4725.000 3122.2053 698.1463 1461.2371 #> 3: 1 4 19 5647.368 2804.9332 643.4958 1351.9345 #> 4: 1 6 19 6678.947 2495.5540 572.5194 1202.8185 #> 5: 1 8 19 7968.421 2102.3526 482.3128 1013.3015 #> 6: 1 10 19 9305.263 1487.4487 341.2441 716.9273 #> 7: 1 12 19 10852.632 1157.2480 265.4909 557.7757 #> 8: 1 14 18 12338.889 1387.0327 326.9267 689.7551 #> 9: 1 16 17 14464.706 2198.4518 533.2029 1130.3396 #> 10: 1 18 17 15894.118 2658.4912 644.7788 1366.8700 #> 11: 1 20 17 17041.176 3432.0498 832.3943 1764.5972 #> 12: 1 21 16 17775.000 3823.7769 955.9442 2037.5469 #> 13: 2 0 10 4070.000 3360.4854 1062.6788 2403.9464 #> 14: 2 2 10 4940.000 3386.1652 1070.7994 2422.3166 #> 15: 2 4 10 5980.000 3226.5022 1020.3096 2308.1006 #> 16: 2 6 10 7540.000 2995.8647 947.3756 2143.1125 #> 17: 2 8 10 9170.000 1941.7095 614.0224 1389.0153 #> 18: 2 10 10 10850.000 1077.7143 340.8032 770.9503 #> 19: 2 12 10 13130.000 1127.5312 356.5567 806.5872 #> 20: 2 14 10 14190.000 1528.4023 483.3232 1093.3531 #> 21: 2 16 10 16470.000 2299.0849 727.0345 1644.6662 #> 22: 2 18 10 18770.000 3338.9549 1055.8702 2388.5444 #> 23: 2 20 10 20560.000 4191.7684 1325.5536 2998.6105 #> 24: 2 21 10 21470.000 5088.5426 1609.1385 3640.1241 #> 25: 3 0 10 4080.000 2827.6080 894.1682 2022.7489 #> 26: 3 2 10 5040.000 2759.4930 872.6283 1974.0223 #> 27: 3 4 10 6220.000 2666.0100 843.0664 1907.1487 #> 28: 3 6 10 7790.000 2343.1511 740.9694 1676.1893 #> 29: 3 8 10 9840.000 1785.7046 564.6894 1277.4161 #> 30: 3 10 10 11710.000 1202.1922 380.1665 859.9965 #> 31: 3 12 10 14440.000 1194.7923 377.8265 854.7029 #> 32: 3 14 10 16450.000 1259.0895 398.1591 900.6984 #> 33: 3 16 10 19740.000 1922.9222 608.0814 1375.5756 #> 34: 3 18 10 23310.000 3217.0338 1017.3154 2301.3273 #> 35: 3 20 10 25890.000 4086.1992 1292.1696 2923.0908 #> 36: 3 21 10 27030.000 4871.7298 1540.5762 3485.0255 #> 37: 4 0 10 4100.000 1738.2195 549.6733 1243.4473 #> 38: 4 2 10 5180.000 1681.8054 531.8336 1203.0911 #> 39: 4 4 10 6450.000 1704.6321 539.0520 1219.4203 #> 40: 4 6 10 8390.000 1724.7248 545.4059 1233.7938 #> 41: 4 8 10 10560.000 1688.3489 533.9028 1207.7720 #> 42: 4 10 10 12600.000 1663.9228 526.1786 1190.2987 #> 43: 4 12 10 15140.000 1280.8176 405.0301 916.2417 #> 44: 4 14 10 16180.000 915.5805 289.5320 654.9668 #> 45: 4 16 10 18200.000 1120.4764 354.3258 801.5406 #> 46: 4 18 10 20290.000 1955.3833 618.3465 1398.7970 #> 47: 4 20 9 23388.889 2910.1735 970.0578 2236.9574 #> 48: 4 21 9 23855.556 3497.7292 1165.9097 2688.5927 #> Diet Time N weight2 sd se ci #>