Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Selected-descriptive-and-inferential-statistics-in-r-for-under… #15

Open
wants to merge 1 commit into
base: operations
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
---
title: "SELECTED DESCRIPTIVE AND INFERENTIAL STATISTICS IN R FOR UNDERGRADUATE PROJECT"
output:
word_document: default
html_document:
df_print: paged
---
BEING A PRACTICAL AND DEMONSTRATION SESSION HELD ON THURSDAY, 18TH MAY, 2023 AT STATISTICS DEPARTMENT, THE FEDERAL POLYTECHNIC OFFA

BY
DR. ABDULKABIR MURITALA


# Descriptives Statistics simulation
```{r}
x=rnorm(100)
mean(x)
```


```{r}
var(x)
```


```{r}
sd(x)
```


```{r}
median(x)
```


```{r}
summary(x)
```


```{r}
barplot(x)
```


```{r}
hist(x)
```


```{r}
qqnorm(x)
```


```{r}
boxplot(x)
```


```{r}
dotchart(x)
```

#Real life data
```{r}
x=c(1,3,5,6,7,8,9,3,2,4)
y=c(2,3,5,6,7,8,4,3,2,1)
z=c(2,3,4,1,2,5,6,7,8,9)
boxplot(x,y,z)
```


```{r}
boxplot(x,y,z,horizontal=T)
```


```{r}
boxplot(x,y,z,horizontal=T,names=c("A","B","C"))
```


```{r}
boxplot(x,y,z,horizontal=T,names=c("A","B","C"),col=c("red","black","blue"))
```


```{r}
par(mfrow=c(2,2))
barplot(x,y,z)
hist(x)
```

#Inferential Statistics
##chi sqaure
```{r}
data <- matrix(c(100, 70, 20, 90, 75, 25), ncol=3, byrow=TRUE)
colnames(data) <- c("Rep","Dem","Ind")
rownames(data) <- c("Male","Female")
data <- as.table(data)
data
```


```{r}
chisq.test(data)
```

#one sample t.test
```{r}
daily.sales=c(5260,5470,5640,6180,6390,6515,6805,7515,7515,8230,8770)
```


```{r}
mean(daily.sales)
```


```{r}
sd(daily.sales)
```


```{r}
quantile(daily.sales)
```


```{r}
t.test(daily.sales)
```


```{r}
t.test(daily.sales,mu=7000)
```

#Two sample
```{r}
dat=read.csv("hnd.csv")
attach(dat)
t.test(exp~sex,var.equal=T)
```

#Paired sample t-test
```{r}
dat=read.csv("hnd2.csv")
t.test(dat$pre,dat$post,paired=T)
```

#Regression
```{r}
x1=runif(50,2,3)
x2=rnorm(50,4,1)
y=2*x1+x2
dat=data.frame(y,x1,x2)
m1=lm(y~x1+x2,dat)
m1
```

```{r}
summary(m1)
```


```{r}
predict(m1)
```

```{r}
plot(y,x1)
```
#Correlation
```{r}
x1=rnorm(100,2,1)
x2=rnorm(100,2,4)
cor(x1,x2)
```


```{r}
cor.test(x1,x2)
```


```{r}
cor.test(x1,x2,method="spearman")
```


```{r}
cor.test(x1,x2,method="kendall")
```

#One way ANOVA
```{r}
x1=runif(50,2,3)
y=2*x1+x1
anova(lm(y~x1))
```
#Two way Anova
```{r}
x1=runif(50,2,3)
x2=rnorm(50,4,1)
y=2*x1+x2
dat=data.frame(y,x1,x2)
anova(lm(y~x1+x2,dat))
```

#Two way Anova with replication
```{r}
x1=runif(50,2,3)
x2=rnorm(50,4,1)
y=2*x1+x2
dat=data.frame(y,x1,x2)
anova(lm(y~x1*x2,dat))
```


#Time series
```{r}
Infla=ts(c(13.8,15.7,3.2,5.4,13.2,34.4,23.7,15.6,16.6),start= c(1970,1))
plot(Infla)
```


```{r}
acf(Infla)
```


```{r}
pacf(Infla)
```


```{r}
library(tseries)
adf.test(Infla)
```


```{r}
adf.test(diff(Infla))
```