{"id":627,"date":"2014-06-03T11:05:40","date_gmt":"2014-06-03T16:05:40","guid":{"rendered":"http:\/\/homepages.uc.edu\/~yaozo\/wordpress\/?p=627"},"modified":"2014-06-03T11:05:40","modified_gmt":"2014-06-03T16:05:40","slug":"demonstrating-the-power-of-f-test-with-gwidgets","status":"publish","type":"post","link":"https:\/\/zhuoyao.net\/index.php\/2014\/06\/03\/demonstrating-the-power-of-f-test-with-gwidgets\/","title":{"rendered":"Demonstrating the Power of F Test with gWidgets"},"content":{"rendered":"<p>We know the real distribution of the F statistic in linear models &#8212; it is a non-central F distribution. Under H0, we have a central F distribution. Given 1 &#8211; alpha, we can compute the probability of (correctly) rejecting H0. I created a simple demo to illustrate how the power changes as other parameters vary, e.g. the degrees of freedoms, the non-central parameter and alpha. Here is the video:<\/p>\n<p>And for those who might be interested, here is the code (you need to install the gWidgets package first and I recommend the RGtk2 interface). Have fun:<\/p>\n<pre>## install.packages('gWidgetsRGtk2') first if not installed\n if (!require(\"gWidgetsRGtk2\")) install.packages(\"gWidgetsRGtk2\")\n if (!require(\"cairoDevice\")) install.packages(\"cairoDevice\")\n library(gWidgetsRGtk2)\n options(guiToolkit = \"RGtk2\")\n tbl = glayout(container = gwindow(\"Power of the F Test\"), spacing = 0)\n tbl[1, 1:4, anchor = c(0, 0), expand = TRUE] = g.f = ggraphics(container = tbl,\n expand = TRUE, ps = 11)\n tbl[2, 1, anchor = c(1, 0)] = \"numerator df\"\n tbl[2, 2, anchor = c(0, 0), expand = TRUE] = g.dfn = gslider(from = 1,\n to = 50, value = 3, container = tbl, handler = function(h, ...) {\n p.Ftest(dfn = svalue(h$obj))\n })\n tbl[2, 3, anchor = c(1, 0)] = \"denominator df\"\n tbl[2, 4, anchor = c(0, 0), expand = TRUE] = g.dfd = gslider(from = 1,\n to = 50, value = 20, container = tbl, handler = function(h, ...) {\n p.Ftest(dfd = svalue(h$obj))\n })\n tbl[3, 1, anchor = c(1, 0)] = \"delta^2\"\n tbl[3, 2, anchor = c(0, 0), expand = TRUE] = g.ncp = gslider(from = 0,\n to = 100, value = 10, container = tbl, handler = function(h, ...) {\n p.Ftest(ncp = svalue(h$obj))\n })\n tbl[3, 3, anchor = c(1, 0)] = \"alpha\"\n tbl[3, 4, anchor = c(0, 0), expand = TRUE] = g.alpha = gslider(from = 0,\n to = 1, by = 0.01, value = 0.05, container = tbl, handler = function(h,\n ...) {\n p.Ftest(alpha = svalue(h$obj))\n })\n tbl[4, 1, anchor = c(1, 0)] = \"x range\"\n tbl[4, 2:4, anchor = c(0, 0), expand = TRUE] = g.xr = gslider(from = 1,\n to = 50, value = 15, container = tbl, handler = function(h, ...) {\n p.Ftest(xr = svalue(h$obj))\n })\n ## draw the graph\n p.Ftest = function(dfn = svalue(g.dfn), dfd = svalue(g.dfd),\n ncp = svalue(g.ncp), alpha = svalue(g.alpha), xr = svalue(g.xr)) {\n x = seq(0.001, xr, length.out = 300)\n yc = df(x, dfn, dfd)\n yn = df(x, dfn, dfd, ncp = ncp)\n par(mar = c(4.5, 4, 1, 0.05))\n plot(x, yc, type = \"n\", ylab = \"Density\", ylim = c(0, max(yc, yn)))\n xq = qf(1 - alpha, dfn, dfd)\n polygon(c(xq, x[x &gt;= xq], xr), c(0, yn[x &gt; xq], 0), col = \"gray\",\n border = NA)\n lines(x, yc, lty = 1)\n lines(x, yn, lty = 2)\n legend(\"topright\", c(as.expression(substitute(F[list(df1,\n df2)] ~ \" density\", list(df1 = dfn, df2 = dfd))), as.expression(substitute(F[list(df1,\n df2)](ncp) ~ \" density\", list(df1 = dfn, df2 = dfd, ncp = ncp))),\n as.expression(substitute(\"Power = \" ~ p, list(p = round(1 -\n pf(xq, dfn, dfd, ncp = ncp), 4))))), lty = c(1:2,\n NA), fill = c(NA, NA, \"gray\"), border = NA, bty = \"n\")\n return(1 - pf(xq, dfn, dfd, ncp = ncp))\n }\n p.Ftest()<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>We know the real distribution of the F statistic in linear models &#8212; it is a non-central F distribution. Under H0, we have a central&hellip; <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-627","post","type-post","status-publish","format-standard","hentry","category-r"],"_links":{"self":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/627","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/comments?post=627"}],"version-history":[{"count":0,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/posts\/627\/revisions"}],"wp:attachment":[{"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/media?parent=627"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/categories?post=627"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zhuoyao.net\/index.php\/wp-json\/wp\/v2\/tags?post=627"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}