24小时热门版块排行榜    

CyRhmU.jpeg
南方科技大学公共卫生及应急管理学院2025级博士研究生招生报考通知
查看: 615  |  回复: 10
当前主题已经存档。

cheshg

铜虫 (正式写手)

[交流] 【求助】SAS问题

想计算相关系数,有两个变量一个变量是数据形式的,一个 不是,这样应该怎么求相关系数 ???请教  

[ Last edited by cheshg on 2009-6-20 at 00:05 ]
回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)

给出部分数据看看……
2楼2009-05-17 22:17:05
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

cheshg

铜虫 (正式写手)

★ ★
mingdong(金币+2,VIP+0):谢谢您的交流! 6-25 15:59
SAS ---相关系数

相求一组是数字形式的变量,量一组不是数字形式的标量的相关系数?怎么求 请高手知道

例如:
变量X          变量Y
  A              1.1   1.2
  B              1.3   1.2
   C               1.4  1.5

每个变量X对照两个以上的变量Y

这样怎么求相关性,或者决定系数 就是X决定Y是多少 ?
3楼2009-06-14 21:37:53
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)

★ ★
小木虫(金币+0.5):给个红包,谢谢回帖交流
mingdong(金币+1,VIP+0):谢谢! 6-15 14:47
这个似乎没有办法吧。以某个 y 对 x 可以获得线性模型的回归系数(决定系数)。但你的数据集给出的结果都会是 1,呵呵……
4楼2009-06-14 22:17:44
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

cheshg

铜虫 (正式写手)

重新给定一些数据呢?看看可以求么
landform        landuse        SOC
tableland        grassland        8.28
tableland        grassland        9.10
tableland        grassland        8.25
tableland        orchard        7.21
tableland        orchard        7.27
tableland        orchard        7.27
slopeland        orchard        10.20
slopeland        orchard        11.21
slopeland        orchard        10.21
slopeland  grassland      9.23
slopeland  grassland      9.31
slopeland  grassland    9.32


我相求Landform ,Landuse分别 与SOC 的相关性,能求么??
5楼2009-06-20 00:12:09
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)

★ ★ ★
小木虫(金币+0.5):给个红包,谢谢回帖交流
q68(金币+2,VIP+0):多多指教! 6-20 07:17
landform 与 SOC 之间的相关性较高,R^2 为 0.6699
landuse 与 SOC 之间的相关性较差, R^2 为 6.589e-05

楼上似乎是做土壤方面的,个人觉得对于你的这个实验数据,用方差分析似乎更能说明问题,相反相关性分析似乎不能解释更多的东西。

我是用 R (http://www.r-project.org) 中的 lm() 函数完成上述分析的,我想 SAS 也一定可以做,只是我对 SAS 不是很熟悉罢了。
CODE:
> options(contrasts=c("contr.SAS", "contr.poly"))
> summary(lm(SOC ~ landform, soil))

Call:
lm(formula = SOC ~ landform, data = soil)

Residuals:
    Min      1Q  Median      3Q     Max
-0.6867 -0.6267 -0.1533  0.3608  1.2967

Coefficients:
                  Estimate Std. Error t value Pr(>|t|)   
(Intercept)         7.8967     0.3165  24.948 2.45e-10 ***
landformslopeland   2.0167     0.4476   4.505  0.00113 **
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.7753 on 10 degrees of freedom
Multiple R-squared: 0.6699,     Adjusted R-squared: 0.6369
F-statistic:  20.3 on 1 and 10 DF,  p-value: 0.001134

> summary(lm(SOC ~ landuse, soil))

Call:
lm(formula = SOC ~ landuse, data = soil)

Residuals:
   Min     1Q Median     3Q    Max
-1.685 -0.905  0.250  0.630  2.315

Coefficients:
                 Estimate Std. Error t value Pr(>|t|)   
(Intercept)        8.8950     0.5509  16.146 1.72e-08 ***
landusegrassland   0.0200     0.7791   0.026     0.98   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.349 on 10 degrees of freedom
Multiple R-squared: 6.589e-05,  Adjusted R-squared: -0.09993
F-statistic: 0.0006589 on 1 and 10 DF,  p-value: 0.98

> anova(aov(SOC ~ landform, soil))
Analysis of Variance Table

Response: SOC
          Df  Sum Sq Mean Sq F value   Pr(>F)   
landform   1 12.2008 12.2008  20.297 0.001134 **
Residuals 10  6.0113  0.6011                    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> anova(aov(SOC ~ landuse, soil))
Analysis of Variance Table

Response: SOC
          Df  Sum Sq Mean Sq F value Pr(>F)
landuse    1  0.0012  0.0012   7e-04   0.98
Residuals 10 18.2109  1.8211               
> anova(aov(SOC ~ landform + landuse, soil))
Analysis of Variance Table

Response: SOC
          Df  Sum Sq Mean Sq F value   Pr(>F)   
landform   1 12.2008 12.2008 18.2706 0.002067 **
landuse    1  0.0012  0.0012  0.0018 0.967113   
Residuals  9  6.0101  0.6678                    
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

6楼2009-06-20 00:42:24
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

cheshg

铜虫 (正式写手)

R 这个程序看不懂 呵呵 。。。 但还是谢谢了
7楼2009-06-20 20:23:31
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)


小木虫(金币+0.5):给个红包,谢谢回帖交流
不需要看程序,看结果就是了,呵呵……
8楼2009-06-20 20:33:16
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)

★ ★ ★ ★
小木虫(金币+0.5):给个红包,谢谢回帖交流
mingdong(金币+3,VIP+0):谢谢您的交流! 6-25 15:59
给你 SAS 回归的结果:
CODE:
                                          The SAS System          20:33 Tuesday, June 20, 2009  21

                                        The REG Procedure
                                          Model: MODEL1
                                     Dependent Variable: SOC

                                       Analysis of Variance

                                              Sum of           Mean
          Source                   DF        Squares         Square    F Value    Pr > F

          Model                     1       12.20083       12.20083      20.30    0.0011
          Error                    10        6.01127        0.60113
          Corrected Total          11       18.21210


                       Root MSE              0.77532    R-Square     0.6699
                       Dependent Mean        8.90500    Adj R-Sq     0.6369
                       Coeff Var             8.70661


                                       Parameter Estimates

                                    Parameter       Standard
               Variable     DF       Estimate          Error    t Value    Pr > |t|

               Intercept     1        9.91333        0.31652      31.32      <.0001
               landform1     1       -2.01667        0.44763      -4.51      0.0011

                                          The SAS System          20:33 Tuesday, June 20, 2009  22

                                        The REG Procedure
                                          Model: MODEL1
                                     Dependent Variable: SOC

                                       Analysis of Variance

                                              Sum of           Mean
          Source                   DF        Squares         Square    F Value    Pr > F

          Model                     1        0.00120        0.00120       0.00    0.9800
          Error                    10       18.21090        1.82109
          Corrected Total          11       18.21210


                       Root MSE              1.34948    R-Square     0.0001
                       Dependent Mean        8.90500    Adj R-Sq    -0.0999
                       Coeff Var            15.15416


                                       Parameter Estimates

                                    Parameter       Standard
               Variable     DF       Estimate          Error    t Value    Pr > |t|

               Intercept     1        8.89500        0.55092      16.15      <.0001
               landuse1      1        0.02000        0.77912       0.03      0.9800

相关的源程序如下:
CODE:
data ex;
input landform $        landuse $        SOC;
if landform eq 'tablelan' then landform1 = 1; else landform1 = 0;
if landform eq 'slopelan' then landform2 = 1; else landform2 = 0;
if landuse eq 'grasslan' then landuse1 = 1; else landuse1 = 0;
if landuse eq 'orchard' then landuse2 = 1; else landuse2 = 0;
datalines;
tableland        grassland        8.28
tableland        grassland        9.10
tableland        grassland        8.25
tableland        orchard        7.21
tableland        orchard        7.27
tableland        orchard        7.27
slopeland        orchard        10.20
slopeland        orchard        11.21
slopeland        orchard        10.21
slopeland  grassland      9.23
slopeland  grassland      9.31
slopeland  grassland    9.32
;
proc reg data = ex;
model SOC = landform1;
/* model SOC = landform2; */
run;
proc reg data = ex;
model SOC = landuse1;
/* model SOC = landuse2; */
run;
quit;

[ Last edited by snoopyzhao on 2009-6-20 at 21:34 ]
9楼2009-06-20 21:32:52
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

snoopyzhao

至尊木虫 (职业作家)

★ ★ ★
小木虫(金币+0.5):给个红包,谢谢回帖交流
zeoliters(金币+2,VIP+0):感谢回帖交流! 6-21 12:45
注意程序的结果与 R 给出的结果可能不一样,但实际上是一样的,当你用 /* ... */ 中的部分代替现在的 model,给出的结果是一致的。

其实从给出的方差结果上可以看出,这样的线性回归模型就是方差分析模型,呵呵……
10楼2009-06-20 21:38:53
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 cheshg 的主题更新
普通表情 高级回复(可上传附件)
信息提示
请填处理意见