Skip to main content
v2026.11,986 entries · CC-BY 4.0

dnorm in R: Syntax, Arguments and Worked Examples

dnorm in R returns the normal density at x. See its arguments, worked values you can check by hand, why density can exceed 1, and the SciPy equivalent.

Written and maintained by CASRAI Editorial Board

Published

On this page

dnorm() is the base R function that returns the height of the normal (Gaussian) probability density curve at one or more values of x. Its call is dnorm(x, mean = 0, sd = 1, log = FALSE), so dnorm(0) returns 0.3989423, the peak of the standard normal curve. The value it returns is a density, not a probability: the probability of landing in a range is the area under the curve, which you get from pnorm().

What dnorm is used for in research

The R manual for the Normal distribution documents four related functions that share one set of arguments: dnorm gives the density, pnorm is the cumulative distribution function, qnorm is the quantile function, and rnorm generates random deviates. Researchers use dnorm when they need the curve itself rather than a tail probability. Typical jobs are:

  • drawing a theoretical normal curve over a histogram of observed data to judge fit by eye (see histograms and the normal distribution);
  • computing the likelihood of an observation under an assumed normal model, which is the building block of maximum-likelihood estimation;
  • checking a hand calculation of the normal probability density function against software output;
  • building the weighting or prior terms in simulation and Bayesian code.

Install or access

dnorm belongs to the stats package, which is part of base R and loads automatically in every session. There is nothing extra to install: download R from the Comprehensive R Archive Network at cran.r-project.org, start R (or RStudio, which runs on top of R), and call the function. To open the official help page for the whole family, run ?dnorm, help("Normal") or ?Normal at the console.

Step-by-step: use dnorm

Arguments

The usage line in the R documentation is dnorm(x, mean = 0, sd = 1, log = FALSE).

Argument Default Meaning (R documentation)
x none Vector of quantiles at which the density is evaluated
mean 0 Vector of means
sd 1 Vector of standard deviations
log FALSE If TRUE, densities are returned as logarithms

Steps

  1. Start with the standard normal. Run dnorm(0). The result is 0.3989423, which equals 1/√(2π), the maximum height of the standard normal curve.
  2. Change the distribution. Supply mean and sd by name: dnorm(1, mean = 2, sd = 0.5) returns 0.1079819.
  3. Evaluate many points at once. The arguments are vectorised, so dnorm(c(-1, 0, 1)) returns three densities in one call (0.2419707, 0.3989423, 0.2419707).
  4. Draw the curve. Create a grid of x values and plot the densities:
    x <- seq(-4, 4, length.out = 200)
    plot(x, dnorm(x), type = "l", xlab = "x", ylab = "Density")
  5. Overlay it on data. For a numeric vector y, draw a density-scaled histogram and add the fitted normal curve:
    hist(y, freq = FALSE)
    curve(dnorm(x, mean = mean(y), sd = sd(y)), add = TRUE)
  6. Get log-densities when you need a log-likelihood. dnorm(y, mean = mean(y), sd = sd(y), log = TRUE) returns the log of each density, and sum() of that vector is the normal log-likelihood of the sample at those parameter values.

Output and how to read it

Density is a height, not a probability

The documented density is f(x) = 1/(√(2π) σ) · exp(−(x − μ)² / (2σ²)). Because it is a height on a curve whose total area is 1, it can exceed 1 when the standard deviation is small. With mean = 0.5 and sd = 0.1, the peak is about 3.989, and dnorm(0.4, mean = 0.5, sd = 0.1) is about 2.4197. This is legitimate: the narrower the curve, the taller it must be to keep an area of 1. Read the value as “how concentrated the distribution is near this x”, and compare densities only for the same distribution.

From density to probability

To get the probability that a value falls between two points, subtract cumulative probabilities: pnorm(b, mean, sd) - pnorm(a, mean, sd). The companion guide to pnorm in R covers that function. For a lookup in the other direction, qnorm converts a probability into a quantile.

Verifying by hand

You can reproduce any output from the documented formula. For dnorm(1, mean = 2, sd = 0.5): (x − μ)² / (2σ²) = 1 / 0.5 = 2, so the density is exp(−2) / (√(2π) × 0.5) = 0.135335 / 1.253314 = 0.1079819, matching the function.

Worked values

The data table below the guide lists densities computed from the documented formula for several x, mean and sd combinations, together with their natural logarithms (what log = TRUE returns).

dnorm vs pnorm, qnorm and rnorm

All four functions take the same mean and sd arguments. Use dnorm for the height of the curve at a point, pnorm for the probability of a value at or below a point, qnorm for the point that corresponds to a given cumulative probability, and rnorm to simulate data. The same pattern exists for other distributions: the t distribution is covered in pt in R.

Edge cases defined in the documentation

  • sd = 0 gives the limit as the standard deviation decreases to 0, a point mass at the mean.
  • A negative sd is an error and returns NaN.
  • Arguments are recycled, so a single mean and sd apply to every element of x, while vectors of different values are matched element by element.

Worked example: a log-likelihood by hand

Suppose three observations y = 4, 5 and 6 are assumed to come from a normal distribution with mean 5 and standard deviation 1. In R, sum(dnorm(c(4, 5, 6), mean = 5, sd = 1, log = TRUE)) adds the three log-densities. By the documented formula, the log-density is −log(√(2π)) − (x − μ)²/2, which is −0.9189385 − (x − 5)²/2. That gives −1.4189385 for y = 4, −0.9189385 for y = 5 and −1.4189385 for y = 6, so the sum is −3.7568155. Summing logs rather than multiplying densities avoids the tiny products that underflow with large samples. Varying mean and sd and keeping the pair with the largest sum is the idea behind maximum-likelihood estimation.

Troubleshooting

  • Warning “NaNs produced”. Check for a negative sd; the documentation says this returns NaN. A common cause is passing a variance, or a computed value that has gone negative, instead of a standard deviation.
  • Density above 1. Not an error; see the section above. If you wanted a probability, use pnorm differences.
  • Curve invisible on a histogram. A histogram drawn with counts sits on a much larger scale than the density. Use hist(y, freq = FALSE) so both are on the density scale.
  • Wrong result from positional arguments. The second argument is mean and the third is sd. Name them (mean =, sd =) to avoid swapping them.
  • Zero density in the tails. Very extreme x values underflow to 0. Use log = TRUE when you are summing log-likelihoods.
  • Could not find function. Check the spelling: the function is lowercase dnorm, and R is case sensitive.

Free alternatives

R itself is free, and so is the Python equivalent. SciPy’s scipy.stats.norm exposes the same density with different argument names: loc is the mean and scale is the standard deviation. The SciPy documentation states that norm.pdf(x, loc, scale) is identically equivalent to norm.pdf(y) / scale with y = (x - loc) / scale, and that the standard form is f(x) = exp(−x²/2) / √(2π).

Task R (stats, base) Python (SciPy)
Normal density dnorm(x, mean, sd) scipy.stats.norm.pdf(x, loc, scale)
Default parameters mean = 0, sd = 1 loc = 0, scale = 1
Log density dnorm(x, mean, sd, log = TRUE) scipy.stats.norm.logpdf(x, loc, scale)

FAQ

What does dnorm do in R?

It returns the probability density of the normal distribution at the values you give it, using the mean and standard deviation you supply (0 and 1 by default).

What is the difference between dnorm and pnorm?

dnorm is the height of the bell curve at a point; pnorm is the cumulative probability up to that point, that is, the area under the curve to its left. See pnorm in R.

Why is my dnorm result greater than 1?

Because it is a density. When the standard deviation is below about 0.4 the peak 1/(√(2π) σ) exceeds 1, and the total area under the curve is still 1.

How do I use dnorm in R with my own data?

Estimate the mean and standard deviation from the sample and pass them in: dnorm(x, mean = mean(y), sd = sd(y)), as in step 5 above.

Is “dnorm r” the same function?

Yes. Searches for “dnorm r” refer to the same R function, dnorm; the letter R names the language.

Sources

Data: dnorm() values computed from the documented normal density formula

Normal density and log-density at selected x, mean and sd values, computed from the formula f(x) = exp(-(x-mu)^2/(2 sigma^2))/(sqrt(2 pi) sigma) given in the R stats manual for the Normal distribution; each row corresponds to one dnorm() call.

dnorm() values computed from the documented normal density formula
R callxmeansdDensity (dnorm)Log density (log = TRUE)
dnorm(0, mean = 0, sd = 1)0010.3989423-0.9189385
dnorm(1, mean = 0, sd = 1)1010.2419707-1.4189385
dnorm(2, mean = 0, sd = 1)2010.053991-2.9189385
dnorm(0.5, mean = 0, sd = 1)0.5010.3520653-1.0439385
dnorm(1, mean = 2, sd = 0.5)120.50.1079819-2.2257914
dnorm(0.4, mean = 0.5, sd = 0.1)0.40.50.12.41970720.8836466
dnorm(0.5, mean = 0.5, sd = 0.1)0.50.50.13.98942281.3836466
dnorm(170, mean = 175, sd = 7)17017570.0441593-3.1199507

Sources

Compiled by CASRAI from the sources above. Free to reuse under CC BY 4.0 with attribution.

Follow CASRAI

Research-administration guidance, standards updates and independent tool reviews.

Ask CASRAI · full access

Ask about dnorm in R: Syntax, Arguments and Worked Examples

Full access: large monthly usage, up to 10 source passages behind each answer, and MCP and API access for Claude Code, Codex and other CLIs. Cancel any time.

An AI assistant for research: funder rules, compliance, methods and publishing. It links the sources behind its answers and labels answers that come from a web search.

Answers draw on CASRAI's guides and dictionary plus the federal and funder documents we index: Federal Register, Grants.gov, Regulations.gov and UKRI.

Works on this site and inside Claude, Cursor and the AI tools you already use.

Everything CASRAI publishes — this page, the dictionary, the guides and the news — stays open to read, with no account and no card.

Referenced across the research world

University of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logoUniversity of Cambridge logoColumbia University logoCrossref logoUniversity of Edinburgh logoHarvard University logoUniversity of Oxford logoPrinceton University logoStanford School of Medicine logoUniversity College London logoORCID logo
  • University of Cambridge logo
  • Columbia University logo
  • Crossref logo
  • University of Edinburgh logo
  • Harvard University logo
  • University of Oxford logo
  • Princeton University logo
  • Stanford School of Medicine logo
  • University College London logo
  • ORCID logo

View CASRAI adoption →