[R] How to generate table output of a series of lm's

Martin Elff elff at sowi.uni-mannheim.de
Tue Feb 5 16:16:52 CET 2008


On Tuesday 05 February 2008 (15:54:26), Daniel Dunn wrote:
> I have a related question.  Suppose I generate a series of linear models
>
> modco=list()
> modco[[length(modco)+1]]=lm(normskvop ~ I(nts^0.5)-1, data = colo,
> weights=wtz)
> modco[[length(modco)+1]]=lm(normskvop ~ I(nts^0.5)-1, data = colo,
> weights=wtz, subset=sector!="X")
> modco[[length(modco)+1]]=lm(normskvop ~ I(nts^0.5)-1, data = colo,
> weights=wtz, subset=sector!="A")
> modco[[length(modco)+1]]=lm(normskvop ~ I(nts^0.5)-1, data = colo,
> weights=wtz, subset=sector=="A")
> modco[[length(modco)+1]]=lm(normskvop ~ I(nts^0.5)-1, data = colo,
> weights=wtz, subset=sector=="M")
>
> I would like to have a table of the coefficients (including the t value &
> the Pr(>|t|) value) of the five models akin to Peter Dalgaard's elegant
> "sapply(t,unlist)" solution below.
>

If I am not mistaken, what you want is the following:

modco <- list(
	lm(normskvop ~ I(nts^0.5)-1, data = colo,weights=wtz),
	lm(normskvop ~ I(nts^0.5)-1, data = colo,weights=wtz, subset=sector!="X"),
	lm(normskvop ~ I(nts^0.5)-1, data = colo,weights=wtz, subset=sector!="A"),
	lm(normskvop ~ I(nts^0.5)-1, data = colo,weights=wtz, subset=sector=="A"),
	lm(normskvop ~ I(nts^0.5)-1, data = colo,weights=wtz, subset=sector=="M")
	)

sapply(modco,function(x) coef(summary(x)))

Best,

Martin



More information about the R-help mailing list