Skip to content

Commit

Permalink
re-render book
Browse files Browse the repository at this point in the history
  • Loading branch information
hcp4715 committed Sep 20, 2024
1 parent 11e8bac commit c979cd5
Show file tree
Hide file tree
Showing 41 changed files with 273 additions and 276 deletions.
80 changes: 36 additions & 44 deletions Book/1001-lesson1_2024.Rmd

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Book/1004-lesson4_2024.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ cat(normalized_path)
pacman::p_load(here)
# here::here()
here::here("data","penguin","penguin_rawdata.csv")
here::here("Book","data","penguin","penguin_rawdata.csv")
```

[注:在Python及大多数编程语言中,路径都支持斜杠(/)]
Expand Down Expand Up @@ -162,7 +162,7 @@ OK,我们前面演示了如何通过点击的方式读取数据。那么我们

```{r echo=TRUE, eval=FALSE}
# 读取数据,命名为penguin_data
penguin_data = import(here::here('data', 'penguin', 'penguin_rawdata.csv'))
penguin_data = import(here::here("Book",'data', 'penguin', 'penguin_rawdata.csv'))
# 查看头(head) 5 行,有头就有尾(tail)
# head(penguin_data,n = 3)
# tail(penguin_data,n = 3)
Expand Down
8 changes: 4 additions & 4 deletions Book/1005-lesson5_2024.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ knitr::include_graphics('./pic/chp5/abspath.jpg')
在R语言中,路径分隔符要求为斜杠(/),注意不能直接从路径栏中直接复制地址。这是一个非常细节的问题,但也有更加方便的方式来解决这个问题,即使用`here::here()`函数,只需要在这个函数中按顺序依次输出,比如对于上面的相对路径就可以写为:

```{r eval=FALSE}
here::here('data','penguin','penguin_rawdata.csv')
here::here("Book",'data','penguin','penguin_rawdata.csv')
```

## 读取数据
Expand All @@ -126,7 +126,7 @@ knitr::include_graphics('./pic/chp5/imp1.png')
当然,我们更推荐使用代码的方式来导入数据:

```{r}
penguin_data = bruceR::import(here::here('data', 'penguin', 'penguin_rawdata.csv'))
penguin_data = bruceR::import(here::here("Book",'data', 'penguin', 'penguin_rawdata.csv'))
ncol(penguin_data)
nrow(penguin_data)
```
Expand Down Expand Up @@ -562,14 +562,14 @@ file、encoding
## 没有声明形参
penguin_data =
bruceR::import(
here::here('data', 'penguin', 'penguin_rawdata.csv'), ### file
here::here("Book",'data', 'penguin', 'penguin_rawdata.csv'), ### file
NULL ### encoding
)
## 如果声明形参,顺序可以调换
penguin_data =
bruceR::import(
encoding = NULL,
file = here::here('data', 'penguin', 'penguin_rawdata.csv')
file = here::here("Book",'data', 'penguin', 'penguin_rawdata.csv')
)
## 当然,如果按照这个顺序不输入形参的话会报错,大家可自行尝试
```
Expand Down
8 changes: 4 additions & 4 deletions Book/1006-lesson6_2024.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ temperature。右边则是用身体温度来预测其他变量。我们主要关

```{r}
# 导入数据
df1 <- bruceR::import(here::here('data', 'penguin', 'penguin_rawdata.csv'))
df1 <- bruceR::import(here::here("Book",'data', 'penguin', 'penguin_rawdata.csv'))
```

下面是被读取的数据文件:
Expand Down Expand Up @@ -773,7 +773,7 @@ for (i in 1:10){
```{r for loop list.files, error=FALSE}
# 把所有符合某种标题的文件全部读取到一个list中
# 使用 full.names 参数获取完整路径的文件列表
files <- list.files(here::here("data", "match"), pattern = "data_exp7_rep_match_.*\\.out$", full.names = TRUE)
files <- list.files(here::here("Book","data", "match"), pattern = "data_exp7_rep_match_.*\\.out$", full.names = TRUE)
head(files, n = 10L)
str(files)
```
Expand Down Expand Up @@ -857,7 +857,7 @@ rm(df, files, i)

```{r error=FALSE}
# 获取所有的.out文件名
files <- list.files(here::here("data", "match"), pattern = "data_exp7_rep_match_.*\\.out$", full.names = TRUE)
files <- list.files(here::here("Book","data", "match"), pattern = "data_exp7_rep_match_.*\\.out$", full.names = TRUE)
# 读取每个.out文件,并进行数据清洗
df3 <- lapply(files, function(file) {
df <- read.table(file, header = TRUE)
Expand All @@ -882,7 +882,7 @@ OK,假定大家都理解了这个`forloop`,那就我们就能够把这个`df
```{r error=FALSE}
#for loop 或 lapply的都可以
write.csv(df3,
file = here::here("data", "match","match_raw.csv"),
file = here::here("Book","data", "match","match_raw.csv"),
row.names = FALSE)
```

Expand Down
8 changes: 4 additions & 4 deletions Book/1007-lesson7_2024.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pacman::p_load(here,skimr,quartets,GGally,showtext,bruceR,tidyverse,DataExplorer
# 所有数据路径
files <- list.files(
## <- & =
here::here("data", "match"),
here::here("Book", "data", "match"),
pattern = "data_exp7_rep_match_.*.out$",
full.names = TRUE)
```
Expand Down Expand Up @@ -72,7 +72,7 @@ rm(df, files, i)
## 上节课介绍了write.csv,也可使用bruceR::export
bruceR::export(
df3,
file = here::here("data", "match","match_raw.csv"))
file = here::here("Book","data", "match","match_raw.csv"))
## 当然,export 不仅可以保存数据,也可以输出模型结果
Expand Down Expand Up @@ -133,10 +133,10 @@ Analysis,EDA),在传统的心理学中,我们通常会清楚地知道要
```{r eval = T}
# 读取数据
pg_raw <- bruceR::import(here::here(
"data", "penguin","penguin_rawdata.csv"))
"Book","data", "penguin","penguin_rawdata.csv"))
mt_raw <- bruceR::import(here::here(
"data", "match","match_raw.csv"))
"Book","data", "match","match_raw.csv"))
```

### 常用函数介绍
Expand Down
2 changes: 1 addition & 1 deletion Book/1008-lesson8_2024.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ $$t = \frac{\bar{X}_1 - \bar{X}_2}{\sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}}}

这些步骤都是数据预处理的一部分,是进行*t*检验之前必要的步骤。
```{r preprocessing}
df.penguin <- bruceR::import(here::here('data', 'penguin', 'penguin_rawdata.csv')) %>%
df.penguin <- bruceR::import(here::here("Book",'data', 'penguin', 'penguin_rawdata.csv')) %>%
dplyr::mutate(subjID = row_number()) %>%
dplyr::select(subjID,Temperature_t1, Temperature_t2, socialdiversity,
Site, DEQ, romantic, ALEX1:ALEX16) %>% # 选择变量
Expand Down
4 changes: 2 additions & 2 deletions Book/1009-lesson9_2024.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ xaringanExtra::use_panelset()

[预处理]
```{r}
df.penguin <- bruceR::import(here::here('data', 'penguin', 'penguin_rawdata.csv')) %>%
df.penguin <- bruceR::import(here::here("Book",'data', 'penguin', 'penguin_rawdata.csv')) %>%
dplyr::mutate(subjID = row_number()) %>%
dplyr::select(subjID,Temperature_t1, Temperature_t2, socialdiversity,
Site, DEQ, romantic, ALEX1:ALEX16) %>%
Expand Down Expand Up @@ -106,7 +106,7 @@ df.penguin %>%

[预处理]
```{r}
mt_raw <- bruceR::import(here::here('data','match','match_raw.csv'))
mt_raw <- bruceR::import(here::here("Book",'data','match','match_raw.csv'))
mt_raw <- mt_raw %>%
tidyr::extract(Shape,
Expand Down
2 changes: 1 addition & 1 deletion Book/1010-lesson10_2024.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ options(scipen=99999,digits = 5)

```{r, echo = FALSE}
#读取数据
df.match <- bruceR::import(here::here('data','match','match_raw.csv')) %>%
df.match <- bruceR::import(here::here("Book",'data','match','match_raw.csv')) %>%
tidyr::extract(Shape,
into = c('Valence', 'Identity'),
regex = '(moral|immoral)(Self|Other)',
Expand Down
4 changes: 2 additions & 2 deletions Book/1011-lesson11_2024.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ $$= i_4 + c'X + abX + e_5$$

```{r echo = F}
# 数据导入
pg_raw = bruceR::import(here::here('data','penguin','penguin_rawdata_full.csv'))
pg_raw = bruceR::import(here::here("Book",'data','penguin','penguin_rawdata_full.csv'))
# 计算CSI
### get the column names:
Expand Down Expand Up @@ -509,7 +509,7 @@ grViz(

```{r}
# 数据导入
pg_raw = bruceR::import(here::here('data','penguin','penguin_rawdata_full.csv'))
pg_raw = bruceR::import(here::here("Book",'data','penguin','penguin_rawdata_full.csv'))
```

数据预处理这里,可能会有很多这种变量名的选择,还有一些重新编码,
Expand Down
2 changes: 1 addition & 1 deletion Book/1012-lesson12_2024.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ options(scipen=99999,digits = 5)
首先这是实验中每个试次的数据。

```{r}
df.match.trial <- bruceR::import(here::here('data','match','match_raw.csv')) %>%
df.match.trial <- bruceR::import(here::here("Book",'data','match','match_raw.csv')) %>%
tidyr::extract(Shape,
into = c('Valence', 'Identity'),
regex = '(moral|immoral)(Self|Other)',
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Book/_book/_main_files/figure-html/unnamed-chunk-255-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Book/_book/_main_files/figure-html/unnamed-chunk-275-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Book/_book/_main_files/figure-html/unnamed-chunk-277-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Book/_book/_main_files/figure-html/unnamed-chunk-278-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Book/_book/_main_files/figure-html/unnamed-chunk-288-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Book/_book/_main_files/figure-html/unnamed-chunk-289-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Book/_book/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ <h1>
<div id="header">
<h1 class="title">R语言在心理学研究中的应用: 从原始数据到可重复的论文手稿(V2)</h1>
<p class="author"><em>胡传鹏(等)</em></p>
<p class="date"><em>2024年09月12日</em></p>
<p class="date"><em>2024年09月20日</em></p>
</div>
<div id="引言" class="section level1 unnumbered hasAnchor">
<h1>引言<a href="index.html#引言" class="anchor-section" aria-label="Anchor link to header"></a></h1>
Expand Down
Loading

0 comments on commit c979cd5

Please sign in to comment.