need help calculating the indicator function

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

need help calculating the indicator function

Ablaye Ngalaba
Hello,
please, I need to calculate the indicator function as I underlined in my
attached pdf file but I can't define a code in programming language that
deals with this case. Please help me with a code whether it's in python or
R can help me.



   Sincerely.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.

code algo test.pdf (194K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: need help calculating the indicator function

Bert Gunter-2
Is this a homework problem? The posting guide linked below explicitly says:

"*Basic statistics and classroom homework:* R-help is not intended for
these."



Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Jan 29, 2021 at 2:20 PM Ablaye Ngalaba <[hidden email]>
wrote:

> Hello,
> please, I need to calculate the indicator function as I underlined in my
> attached pdf file but I can't define a code in programming language that
> deals with this case. Please help me with a code whether it's in python or
> R can help me.
>
>
>
>    Sincerely.
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: need help calculating the indicator function

David Winsemius
In reply to this post by Ablaye Ngalaba
Perhaps (in R):


n_i <- cumsum( Y==l )


You should read further regarding R's logical class, and operators that
work on it, and how it is coerced.

--

David

On 1/29/21 6:27 AM, Ablaye Ngalaba wrote:

> Hello,
> please, I need to calculate the indicator function as I underlined in my
> attached pdf file but I can't define a code in programming language that
> deals with this case. Please help me with a code whether it's in python or
> R can help me.
>
>
>
>     Sincerely.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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]]

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: need help calculating the indicator function

Rui Barradas
In reply to this post by Ablaye Ngalaba
Hello,

Maybe this?

n_l <- function(Y, l, na.rm = FALSE) sum(Y == l, na.rm = na.rm)

set.seed(2020)
q <- 6
y <- sample(q, 10, TRUE)

l <- 4
n_l(y, l)
#[1] 3


Hope this helps,

Rui Barradas


Às 14:27 de 29/01/21, Ablaye Ngalaba escreveu:

> Hello,
> please, I need to calculate the indicator function as I underlined in my
> attached pdf file but I can't define a code in programming language that
> deals with this case. Please help me with a code whether it's in python or
> R can help me.
>
>
>
>     Sincerely.
>
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: need help calculating the indicator function

Rui Barradas
Hello,

Please cc the list, R-Help is threaded and your doubt and answers might
be of interest to others.

With a vector Y, you want 0 in all Y != l and 1 in all Y == l?


n_l <- function(Y, l) as.integer(Y == l)


Hope this helps,

Rui Barradas

Às 11:26 de 30/01/21, Ablaye Ngalaba escreveu:

> Hello Rui,
> thank you for answering me.
> I compiled your code, it's true that it works but it still gives the
> value "3". What I want is to find either 1 if Y==l or 0 in case y
> differs from l.
>
>
> Good day
>
> Le sam. 30 janv. 2021 à 10:42, Ablaye Ngalaba <[hidden email]
> <mailto:[hidden email]>> a écrit :
>
>     Thanks.
>
>     Le sam. 30 janv. 2021 à 05:38, Rui Barradas <[hidden email]
>     <mailto:[hidden email]>> a écrit :
>
>         Hello,
>
>         Maybe this?
>
>         n_l <- function(Y, l, na.rm = FALSE) sum(Y == l, na.rm = na.rm)
>
>         set.seed(2020)
>         q <- 6
>         y <- sample(q, 10, TRUE)
>
>         l <- 4
>         n_l(y, l)
>         #[1] 3
>
>
>         Hope this helps,
>
>         Rui Barradas
>
>
>         Às 14:27 de 29/01/21, Ablaye Ngalaba escreveu:
>          > Hello,
>          > please, I need to calculate the indicator function as I
>         underlined in my
>          > attached pdf file but I can't define a code in programming
>         language that
>          > deals with this case. Please help me with a code whether it's
>         in python or
>          > R can help me.
>          >
>          >
>          >
>          >     Sincerely.
>          >
>          >
>          > ______________________________________________
>          > [hidden email] <mailto:[hidden email]> mailing
>         list -- To UNSUBSCRIBE and more, see
>          > 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.
>          >
>

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.