You came close. Here is how it might be done:
individual <- rep(c(1,1,6,8,8,9,9,9,12,12),2) day <- rep(c(4,17,12,12,17,3,9,22,13,20),2) condition <- rep(c(0.72, 0.72, 0.67, 0.73, 0.76, 0.65, 0.68, 0.78, 0.73, 0.71),2) test <- data.frame(individual, day, condition) #ind.id <- unique(test$individual) #ind.list <- lapply(1:length(ind.id), function(i){ subset(test, test$individual==ind.id[i])}) #lms <- lapply(ind.list, lm, formula=condition~day) require(plyr) func1 <- function(...) { lm(condition~day, data = test) } lms <- lapply(1:10, func1) lms func2 <- function(fit) { F <- (summary(fit))$fstatistic P <- 1-pf(F[1], F[2],F[3]) # notice how we must calculate the p-value data.frame(r.squared = summary(fit)$r.squared, p.value = P) } ldply(lms, func2) ----------------Contact Details:------------------------------------------------------- Contact me: tal.gal...@gmail.com | 972-52-7275845 Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) | www.r-statistics.com (English) ---------------------------------------------------------------------------------------------- On Sun, Apr 29, 2012 at 9:04 AM, Kristi Glover <kristi.glo...@hotmail.com>wrote: > > Hello R User, > I was trying to display r.squared and p value in table from regression, > but I could not display these parameters in the table (matrix) > > for example > individual <- c(1,1,6,8,8,9,9,9,12,12) > day <- c(4,17,12,12,17,3,9,22,13,20) > condition <- c(0.72, 0.72, 0.67, 0.73, 0.76, 0.65, 0.68, 0.78, 0.73, 0.71) > test <- data.frame(individual, day, condition) > ind.id <- unique(test$individual) > ind.list <- lapply(1:length(ind.id), function(i){ subset(test, > test$individual==ind.id[i])}) > lms <- lapply(ind.list, lm, formula=condition~day) > ldply(lms, function(x) x$coefficients) > here I can display coefficients, here I need to write code for r2.squared > > I tried with following script > > summary(ldply(lms, function(x) )$r.squared, $p value) > but it did not work. > > can any one help me? > > thanks > Kristi > > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@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. > [[alternative HTML version deleted]] ______________________________________________ R-help@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.