library(readxl)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
district<-read_excel("district.xls")
library(pastecs)
##
## Attaching package: 'pastecs'
## The following objects are masked from 'package:dplyr':
##
## first, last
## The following object is masked from 'package:tidyr':
##
## extract
bilingual<-district%>%select(DPETBILP,DPSTBIFP)
summary(district$DPETBILP)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 0.00 2.90 7.30 12.58 16.80 100.00
summary(district$DPSTBIFP)
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 0.000 0.000 0.000 2.311 2.100 94.300 3
bilingual_clean<-bilingual%>%na.omit(.)
ggplot(bilingual_clean,aes(DPETBILP,DPSTBIFP))+geom_point()

stat.desc(district$DPFPABILP,norm = T)
## nbr.val nbr.null nbr.na min max range
## 1.202000e+03 1.840000e+02 5.000000e+00 0.000000e+00 2.600000e+01 2.600000e+01
## sum median mean SE.mean CI.mean.0.95 var
## 9.010000e+02 4.000000e-01 7.495840e-01 3.817826e-02 7.490350e-02 1.752011e+00
## std.dev coef.var skewness skew.2SE kurtosis kurt.2SE
## 1.323635e+00 1.765827e+00 9.156793e+00 6.488301e+01 1.414057e+02 5.013990e+02
## normtest.W normtest.p
## 4.668057e-01 1.004389e-50
hist(district$DPETBILP, breaks = 10, probability = T)
lines(density(district$DPETBILP),col= 'red',lwd=2)

hist(log(district$DPETBILP),breaks = 10, probability = T)
lines(density(log(district$DPETBILP)),col= 'red',lwd=2)

district_DPETBILP_log<-district%>%mutate(log_DPETBILP=log(DPETBILP))%>%select(DPETBILP,log_DPETBILP)
head(district_DPETBILP_log)
## # A tibble: 6 × 2
## DPETBILP log_DPETBILP
## <dbl> <dbl>
## 1 1 0
## 2 2.7 0.993
## 3 4.1 1.41
## 4 2 0.693
## 5 16.1 2.78
## 6 6.8 1.92
sqrt(0)
## [1] 0
log(0)
## [1] -Inf