In R, I can fit a Probability Density Function to some empirical data using the following code:  energy &lt;- rnorm(30) * 20 dens &lt;- density(energy) sum(dens$y)*diff(dens$x[1:2]) hist(energy,probability=TRUE) lines(density(energy),col="red")   This produces the following graph of the Probability Density Function (PDF):    Howevever, I would like to fit a student-t distribution to this data instead. I'm wondering if its possible to do this and if its possible to plot the result like in the diagram above?
122165
The data I am using can be found here:  The variable is called "alvsloss".  I want to fit a distribution to my financial data. First of all, I started with a normal distribution.  The pdf is given by:  $\frac{1}{\sqrt{2\pi\sigma^2}}\operatorname{exp}\left\{-\frac{\left(x-\mu\right)^2}{2\sigma^2}\right\}$  and the log likelihood, which is to be maximized is given by  $  \ln\mathcal{L}(\mu,\sigma^2) = \sum_{i=1}^n \ln f(x_i;\,\mu,\sigma^2) = -\frac{n}{2}\ln(2\pi) - \frac{n}{2}\ln\sigma^2 - \frac{1}{2\sigma^2}\sum_{i=1}^n (x_i-\mu)^2. $  which gives as a solution  $   \hat{\mu} = \overline{x} \equiv \frac{1}{n}\sum_{i=1}^n x_i, \qquad \hat{\sigma}^2 = \frac{1}{n} \sum_{i=1}^n (x_i - \overline{x})^2. $  I can calculate this in R via mean(alvsloss) and sd(alvsloss) and get the values -0.0004270872 and 0.02304159 or I do   library(MASS) fitdistr(alvsloss, "normal")   and get the solution         mean             sd         -0.0004270872    0.0230371244   ( 0.0004535429) ( 0.0003207033)   Ok, I understand this. But now my problem arises, I tried this with the t distribution. The pdf is given by:  $\textstyle\frac{\Gamma \left(\frac{\nu+1}{2} \right)} {\sqrt{\nu\pi}\,\Gamma \left(\frac{\nu}{2} \right)} \left(1+\frac{x^2}{\nu} \right)^{-\frac{\nu+1}{2}}\!$  the log likelihood can be found here:  formula (17.8) (x is denoted by $\epsilon$. I am not understanding where the $h_i$ comes from in the formula, but this is not my main question.)  First question: Seems to me, that there is no closed form solution?  Second question: I do fitdistr(alvsloss, "t")  and get the output    m               s               df         -0.0004919768    0.0130128873    2.6340459185   ( 0.0003182568) ( 0.0003453702) ( 0.1620424078) Es gab 28 Warnungen (Anzeige mit warnings())   I am not understanding, why I have three parameters now? The df is the $\nu$, but the others? What is R doing? Since there is no closed form solution, I guess it is using a iterated algorithm? Should I bother about the 28 warnings? They are:  Warnmeldungen:  1: In dt((x - m)/s, df, log = TRUE) : NaNs wurden erzeugt 2: In dt((x - m)/s, df, log = TRUE) : NaNs wurden erzeugt 3: In dt((x - m)/s, df, log = TRUE) : NaNs wurden erzeugt 4: In dt((x - m)/s, df, log = TRUE) : NaNs wurden erzeugt 5: In dt((x - m)/s, df, log = TRUE) : NaNs wurden erzeugt 6: In dt((x - m)/s, df, log = TRUE) : NaNs wurden erzeugt 7: In dt((x - m)/s, df, log = TRUE) : NaNs wurden erzeugt 8: In log(s) : NaNs wurden erzeugt 9: In log(s) : NaNs wurden erzeugt 10: In log(s) : NaNs wurden erzeugt 11: In log(s) : NaNs wurden erzeugt 12: In log(s) : NaNs wurden erzeugt 13: In log(s) : NaNs wurden erzeugt 14: In log(s) : NaNs wurden erzeugt 15: In log(s) : NaNs wurden erzeugt 16: In log(s) : NaNs wurden erzeugt 17: In dt((x - m)/s, df, log = TRUE) : NaNs wurden erzeugt 18: In log(s) : NaNs wurden erzeugt 19: In log(s) : NaNs wurden erzeugt 20: In dt((x - m)/s, df, log = TRUE) : NaNs wurden erzeugt 21: In dt((x - m)/s, df, log = TRUE) : NaNs wurden erzeugt 22: In dt((x - m)/s, df, log = TRUE) : NaNs wurden erzeugt 23: In log(s) : NaNs wurden erzeugt 24: In log(s) : NaNs wurden erzeugt 25: In log(s) : NaNs wurden erzeugt 26: In log(s) : NaNs wurden erzeugt 27: In log(s) : NaNs wurden erzeugt 28: In log(s) : NaNs wurden erzeugt   And how can I plot this distribution with the estimated parameters?
49544
The data I'm working with are highly skewed, with the vast majority of data concentrated at 0. It seems really hard to highlight the differences between these kind of distributions:  gamma1 &lt;- rgamma(10000, shape=0.05, rate=1) gamma2 &lt;- rgamma(10000, shape=0.055, rate=0.98) gamma3 &lt;- rgamma(10000, shape=0.06, rate=0.95)  c(mean(gamma1), mean(gamma2), mean(gamma3))  [1] 0.04845668 0.05253655 0.05797983  ks.test(gamma1, gamma2)   Two-sample Kolmogorov-Smirnov test    data:  gamma1 and gamma2     D = 0.0433, p-value = 1.44e-08     alternative hypothesis: two-sided  ks.test(gamma2, gamma3)   Two-sample Kolmogorov-Smirnov test   data:  gamma2 and gamma3    D = 0.0456, p-value = 1.864e-09    alternative hypothesis: two-sided    ks.test(gamma1, gamma3)  Two-sample Kolmogorov-Smirnov test   data:  gamma1 and gamma3    D = 0.0798, p-value &lt; 2.2e-16    alternative hypothesis: two-sided   As most of the data is at 0, histograms are not very helpful for seeing the differences between the distributions (not to mention the fact there doesn't seem to be a convenient way to plot a histogram with multiple distributions in R, see ):    Violin plots seem to misrepresent the shape of the distributions (they look a lot more normal-like than they really are) and since the means are very low, the boxes are almost invisible:    Since these plot aren't really showing anything useful, I was wondering if there is a better way to visualise skewed distributions?
34295
Basically, I'm just trying to plot a curve over my histogram for the weight of a few students.   lines(density(weight), lwd = 2, col = "red")   However, what I get is a line on the bottom of the graph. I suppose the density has to be such that the integral of the curve is 1. What command should I be using instead of density, if I want to have a fitting curve for the histogram?
29256
Inspired by my other , I would like to ask how does one find the mode of a probability density function (PDF) of a function $f(x)$?  Is there any "cook-book" procedure for this? Apparently, this task is much more difficult than it seems at first.
114991
I have a data set with following structure:  a word | number of occurrence of a word in a document | a document id    How can I perform a test for normal distribution in R? Probably it is an easy question but I am a R newbie.
29152
For a simulation study I have to generate random variables that show a predefined (population) correlation to an existing variable $Y$.  I looked into the R packages copula and CDVine which can produce random multivariate distributions with a given dependency structure. It is, however, not possible to fix one of the resulting variables to an existing variable.  Any ideas and links to existing functions are appreciated!  &nbsp;  Conclusion: Two valid answers came up, with different solutions:   An R  by caracal, which calculates a random variable with an exact (sample) correlation to a predefined variable An R  I found myself, which calculates a random variable with a defined population correlation to a predefined variable     [@ttnphns' addition: I took the liberty to expand the question title from single fixed variable case to arbitrary number of fixed variables; i.e. how to generate a variable having predefined corretation(s) with some fixed, existing variable(s)]
103658
I want to fit lognormal distribution to my data, using python scipy.stats.lognormal.fit. According to the , fit returns shape, loc, scale parameters. But, lognormal distribution normally needs only : mean and standard deviation.  How to interpret the results from scipy fit function? How to get mean and standard deviation?
105675
I have 320 data points - each has a redshift and a turnover-frequency, and I want to fit a correlation between them (a linear fit). However, 120 of the turnover-frequency values are upper limits. As shown below the relationship is very weak:   the red points have upper limits for their turnover-frequency value. I would like to fit a straight line to this data that accounts for the upper limits. I think the tobit model in R can do this, but I'm not too sure (I'm new to R by the way); before I start with that, are there other methods in R I should consider?
4887
plot(density(rexp(100))   Obviously all density to the left of zero represents bias.  I'm looking to summarize some data for non-statisticians, and I want to avoid questions about why non-negative data has density to the left of zero.  The plots are for randomization checking; I want to show the distributions of variables by treatment and control groups. The distributions are often exponential-ish.  Histograms are tricky for various reasons.    A quick google search gives me work by statisticians on non-negative kernels, e.g.:  .    But has any of it been implemented in R?  Of implemented methods, are any of them "best" in some way for descriptive statistics?  EDIT:  even if the from command can solve my current problem, it'd be nice to know whether anyone has implemented kernels based on literature on non-negative density estimation
33734
I have a 2-D probability distribution along the lines of this plot:  I know how to find the confidence interval for a 1-D probability distribution (by the definition of standard deviation or the 68-95-99 rule) but I don't know how to generalize that to 2-D to get a confidence region. I've been looking at Principle Component Analysis and covariance matrices, but most explanations or examples are for a 2D distribution of random vectors rather than a probability distribution so I'm not quite sure how to generalize it. How would I find the 1-$\sigma$/2-$\sigma$ regions for a 2D probability distribution? Edit: The question that was linked in the duplicate message refers to random vectors, whereas what I have is a probability distribution from data, with a continuous 2-D probability function as opposed to random vectors. As such, I cannot find the covariance matrix between two vectors because I DO NOT HAVE TWO VECTORS, and therefore cannot apply the process described in the linked question. If I were to analogize to 1-D, my issue is the difference between the standard deviation for a random distribution of samples, $\sigma=\sqrt{\frac{1}{N}\sum (x_{i}-\bar{x})^{2}}$, and the standard deviation for a probability distribution $\sigma=\sqrt{\sum (x_{i}-\bar{x})^{2}P(x_{i})}$. As far as I can tell, the method involving the covariance matrix is a generalization of the former. I need a generalization of the latter. If I'm wrong in my understanding, please let me know, but I don't think the other question gives me what I need.
264
Let $X_1,X_2, \ldots , X_n$ be independent and identically distributed Uniform random variables on the interval (0, a) for a > 0, each having a density function $f(x) = \frac{1}{a}$, $0&lt;x&lt;a$. Let $X_{(1)},X_{(2)}, \ldots , X_{(n)}$ denote the order statistics. The range of the data is defined as $R = X_{(n)}−X_{(1)}$ and the midrange is defined as $V = \frac{1}{2}(X_{(1)}+X_{(n)})$ Derive the joint distribution of $(R, V )$ and deduce the marginal distributions of $R$ and $V.$  Attempt:   First I am attempting to generate the joint distribution of $(V,X_{(1)})$ and then integrate out the $X_{(1)}$.   For the joint distribution of $(V,X_{(1)})$ I have:   $$ f_{v,x_{(1)}}(v,x_{(1)})=2n(n-1)\int_{-\infty}^v [F(2v-x_{(1)})-F(x_{(1)})]^{n-2} f(2v-x_{(1)})f(x_{(1)}) \, dx_{(1)}$$  At this point I have no idea how to integrate out the $x_{(1)}$.  Edit: I have located the joint distribution of the range and mid-range:  $$ f_{r,v}(r,v) = n(n-1) \left[F\left(v+\frac{r}{2}\right) - \left(F\left(v-\frac{r}{2}\right)\right)\right]^{n-2} f\left(v-\frac r 2 \right) f(v+\frac{r}{2})$$  For each marginal distribution, I have to integrate out:  $$ f_r(r) = \int_{-\infty}^\infty n(n-1)[F(v+\frac{r}{2})-(F(v-\frac{r}{2})]^{n-2}f(v-\frac{r}{2})f(v+\frac{r}{2}) \, dv$$  $$ f_v(v) = \int_0^{\infty}n(n-1)[F(v+\frac{r}{2})-(F(v-\frac{r}{2})]^{n-2}f(v-\frac{r}{2})f(v+\frac{r}{2}) \, dr$$
13981
What is the reason that a likelihood function is not a pdf (probability density function)?
19902
I know how to draw a density histogram using pgfplots from this answer: .  But how can I draw an estimate line on the histogram like this?    \documentclass{article} \usepackage{pgfplots} \begin{document} \pgfplotsset{     small,     every axis plot post/.style={         fill=orange!75,         draw=orange!50!black     },     trim axis left }  \begin{tikzpicture} \begin{axis}[ymin=0, title=\texttt{hist=density}] \addplot [hist=density] table [y index=0] {random.txt}; \end{axis} \end{tikzpicture} \end{document}
32267
I do a linear regression using R lm function:  x = log(errors) plot(x,y) lm.result = lm(formula = y ~ x) abline(lm.result, col="blue") # showing the "fit" in blue     but it does not fit well. Unfortunately I can't make sense of the manual.  Can someone point me in the right direction to fit this better?  By fitting I mean I want to minimize the Root Mean Squared Error (RMSE).    Edit: I have posted a related question (it's the same problem) here:   and the raw data here:    except that on that  x is what is called errors on the present page here, and there are less samples (1000 vs 3000 in the present page plot). I wanted to make things simpler in the other question.
50265
$F$ is a distribution function .Take any $a \in \mathbb{R}$.  Then evaluate : $\displaystyle\int_{\mathbb{R}} (F(x+a)-F(x)) dx$   As it is a general distribution function , I cannot employ densities to solve this problem . Any insights or a complete solution will be very appreciated .
87869
I have an answer but I'm not sure if I'm doing it right: $f(x)$ is the pdf $f(x)=2e^{-2x}$, then, if the random variable $Y=\ln(X)$, then we simply substitute:  $P(Y \leq y)$=  $P(2e^{-2X} \leq y)$  $P(-4X \leq y)$ since $y=ln(x)$  $P(X \leq - \dfrac {1} {4} y)$  This is the distribution function, right?  Thanks!
29436
I am new to probability course and find concepts very confusing. I am learning maximum likelihood estimation and as a starting point for that do we find the density or the distribution?   In general, do we find the distribution from density or is it vice versa and how does one find it? For example, for Gaussian distribution do we find the density of a variable or the distribution so as to estimate unknown parameter A in the case x[n] = A + w[n] where w[n] are uncorrelated gaussian noise. This may sound too trivial but I am really confused. In many contexts I have come across where pdf = prob. density function and in some areas I find pdf = prob distribution function !!