pearselab / r-intro-jenessalemon

r-intro-jenessalemon created by GitHub Classroom
0 stars 1 forks source link

lesson_2 #12 #8

Open jenessalemon opened 7 years ago

jenessalemon commented 7 years ago

This problem starts on 266 @Wolflab: I tried thinking it out in English before I coded it. I went a LITTLE better, but my for loop is not iterating over each value in n, it is just returning a single 1 or a 0. Even for the one value that the function does return, I'm not sure that a 1 or a 0 gives us any information about abundance.

Wolflab commented 7 years ago

I'm looking

Wolflab commented 7 years ago

I see a couple of problems. Easy to fix. You are really close. In fact, it is better than mine. But first, let me see the English (pseudo) code. That will point to the problem.

jenessalemon commented 7 years ago

The pseudo code was commented in the code...maybe I need a better English version! Pseudo code: '''Bernoulli Distribution is a special case of the Binomial distribution where n = 1. Algorithm: Part 1. Need a function to simulate the probability that a species will be present at a site. I need a Binomial distribution with 1 draw, and varying probability.''' 'This returns a 1 if the species is present, and a 0 if it is not. Part 2: we need to write a function for abundance, but only if there is indeed, species present. So we probably need an if statement. The abundance shouldn't differ much from the presence function, except now we are sampling from a Poisson distribution, and also we need to evaluate at n sites (which should require a for loop).'''

Wolflab commented 7 years ago

That is just an English paragraph. Rewrite it with indents and brief statements

Your r code does not follow your English

P

Sent from my iPhone

On Nov 3, 2016, at 2:26 PM, jenessalemon notifications@github.com<mailto:notifications@github.com> wrote:

The pseudo code was commented in the code...maybe I need a better English version! Pseudo code: '''Bernoulli Distribution is a special case of the Binomial distribution where n = 1. Algorithm: Part 1. Need a function to simulate the probability that a species will be present at a site. I need a Binomial distribution with 1 draw, and varying probability.''' 'This returns a 1 if the species is present, and a 0 if it is not. Part 2: we need to write a function for abundance, but only if there is indeed, species present. So we probably need an if statement. The abundance shouldn't differ much from the presence function, except now we are sampling from a Poisson distribution, and also we need to evaluate at n sites (which should require a for loop).'''

You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/pearselab/r-intro-jenessalemon/issues/8#issuecomment-258263554, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACrBAMvyFawbl2RVk9t6S3KGIPkeAbXSks5q6kNcgaJpZM4Ko2-B.

jenessalemon commented 7 years ago

I'm not sure what you mean by that, and every time I try either my paragraph or my code comes out! :) Do you have an example of pseudo code? Here's my best guess:

Presence function random draw from biomial distribution return the draw

Abundance function for loop to iterate through each site if there is a species present at this site, draw from a poisson distribution if not, print out that there are no species in that location

Wolflab commented 7 years ago

Give me 10 minutes. Can't type on phone

Sent from my iPhone

On Nov 3, 2016, at 3:29 PM, jenessalemon notifications@github.com<mailto:notifications@github.com> wrote:

I'm not sure what you mean by that, and every time I try either my paragraph or my code comes out! :) Do you have an example of pseudo code? Here's my best guess:

Presence function random draw from biomial distribution return the draw

Abundance function for loop to iterate through each site if there is a species present at this site, draw from a poisson distribution if not, print out that there are no species in that location

You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/pearselab/r-intro-jenessalemon/issues/8#issuecomment-258279840, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACrBAAeqTjC7XsnlQ4vEgs5CrNrNgphqks5q6lJGgaJpZM4Ko2-B.

Wolflab commented 7 years ago

OK - Back in office. I will send you some example text in a few minutes then head home and stay online to help you all evening

OK?

Paul

From: jenessalemon notifications@github.com<mailto:notifications@github.com> Reply-To: pearselab/r-intro-jenessalemon reply@reply.github.com<mailto:reply@reply.github.com> Date: Thursday, November 3, 2016 at 3:29 PM To: pearselab/r-intro-jenessalemon r-intro-jenessalemon@noreply.github.com<mailto:r-intro-jenessalemon@noreply.github.com> Cc: Paul Wolf paul.wolf@usu.edu<mailto:paul.wolf@usu.edu>, Mention mention@noreply.github.com<mailto:mention@noreply.github.com> Subject: Re: [pearselab/r-intro-jenessalemon] lesson_2 #12 (#8)

I'm not sure what you mean by that, and every time I try either my paragraph or my code comes out! :) Do you have an example of pseudo code? Here's my best guess:

Presence function random draw from biomial distribution return the draw

Abundance function for loop to iterate through each site if there is a species present at this site, draw from a poisson distribution if not, print out that there are no species in that location

You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/pearselab/r-intro-jenessalemon/issues/8#issuecomment-258279840, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACrBAAeqTjC7XsnlQ4vEgs5CrNrNgphqks5q6lJGgaJpZM4Ko2-B.

Wolflab commented 7 years ago

OK, talking aloud first (I need a duck). I think your initial words are fantastic. But then I would do this. Please note that you have solved this more elegantly than I did.

You are doing this for n sites (n is an argument in your function). I did not do this - very good idea.

So you want to repeat across sites and output a list of abundance values (note that your code only returns one item.)

So:

Create function Initialize a vector of length n For each of n sites: If present: Calculate abundance and append to vector Else (absent) Add zero to vector (you want to include these in your calculation - right?) Return vector, which should be a list of all your abundances across n sites

See how I went from pure english paragraph (which is very helpful) to breaking down the problem into bite size pieces. Always dissect the problem as small as it will go

Let me know what you think. You could move on to another question and come back to this later. I find that is a much faster way to work. Less satisfying but I fix things faster when I come back after a break

Just an idea

Paul

From: jenessalemon notifications@github.com<mailto:notifications@github.com> Reply-To: pearselab/r-intro-jenessalemon reply@reply.github.com<mailto:reply@reply.github.com> Date: Thursday, November 3, 2016 at 3:29 PM To: pearselab/r-intro-jenessalemon r-intro-jenessalemon@noreply.github.com<mailto:r-intro-jenessalemon@noreply.github.com> Cc: Paul Wolf paul.wolf@usu.edu<mailto:paul.wolf@usu.edu>, Mention mention@noreply.github.com<mailto:mention@noreply.github.com> Subject: Re: [pearselab/r-intro-jenessalemon] lesson_2 #12 (#8)

I'm not sure what you mean by that, and every time I try either my paragraph or my code comes out! :) Do you have an example of pseudo code? Here's my best guess:

Presence function random draw from biomial distribution return the draw

Abundance function for loop to iterate through each site if there is a species present at this site, draw from a poisson distribution if not, print out that there are no species in that location

You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/pearselab/r-intro-jenessalemon/issues/8#issuecomment-258279840, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACrBAAeqTjC7XsnlQ4vEgs5CrNrNgphqks5q6lJGgaJpZM4Ko2-B.

jenessalemon commented 7 years ago

That's true it can definitely help to move on and then come back, as long as I don't just keep moving on and never coming back! Especially the day before the assignment is due. I think I totally see how to fix my code, I just need to store the values in a list somehow. I will figure it out and do another commit.

willpearse commented 7 years ago

If you would like, you can schedule office hours with me tomorrow morning.

On Thu, 3 Nov 2016 at 22:28 jenessalemon notifications@github.com wrote:

That's true it can definitely help to move on and then come back, as long as I don't just keep moving on and never coming back! Especially the day before the assignment is due. I think I totally see how to fix my code, I just need to store the values in a list somehow. I will figure it out and do another commit.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/pearselab/r-intro-jenessalemon/issues/8#issuecomment-258293124, or mute the thread https://github.com/notifications/unsubscribe-auth/ABLcUgYiVbhu6uX3gJc01COGYUzgb2C-ks5q6l_ygaJpZM4Ko2-B .

jenessalemon commented 7 years ago

12 works! Will, I may have to do that.