Hi! I'm trying to use sapply to my dataframe for z.test function (teaching demos package) Sep=cbind(kIp,k02p,k04p,k07p) Sep=as.data.frame(Sep) kzt=sapply(Sep, function(m) z.test(m,sd(m))) Error in z.test(m, sd(Sep)) : You must specify a Standard Deviation of the population kzt=sapply(Sep, function(m) z.test(m,sd(Sep))) Error in z.test(m, sd(Sep)) : You must specify a Standard Deviation of the population #obviously it can't process the z.test because of the sd function embedded inside the function. can someone point me how to fix this. Many thanks! [[alternative HTML version deleted]]
Hello, Without a data example I can't test this but, the call to ?z.test seems to be wrong, you are passing a value for argument 'mu' equal to sd(m) but _not_ passing a value for argument 'stdev'. Try kzt <- sapply(Sep, function(m) z.test(m, stdev = sd(m))) Hope this helps, Rui Barradas Em 17-10-2012 07:45, Balqis escreveu:> Hi! > I'm trying to use sapply to my dataframe for z.test function (teaching > demos package) > > > Sep=cbind(kIp,k02p,k04p,k07p) > Sep=as.data.frame(Sep) > > kzt=sapply(Sep, function(m) z.test(m,sd(m))) > Error in z.test(m, sd(Sep)) : > You must specify a Standard Deviation of the population > > kzt=sapply(Sep, function(m) z.test(m,sd(Sep))) > Error in z.test(m, sd(Sep)) : > You must specify a Standard Deviation of the population > > #obviously it can't process the z.test because of the sd function embedded > inside the function. can someone point me how to fix this. Many thanks! > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.
On Wed, Oct 17, 2012 at 7:45 AM, Balqis <aehan3616 at gmail.com> wrote:> Sep=cbind(kIp,k02p,k04p,k07p) > Sep=as.data.frame(Sep) >I see Rui has already taken a stab at your question, but I just want to chime in to say the preceeding is really a terrible idiom. It would be much _much_ better to write Sep = data.frame(klp, k02p, k04p, k07p) data.frame() is the function for making data.frames(). If you cbind() things together, you usually wind up with a matrix which requires all its elements to be of one type. This, of course, defeats the entire point of data frames which is to allow different columns to have different points. Cheers, Michael
Rui answered the main question by pointing out that you need z.test(m, stdev=s(m)), or you could use z.test(m,,sd(m)), but I think the stdevapproach is clearer. But you are really abusing the concept of z tests in general (and the z.test function in particular) by using the sd of the sample. If you use the sd of the sample then you should be doing a t test (and the t.test function does this simpler than the z.test function). The z.test function was designed to use in classes that introduce the concepts of inference using the generally unrealistic (but simpler) case of knowing the population standard deviation, but not the mean. The z.test function was to be a bridge so that the students could use a function that was similar to the t.test function that they would eventually use. On Wed, Oct 17, 2012 at 12:45 AM, Balqis <aehan3616 at gmail.com> wrote:> Hi! > I'm trying to use sapply to my dataframe for z.test function (teaching > demos package) > > > Sep=cbind(kIp,k02p,k04p,k07p) > Sep=as.data.frame(Sep) > > kzt=sapply(Sep, function(m) z.test(m,sd(m))) > Error in z.test(m, sd(Sep)) : > You must specify a Standard Deviation of the population > > kzt=sapply(Sep, function(m) z.test(m,sd(Sep))) > Error in z.test(m, sd(Sep)) : > You must specify a Standard Deviation of the population > > #obviously it can't process the z.test because of the sd function embedded > inside the function. can someone point me how to fix this. Many thanks! > > [[alternative HTML version deleted]] > > ______________________________________________ > 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.-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com