Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
FINAL
#install.packages(c("ggplot2","MASS","dplyr","lattice"))
#install.packages("plyr")
#install.packages("dplyr")
#install.packages("boot")
#install.packages("grphics")
#install.packages("lattice")
#install.packages("magrittr")
library(magrittr)
library(installr)
library(lattice)
library(ISLR)
library(plyr)
library(readr)
library(boot)
library(Rcpp)
library(reshape)
library(reshape2)
library(stringi)
library(MASS,readr)
require(graphics)
#load_data------
for( i in 1:10 ){
paste("C:/Program Files/R/Data/Loose5B/LB/PCA0102_Loose5Big_ef123/big", "\t",i,
"txt",sep ="\t",escape_double = FALSE, col_names = FALSE) -> aa
bb <- read.csv(aa)
list(bb)
#ks.test(bb)
}
#way 1
big_1_ <- read_delim("C:/Program Files/R/Data/Loose5B/LB/PCA0102_Loose5Big_ef123/big (1).txt",
"\t", escape_double = FALSE, col_names = FALSE,
trim_ws = TRUE)
#way 2
##loose 5b/LB------result_1/2/3----
#LB
flist<- dir("C:/Program Files/R/Data/Loose5B/LB/PCA0102_Loose5Big_ef123/", "*.txt", recursive=TRUE)
result<-list()
for(path in flist) {
setwd(dir = "C:/Program Files/R/Data/Loose5B/LB/PCA0102_Loose5Big_ef123/")
name <- basename(path)
result[[path]]<-read_csv(path, col_names = FALSE)
}
View(result[path])
#View(result) #3057entries
#LB2
flist<- dir("C:/Program Files/R/Data/Loose5B/LB (2)/PCA0102_Loose5Big_ef135/", "*.txt", recursive=TRUE)
result2<-list()
for(path in flist) {
setwd(dir = "C:/Program Files/R/Data/Loose5B/LB (2)/PCA0102_Loose5Big_ef135/")
name <- basename(path)
result2[[path]]<-read_csv(path, col_names = FALSE)
}
View(result2[path])
#View(result2)#2092 entries
#LB3
flist<- dir("C:/Program Files/R/Data/Loose5B/LB (3)/PCA0102_Loose5Big_ef135/", "*.txt", recursive=TRUE)
result3<-list()
for(path in flist) {
setwd(dir = "C:/Program Files/R/Data/Loose5B/LB (3)/PCA0102_Loose5Big_ef135/")
name <- basename(path)
result3[[path]]<-read_csv(path, col_names = FALSE)
}
View(result3[path])
#View(result3) #2092 entries
##loose 5s--------result_4/5/6----
flist<- dir("C:/Program Files/R/Data/Loose5S/LB5s_/PCA0102_Loose5Small_ef123/", "*.txt", recursive=TRUE)
result4 <- list()
for(path in flist) {
setwd(dir = "C:/Program Files/R/Data/Loose5S/LB5s_/PCA0102_Loose5Small_ef123/")
name <- basename(path)
result4[[path]]<-read_csv(path, col_names = FALSE)
}
View(result4[])
#View(result4) #2092 entries
flist<- dir("C:/Program Files/R/Data/Loose5S/LB5s_ (2)/PCA0102_Loose5Small_ef135/", "*.txt", recursive=TRUE)
result5 <- list()
for(path in flist) {
setwd(dir = "C:/Program Files/R/Data/Loose5S/LB5s_ (2)/PCA0102_Loose5Small_ef135/")
name <- basename(path)
result5[[path]]<-read_csv(path, col_names = FALSE)
}
View(result5[])
flist<- dir("C:/Program Files/R/Data/Loose5S/LB5s_ (3)/PCA0102_Loose5Small_ef135/", "*.txt", recursive=TRUE)
result6 <- list()
for(path in flist) {
setwd(dir = "C:/Program Files/R/Data/Loose5S/LB5s_ (3)/PCA0102_Loose5Small_ef135/")
name <- basename(path)
result6[[path]]<-read_csv(path, col_names = FALSE)
}
View(result6[])
##loose 6b--------result_7/8----
flist<- dir("C:/Program Files/R/Data/Loose6B/L6B/PCA0102_Loose6Big_ef123/", "*.txt", recursive=TRUE)
result7 <- list()
for(path in flist) {
setwd(dir = "C:/Program Files/R/Data/Loose6B/L6B/PCA0102_Loose6Big_ef123/")
name <- basename(path)
result7[[path]]<-read_csv(path, col_names = FALSE)
}
View(result7[])
flist<- dir("C:/Program Files/R/Data/Loose6B/L6B (2)/PCA0102_Loose6Big_ef135/", "*.txt", recursive=TRUE)
result8 <- list()
for(path in flist) {
setwd(dir = "C:/Program Files/R/Data/Loose6B/L6B (2)/PCA0102_Loose6Big_ef135/")
name <- basename(path)
result8[[path]]<-read_csv(path, col_names = FALSE)
}
View(result8[])
##loose 6s--------result_9/10-----
flist<- dir("C:/Program Files/R/Data/Loose6S/L6s/PCA0102_Loose6Small_ef123/", "*.txt", recursive=TRUE)
result9 <- list()
for(path in flist) {
setwd(dir = "C:/Program Files/R/Data/Loose6S/L6s/PCA0102_Loose6Small_ef123/")
name <- basename(path)
result9[[path]]<-read_csv(path, col_names = FALSE)
}
View(result9[])
flist<- dir("C:/Program Files/R/Data/Loose6S/L6s (2)/PCA0102_Loose6Small_ef135/", "*.txt", recursive=TRUE)
result10 <- list()
for(path in flist) {
setwd(dir = "C:/Program Files/R/Data/Loose6S/L6s (2)/PCA0102_Loose6Small_ef135/")
name <- basename(path)
result10[[path]]<-read_csv(path, col_names = FALSE)
}
View(result10[])
##normal-----result_N%PCA-----
#normal 123
flist<- dir("C:/Program Files/R/Data/Normal123/normal/PCA01", "*.txt", recursive=TRUE)
result_N1p1<-list()
for(path in flist) {
setwd(dir = "C:/Program Files/R/Data/Normal123/normal/PCA01")
name <- basename(path)
result_N1p1[[path]]<-read_csv(path, col_names = FALSE)
}
View(result_N1p1[path])
View(result_N1p1) #3057 entries
flist<- dir("C:/Program Files/R/Data/Normal123/normal/PCA02", "*.txt", recursive=TRUE)
result_N1p2<-list()
for(path in flist) {
setwd(dir = "C:/Program Files/R/Data/Normal123/normal/PCA02")
name <- basename(path)
result_N1p2[[path]]<-read_csv(path, col_names = FALSE)
}
View(result_N1p2[path])
View(result_N1p2) #3057 entries
#normal 135
flist<- dir("C:/Program Files/R/Data/Normal135/normal/PCA01", "*.txt", recursive=TRUE)
result_N2p1<-list()
for(path in flist) {
setwd(dir = "C:/Program Files/R/Data/Normal135/normal/PCA01")
name <- basename(path)
result_N2p1[[path]]<-read_csv(path, col_names = FALSE)
}
View(result_N2p1[path])
View(result_N2p1) #2092 entries
flist<- dir("C:/Program Files/R/Data/Normal135/normal/PCA02", "*.txt", recursive=TRUE)
result_N2p2<-list()
for(path in flist) {
setwd(dir = "C:/Program Files/R/Data/Normal135/normal/PCA02")
name <- basename(path)
result_N2p2[[path]]<-read_csv(path, col_names = FALSE)
}
View(result_N2p2[path])
View(result_N2p2) #2092 entries
--------------------------
# manipulate --------------------------------------------------------------
#result1
mean(result2$`3b_3P13PCA01_Normal01~06ef1Loose5Big01_1.txt`$X1)
par(mfcol = c(3,3))
plot(result$`big (10).txt`$x1.1)
lb1_1 <- result
lb2_1 <- result2$`3b_3P13PCA01_Normal01~06ef1Loose5Big01_1.txt`$X1
mean(lb2_1)
#result2
lbb_1 <- result2$`3b_3P13PCA01_Normal01~06ef1Loose5Big01_1.txt`$X1
View(result2[])
for(i in 1:100){
x = rnorm(200)
#data.frame(as.numeric(result2[]))
hist(x, main ="")
}
boxplot(result2$`3b_3P13PCA01_Normal01~06ef1Loose5Big01_1.txt`$X1)
layout(matrix(0.5,0.5,0.5,0.5))
for(i in 1:10){
i <- sample(result2[[]],10,replace = TRUE)
View(i)
}
# data_bind ---------------------------------------------------------------
r1 = as.data.frame(result)
r2 = as.data.frame(result2)
r3 = as.data.frame(result3)
r4 = as.data.frame(result4)
r5 = as.data.frame(result5)
r6 = as.data.frame(result6)
r7 = as.data.frame(result7)
r8 = as.data.frame(result8)
r9 = as.data.frame(result9)
r10 = as.data.frame(result10)
rN1p1 = as.data.frame(result_N1p1)
rN1p2 = as.data.frame(result_N1p2)
rN2p1 = as.data.frame(result_N2p1)
rN2p2 = as.data.frame(result_N2p2)
#?do.call()
A <- 2
f <- function(x) print(x^2)
env <- new.env()
assign("A", 10, envir = env)
assign("f", f, envir = env)
f <- function(x) print(x)
f()
#````````{
#你要從result,result1,result2,... 就開始改了
#寫一個 result <- list()
#然後把原本的result放到result[[1]], result2放到result[[2]],...
#最後寫do.call(what = rbind, result)即可
#``````````}
View(r2[sample(nrow(r2),30),])
rr1<-r1[sample(nrow(r1),30),]
rr2<-r2[sample(nrow(r2),30),]
rr3<-r3[sample(nrow(r3),30),]
rr4<-r4[sample(nrow(r4),30),]
rr5<-r5[sample(nrow(r5),30),]
rr6<-r6[sample(nrow(r6),30),]
rr7<-r7[sample(nrow(r7),30),]
rr8<-r8[sample(nrow(r8),30),]
rr9<-r9[sample(nrow(r9),30),]
rr10<-r10[sample(nrow(r10),30),]
spc_all <- cbind(rr1,rr2,rr3,rr4,rr5,rr6,rr7,rr8,rr9,rr10) #numers ROW NOT MATCH
qqnorm(spc_all[6,])
View(spc_all[2,])
View(t(spc_all))
#visualization-------------30graphics-----
#result2
r2 = as.data.frame(result2)
par(mar = c(1,1,1,1),mfrow = c(6,5),mfcol = c(5,6))
for(i in 1:30){
x = r2[i,]
qqnorm(x);qqline(x,col = 2,xlab = "Z value")
}
layout(matrix(1,1,1)) #?T?w?e??1;1;1 <reconstruct graph
#result3
r3 = as.data.frame(result3)
par(mar = c(1,1,1,1),mfrow = c(6,5),mfcol = c(5,6))
for(i in 1:30){
x = r3[i,]
qqnorm(x);qqline(x,col = 1,xlab = "Z value")
}
layout(matrix(1,1,1)) #?T?w?e??1;1;1 <reconstruct graph
#result4
r4 = as.data.frame(result4)
par(mar = c(1,1,1,1),mfrow = c(6,5),mfcol = c(5,6))
for(i in 1:30){
x = r4[i,]
qqnorm(x);qqline(x,col = 3,xlab = "Z value")
}
layout(matrix(1,1,1)) #?T?w?e??1;1;1 <reconstruct graph
#result5
r5 = as.data.frame(result5)
par(mar = c(1,1,1,1),mfrow = c(6,5),mfcol = c(5,6))
for(i in 1:30){
x = r5[i,]
qqnorm(x);qqline(x,col = 6,xlab = "Z value" )
}
layout(matrix(1,1,1)) #adjust draftmap to 1;1;1 <reconstruct graph
------------------------------
#result2
r2 = as.data.frame(result2)
par(mar = c(1,1,1,1),mfrow = c(2,2))
for(i in 1:6){
y = r2[i,]
x = r2[,i]
z = seq(-10,10,0.01)
# boxplot(x)
contour(x,y,z)
}
layout(matrix(1,1,1)) #djust draftmap to 1;1;1 <reconstruct graph
plot(x=rN1[1,],y=rN1[2,],data = rN1)
##conclusion-----
for(i in 1:10){
AAA <- print(shapiro.test(t(spc_all)[i,]))
shapiro.test(t(spc_all)[i,])
if( AAA$p.value < 0.1){
yyy <- print("Reject")
}else{
print("Accept");break}
qqnorm(t(spc_all)[i,]);qqline(t(spc_all),col = 3);
}
#rN1p1
count_Reject = 0
for(i in 1:30) {
BBB <- print(shapiro.test(t(rN1p1[i,])))
shapiro.test(t(rN1p1[i,]))
if( BBB$p.value < 0.1){
yyy <- print("Reject")
count_Reject = count_Reject + 1
}else{
print("Accept");
qqnorm(t(rN1p1[i,]));qqline(t(rN1p1[i,]),col = 10);
abline(h = -1:5, v = -2:3, col = "blue", lty = 3, lwd =1.5)
}
# aggregate(count_Reject)
}
print(count_Reject)
View(t(rN1p1[i,]))
View(t(rN1p1))
?which()
BBB
#rN1p2
count_Reject = 0
for(i in 1:30) {
BBB <- print(shapiro.test(t(rN1p2[i,])))
shapiro.test(t(rN1p2[i,]))
if( BBB$p.value < 0.1){
yyy <- print("Reject")
count_Reject = count_Reject + 1
}else{
print("Accept");
qqnorm(t(rN1p2[i,]));qqline(t(rN1p2[i,]),col = 10);
abline(h = -1:5, v = -2:3, col = "blue", lty = 3, lwd =1.5)
}
# aggregate(count_Reject)
}
print(count_Reject)
View(t(rN1p2[,1]))
#rN2p1
count_Reject = 0
for(i in 1:2092) {
BBB <- print(shapiro.test(t(rN2p1[i,])))
shapiro.test(t(rN2p1[i,]))
if( BBB$p.value < 0.1){
yyy <- print("Reject")
count_Reject = count_Reject + 1
}else{
print("Accept");
qqnorm(t(rN2p1[i,]));qqline(t(rN2p1[i,]),col = 10);
abline(h = -1:5, v = -2:3, col = "blue", lty = 3, lwd =1.5)
}
# aggregate(count_Reject)
}
print(count_Reject)
#rN2p2
count_Reject = 0
for(i in 1:2092) {
BBB <- print(shapiro.test(t(rN2p2[i,])))
shapiro.test(t(rN2p2[i,]))
if( BBB$p.value < 0.1){
yyy <- print("Reject")
count_Reject = count_Reject + 1
}else{
print("Accept");
qqnorm(t(rN2p2[i,]));qqline(t(rN2p2[i,]),col = 10);
abline(h = -1:5, v = -2:3, col = "blue", lty = 3, lwd =1.5)
}
# aggregate(count_Reject)
}
print(count_Reject)
shapiro_test_df <- function(df, bonf= TRUE, alpha= 0.05) {
l <- lapply(df, shapiro.test)
s <- do.call("c", lapply(l, "[[", 1))
p <- do.call("c", lapply(l, "[[", 2))
if (bonf == TRUE) {
sig <- ifelse(p > alpha / length(l), "H0", "Ha")
} else {
sig <- ifelse(p < alpha, "H0", "Ha")
}
return(list(statistic= s,
p.value= p,
significance= sig,
method= ifelse(bonf == TRUE, "Shapiro-Wilks test with Bonferroni Correction",
"Shapiro-Wilks test without Bonferroni Correction")))
}
shapiro_test_df(spc_all[,1])
for( i in 1:10 ){
temp <- paste("rr",i,sep = "")
#RBdata = temp[sample(nrow(temp),30),]
}
temp <- paste("rr",1:10,sep = "")
f3 <- function(n){
df <- data.frame(x = numeric(n), y = character(n), stringsAsFactors = FALSE)
for(i in 1:n){
df$x[i] <- i
df$y[i] <- toString(i)
}
df
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.