第三课实验

> x1=rnorm(100,mean=80,sd=5)
> x1
  [1] 79.35007 83.11081 76.33307 79.00368 80.66916 83.94332 79.51286 79.22252 82.55897 80.53065 82.40369 79.82469 79.33337 78.80269 78.78363 83.73381 69.66598 70.94210 78.82227 80.31673 76.69290
 [22] 71.92647 74.13692 74.98949 83.46115 81.35233 87.18409 76.68216 76.22651 82.47930 91.51744 76.80754 85.02993 80.69771 81.38791 74.31143 86.04885 84.88543 71.54022 89.10342 88.18036 84.48084
 [43] 87.34199 79.28709 79.08603 85.06840 84.87539 77.31056 81.43674 82.06004 84.97153 84.44341 80.12552 77.42104 82.67528 81.25215 78.22304 72.11099 81.86992 67.06852 74.57337 82.69681 77.91911
 [64] 86.91320 84.53494 77.82056 75.96443 85.30792 83.16598 79.16012 82.89330 70.35211 76.27649 81.22488 76.50190 78.21518 76.74423 76.76749 82.33542 75.98212 76.94906 78.82798 86.91889 75.03476
 [85] 84.27175 81.49535 72.08693 77.53209 77.15376 88.47940 76.15635 72.45879 83.50642 80.85959 85.25504 85.56596 75.82446 82.82352 78.28314 74.96655
> median(x1)
[1] 79.66878
> quantile(x1)
      0%      25%      50%      75%     100%
67.06852 76.73140 79.66878 83.23977 91.51744
> quantile(x1,probs=seq(0,1,0.2))
      0%      20%      40%      60%      80%     100%
67.06852 76.26649 78.81444 81.36657 84.30608 91.51744
> fivenum(x1,na.rm=True)
错误于fivenum(x1, na.rm = True) : 找不到对象'True'
> fivenum(x1,na.rm=TRUE)
[1] 67.06852 76.71857 79.66878 83.31356 91.51744
> shapiro.test(x1)
        Shapiro-Wilk normality test
data:  x1
W = 0.9937, p-value = 0.9258
> p值大于0.05
错误: 找不到对象'p值大于0.05'
> 正态分布检测
错误: 找不到对象'正态分布检测'
>
> 概率描述
错误: 找不到对象'概率描述'
> 多元数据的数据特征==========================
> 下
错误: 找不到对象'下'
> x
[1] 1 2 6
> x1
  [1] 79.35007 83.11081 76.33307 79.00368 80.66916 83.94332 79.51286 79.22252 82.55897 80.53065 82.40369 79.82469 79.33337 78.80269 78.78363
 [16] 83.73381 69.66598 70.94210 78.82227 80.31673 76.69290 71.92647 74.13692 74.98949 83.46115 81.35233 87.18409 76.68216 76.22651 82.47930
 [31] 91.51744 76.80754 85.02993 80.69771 81.38791 74.31143 86.04885 84.88543 71.54022 89.10342 88.18036 84.48084 87.34199 79.28709 79.08603
 [46] 85.06840 84.87539 77.31056 81.43674 82.06004 84.97153 84.44341 80.12552 77.42104 82.67528 81.25215 78.22304 72.11099 81.86992 67.06852
 [61] 74.57337 82.69681 77.91911 86.91320 84.53494 77.82056 75.96443 85.30792 83.16598 79.16012 82.89330 70.35211 76.27649 81.22488 76.50190
 [76] 78.21518 76.74423 76.76749 82.33542 75.98212 76.94906 78.82798 86.91889 75.03476 84.27175 81.49535 72.08693 77.53209 77.15376 88.47940
 [91] 76.15635 72.45879 83.50642 80.85959 85.25504 85.56596 75.82446 82.82352 78.28314 74.96655
> 方差、协方差矩阵、关联系数
> x2=round(rnorm(100,mean=80,sd=5))
> x3=round(rnorm(100,mean=70,sd=6))
> x1=round(runif(100,min=60,max=100))
> x=data.frame(x1,x2,x3)
> x
     x1 x2 x3
1    75 76 71
2   100 76 65
3    64 80 72
4    96 86 66
5    82 70 82
6    74 77 63
7    85 80 76
8    97 81 73
9    64 79 66
10   74 69 66
11  100 86 75
12   67 83 64
13   76 86 74
14   95 81 58
15   71 80 72
16   64 86 74
17   68 71 68
18   79 78 71
19   85 87 81
20   99 70 73
21   85 73 63
22   95 78 74
23   84 74 81
24   70 83 75
25   76 79 71
26   93 82 66
27   63 83 79
28   94 88 72
29   92 73 75
30   87 79 71
31   87 77 68
32   75 80 63
33   96 78 71
34   72 88 64
35   74 80 70
36   88 84 77
37   99 88 71
38   62 70 73
39   94 77 58
40   68 78 83
41   61 89 61
42   85 72 54
43   93 83 79
44   72 80 78
45   86 84 82
46   85 76 70
47   69 79 62
48   70 75 80
49   80 80 69
50   89 85 70
51   98 80 74
52   75 77 70
53   79 82 65
54   79 80 64
55   78 75 57
56   66 81 71
57   80 71 70
58  100 79 64
59   76 86 67
60   60 76 62
61   76 83 79
62   94 79 66
63   71 78 68
64   79 88 71
65   65 81 63
66   60 81 76
67   71 78 74
68   83 86 70
69   97 81 61
70   65 72 73
71   62 77 84
72   69 80 63
73   71 74 64
74   93 77 70
75   82 80 74
76   62 88 63
77   72 81 69
78   83 74 68
79   62 85 71
80   98 81 65
81   86 77 65
82   99 76 74
83   67 76 77
84   84 79 77
85   78 76 68
86   94 79 71
87   64 81 75
88   75 73 72
89   76 79 73
90   94 86 72
91   98 76 72
92   97 79 63
93   98 85 72
94   89 75 67
95   78 82 65
96   61 73 73
97   73 80 61
98   94 82 72
99   94 82 68
100  75 71 66
> 协方差函数cov,相关系数函数cor()
> cov(x$x1,x$x2)
[1] 3.761111
> cor(x$x1,x$x2)
[1] 0.06486126
> cor(x$x3,x$x2)
[1] 0.04182909
> cor(x[1:3])
            x1         x2          x3
x1  1.00000000 0.06486126 -0.05695914
x2  0.06486126 1.00000000  0.04182909
x3 -0.05695914 0.04182909  1.00000000
> cov(x[1:3])
           x1        x2        x3
x1 148.826162  3.761111 -4.248586
x2   3.761111 22.593434  1.215657
x3  -4.248586  1.215657 37.383737
>
>
>
> cor.test(x1,x2)
        Pearson's product-moment correlation
data:  x1 and x2
t = 0.6434, df = 98, p-value = 0.5214
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.1332545  0.2579926
sample estimates:
       cor
0.06486126
> plot(iris[1,2])
> plot(iris[which(iris$Species="setosa"),1:2])
错误: 意外的'='在"plot(iris[which(iris$Species="里
> plot(iris[which(iris$Species=="setosa"),1:2])
> plot(iris[1:22])
错误于`[.data.frame`(iris, 1:22) : undefined columns selected
> plot(iris[1:2])
> cor(iris[1],iris[2])
             Sepal.Width
Sepal.Length  -0.1175698
> cor(iris[2],iris[3])
            Petal.Length
Sepal.Width   -0.4284401
> 相关分析分析相关系数是否大于0.05
错误: 找不到对象'相关分析分析相关系数是否大于0.05'
> cor.test(iris$Sepal.Length,iris$Sepal.Width)
        Pearson's product-moment correlation
data:  iris$Sepal.Length and iris$Sepal.Width
t = -1.4403, df = 148, p-value = 0.1519
alternative hypothesis: true correlation is not equal to 0
95 percent confidence interval:
 -0.27269325  0.04351158
sample estimates:
       cor
-0.1175698
> cor.test(iris[which(iris$Species="setosa"),iris$Sepal.Length,iris$Sepal.Width])
错误: 意外的'='在"cor.test(iris[which(iris$Species="里
> cor.test(iris[which(iris$Species="setosa"),iris$Sepal.Length:iris$Sepal.Width])
错误: 意外的'='在"cor.test(iris[which(iris$Species="里
> cor.test(iris[which(iris$Species=="setosa"),iris$Sepal.Length:iris$Sepal.Width])
错误于cor.test.default(iris[which(iris$Species == "setosa"), iris$Sepal.Length:iris$Sepal.Width]) :
  缺少参数"y",也没有缺省值
此外: 警告信息:
1: In iris$Sepal.Length:iris$Sepal.Width :
  数值表达式一共有150元素: 只用了第一个
2: In iris$Sepal.Length:iris$Sepal.Width :
  数值表达式一共有150元素: 只用了第一个
> cor.test(iris[which(iris$Species=="setosa"),iris$Sepal.Length,iris$Sepal.Width])
错误于`[.data.frame`(iris, which(iris$Species == "setosa"), iris$Sepal.Length,  :
  undefined columns selected
>  cor.test(iris[which(iris$Species=="setosa"),iris$Sepal.Length],(iris[which(iris$Species=="setosa"),iris$Sepal.Length]
+
+ 1
错误: 意外的数值量 于
"
1"
>  cor.test(iris[which(iris$Species=="setosa"),iris$Sepal.Length],iris[which(iris$Species=="setosa"),iris$Sepal.Width])
错误于`[.data.frame`(iris, which(iris$Species == "setosa"), iris$Sepal.Length) :
  undefined columns selected
>
>
>
> a=lm(x1~x2)
> a
Call:
lm(formula = x1 ~ x2)
Coefficients:
(Intercept)           x2 
    67.1807       0.1665 
> plot(x1,x2)
> summary(a)
Call:
lm(formula = x1 ~ x2)
Residuals:
    Min      1Q  Median      3Q     Max
-20.996  -9.540  -1.582  12.253  20.168
Coefficients:
            Estimate Std. Error t value Pr(>|t|)  
(Intercept)  67.1807    20.5654   3.267   0.0015 **
x2            0.1665     0.2587   0.643   0.5214  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 12.24 on 98 degrees of freedom
Multiple R-squared: 0.004207,   Adjusted R-squared: -0.005954
F-statistic: 0.414 on 1 and 98 DF,  p-value: 0.5214
> 方差分析anova(a)
错误: 没有"方差分析anova"这个函数
> anova(a)
Analysis of Variance Table
Response: x1
          Df Sum Sq Mean Sq F value Pr(>F)
x2         1     62  61.985   0.414 0.5214
Residuals 98  14672 149.712              
> z=data.frame(x=10)
> z
   x
1 10
> predict(a,z)
       1        2        3        4        5        6        7        8        9       10       11       12       13       14       15       16
79.83233 79.83233 80.49820 81.49702 78.83351 79.99880 80.49820 80.66467 80.33174 78.66704 81.49702 80.99761 81.49702 80.66467 80.49820 81.49702
      17       18       19       20       21       22       23       24       25       26       27       28       29       30       31       32
78.99998 80.16527 81.66349 78.83351 79.33292 80.16527 79.49939 80.99761 80.33174 80.83114 80.99761 81.82996 79.33292 80.33174 79.99880 80.49820
      33       34       35       36       37       38       39       40       41       42       43       44       45       46       47       48
80.16527 81.82996 80.49820 81.16408 81.82996 78.83351 79.99880 80.16527 81.99643 79.16645 80.99761 80.49820 81.16408 79.83233 80.33174 79.66586
      49       50       51       52       53       54       55       56       57       58       59       60       61       62       63       64
80.49820 81.33055 80.49820 79.99880 80.83114 80.49820 79.66586 80.66467 78.99998 80.33174 81.49702 79.83233 80.99761 80.33174 80.16527 81.82996
      65       66       67       68       69       70       71       72       73       74       75       76       77       78       79       80
80.66467 80.66467 80.16527 81.49702 80.66467 79.16645 79.99880 80.49820 79.49939 79.99880 80.49820 81.82996 80.66467 79.49939 81.33055 80.66467
      81       82       83       84       85       86       87       88       89       90       91       92       93       94       95       96
79.99880 79.83233 79.83233 80.33174 79.83233 80.33174 80.66467 79.33292 80.33174 81.49702 79.83233 80.33174 81.33055 79.66586 80.83114 79.33292
      97       98       99      100
80.49820 80.83114 80.83114 78.99998
警告信息:
'newdata'有1行但变量里有100行
> a=lm(x2,x3)
错误于formula.default(object, env = baseenv()) : 公式不对
> a=lm(x2~x3)
> a
Call:
lm(formula = x2 ~ x3)
Coefficients:
(Intercept)           x3 
   77.07404      0.03252 
> summary(a)
Call:
lm(formula = x2 ~ x3)
Residuals:
     Min       1Q   Median       3Q      Max
-10.2203  -3.2121   0.1497   2.8123   9.9423
Coefficients:
            Estimate Std. Error t value Pr(>|t|)   
(Intercept) 77.07404    5.51222  13.982   <2e-16 ***
x3           0.03252    0.07846   0.414    0.679   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 4.773 on 98 degrees of freedom
Multiple R-squared: 0.00175,    Adjusted R-squared: -0.008437
F-statistic: 0.1718 on 1 and 98 DF,  p-value: 0.6795
> predict(a,z)
       1        2        3        4        5        6        7        8        9       10       11       12       13       14       15       16       17       18       19       20       21
79.38284 79.18773 79.41536 79.22025 79.74055 79.12270 79.54544 79.44788 79.22025 79.22025 79.51292 79.15522 79.48040 78.96011 79.41536 79.48040 79.28529 79.38284 79.70803 79.44788 79.12270
      22       23       24       25       26       27       28       29       30       31       32       33       34       35       36       37       38       39       40       41       42
79.48040 79.70803 79.51292 79.38284 79.22025 79.64299 79.41536 79.51292 79.38284 79.28529 79.12270 79.38284 79.15522 79.35033 79.57795 79.38284 79.44788 78.96011 79.77306 79.05766 78.83003
      43       44       45       46       47       48       49       50       51       52       53       54       55       56       57       58       59       60       61       62       63
79.64299 79.61047 79.74055 79.35033 79.09018 79.67551 79.31781 79.35033 79.48040 79.35033 79.18773 79.15522 78.92759 79.38284 79.35033 79.15522 79.25277 79.09018 79.64299 79.22025 79.28529
      64       65       66       67       68       69       70       71       72       73       74       75       76       77       78       79       80       81       82       83       84
79.38284 79.12270 79.54544 79.48040 79.35033 79.05766 79.44788 79.80558 79.12270 79.15522 79.35033 79.48040 79.12270 79.31781 79.28529 79.38284 79.18773 79.18773 79.48040 79.57795 79.57795
      85       86       87       88       89       90       91       92       93       94       95       96       97       98       99      100
79.28529 79.38284 79.51292 79.41536 79.44788 79.41536 79.41536 79.12270 79.41536 79.25277 79.18773 79.44788 79.05766 79.41536 79.28529 79.22025
警告信息:
'newdata'有1行但变量里有100行
>

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27573546/viewspace-747244/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/27573546/viewspace-747244/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值