[R] Issues when trying to fit a curve when generating random deviates
Daniel Nordlund
djnord|und @end|ng |rom gm@||@com
Mon Sep 19 08:16:49 CEST 2022
On 9/18/2022 9:44 PM, Rui Barradas wrote:
> Hello,
>
> I cannot reproduce the error.
>
> Anyway, if the data is discrete a bar plot might be more appropriate.
>
>
> barplot(table(x),
> col = "green",
> main = "Bar plot of Binomial Distribution B(20,0.4)")
>
>
> Or, to have proportions,
>
> barplot(table(x)/length(x), etc)
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 05:01 de 19/09/2022, Paul Bernal escreveu:
>> Dear friends,
>>
>> Hope you are doing great.
>>
>> I first generated random deviates from a binomial distribution with the
>> following code (I had to generate from a B(20,0.4) dist):
>> #Setting seed
>> set.seed(1234567)
>>
>> #Generating 1000 random deviates from a B(20,0.4) Distribution
>> x <- rbinom(1000,20,0.4)
>> #Generating histogram for x
>> hist(x, col = c("green"),main="Histogram of Binomial Distribution
>> B(20,0.4)",freq=F)
>> #Generating the curve for x
>> There were 50 or more warnings (use warnings() to see the first 50)
>> warnings()
>> #the first 5 warnings are shown, but all the warnings are similar
>> Warning messages:
>> 1: In dbinom(x, 1000, 0.4) : non-integer x = 2.120000
>> 2: In dbinom(x, 1000, 0.4) : non-integer x = 2.240000
>> 3: In dbinom(x, 1000, 0.4) : non-integer x = 2.360000
>> 4: In dbinom(x, 1000, 0.4) : non-integer x = 2.480000
>> 5: In dbinom(x, 1000, 0.4) : non-integer x = 2.600000
>> and the curve was not generated for the histogram.
>>
>> Any ideas on what I could be doing wrong?
>>
>> Best regards,
>>
>> Paul
>>
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help using r-project.org 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.
>
> ______________________________________________
> R-help using r-project.org 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.
Paul,
I don't see the code you used to generate the curve. What kind of curve
are you trying to plot, and why are you trying to plot that curve? As
Rui suggested, it typically doesn't make sense to use line plots to
represent discrete data. If you explain what your end goal is, someone
may be able to provide better help.
Dan
--
Daniel Nordlund
Port Townsend, WA USA
--
This email has been checked for viruses by Avast antivirus software.
www.avast.com
More information about the R-help
mailing list