I have a sample dataset with 31 values. I ran a two-tailed t-test using R to test if the true mean is equal to 10:

t.test(x=data, mu=10, conf.level=0.95)


Output:

t = 11.244, df = 30, p-value = 2.786e-12
alternative hypothesis: true mean is not equal to 10 
95 percent confidence interval:
 19.18980 23.26907 
sample estimates:
mean of x 
 21.22944 


Now I'm trying to do the same thing manually:

t.value = (mean(data) - 10) / (sd(data) / sqrt(length(data))) 
p.value = dt(t.value, df=length(lengths-1))


The t-value calculated using this method is the same as output by the t-test R function. The p-value, however, comes out to be 3.025803e-12.

Any ideas what I'm doing wrong?

Thanks!

EDIT

Here is the full R code, including my dataset:

# Raw dataset -- 32 observations
data = c(21.75, 18.0875, 18.75, 23.5, 14.125, 16.75, 11.125, 11.125, 14.875, 15.5, 20.875,
            17.125, 19.075, 25.125, 27.75, 29.825, 17.825, 28.375, 22.625, 28.75, 27, 12.825, 
            26, 32.825, 25.375, 24.825, 25.825, 15.625, 26.825, 24.625, 26.625, 19.625)

# Student t-Test
t.test(x=data, mu=10, conf.level=0.95)

# Manually calculate p-value
t.value = (mean(data) - 10) / (sd(data) / sqrt(length(data)))
p.value = dt(t.value, df=length(data) - 1)


Use pt and make it two-tailed.

> 2*pt(11.244, 30, lower=FALSE)
[1] 2.785806e-12

