The first thing I'd mention is that *apply are really just well implemented
loops themselves so you can't expect true magic from them. However, if you
really want to use them rather than just a regular loop (which seems more
intuitive for a request like this), this might do what you are looking for.

TwoRegs <- function(splitIndx, Variates) {
    Vars1 = Variates[(1:splitIndx)]; m1 = lm(Vars1 ~ 1)
    if(splitIndx != length(x)) {Vars2 = Variates[-(1:splitIndx)]; m2 =
lm(Vars2 ~ 1)}

    if(splitIndx != length(x)) list(FirstPart = m1, SecondPart = m2) else m1
}

lapply(seq_along(x),  TwoRegs, x) # where x is your data

You probably need to use a list object if you want to hold on to the entire
lm regression object and I believe this precludes any use of sapply of
lapply, but if you are only interested in certain characteristics of the
regression, you can extract them within the TwoRegs function. Here I've used
the lapply framework to index over the length of x which seems to give what
you were asking for.

Does this help?

Michael Weylandt



On Tue, Sep 13, 2011 at 12:42 PM, Trying To learn again <
tryingtolearnagain@gmail.com> wrote:

> Hi Michael,
>
> First of all thanks for your response.
>
> I do know that if I make my stimation on a single data the regression has
> no sense but it will be getting sense in the growing next estimations.
>
> I change my asking doubt.
>
> I want to use this regressions as a first filter. Only this.
>
> Can anyone send information or webpages related with the use of mapply,
> sapply (so that one can avoid loops)
>
> Receive my apologuises if again my questions are too simple.
>
>
> 2011/9/12 R. Michael Weylandt <michael.weylandt@gmail.com>
>
>> I may be totally off base with this, but I'm wondering what exactly this
>> would suggest or why you want to do it. Specifically "multiple regression
>> with only intercept" -- how is it multiple if you don't have any regressors?
>> Furthermore, you want to run a "regression" on a single data point --
>> really?
>>
>> Best I can figure, an "intercept-only" regression is basically just the
>> mean of the data (if you have no variates, your best estimate as to the mean
>> of what you'll see is, well, just the mean [plus or minus some stuff about
>> the median we'll ignore here]....) If I'm right about this, use of the lm()
>> function is far more powerful than you actually need and a simple cumulative
>> rolling mean, in conjunction with the rev() function, will suffice.
>>
>> Maybe you could say more about this odd request and we could provide a
>> little more guidance,
>>
>> Michael Weylandt
>>
>> On Mon, Sep 12, 2011 at 10:20 AM, Trying To learn again <
>> tryingtolearnagain@gmail.com> wrote:
>>
>>> Hi all,
>>>
>>> I have a time series a column vector with the ordered data so that the
>>> first
>>> column is the first observation and so on.
>>>
>>> The fact is that I want to run a multiple regression with only intercept.
>>>
>>> My first task is to run the regression on the first observation (1 from
>>> 276)
>>> and at the same time the same type of regressión on the 275 data.
>>>
>>> Then, is to run a regression on 2 of the data (the first and the second
>>> observation) and other with the 274 rest of observations....
>>>
>>> ...
>>>
>>> The final tram of the loop would the to run 1 regression with the 275
>>> first
>>> observations and one with the last observation.
>>>
>>> I want to save each pair of regression made in each loop.
>>>
>>> I have seen that the regression I want is
>>>
>>> data˜1
>>>
>>> But how Shoud I use mapply or sapply? To run avoind using loops?
>>>
>>> Thanks in advance¡¡¡
>>>
>>> Hope someone can send me examples similar o documents to try to make by
>>> my
>>> own.
>>>
>>> I attach the data.
>>>
>>> ______________________________________________
>>> 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]]

