找回密码
 立即注册
查看: 5211|回复: 5

相关系数检验的概率P-值怎么求

[复制链接]
发表于 2014-4-15 22:12:30 | 显示全部楼层 |阅读模式
    x=c(90.0,95.0,82.0,91.0,100.0,87.0,91.0,90.0,86.0,87.0,98.0,88.0,82.0,87.0,92.0,93.0,
95.0,84.0,83.0,89.0,87.0,90.0,82.0,95.0,81.0,83.0,86.0,93.0,95.0,96.0,97.0,81.0,88.0,85.0,95.0)

y=c(63.0,71.0,79.0,73.0,74.0,65.0,67.0,73.0,60.0,76.0,71.0,72.0,75.0,62.0,67.0,74.0,78.0,
68.0,74.0,71.0,60.0,70.0,67.0,69.0,79.0,73.0,74.0,60.0,60.0,75.0,77.0,70.0,63.0,73.0,68.0)
cor算出XY两个两个样本的相关系数-0.052后,那么相关系数检验的概率P-值怎么求啊?


回复

使用道具 举报

发表于 2014-4-16 00:09:31 | 显示全部楼层
>  x=c(90.0,95.0,82.0,91.0,100.0,87.0,91.0,90.0,86.0,87.0,98.0,88.0,82.0,87.0,92.0,93.0,95.0,84.0,83.0,89.0,87.0,90.0,82.0,95.0,81.0,83.0,86.0,93.0,95.0,96.0,97.0,81.0,88.0,85.0,95.0)
>
> y=c(63.0,71.0,79.0,73.0,74.0,65.0,67.0,73.0,60.0,76.0,71.0,72.0,75.0,62.0,67.0,74.0,78.0,68.0,74.0,71.0,60.0,70.0,67.0,69.0,79.0,73.0,74.0,60.0,60.0,75.0,77.0,70.0,63.0,73.0,68.0)
>
> cor(x,y)
[1] -0.05180596
> cor.test(x,y)

        Pearson's product-moment correlation

data:  x and y
t = -0.298, df = 33, p-value = 0.7676
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
-0.3785177  0.2863848
sample estimates:
        cor
-0.05180596

回复

使用道具 举报

 楼主| 发表于 2014-4-16 13:31:29 | 显示全部楼层
谢谢,刚开始学R,也只是想知道课本SPSS上的如何用R来实现,但是不一样的啊,课本上的是paired sample  test,这该如何实现?求大神
回复

使用道具 举报

 楼主| 发表于 2014-4-16 13:32:37 | 显示全部楼层
rchina 发表于 2014-4-16 00:09
>  x=c(90.0,95.0,82.0,91.0,100.0,87.0,91.0,90.0,86.0,87.0,98.0,88.0,82.0,87.0,92.0,93.0,95.0,84.0,83 ...

谢谢,刚开始学R,也只是想知道课本SPSS上的如何用R来实现,但是不一样的啊,课本上的是paired sample  test,这该如何实现?求大神
回复

使用道具 举报

发表于 2014-4-17 13:08:50 | 显示全部楼层
说明发给你,你看看啥能用上
Test for Association/Correlation Between Paired Samples

Description

Test for association between paired samples, using one of Pearson's product moment correlation coefficient, Kendall's tau or Spearman's rho.

Usage

cor.test(x, ...)

## Default S3 method:
cor.test(x, y,
         alternative = c("two.sided", "less", "greater"),
         method = c("pearson", "kendall", "spearman"),
         exact = NULL, conf.level = 0.95, continuity = FALSE, ...)

## S3 method for class 'formula'
cor.test(formula, data, subset, na.action, ...)
Arguments

x, y       
numeric vectors of data values. x and y must have the same length.

alternative       
indicates the alternative hypothesis and must be one of "two.sided", "greater" or "less". You can specify just the initial letter. "greater" corresponds to positive association, "less" to negative association.

method       
a character string indicating which correlation coefficient is to be used for the test. One of "pearson", "kendall", or "spearman", can be abbreviated.

exact       
a logical indicating whether an exact p-value should be computed. Used for Kendall's tau and Spearman's rho. See ‘Details’ for the meaning of NULL (the default).

conf.level       
confidence level for the returned confidence interval. Currently only used for the Pearson product moment correlation coefficient if there are at least 4 complete pairs of observations.

continuity       
logical: if true, a continuity correction is used for Kendall's tau and Spearman's rho when not computed exactly.

formula       
a formula of the form ~ u + v, where each of u and v are numeric variables giving the data values for one sample. The samples must be of the same length.

data       
an optional matrix or data frame (or similar: see model.frame) containing the variables in the formula formula. By default the variables are taken from environment(formula).

subset       
an optional vector specifying a subset of observations to be used.

na.action       
a function which indicates what should happen when the data contain NAs. Defaults to getOption("na.action").

...       
further arguments to be passed to or from methods.

Details

The three methods each estimate the association between paired samples and compute a test of the value being zero. They use different measures of association, all in the range [-1, 1] with 0 indicating no association. These are sometimes referred to as tests of no correlation, but that term is often confined to the default method.

If method is "pearson", the test statistic is based on Pearson's product moment correlation coefficient cor(x, y) and follows a t distribution with length(x)-2 degrees of freedom if the samples follow independent normal distributions. If there are at least 4 complete pairs of observation, an asymptotic confidence interval is given based on Fisher's Z transform.

If method is "kendall" or "spearman", Kendall's tau or Spearman's rho statistic is used to estimate a rank-based measure of association. These tests may be used if the data do not necessarily come from a bivariate normal distribution.

For Kendall's test, by default (if exact is NULL), an exact p-value is computed if there are less than 50 paired samples containing finite values and there are no ties. Otherwise, the test statistic is the estimate scaled to zero mean and unit variance, and is approximately normally distributed.

For Spearman's test, p-values are computed using algorithm AS 89 for n < 1290 and exact = TRUE, otherwise via the asymptotic t approximation. Note that these are ‘exact’ for n < 10, and use an Edgeworth series approximation for larger sample sizes (the cutoff has been changed from the original paper).

Value

A list with class "htest" containing the following components:

statistic       
the value of the test statistic.

parameter       
the degrees of freedom of the test statistic in the case that it follows a t distribution.

p.value       
the p-value of the test.

estimate       
the estimated measure of association, with name "cor", "tau", or "rho" corresponding to the method employed.

null.value       
the value of the association measure under the null hypothesis, always 0.

alternative       
a character string describing the alternative hypothesis.

method       
a character string indicating how the association was measured.

data.name       
a character string giving the names of the data.

conf.int       
a confidence interval for the measure of association. Currently only given for Pearson's product moment correlation coefficient in case of at least 4 complete pairs of observations.

References

D. J. Best & D. E. Roberts (1975), Algorithm AS 89: The Upper Tail Probabilities of Spearman's rho. Applied Statistics, 24, 377–379.

Myles Hollander & Douglas A. Wolfe (1973), Nonparametric Statistical Methods. New York: John Wiley & Sons. Pages 185–194 (Kendall and Spearman tests).

See Also

Kendall in package Kendall.

pKendall and pSpearman in package SuppDists, spearman.test in package pspearman, which supply different (and often more accurate) approximations.

Examples

## Hollander & Wolfe (1973), p. 187f.
## Assessment of tuna quality.  We compare the Hunter L measure of
##  lightness to the averages of consumer panel scores (recoded as
##  integer values from 1 to 6 and averaged over 80 such values) in
##  9 lots of canned tuna.

x <- c(44.4, 45.9, 41.9, 53.3, 44.7, 44.1, 50.7, 45.2, 60.1)
y <- c( 2.6,  3.1,  2.5,  5.0,  3.6,  4.0,  5.2,  2.8,  3.8)

##  The alternative hypothesis of interest is that the
##  Hunter L value is positively associated with the panel score.

cor.test(x, y, method = "kendall", alternative = "greater")
## => p=0.05972

cor.test(x, y, method = "kendall", alternative = "greater",
         exact = FALSE) # using large sample approximation
## => p=0.04765

## Compare this to
cor.test(x, y, method = "spearm", alternative = "g")
cor.test(x, y,                    alternative = "g")

## Formula interface.
require(graphics)
pairs(USJudgeRatings)
cor.test(~ CONT + INTG, data = USJudgeRatings)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|R语言中文网

GMT+8, 2024-11-25 11:44 , Processed in 0.024784 second(s), 17 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表