# Re: [R] Applying lm to data with combn

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Fri, 8 Feb 2008 15:56:47 -0200

I think what you want is this:

lapply(apply(combn(5, 4), 2, function(x)mD[,x]), function(x)lm(X.SSMII ~ ., data=x))

On 08/02/2008, AliR <aaliraja_at_gmail.com> wrote:
>
> http://www.nabble.com/file/p15359204/test.data.csv
> http://www.nabble.com/file/p15359204/test.data.csv test.data.csv
>
> Hi,
>
> I have used apply to have certian combinations, but when I try to use these
> combinations I get the error
> [Error in eval(expr, envir, enclos) : object "X.GDAXI" not found]. being a
> novice I donot understand that after applying combination to the data I cant
> access it and use lm on these combinations. The data frame either is no
> longer a matrix, how can I access the data and make it work for lm!!
>
>
>
>
>
>
>
> matrix format
>
>
> mD =head(fruit[, 1:5])# only first five used in combinations
> #X.SSMII = head(fruit[, 6])# Keep it for referebce
> nmax = NULL
> n = ncol(mD)# dont take the last column for reference purpose
> if(is.null(nmax)) nmax = n
>
> mDD = apply(combn(5, 1),1, FUN= function(y) mD[, y])# to
>
>
>
> fg = lm( X.SSMII ~ X.GDAXI + X.FTSE + X.FCHI + X.IBEX, data = mDD )#
> regress on combos
>
> s = cbind(s, Residuals = residuals(fg))# take residuals
>
> print(mD)
>
> --
> View this message in context: http://www.nabble.com/Applying-lm-to-data-with-combn-tp15359204p15359204.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> and provide commented, minimal, self-contained, reproducible code.
>

```--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help