{"action":"created","issue":{"url":"https://api.github.com/repos/harrelfe/Hmisc/issues/61","repository_url":"https://api.github.com/repos/harrelfe/Hmisc","labels_url":"https://api.github.com/repos/harrelfe/Hmisc/issues/61/labels{/name}","comments_url":"https://api.github.com/repos/harrelfe/Hmisc/issues/61/comments","events_url":"https://api.github.com/repos/harrelfe/Hmisc/issues/61/events","html_url":"https://github.com/harrelfe/Hmisc/issues/61","id":191674877,"number":61,"title":"summaryM - Error in specs[[tr$namefun]] ","user":{"login":"tormodb","id":4706223,"avatar_url":"https://avatars.githubusercontent.com/u/4706223?v=3","gravatar_id":"","url":"https://api.github.com/users/tormodb","html_url":"https://github.com/tormodb","followers_url":"https://api.github.com/users/tormodb/followers","following_url":"https://api.github.com/users/tormodb/following{/other_user}","gists_url":"https://api.github.com/users/tormodb/gists{/gist_id}","starred_url":"https://api.github.com/users/tormodb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tormodb/subscriptions","organizations_url":"https://api.github.com/users/tormodb/orgs","repos_url":"https://api.github.com/users/tormodb/repos","events_url":"https://api.github.com/users/tormodb/events{/privacy}","received_events_url":"https://api.github.com/users/tormodb/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2016-11-25T10:51:26Z","updated_at":"2016-11-25T15:50:41Z","closed_at":null,"body":"Dear Prof. Harrel. \r\n\r\nI am currently encountering an error with summaryM. I am using a separate categorical chi square test specified using catTest: \r\n\r\n```\r\ncatTestchisq.sim_p <- function (tab) {\r\n    st <- if (!is.matrix(tab) || nrow(tab) < 2 | ncol(tab) < \r\n        2) \r\n        list(p.value = NA, statistic = NA, parameter = NA)\r\n    else {\r\n        rowcounts <- tab %*% rep(1, ncol(tab))\r\n        tab <- tab[rowcounts > 0, ]\r\n        if (!is.matrix(tab)) \r\n            list(p.value = NA, statistic = NA, parameter = NA)\r\n        else chisq.test(tab, correct = FALSE, simulate.p.value = T)\r\n    }\r\n    list(P = st$p.value, stat = st$statistic, df = st$parameter, \r\n        testname = \"Pearson\", statname = \"Chi-square\", latexstat = \"\\\\chi^{2}_{df}\", \r\n        plotmathstat = \"chi[df]^2\")\r\n}\r\n```\r\n\r\nand referring to it using (in your example form the help file)\r\n\r\n`f <- summaryM(age + sex + sbp + Symptoms ~ treatment, test=TRUE, catTest = catTestchisq.sim_p)`.\r\n\r\nThis previously worked fine, but I am currently experiencing the following error:\r\n\r\n```\r\nError in specs[[tr$namefun]] : \r\n  attempt to select less than one element in get1index\r\n```\r\n\r\nwhen running this on both my original analysis, and your sample from help. I am working on data with cells with few numbers, so the monte-carlo simulated _p_-values have been necessary for creating my table (at least, this is my current understanding). \r\n\r\n"},"comment":{"url":"https://api.github.com/repos/harrelfe/Hmisc/issues/comments/262984197","html_url":"https://github.com/harrelfe/Hmisc/issues/61#issuecomment-262984197","issue_url":"https://api.github.com/repos/harrelfe/Hmisc/issues/61","id":262984197,"user":{"login":"harrelfe","id":1150682,"avatar_url":"https://avatars.githubusercontent.com/u/1150682?v=3","gravatar_id":"","url":"https://api.github.com/users/harrelfe","html_url":"https://github.com/harrelfe","followers_url":"https://api.github.com/users/harrelfe/followers","following_url":"https://api.github.com/users/harrelfe/following{/other_user}","gists_url":"https://api.github.com/users/harrelfe/gists{/gist_id}","starred_url":"https://api.github.com/users/harrelfe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/harrelfe/subscriptions","organizations_url":"https://api.github.com/users/harrelfe/orgs","repos_url":"https://api.github.com/users/harrelfe/repos","events_url":"https://api.github.com/users/harrelfe/events{/privacy}","received_events_url":"https://api.github.com/users/harrelfe/received_events","type":"User","site_admin":false},"created_at":"2016-11-25T15:50:41Z","updated_at":"2016-11-25T15:50:41Z","body":"There is one line that needs to be added for Hmisc_4.0, and one line to change to handle the fact that simulated p-values do not return d.f.  See below.\r\n```\r\nrequire(Hmisc)\r\nsrc <- example(summaryM, give.lines=TRUE)\r\neval(parse(text=src[1:34]))\r\n# xless(f)    # see built-in cat. test\r\n\r\ncatTestchisq.sim_p <- function(tab) {\r\n    st <- if (! is.matrix(tab) || nrow(tab) < 2 || ncol(tab) <  2) \r\n        list(p.value = NA, statistic = NA, parameter = NA)\r\n    else {\r\n        rowcounts <- tab %*% rep(1, ncol(tab))\r\n        tab <- tab[rowcounts > 0, ]\r\n        if (! is.matrix(tab)) \r\n            list(p.value = NA, statistic = NA, parameter = NA)\r\n        else chisq.test(tab, correct = FALSE, simulate.p.value = TRUE)\r\n    }\r\n    list(P            = st$p.value,\r\n         stat         = st$statistic,\r\n         df           = (nrow(tab) - 1) * (ncol(tab) - 1),   # st$parameter NA\r\n         testname     = \"Pearson\",\r\n         namefun      = 'chisq',     # must add this line for Hmisc_4.0\r\n         statname     = \"Chi-square\",\r\n         latexstat    = \"\\\\chi^{2}_{df}\", \r\n         plotmathstat = \"chi[df]^2\")\r\n}\r\n\r\n\r\nf <- summaryM(age + sex + sbp + Symptoms ~ treatment, test=TRUE,\r\n              catTest = catTestchisq.sim_p)\r\nf\r\n\r\n```"}}
{"actor":{"display_login":"harrelfe"}}