Save a vector of model objects

25 views
Skip to first unread message

eitan lifshits

unread,
Mar 15, 2015, 4:13:46 AM3/15/15
to israel-r-...@googlegroups.com
Hi,
Is there a general way of keeping multiple similar models objects in a vector (like in C#)?
This, to be also applied for predictions as well.
Something like 

for(i in 1:100) {
data.bs = bootstrap(data)
ModelsVector[i] = Model (Response~., data.bs,...)
}

Thanks

Liad Shekel

unread,
Mar 15, 2015, 5:38:06 AM3/15/15
to Israel R User Group
list?

--
You received this message because you are subscribed to the Google Groups "Israel R User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-g...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
:-)

eitan lifshits

unread,
Mar 15, 2015, 5:52:26 AM3/15/15
to israel-r-...@googlegroups.com
You mean list of lists?
Can i use the function pred.model?
Can you give an example?


On Sunday, March 15, 2015 at 2:38:06 AM UTC-7, Liad wrote:
list?

On Sun, Mar 15, 2015 at 10:13 AM, eitan lifshits <eita...@gmail.com> wrote:
Hi,
Is there a general way of keeping multiple similar models objects in a vector (like in C#)?
This, to be also applied for predictions as well.
Something like 

for(i in 1:100) {
data.bs = bootstrap(data)
ModelsVector[i] = Model (Response~., data.bs,...)
}

Thanks

--
You received this message because you are subscribed to the Google Groups "Israel R User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-group+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
:-)

Liad Shekel

unread,
Mar 15, 2015, 6:26:02 AM3/15/15
to Israel R User Group
You can use any R object to replace lm1 (the lm object).

list_of_models <- vector("list", 100) 
​for (i in 1:100){
lm1 <- lm(y ~ x, subset = sample( ...whatever... ) )
list_of_models[i] <- lm1
}​

Then, you can use sapply to create lists based on the lm object):

list_of_models %>% sapply(function(x) x$fitted )
or 
list_of_models %>% sapply(function(x) predict(x) )

[[equivalent to sapply(list_of_models, function(x) predict(x) )]]



To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-g...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
:-)

eitan lifshits

unread,
Mar 15, 2015, 10:55:51 AM3/15/15
to israel-r-...@googlegroups.com
Thanks!
Just needed to add 
list_of_models[[i]] <- lm1
list?

To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-group+unsubscribe...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
:-)

--
You received this message because you are subscribed to the Google Groups "Israel R User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-group+unsub...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
:-)
Reply all
Reply to author
Forward
0 new messages