Re: [R] Function to crop p-values from multiple Anovas

From: Berend Hasselman <bhh_at_xs4all.nl>
Date: Wed, 23 Mar 2011 12:46:26 -0700 (PDT)

micfalb-r wrote:
>
>
> &gt; p.fun &lt;- function(arg) {
> two_way_anova &lt;- aov(arg ~ age * treatment, data = example.df)
> two_way_sum &lt;- summary(two_way_anova)
> p_values &lt;- two_way_sum[[1]]$&quot;Pr(&gt;F)&quot;[1:3]
> return(p_values)
> }
>
> Unfortunately my setup seems to be flawed as I'm not capable to call my
> function:
> &gt; p.fun(gene1)
> Error in eval(expr, envir, enclos) : object 'gene1' not found
> &gt; p.fun(&quot;gene1&quot;)
> Error in model.frame.default(formula = arg ~ age * treatment, data =
> example.df, :
> variable lengths differ (found for 'age')
> and provide commented, minimal, self-contained, reproducible code.
>

Try this for your function

p.fun <- function(arg) {

    lhs <- get(arg, envir=as.environment(example.df))

    two_way_anova <- aov(lhs ~ age * treatment, data = example.df)
    two_way_sum   <- summary(two_way_anova)
    p_values      <- two_way_sum[[1]]$"Pr(>F)"[1:3]
    return(p_values)
}

Use with

p.fun("gene1")

There are surely more elegant methods. E.g. no quotes in the argument of the p.fun call.

/Berend

--
View this message in context: http://r.789695.n4.nabble.com/Function-to-crop-p-values-from-multiple-Anovas-tp3400271p3400434.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Wed 23 Mar 2011 - 19:48:37 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 23 Mar 2011 - 19:50:24 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive