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"],stdev)/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
Hi! I?m using the function for a data frame, but up to now it only works with single vectors, such as backsin(variable,grouping.factor) Actually, you?re right, the "..." in the function definition is not needed...:-) Regards Christoph Erin Hodgess wrote:>Hello Christoph! > >I have a question about your question, please: > >In your first line of code, >backsin <- function(x,y,...){ > >why do you have the three dots at the end? > >Also, what kind of data sets are you applying this to, please? > >Data frames or Matrixes? > >Thanks, >Erin >mailto: hodgess at gator.uhd.edu > >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"],stdev)/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
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 > > > > >
Dear Jari, I had included the test for NA?s just to be sure the function can handle datasets with missing values. Here?s an updated version without this specification: backsin<-function(x,y){ backtransf<-list() back<-((sin(x))^2)*100 backtransf$mback<-tapply(back,y,mean) backtransf$sdback<-tapply(back,y,sd)/sqrt(length(y)) backtransf } Jari Oksanen wrote:>Christoph, > >I guess your "NA" refers to Not Available (missing, NA). In that case, >you should check it with is.na() instead of != "NA". See this: > > > >>x <- c(3,4,NA,5) >>x != "NA" >> >> >[1] TRUE TRUE NA TRUE > > >>!is.na(x) >> >> >[1] TRUE TRUE FALSE TRUE > >No idea if this helps, but it was a problem with the code anyway. > >cheers, jari oksanen >On Fri, 2005-01-28 at 11:04 +0100, Christoph Scherber wrote: > > >>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 >>> >>> >>> >>> >>> >>> >>> >>______________________________________________ >>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 >> >> > > > >
Hi Christoph On 28 Jan 2005 at 11:04, Christoph Scherber wrote:> 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 >why not do it in several steps: omit <- !is.na(yourdf$y) transfy <- ((sin(yourdf$y[omit]))^2)*100 transm <- aggregatey(list(m=transfy), list(A,B,C,D), mean) transs <- aggregate(list(s=transfy), list(A,B,C,D), function(x) (sd(x)/sqrt(length(x))) # I hope I have corect no of () cbind(transm,transs$s) and if you feel like you can pack it to some function. Cheers Petr> 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(leng > >> th(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 > > > > > > > > > > > > ______________________________________________ > 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.htmlPetr Pikal petr.pikal at precheza.cz