0

What I entered in the console (alp, DF1, DF2 are defined):

    LT <- left.tail=FALSE
    q <- qf(alp, DF1, DF2, LT)
    q

What I got:

     LT <- left.tail=FALSE
     Error in LT <- left.tail = FALSE : could not find function "<-<-"
     > q <- qf(alp, DF1, DF2, LT)
     > q
     [1] 0.4490486

The answer I am looking for is 2.22, which I get when the Lower Tail is defined as false.

Why is it telling me that "<-<-" is not avaible, I did not write this function? And is there a way to store a TRUE/ FALSE value for lower.tail?

For further explanation, I am trying to write a code where I simply have to enter the values on the top and get the answer out of it:

data.entry(1)


a1 <- mean(var2)
v1 <- var(var2)
SD1 <- sd(var2)
n1 <- max(n)
a2 <- mean(var3)
v2 <- var(var3)
SD2 <- sd(var3)
n2 <- max(n)

int <- 1-0.9 #given interval
LT <- FALSE #Right Tailed- H1: >/ =/=
TT <- 0 #Two Tailes- H1: = / =/=

alp.O <- 0.1 #Given Alpha 
alp <- alp.O/(1+TT)
DF1 <- n1 - 1
DF2 <- n2 -1
q <- qf(alp, DF1, DF2, left.tail=LT) #ALP, DF1, DF2
f <- q-2*q*RT #t-Critical Value - Rejection Level
F <-  v1/v2 #Parameter of Interest1 / Parameter of Interest2
  
print(F==f)

print(F>f)

print(F<f)

It's not done yet and there are some residuals from older code, please ignore them.

  • 1
    Maybe you want `LT <- left.tail==FALSE`, which is `LT <- !left.tail` or use `LT <- left.tail <- FALSE` if it is what you want – Clemsang Feb 04 '22 at 15:45
  • You need to do `LT = FALSE` and use it within the `qf` function. you do not need the `left.tail` – Onyambu Feb 04 '22 at 16:33

3 Answers3

2

This looks to me like a parser oddity in R. The expression

 LT <- left.tail=FALSE

is parsed as

 (LT <- left.tail) = FALSE

which is the same as

 `<-`(LT, left.tail) = FALSE

which is the same as

 `<-<-`(LT, left.tail, FALSE)

which is where your error message came from.

I call this an oddity, because I would have expected it to be parsed the same as

LT <- left.tail <- FALSE

which assigns FALSE to left.tail and then to LT.

user2554330
  • 37,248
  • 4
  • 43
  • 90
0

In R, you can assign using 2 different operators: <- and =.

That is, if you want to assign the value of 3 to the variable x, you can write either x<-3 or x=3.

When you write: LT <- left.tail=FALSE, instead of testing whether left.tail is FALSE (which you'd do with the comparison operator ==) you're setting up a double assignment – that is, assigning the value FALSE to left.tail and LT. You can actually do that if you use the same operator: x=y=4 or k<-d<-5 both work as expected. If you mix these operators, though, you get an error.

I'm not exactly sure what is going on behind the scenes to generate the function <-<-, but I do know it's a result of R trying to deal with combining the 2 different assignment operators in a single expression. If you do want to do the double assignment, just use the same operator:

LT <- left.tail <- FALSE

In your case, I don't think you want to do a double assignment. Likely, you want to test if left.tail is FALSE, and store that result in LT. You can do that in a few ways:

# Tests for only FALSE values
LT <- left.tail==FALSE
LT <- isFALSE(left.tail)

# Tests for "falsy" values like 0
LT <- !left.tail
divibisan
  • 11,659
  • 11
  • 40
  • 58
  • What exactly do you mean by `falsy`? if `left.tail` is already `FALSE` then just `LT <- !left.tail` Note that `0` is indeed FALSE. ie check `0 == FALSE` which is done through implicit coercion. OP wants to assign and not compare. read through the question please – Onyambu Feb 04 '22 at 16:31
  • @Onyambu "Falsy" means values that evaluate to false but are not themselves false. `isFALSE(left.tail) ` only returns TRUE if `left.tail` is actually the logical value FALSE, wheras `!left.tail` will return TRUE for other values like 0. The choice depends on the specific needs of their program. And from their question, it's certainly not clear where the typo is: do they want to assign to both, or compare – divibisan Feb 04 '22 at 18:08
0

The correct way to do this is

qf(p = alp, df1 = DF1, df2 = DF2, lower.tail = FALSE)

Note that qf(alp, DF1, DF2, FALSE) passes FALSE to the fourth argument of qf(), which is ncp and not lower.tail.

Thierry
  • 18,049
  • 5
  • 48
  • 66