[R] creating a loop for a function

R. Michael Weylandt michael.weylandt at gmail.com
Thu Oct 6 21:06:42 CEST 2011


To see what sort of things are available from Box.test() (and most
everything else), hit ?Box.test and scroll down to "Value". There's
actually more but its not called so frequently in my experience

Michael

On Thu, Oct 6, 2011 at 3:04 PM, upananda pani <upananda.pani at gmail.com> wrote:
> Respected Sir,
> I am grateful to you for helping me out. Earlier i used to directly the
> formula without calling for statstic, parameter or p-value. As i am learning
> R first time, i can see how deep i have to go to learn it.
> With regards,
> Upananda
>
> On Fri, Oct 7, 2011 at 12:00 AM, R. Michael Weylandt
> <michael.weylandt at gmail.com> wrote:
>>
>> Well you said you wanted statistics from the test, but you didn't say
>> which statistics you wanted: any of the following would work:
>>
>> sapply(1:10, function(i) Box.test (lfut, lag = i, type="Ljung")$statistic)
>> sapply(1:10, function(i) Box.test (lfut, lag = i, type="Ljung")$parameter)
>> sapply(1:10, function(i) Box.test (lfut, lag = i, type="Ljung")$p.value)
>>
>> "extractor" wasn't quite the right word, but more or less that's the
>> idea (if you happen to know it from other programming contexts).
>>
>> Michael
>>
>>
>> On Thu, Oct 6, 2011 at 1:43 AM, upananda pani <upananda.pani at gmail.com>
>> wrote:
>> > Respected Sir,
>> > I am grateful to you for your reply. This is working perfectly fine. I
>> > do
>> > not know how to add extractors. Please give me one example with this
>> > function.
>> > With regards,
>> > Upananda
>> >
>> > On Thu, Oct 6, 2011 at 1:04 AM, R. Michael Weylandt
>> > <michael.weylandt at gmail.com> wrote:
>> >>
>> >> lapply(1:10, function(i) Box.test (lfut, lag = i, type="Ljung"))
>> >>
>> >> Add extractors to get statistics as desired.
>> >>
>> >> Michael Weylandt
>> >>
>> >> On Wed, Oct 5, 2011 at 1:09 PM, upananda pani <upananda.pani at gmail.com>
>> >> wrote:
>> >> > Dear All,
>> >> >
>> >> > I want to create a loop within a function r. The example follows:
>> >> >
>> >> > Box.test (lfut, lag = 1, type="Ljung")
>> >> >
>> >> > if i want to compute the Box.test for lag 1 to 10, I have to write
>> >> > manually
>> >> >  change each time for different lag. So i wan to write a loop for the
>> >> > lag 1
>> >> > to 10 and return the statistics for each lag. Is there any method to
>> >> > do
>> >> > this
>> >> > ?
>> >> >
>> >> > With regards,
>> >> > Upananda
>> >> >
>> >> > --
>> >> >
>> >> >
>> >> > You may delay, but time will not.
>> >> >
>> >> >
>> >> > Research Scholar
>> >> > alternative mail id: upani at iitkgp.ac.in
>> >> > Department of HSS, IIT KGP
>> >> > KGP
>> >> >
>> >> >        [[alternative HTML version deleted]]
>> >> >
>> >> > ______________________________________________
>> >> > R-help at 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.
>> >> >
>> >
>> >
>> >
>> > --
>> >
>> >
>> > You may delay, but time will not.
>> >
>> >
>> > Research Scholar
>> > alternative mail id: upani at iitkgp.ac.in
>> > Department of HSS, IIT KGP
>> > KGP
>> >
>> >
>
>
>
> --
>
>
> You may delay, but time will not.
>
>
> Research Scholar
> alternative mail id: upani at iitkgp.ac.in
> Department of HSS, IIT KGP
> KGP
>
>



More information about the R-help mailing list