There is histfit function in Matlab would plot histogram and fit the distribution by bin values.
The distribution's parameters have to be estimated.
How to implement histfit in r? I searched for a long time, but it has no lucky.
This post have mentioned this before, but there is no preferable solution. The sn package seems support several distribution, not so much.
I explore the data with hist function, the histogram shows gamma distribution in gerneral.
But if I add up bins and show it again, the graph will show more details, and gamma distribution fails.
fitdistr would fail to find parameters also.
so I want to fit the data just using the coarse data from histogram. This is the question, thank you for your help.
The fitdistr function in the MASS package can be used to find parameters for a given distribution (including gamma). The function density and the logspline package (and others) can be used to estimate the density function of the data without assuming a specific distribution.
The lines and curve functions can be used to add an estimated density curve to a plotted histogram (use prob=TRUE when creating the histogram).
If you want to compare your data to a specific distribution then tools like qqplots (qqplot function or others) or visual tests (vis.test in the TeachingDemos package) will probably be better than a histogram and density plot.
I have to answer it myself, package 'bda' could fit the binned data in several distributions, however it could only binning data by rounding.
Related
Is there a way to produce plots with gratia that have the y-axis on the response variable scale similar to the scale="response" visreg function? I know scale is already an option for the y-axis in gratia, but just for axis range and not transforming the variable.
Thinking of something like:
draw(mymodel, type="response")?
This is a current feature request for the package: https://github.com/gavinsimpson/gratia/issues/79
If I ever surface from creating content for two new courses this semester adding this is a top priority for me.
Currently the best I can suggest is to evaluate the smooth using evaluate_smooth(), then use mutate() to apply the inverse of the link function to the estimated value and the confidence interval, and then use the draw() method for those objects to produce the plot, with cowplot or patchwork to plot multiple plots on a single page/device.
I have a vector which I have made a density function for. It is a curve with multiple peaks, and I want to perform a Gaussian deconvolution in order to represent my density curve with multiple Gaussian curves. I am hoping there is a package that will allow me to do this, but I haven't found anything that has worked for me so far. I tried to follow the example given here (https://www.r-bloggers.com/fitting-mixture-distributions-with-the-r-package-mixtools/) but the vector I am working with is ~400 mb and won't play nicely with the mixtools package tools. I need something that will work with the size of the datasets I am working with or be able to work with the density curve directly. Any help appreciated, thank you!
I do not have sample data but I am happy to have it explained with the faithful dataset in R, I know I can find the density of faithful$waiting with density(faithful$waiting) and it plots just fine, but the deconvolution has me stuck.
How does one reproduce this figure from Elements of Statistical Learning page 166?
I understand that a regression is fit to the data using age and obesity as features. But I am wondering how to represent the fitted surface using contours as is shown in the figure. I would prefer an R implementation because I believe that is what was used in this case.
I have some data which I would like to fit with a model. For this example we have been using LOESS smoothing (<1.000 observations). We applied LOESS smoothing using the geom_smooth() function from the ggplot package. So far, so good.
The next step was to acquire a first derivative of the smoothed curve, and as far as we know this is not possible to extract from geom_smooth(). Thus, we sought to manually create our model using loess() and use this to extract our first derivative from this.
Strangely however, we observed that the plotted geom_smooth() curve is different from the manually constructed loess() curve. This can be observed in the figure which is shown underneath; in red the geom_smooth() and in orange the loess() function.
If somebody would be interested, a minimal working reproducible example can be found here.
Would somebody be able to pinpoint why the curves are different? Is this because of the optimization settings of both curves? In order to acquire a meaningful derivative we need to ensure that these curves are identical.
I'm not sure if that's the right terminology.
I've entered some data into R, and I've put a smooth.spline through it using the following command.
smoothingSpline = smooth.spline(year, rate, spar=0.35)
plot(x,y)
lines(smoothingSpline)
Now I'd like to measure some limits (or where the curve is at a given x point), and maybe do some predictive analysis on points that extend beyond the graph.
Are there commands in R for measuring (or predicting) the points along a curve?
Is ?predict.smooth.spline what you are looking for?