1

我正在尝试在(https://rstudio-pubs-static.s3.amazonaws.com/372492_3e05f38dd3f248e89cdedd317d603b9a.html)找到“使用 R 的固定/随机效应模型”练习

然而,对于家庭作业,我被要求使用不同的数据集,其中包含不同诊所患者的整容手术信息。

我尝试使用 coplot 来绘制我的数据集,如下所示:

coplot(y ~ Surgery|Clinic, type="b", data=cosmsur)

但我收到以下错误:

Error in eval(y, data, parent.frame()) : object 'y' not found

使用 ?coplot 检查了 coplot 信息后,我看不到如何找不到对象“y”,因为它只是定义了绘图的 y 轴 - 请问出了什么问题?

这是我一直在使用以解决此错误的代码:

# First, set wd to: [setwd("~/OneDrive - University College London/2. UCL DEGREE/COURSES/1. PSYC0223- Introduction to Statistics for Psychology/R Studio/Metacognition and Optimal Reminders/Session 3/My Practice")]
# Then, load the specialist libraries you need for this exercise:
library(tidyverse) # Modern data science library 
library(plm)       # Panel data analysis library
library(car)       # Companion to applied regression
library(gplots)    # Various programing tools for plotting data
library(tseries)   # For timeseries analysis
library(lmtest)    # For hetoroskedasticity analysis
# Finally, define your dataset for this R sc ript: cosmsur for "Cosmetic Surgery" data from the "Mixed and Random Effects Modelling" topic in your PSYC0223 Course:
cosmsur <- read_csv("Cosmetic_Surgery.csv")
### Data Import and Tidying
head(cosmsur)
# We now need to set cosmsur as panel data:
# Remember, you can achieve this using the plm funcion [cosmsur <- plm.data(cosmsur, index=c("surgery","clinic"))]
# But use of 'plm.data' is discouraged, better use 'pdata.frame' instead:
cosmsur <- pdata.frame(cosmsur, index=c("Post_QoL","Surgery","Clinic"))
# Warning message:In pdata.frame(cosmsur, index = c("Post_QoL", "Surgery", "Clinic")) :duplicate couples (id-time) in resulting pdata.frame; to find out which, use e.g. table(index(your_pdataframe), useNA = "ifany"):
table(index(cosmsur), useNA = "ifany")
head(cosmsur)
## 2.1 View tabular data
cosmsur
### 3 Exploratory Data Analysis
# Let's first visualise our dataset using a special plot function "coplot":
coplot(y ~ Surgery|Clinic, type="b", data=cosmsur)
Error in eval(y, data, parent.frame()) : object 'y' not found
?coplot
4

0 回答 0