[R] self-written function
Christoph Scherber
Christoph.Scherber at uni-jena.de
Fri Jan 28 11:04:43 CET 2005
Hi!
OK, here are some more details on the function: My dataframe consists of
several columns of categorical variables (let´s call them A,B,C) plus a
column with a response variable y (which is arcsine-square root
transformed proportions)
I am now trying to write a function that automatically gives me the
back-transformed mean values + standard errors for y for each column in
the dataframe. Ideally, this would be something like
tapply(y,list(A,B,C,D),backtransformed.mean)
Here is the correct version of the function:
backsin<-function(x,y){
backtransf<-list()
back<-((sin(x[x!="NA"]))^2)*100
backtransf$mback<-tapply(back,y[x!="NA"],mean)
backtransf$sdback<-tapply(back,y[x!="NA"],std)/sqrt(length(y[x!="NA"]))
backtransf
}
Regards,
Christoph
Petr Pikal wrote:
>Hi
>
>I am not sure if anybody gave you a reply, but do you think you gave
>enough detail about your data, what you expect, what you did, what
>was the response and how it differ from expected output and best of
>all ***working*** example?
>
>BTW, what is stdev?
>
>If you wanted to compute standard deviation sd is enough.
>
>Cheers
>Petr
>
>On 27 Jan 2005 at 12:20, Christoph Scherber wrote:
>
>
>
>>Dear all,
>>
>>I´ve got a simple self-written function to calculate the mean + s.e.
>>from arcsine-transformed data:
>>
>>backsin<-function(x,y,...){
>> backtransf<-list()
>> backtransf$back<-((sin(x[x!="NA"]))^2)*100
>> backtransf$mback<-tapply(backtransf$back,y[x!="NA"],mean)
>> backtransf$sdback<-tapply(backtransf$back,y[x!="NA"],std)/sqrt(length(y[x!="NA"]))
>>
>>backtransf
>>
>>
>>}
>>
>>I would like to apply this function to whole datasets, such as
>>
>>tapply(variable,list(A,B,C,D),backsin)
>>
>>Of course, this doesn´t work with the way in which the backsin()
>>function is specified.
>>
>>Does anyone have suggestions on how I could improve my function?
>>
>>Regards,
>>Christoph
>>
>>______________________________________________
>>R-help at stat.math.ethz.ch mailing list
>>https://stat.ethz.ch/mailman/listinfo/r-help
>>PLEASE do read the posting guide!
>>http://www.R-project.org/posting-guide.html
>>
>>
>
>Petr Pikal
>petr.pikal at precheza.cz
>
>
>
>
>
More information about the R-help
mailing list