《基于R语言数据挖掘的统计与分析》pdf下载在线阅读全文,求百度网盘云资源

Python054

《基于R语言数据挖掘的统计与分析》pdf下载在线阅读全文,求百度网盘云资源,第1张

《基于R语言数据挖掘的统计与分析》百度网盘pdf最新全集下载:

链接:https://pan.baidu.com/s/1XUAtM1-Fb-igAVYq_nZtlQ

?pwd=ms2x 提取码:ms2x

简介:《基于R的统计分析与数据挖掘(统计数据分析与应用丛书)》聚焦当今备受国内外数据分析师和数据应用者关注的R语言,关注如何借助R实现统计分析和数据挖掘。

它既不是仅侧重理论讲解的统计分析和数据挖掘教科书,也不是仅侧重R编程操作的使用手册,而是以数据分析贯穿全书的两者的有机结合。   

R语言与统计-1:t检验与秩和检验

R语言与统计-2:方差分析

拟合优度检验是用卡方统计量进行统计显著性检验的重要内容之一。它是依据总体分布状况,计算出分类变量中各类别的期望频数,与分布的观察频数进行对比,判断期望频数与观察频数是否有显著差异,从而达到从分类变量进行分析的目的。

简单来说,就是检验样本数据分布是否与已知总体的分布是一致的

如若已知人群中四种血型的占比为0.1 0.5 0.2 0.2,看该组男性的血型分布是否与人群的一致。参数p:传入已知总体的参数情况。

两者写法一样,解释的方法不一样。

卡方齐性检验:比较不同的分类水平下,各个类型的比例是否一致。

卡方独立性检验:

对于行变量为无序分类,列变量为有序分类的数据,由于不能忽略等级关系,也只能使用CMH检验,而不能使用皮尔森卡方检验。

使用CMH检验查看盘尼西林的水平和是否推迟注射对兔子的结局是否有影响。

mantelhaen.test()函数

p值>0.05,无统计学意义。将盘尼西林分为5层水平后,立即注射和推迟1.5h注射的OR值是2.076923

mantelhaen.test()函数

income是一个有序分类变量。结果显示工资水平对工作满意度没有显著的统计学关系。

mcnemar.test()函数

R语言基本数据分析

本文基于R语言进行基本数据统计分析,包括基本作图,线性拟合,逻辑回归,bootstrap采样和Anova方差分析的实现及应用。

不多说,直接上代码,代码中有注释。

1. 基本作图(盒图,qq图)

#basic plot

boxplot(x)

qqplot(x,y)

2. 线性拟合

#linear regression

n = 10

x1 = rnorm(n)#variable 1

x2 = rnorm(n)#variable 2

y = rnorm(n)*3

mod = lm(y~x1+x2)

model.matrix(mod) #erect the matrix of mod

plot(mod) #plot residual and fitted of the solution, Q-Q plot and cook distance

summary(mod) #get the statistic information of the model

hatvalues(mod) #very important, for abnormal sample detection

3. 逻辑回归

#logistic regression

x <- c(0, 1, 2, 3, 4, 5)

y <- c(0, 9, 21, 47, 60, 63) # the number of successes

n <- 70 #the number of trails

z <- n - y #the number of failures

b <- cbind(y, z) # column bind

fitx <- glm(b~x,family = binomial) # a particular type of generalized linear model

print(fitx)

plot(x,y,xlim=c(0,5),ylim=c(0,65)) #plot the points (x,y)

beta0 <- fitx$coef[1]

beta1 <- fitx$coef[2]

fn <- function(x) n*exp(beta0+beta1*x)/(1+exp(beta0+beta1*x))

par(new=T)

curve(fn,0,5,ylim=c(0,60)) # plot the logistic regression curve

3. Bootstrap采样

# bootstrap

# Application: 随机采样,获取最大eigenvalue占所有eigenvalue和之比,并画图显示distribution

dat = matrix(rnorm(100*5),100,5)

no.samples = 200 #sample 200 times

# theta = matrix(rep(0,no.samples*5),no.samples,5)

theta =rep(0,no.samples*5)

for (i in 1:no.samples)

{

j = sample(1:100,100,replace = TRUE)#get 100 samples each time

datrnd = dat[j,]#select one row each time

lambda = princomp(datrnd)$sdev^2#get eigenvalues

# theta[i,] = lambda

theta[i] = lambda[1]/sum(lambda)#plot the ratio of the biggest eigenvalue

}

# hist(theta[1,]) #plot the histogram of the first(biggest) eigenvalue

hist(theta)#plot the percentage distribution of the biggest eigenvalue

sd(theta)#standard deviation of theta

#上面注释掉的语句,可以全部去掉注释并将其下一条语句注释掉,完成画最大eigenvalue分布的功能

4. ANOVA方差分析

#Application:判断一个自变量是否有影响 (假设我们喂3种维他命给3头猪,想看喂维他命有没有用)

#

y = rnorm(9)#weight gain by pig(Yij, i is the treatment, j is the pig_id), 一般由用户自行输入

#y = matrix(c(1,10,1,2,10,2,1,9,1),9,1)

Treatment <- factor(c(1,2,3,1,2,3,1,2,3)) #each {1,2,3} is a group

mod = lm(y~Treatment) #linear regression

print(anova(mod))

#解释:Df(degree of freedom)

#Sum Sq: deviance (within groups, and residuals) 总偏差和

# Mean Sq: variance (within groups, and residuals) 平均方差和

# compare the contribution given by Treatment and Residual

#F value: Mean Sq(Treatment)/Mean Sq(Residuals)

#Pr(>F): p-value. 根据p-value决定是否接受Hypothesis H0:多个样本总体均数相等(检验水准为0.05)

qqnorm(mod$residual) #plot the residual approximated by mod

#如果qqnorm of residual像一条直线,说明residual符合正态分布,也就是说Treatment带来的contribution很小,也就是说Treatment无法带来收益(多喂维他命少喂维他命没区别)

如下面两图分别是

(左)用 y = matrix(c(1,10,1,2,10,2,1,9,1),9,1)和

(右)y = rnorm(9)

的结果。可见如果给定猪吃维他命2后体重特别突出的数据结果后,qq图种residual不在是一条直线,换句话说residual不再符合正态分布,i.e., 维他命对猪的体重有影响。