OpenR - All posts https://connect.xjtlu.edu.cn/,g,1370 https://connect.xjtlu.edu.cn/theme/modern/images/site-logo.svg https://connect.xjtlu.edu.cn/favicon.ico Mahara 2023-04-07T13:11:05+08:00 Re: Question for ANOVA Post-hoc test https://connect.xjtlu.edu.cn/,1300,3202 Either is fine. When you use p.adj = "none", you compare the p values with alpha/m (0.0167 in this example):

>
pairwise.t.test(dtf2\$wg, dtf2\$diet, pool.sd = FALSE,var.equal = TRUE, p.adj = "none") Pairwise comparisons using t tests with non-pooled SD data: dtf2\$wg and dtf2\$diet diet1 diet2 diet2 0.0018 - diet3 0.0010 0.2879 P value adjustment method: none

When you use p.adj = "bonferroni", you compare the p values with alpha (0.05 in this example):

>
pairwise.t.test(dtf2\$wg, dtf2\$diet, pool.sd = FALSE,var.equal = TRUE, p.adj = "bonferroni") Pairwise comparisons using t tests with non-pooled SD data: dtf2\$wg and dtf2\$diet diet1 diet2 diet2 0.0055 - diet3 0.0030 0.8636 P value adjustment method: bonferroni

The p-values in the latter is just 3 times the former ones.

]]>
Peng Zhao 2023-04-07T13:11:05+08:00
Question for ANOVA Post-hoc test https://connect.xjtlu.edu.cn/,1300,3199 In this week's lecture,  we used the `pairwise.t.test()` function to conduct one step Bonferroni t-test. The `p.adj` parameter in this function is set to `none` in the lecture material. But after reading the function documentation, it seems that `none` does not adjust p-values for multiple comparisons. So should I change the method to `bonferroni`? ]]>
Xingyu Hu 2023-04-02T20:50:45+08:00
Re: questions about exercise 1.4 of "R for time data" https://connect.xjtlu.edu.cn/,1286,3179 I got it,  thank you.

]]>
Mingrui Li 2023-03-17T17:36:13+08:00
Re: questions about exercise 1.4 of "R for time data" https://connect.xjtlu.edu.cn/,1286,3178 These two questions are both related to factors.

If "weekdays" is not converted into a factor, the plot() function cannot get the x coordinate and fails in mapping the values on the graph.

A character object is nominal, while a factor is ordinal. The sequence of the members in a factor is the x coordinates for plotting.

More details could be found here.

]]>
Peng Zhao 2023-03-17T08:50:05+08:00
questions about exercise 1.4 of "R for time data" https://connect.xjtlu.edu.cn/,1286,3176 dates <- seq(as.Date("2010-09-13"), as.Date("2040-09-13"), by="year")
weekdays <- format(dates, format = "%A")
weekdayplot <- data.frame(years=(format(dates, format = "%Y")),weekdays)
library(ggplot2)
ggplot(weekdayplot, aes(x = weekdays, y = years)) +
geom_point() +
labs(title = "September 13th of 2000 to 2050", x = "Weekday", y = "Year")

plot(years ~ as.factor(weekdays), weekdayplot, main = title)

#### as the codes shows above, why there must be "as.factor" in the last line of codes or will encounter errors like this: #### additionally, the x axisof the figure obtained by the codes of last line are numbers instead of "Monday"....is that true that the xaxis must be numbers?

]]>
Mingrui Li 2023-03-15T17:33:00+08:00
Re: question about layout function https://connect.xjtlu.edu.cn/,1284,3173 thanks for reply, i get it.

]]>
Ziyu Yuan 2023-03-14T00:02:43+08:00
Re: question about layout function https://connect.xjtlu.edu.cn/,1284,3172 I don't think you can skip 2 from c(1, 3:5), and you give 3 widths for 2 columns.

]]>
Peng Zhao 2023-03-13T20:32:25+08:00
question about layout function https://connect.xjtlu.edu.cn/,1284,3171 mymat1 <- matrix(c(1,3:5),nrow = 2)
layout(mat = mymat1,widths = c(1,1,2),heights = c(1,2))

plot(airquality\$Solar.R, airquality\$Ozone)
hist(airquality\$Solar.R)
barplot(airquality\$Month)
plot(airquality\$Solar.R, airquality\$Ozone)

--------

above is my code, and I find that there exists a mistake that "格式矩阵至少要对{1 ... 5}里每一个值都有参考值" when running the second line.

what does it mean? what is "matrix(c(1,3:5))" stand for?

]]>
Ziyu Yuan 2023-03-13T18:06:51+08:00
Re: role_count的环境变量是NA https://connect.xjtlu.edu.cn/,1236,3096 You mentioned 人物别称.txt in your script, but I can't find it in your attachments.

]]>
Peng Zhao 2022-11-23T18:00:22+08:00
Re: role_count的环境变量是NA https://connect.xjtlu.edu.cn/,1236,3094 Because in this step

colnames(role_para) = sapply(roles_l, function(x) x)

you did not set what function(x) x is, the colnames(role_para) will be full of NA. Then in this step

role_count = data.frame(role = factor(colnames(role_para),

you set role_count\$role=factor(colnames(role_para)), then role_count\$role will definately be full of NA.

]]>
Shanxing Gong 2022-11-23T12:59:19+08:00
Re: role_count的环境变量是NA https://connect.xjtlu.edu.cn/,1236,3093 sorry,sir! And then I try to delect the  "levels = colnames(role_para[order(colSums(role_para), decreasing = TRUE)])" .

Run successfully but my box plot cannot be sorted by frequency just as I predicted.

And these two files are my txt used in text analysis.

]]>
Ya Wang 2022-11-22T22:26:34+08:00
Re: role_count的环境变量是NA https://connect.xjtlu.edu.cn/,1236,3092 Please describe your issue in the post, so that everyone could understand it.

Did you upload an irrelevant file?

BTW, in English.

]]>
Peng Zhao 2022-11-22T21:46:04+08:00
role_count的环境变量是NA https://connect.xjtlu.edu.cn/,1236,3091 library(ggplot2)
roles1 = paste0("(", gsub(" ", ")|(", roles), ")")
roles_l = strsplit(roles, " ") # 总结每个人的不同称呼

#计算每个人物出场总次数
role_para = sapply(roles1, grepl, txt)
colnames(role_para) = sapply(roles_l, function(x) x)
role_count = data.frame(role = factor(colnames(role_para),
levels = colnames(role_para[order(colSums(role_para), decreasing = TRUE)])),
count = colSums(role_para))

ggplot(role_count, aes(x = role, y = count, fill = role)) +
geom_bar(stat = "identity", width = 0.75) +
labs(title="倚天屠龙记主要人数登场次数",x="人物",y="登场次数")+
geom_text(aes(label=count),size=5,vjust=-0.2)+
theme(axis.text=element_text(size=20, angle = 90),
axis.title=element_text(size=15,face="bold"),
axis.title.x = element_text(vjust=-1),
legend.position="none",
plot.title = element_text(size=20,face='plain',hjust = 0.5),
panel.grid = element_blank())

]]>
Ya Wang 2022-11-22T20:45:08+08:00
R workshop https://connect.xjtlu.edu.cn/,1217,3068 Dr. Yi Zou and I will give an R workshop series. The time and link for registration could be found at https://connect.xjtlu.edu.cn/user/askalibrarian/library-newsletter-november-2022

Feel free to spread this message to anyone who is interested. Non-XJTLUers could register at https://xjtlu.mike-x.com/ewRyH.

]]>
Peng Zhao 2022-11-03T21:43:20+08:00
Re: 【我和我的屎山代码】else in a serie of if （）{}else{}can not work well https://connect.xjtlu.edu.cn/,1195,3033 #'OH! by some one's reminding I tried to use another else before the second if and it seems can run suuuuuccessfully!'

df_iris = iris

df_setosa=data.frame()
df_versicolor=data.frame()
df_virginica=data.frame()
a=1
b=1
c=1
x=1:150
for (i in x)
{
y = df_iris[i,1:5]
if
(df_iris[i,'Species'] == "setosa")
{df_setosa[a,1:5] = y
a=a+1}
else
if
(df_iris[i,'Species'] == "versicolor")
{df_versicolor[b,1:5] = y
b=b+1}
else
{df_virginica[c,1:5] = y
c=c+1}
}
write.csv(df_setosa, "setosa.csv")
write.csv(df_versicolor,"versicolor.csv")
write.csv(df_virginica,"virginica.csv")

]]>
Zhongpu Yang 2022-09-30T10:46:22+08:00
Re: 【我和我的屎山代码】else in a serie of if （）{}else{}can not work well https://connect.xjtlu.edu.cn/,1195,3032 it seems like else only process in the last if () {}else{} structrue

how can I solve it?

]]>
Zhongpu Yang 2022-09-30T10:43:19+08:00
【我和我的屎山代码】else in a serie of if （）{}else{}can not work well https://connect.xjtlu.edu.cn/,1195,3031 df_iris = iris

df_setosa=data.frame()
df_versicolor=data.frame()
df_virginica=data.frame()
a=1
b=1
c=1
x=1:150
for (i in x)
{
y = df_iris[i,1:5]
if
(df_iris[i,'Species'] == "setosa")
{df_setosa[a,1:5] = y
a=a+1}
if
(df_iris[i,'Species'] == "versicolor")
{df_versicolor[b,1:5] = y
b=b+1}
if
(df_iris[i,'Species'] == "virginica")
{df_virginica[c,1:5] = y
c=c+1}
}
write.csv(df_setosa, "setosa.csv")
write.csv(df_versicolor,"versicolor.csv")
write.csv(df_virginica,"virginica.csv")

#'this can work well but else seem can not work below'

df_iris = iris

df_setosa=data.frame()
df_versicolor=data.frame()
df_virginica=data.frame()
a=1
b=1
c=1
x=1:150
for (i in x)
{
y = df_iris[i,1:5]
if
(df_iris[i,'Species'] == "setosa")
{df_setosa[a,1:5] = y
a=a+1}
if
(df_iris[i,'Species'] == "versicolor")
{df_versicolor[b,1:5] = y
b=b+1}
else
{df_virginica[c,1:5] = y
c=c+1}
}
write.csv(df_setosa, "setosa.csv")
write.csv(df_versicolor,"versicolor.csv")
write.csv(df_virginica,"virginica.csv")

#'this output will be like virginica and setosa both in virginica document'

]]>
Zhongpu Yang 2022-09-30T10:40:44+08:00
Re: ENV221 2022/2023 starts https://connect.xjtlu.edu.cn/,1174,3012 Hello!

]]>
Jiayi Chen 2022-09-17T11:33:39+08:00
Re: ENV221 2022/2023 starts https://connect.xjtlu.edu.cn/,1174,3010 Hello

]]>
Shanxing Gong 2022-09-15T14:32:06+08:00
Re: ENV221 2022/2023 starts https://connect.xjtlu.edu.cn/,1174,3009 Hello!

]]>
Xingyu Hu 2022-09-15T13:53:48+08:00