Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
備用backup_R計畫用
library(readr)
list(auu) <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal01/3b_3PPCA01_Normal01_1.txt")
list(auu)
for( i in 1:5 ){
paste("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal01/3b_3PPCA01_Normal01_",i,".txt",sep ="") = aa
bb <- read.csv(aa)
list(bb)
}
data.frame(bb)
View(bb)
#Normal01_1 <- read.csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal01/3b_3PPCA01_Normal01_1.txt",
# "C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal01/3b_3PPCA01_Normal01_2.txt",
# "C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal01/3b_3PPCA01_Normal01_3.txt")
for(j in 1:3){
ks.test(j)
}
paste0("a", "b")
Normal01_1
summary(Normal01_1)
View(Normal01_1)
#--------no1-----
p1 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal01/3b_3PPCA01_Normal01_1.txt")
head(no1)
#--------N2_------
Normal02_1 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal02/3b_3PPCA01_Normal02_1.txt")
Normal02_2 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal02/3b_3PPCA01_Normal02_2.txt")
Normal02_3 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal02/3b_3PPCA01_Normal02_3.txt")
Normal02_4 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal02/3b_3PPCA01_Normal02_4.txt")
Normal02_5 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal02/3b_3PPCA01_Normal02_5.txt")
Normal02_6 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal02/3b_3PPCA01_Normal02_6.txt")
Normal02_7 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal02/3b_3PPCA01_Normal02_7.txt")
Normal02_8 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal02/3b_3PPCA01_Normal02_8.txt")
Normal02_9 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal02/3b_3PPCA01_Normal02_9.txt")
Normal02_10 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal02/3b_3PPCA01_Normal02_10.txt")
N2_ <- list(Normal02_1,Normal02_2,Normal02_3,Normal02_4,Normal02_5,Normal02_6,Normal02_7,Normal02_8,Normal02_9,Normal02_10)
N2_1 = data.frame(N2_)
#----------N3_-----
Normal03_1 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal03/3b_3PPCA01_Normal03_1.txt")
Normal03_2 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal03/3b_3PPCA01_Normal03_2.txt")
Normal03_3 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal03/3b_3PPCA01_Normal03_3.txt")
Normal03_4 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal03/3b_3PPCA01_Normal03_4.txt")
Normal03_5 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal03/3b_3PPCA01_Normal03_5.txt")
Normal03_6 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal03/3b_3PPCA01_Normal03_6.txt")
Normal03_7 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal03/3b_3PPCA01_Normal03_7.txt")
Normal03_8 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal03/3b_3PPCA01_Normal03_8.txt")
Normal03_9 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal03/3b_3PPCA01_Normal03_9.txt")
Normal03_10 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA01_Normal03/3b_3PPCA01_Normal03_10.txt")
list(paste(Normal103_1, sep="",1:10))
N3<-list(Normal03_1,Normal03_2,Normal03_3,Normal03_4,Normal03_5,Normal03_6,Normal03_7,Normal03_8,Normal03_9,Normal03_10)
N3_ <- data.frame(N3)
summary(N3_)
t.test(N3_)
lm(N3_)
plot(lm(N3_))
head(data.frame(N3))
lapply(Normal03_ )
?lapply()
for(i in 1:length(Normal03_1))
load(Normal03_1[[i]])
#---------no2a---------
## Wush 大方法
paste("year", sep ="" , 1:10)
flist<- dir("C:/Users/Robotlab/Pictures/prc/normal", "*.txt", recursive=TRUE)
result<-list()
for(path in flist) {
name <- basename(path)
result[[path]]<-read_csv(path)
}
ii_Normal01_1 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal01/3b_3PPCA02_Normal01_1.txt")
ii_Normal01_2 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal01/3b_3PPCA02_Normal01_2.txt")
ii_Normal01_3 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal01/3b_3PPCA02_Normal01_3.txt")
ii_Normal01_4 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal01/3b_3PPCA02_Normal01_4.txt")
ii_Normal01_5 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal01/3b_3PPCA02_Normal01_5.txt")
ii_Normal01_6 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal01/3b_3PPCA02_Normal01_6.txt")
ii_Normal01_7 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal01/3b_3PPCA02_Normal01_7.txt")
ii_Normal01_8 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal01/3b_3PPCA02_Normal01_8.txt")
ii_Normal01_9 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal01/3b_3PPCA02_Normal01_9.txt")
ii_Normal01_10 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal01/3b_3PPCA02_Normal01_10.txt")
paste("Normal01_", sep = "", 1:10)
No2_<-list(ii_Normal01_1,ii_Normal01_2,ii_Normal01_3,ii_Normal01_4,ii_Normal01_5,ii_Normal01_6,ii_Normal01_7,ii_Normal01_8,ii_Normal01_9,ii_Normal01_10)
no2a <- data.frame(No2_)
summary(no2a)
for( i in 1 : 10)
{
ks.test(no2a$)
}
#T2.test Robust Hotelling T2 test
T2.test(no2a,no2b)
T2.test(no2b,no2c)
T2.test(no2a,ok_a)
T2.test(no2a,ok_b)
T2.test(no2a,ok_c)
T2.test(no2a,ok_d)
T2.test(no2a,ok_e)
T2.test(no2b,ok_a)
T2.test(no2b,ok_b)
T2.test(no2b,ok_c)
T2.test(no2b,ok_d)
T2.test(no2b,ok_e)
T2.test(no2c,ok_a)
T2.test(no2c,ok_b)
T2.test(no2c,ok_c)
T2.test(no2c,ok_d)
T2.test(no2c,ok_e)
?lapply()
bartlett.test(N3_)
x <- list(a = 1:10, beta = exp(-3:3), logic = c(TRUE,FALSE,FALSE,TRUE))
# compute the list mean for each list element
lapply(x, mean)
?tapply
mean()
n <- 17; fac <- factor(rep(1:3, length = n), levels = 1:5)
fac
table(fac)
tapply(1:n, fac, sum)
tapply(1:n, fac, sum, simplify = FALSE)
tapply(1:n, fac, range)
tapply(1:n, fac, quantile)
require(graphics)
head(InsectSprays)
plot(count ~ spray, data = InsectSprays)
bartlett.test(InsectSprays$count, InsectSprays$spray)
bartlett.test(count ~ spray, data = InsectSprays)
#---------n02b------
ii__Normal02_1 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal02/3b_3PPCA02_Normal02_1.txt")
ii__Normal02_2 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal02/3b_3PPCA02_Normal02_2.txt")
ii__Normal02_3 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal02/3b_3PPCA02_Normal02_3.txt")
ii__Normal02_4 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal02/3b_3PPCA02_Normal02_4.txt")
ii__Normal02_5 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal02/3b_3PPCA02_Normal02_5.txt")
ii__Normal02_6 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal02/3b_3PPCA02_Normal02_6.txt")
ii__Normal02_7 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal02/3b_3PPCA02_Normal02_7.txt")
ii__Normal02_8 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal02/3b_3PPCA02_Normal02_8.txt")
ii__Normal02_9 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal02/3b_3PPCA02_Normal02_9.txt")
ii__Normal02_10 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal02/3b_3PPCA02_Normal02_10.txt")
tempno2 = list(ii__Normal02_1,ii__Normal02_2 ,ii__Normal02_3,ii__Normal02_4,ii__Normal02_5, ii__Normal02_6,
ii__Normal02_7,ii__Normal02_8,ii__Normal02_9,ii__Normal02_10)
no2b <- data.frame(tempno2)
summary(plot(no2b))
bartlett.test(No2_1,no2b)
kruskal.test(No2_1$X.0.00001300,no2b$X.0.00007515)
library(rrcov)
?T2.test()
T2.test(no2b,no2c)
#----------n02c-----
ii_Normal03_1 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal03/3b_3PPCA02_Normal03_1.txt")
ii_Normal03_2 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal03/3b_3PPCA02_Normal03_2.txt")
ii_Normal03_3 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal03/3b_3PPCA02_Normal03_3.txt")
ii_Normal03_4 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal03/3b_3PPCA02_Normal03_4.txt")
ii_Normal03_5 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal03/3b_3PPCA02_Normal03_5.txt")
ii_Normal03_6 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal03/3b_3PPCA02_Normal03_6.txt")
ii_Normal03_7 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal03/3b_3PPCA02_Normal03_7.txt")
ii_Normal03_8 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal03/3b_3PPCA02_Normal03_8.txt")
ii_Normal03_9 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal03/3b_3PPCA02_Normal03_9.txt")
ii_Normal03_10 <- read_csv("C:/Users/Robotlab/Pictures/prc/normal/3b_3PPCA02_Normal03/3b_3PPCA02_Normal03_10.txt")
tempo2 = list(ii_Normal03_1,ii_Normal03_2,ii_Normal03_3,ii_Normal03_4,ii_Normal03_5,ii_Normal03_6,ii_Normal03_7,ii_Normal03_8,ii_Normal03_9,ii_Normal03_10)
no2c = data.frame(tempo2)
summary(plot(no2c))
@Rmj009

This comment has been minimized.

Copy link

commented Oct 26, 2017

nn1 = rep(1:26)
nn1a = c(LETTERS)
table(nn1,nn1a)
m <- cbind(1, 1:7) # the '1' (= shorter vector) is recycled
m
m <- cbind(m, 8:14)[, c(1, 3, 2)] # insert a column
m
cbind(1:7, diag(3)) # vector is subset -> warning

cbind(0, rbind(1, 1:3))
cbind(I = 0, X = rbind(a = 1, b = 1:3)) # use some names
xx <- data.frame(I = rep(0,2))
cbind(xx, X = rbind(a = 1, b = 1:3)) # named differently
?sapply

cbind()
#-----------preilmary----

ok_a = data.frame(ok)
ok_b = data.frame(ok2)
ok_c = data.frame(ok3)
ok_d = data.frame(ok4)
ok_e = data.frame(ok5)
ok_f = data.frame(ok6)

shapiro.test(ok$X__1)
qqnorm(ok$X__1);qqline(ok$X__1,col = 2)
shapiro.test(ok$X__2)
qqnorm(ok$X__2);qqline(ok$X__2,col = 2)
shapiro.test(ok$X__3)
qqnorm(ok$X__3);qqline(ok$X__3,col = 2)
shapiro.test(ok$X__4)
qqnorm(ok$X__4);qqline(ok$X__4,col = 2)
shapiro.test(ok$X__5)
qqnorm(ok$X__5);qqline(ok$X__5,col = 2)

#---------------------------loose ok/ok2/ok3/ok4/ok5/ok6

kruskal.test(ok)
kruskal.test(ok2)
kruskal.test(ok3)
kruskal.test(ok4)
kruskal.test(ok5)
kruskal.test(ok6)

bartlett.test(ok_a)
bartlett.test(ok_b)
bartlett.test(ok_c)
bartlett.test(ok_d)
bartlett.test(ok_e)
bartlett.test(ok_f)
#p-vaule = 1 do not reject H0 not stat sigifiant
#10 sort of data no difference
chisq.test(ok_a)
chisq.test(ok2)
chisq.test(ok3)
chisq.test(ok4)
t.test(ok_a)
ks.test(ok_a,ok_b)
shapiro.test()
?ks.test()
?t.test()
tt1 = sample(ok, 1)
yy1 = sample(N3_, 2,size = 100)
yy1
tt1
lm(tt1 ~ yy1)

?sample()
#T-test
t.test(ok_a$X0,N3_$X0.00029136)
t.test(ok_a,N3_)

f1 = c(paste("ff",sep="",1:10)) ; k1 = length(f1)
f2 = c(paste("FF",sep = "",1:10)) ; k2 = length(f2)
n = sample(ok_a, 10, replace = FALSE)
tm1 = gl(k1, 1,nk1k2,factor(f1))

#----------------------------
summary(ok)
summary(no1)

test Normality ----------------------------------------------------------

example data

#https://stackoverflow.com/questions/33489330/how-to-test-the-normality-of-many-variables-in-r-at-the-same-time
t <- as.data.frame(matrix(rnorm(700), 20,35))
View(t)
no2a
as.data.frame(no2a)
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")))
}

view(no2a_v2)
shapiro_test_df(no2a)
shapiro_test_df(no2a_v2)
shapiro_test_df(t_no2a_v2)
View(t_no2a)
?do.call
length(1)
alpha

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.