best fitting curve from plot in R

后端 未结 2 1893
一向
一向 2021-01-20 12:16

I have a probability density function in a plot called ph that i derived from two samples of data, by the help of a user of stackoverflow, in this way

 few &         


        
相关标签:
2条回答
  • 2021-01-20 12:36

    Assuming you mean that you want to perform a curve fit to the data in ph, then something along the lines of nls(FUN, cbind(ph$counts, ph$mids),...) may work. You need to know what sort of function 'FUN' you think the histogram data should fit, e.g. normal distribution. Read the help file on nls() to learn how to set up starting "guess" values for the coefficients in FUN.

    If you simply want to overlay a curve onto the histogram, then smoo<-spline(ph$mids,ph$counts); lines(smoo$x,smoo$y)

    will come close to doing that. You may have to adjust the x and/or y scaling.

    0 讨论(0)
  • 2021-01-20 12:44

    Do you want a density function?

    x = rnorm(1000)
    hist(x, breaks = 30, freq = FALSE)
    lines(density(x), col = "red")
    
    0 讨论(0)
提交回复
热议问题