Xrystik
Xrystik

Reputation: 47

how to calculate the variance estimate of each row in r

I need to write a small program where I need to ask the user and enter the number of subintervals (2 or more). Divide the elements of the TT vector into a given number of connected, approximately equal subintervals. Calculate variance estimates on each subinterval. Display the results. Using the Bartlett criterion to test the hypothesis of equality of variances on all subintervals – with the alternative "not equal". The task is simple, but I do not know how to find out the variance estimate, at each interval and without a cycle. My code:

> TT
[1] 20.2 18.6 15.0 12.0 11.7 10.9  9.0 11.9 13.3  8.8  8.6  6.1  6.6  6.5 11.4
[16] 12.9  5.4  2.5  4.3  3.0

> n <- as.numeric(readline(prompt = "Enter court intervals: "))
Enter court intervals: 3
> n
[1] 3
> ints = split(TT, cut(seq_along(TT),n))
> ints
$`(0.981,7.33]`
[1] 20.2 18.6 15.0 12.0 11.7 10.9  9.0

$`(7.33,13.7]`
[1] 11.9 13.3  8.8  8.6  6.1  6.6

$`(13.7,20]`
[1]  6.5 11.4 12.9  5.4  2.5  4.3  3.0

And then I don't know how to calculate the variance estimate for each interval without a cycle

Upvotes: 0

Views: 110

Answers (1)

Julien
Julien

Reputation: 1694

If by "cycle", you mean a loop, use lapply:

variance <- lapply(ints, var) # Or sapply(ints, var) 

Upvotes: 1

Related Questions