- R語言中各種分布
rnorm(n,mean=0,sd=1) rexp(n,rate=1) rgamma(n,shape,scale=1) rpois(n,lambda) rweibull(n,shape,scale=1)#weibull分布 rcauchy(n,location=0,scale=1)#Cauchy分布 rbeta(n,shape1,shape2)#beta分布 rt(n,df)#t分布 rf(n,df1,df2)#F分布 rchisq(n,df)#卡方分布 rbinom(n,size,prob)#二項分布 rgeom(n,prob)#幾何分布 rhyper(nn,m,n,k)#超幾何分布 rlogis(n,location=0,scale=1)#logistic分布 rlnorm(n,meanlog=0,sdlog=1)#對數正态 rnbinom(n,size,prob)#負二項分布 runif(n,min,max)#均勻分布
-
median(x1) [1] 99 quantile(x1) 0% 25% 50% 75% 100% 86 95 99 105 115 fivenum:中位數,上四分位數,下四分位數,最大值,最小值 cor:相關系數 cos:協方差
- 一進制線性回歸分析
lm: linear model a=lm(w~1+h) summary(a) Call: lm(formula = y ~ x) Residuals:(對殘差的描述) Min 1Q Median 3Q Max -1.81085 -0.66032 0.01576 0.67239 1.60354 Coefficients: Estimate Std. Error t value Pr(>|t|) (Intercept)(截距) -0.25072 0.44522 -0.563 0.58 x 1.00317 0.03717 26.991 5.16e-16 *** (P值,越小代表預測越準确,***代表預測結果好) --- Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 Residual standard error: 0.9584 on 18 degrees of freedom Multiple R-squared(拟合的越好越接近于1): 0.9759, Adjusted R-squared: 0.9745 F-statistic: 728.5 on 1 and 18 DF, p-value: 5.164e-16 predict(model,data)