| To: | <s-news@lists.biostat.wustl.edu> |
|---|---|
| Subject: | sapply to automate doing a series ofparallel analyses |
| From: | "Hunsicker, Lawrence" <lawrence-hunsicker@uiowa.edu> |
| Date: | Sat, 27 Dec 2008 19:09:43 -0600 |
| Thread-index: | AcloiPelZoPz064vS8KGpCkY16OSGg== |
| Thread-topic: | [S] sapply to automate doing a series ofparallel analyses |
|
So here I am back to the trough for help. You guys are really teaching me how to program S-Plus, and I appreciate the help. So I now have a function named testScrMiss, which does a mixed model logistic regression to test which other values in a data set predict whether a serum creatinine determination was obtained. (You all know the function from my last messages.) The function now works fine, with a single integer parameter indexing the specific column that I want to test. I’d now like to run this function on a long list of columns – indexed by c(5:7,11:12,15:16,20,27:29,32:33,38:42,45,50,55:64,72,77:93,99:100,107) to be specific. So I try: list1 <- c(5:7,11:12,15:16,20,27:29,32:33,38:42,45,50,55:64,72,77:93,99:100,107) sapply(list1, testScrMiss) Aaarrrrgghh! I get the following error: Problem in FUN(...X.sub.i....): Length of x (variable 2) is 5 != length of others (24151) Use traceback() to see the call stack
So I use traceback to see if I can figure out why S-Plus thinks that some variable is length 5. This turns out to be the number of columns in my original data.frame that I reference in the function – the dependent and independent variable in the fixed formula and the three nested levels in the random formula. Now if I run a familiar function like sqrt (remembering that I have a column of integer indices), list1 <- c(5:7,11:12,15:16,20,27:29,32:33,38:42,45,50,55:64,72,77:93,99:100,107) sapply(list1, sqrt) I get the expected outcome – a list of the square roots of my original list. Now I am suspecting that the latter works because the function sqrt is polymorphic, with different functions for a single integer and for a list of integers. But I have been flailing around, trying lots of different ways to get this thing to work, and I have not succeeded yet. So I am again asking for help.
Meanwhile I am going back to Tim Hesterbereg’s comments on scoping problems to see I can understand what is going on. Again, thanks to all for your repeated help.
Larry Hunsicker
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: Writing a function taking a data.frame column name as a parameter, Hunsicker, Lawrence |
|---|---|
| Next by Date: | Re: Writing a function taking a data.frame column name as a parameter, Steve Su |
| Previous by Thread: | Writing a function taking a data.frame column name as a parameter, Hunsicker, Lawrence |
| Next by Thread: | Re: sapply to automate doing a series ofparallel analyses, Steve Su |
| Indexes: | [Date] [Thread] [Top] [All Lists] |