{"action":"opened","issue":{"url":"https://api.github.com/repos/GaryBAYLOR/R-code/issues/10","labels_url":"https://api.github.com/repos/GaryBAYLOR/R-code/issues/10/labels{/name}","comments_url":"https://api.github.com/repos/GaryBAYLOR/R-code/issues/10/comments","events_url":"https://api.github.com/repos/GaryBAYLOR/R-code/issues/10/events","html_url":"https://github.com/GaryBAYLOR/R-code/issues/10","id":94436572,"number":10,"title":"Fligner-Policello test in R","user":{"login":"GaryBAYLOR","id":12647683,"avatar_url":"https://avatars.githubusercontent.com/u/12647683?v=3","gravatar_id":"","url":"https://api.github.com/users/GaryBAYLOR","html_url":"https://github.com/GaryBAYLOR","followers_url":"https://api.github.com/users/GaryBAYLOR/followers","following_url":"https://api.github.com/users/GaryBAYLOR/following{/other_user}","gists_url":"https://api.github.com/users/GaryBAYLOR/gists{/gist_id}","starred_url":"https://api.github.com/users/GaryBAYLOR/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/GaryBAYLOR/subscriptions","organizations_url":"https://api.github.com/users/GaryBAYLOR/orgs","repos_url":"https://api.github.com/users/GaryBAYLOR/repos","events_url":"https://api.github.com/users/GaryBAYLOR/events{/privacy}","received_events_url":"https://api.github.com/users/GaryBAYLOR/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-07-11T04:50:51Z","updated_at":"2015-07-11T04:50:51Z","closed_at":null,"body":"# Fligner-Policello Test in R\r\n\r\nI try to find a package to do FP test, but found nothing. So I make a small crude function which take two vectors as input and return a p-value.\r\n```r\r\nFP.test <- function(x, y) {\r\n\tn <- length(x); m <- length(y)\r\n\tPl.x <- numeric(n); Pl.y <- numeric(m)\r\n\t\r\n\tfor(i in 1:n) {\r\n\t\tPl.x[i] <- sum(y < x[i]) + 1/2 * sum(y == x[i])\r\n\t}\r\n\t\r\n\tfor(i in 1:m) {\r\n\t\tPl.y[i] <- sum(x < y[i]) + 1/2 * sum(x == y[i])\r\n\t}\r\n\t\r\n\tPlxmean <- mean(Pl.x); Plymean <- mean(Pl.y)\r\n\t\r\n\tVx <- (n - 1) * var(Pl.x); Vy <- (m - 1) * var(Pl.y)\r\n\t\r\n\tz <- (sum(Pl.y) - sum(Pl.x)) / (2 * sqrt(Vx + Vy + Plxmean * Plymean))\r\n\t\r\n\tp <- pnorm(abs(z), lower.tail = FALSE) * 2\r\n\t\r\n\treturn (list(p.value = p))\r\n\t\r\n}\r\n```\r\nWe can try some example\r\n```r\r\n> set.seed(100)\r\n> x <- rnorm(20, mean = 0, sd = 1)\r\n> set.seed(200)\r\n> y <- rnorm(30, mean = 0, sd = 1)\r\n> set.seed(201)\r\n> y1 <- rnorm(30, mean = 1, sd = 1)\r\n> set.seed(202)\r\n> y2 <- rnorm(30, mean = 2, sd = 1)\r\n> set.seed(203)\r\n> y3 <- rnorm(30, mean = 3, sd = 1)\r\n> FP.test(x,y)\r\n$p.value\r\n[1] 0.7070176\r\n\r\n> FP.test(x,y1)\r\n$p.value\r\n[1] 5.794937e-05\r\n\r\n> FP.test(x,y2)\r\n$p.value\r\n[1] 2.43404e-46\r\n\r\n> FP.test(x,y3)\r\n$p.value\r\n[1] 1.124729e-250\r\n\r\n```\r\n\r\n\r\n"}}