I am trying to do the "Fixed/Random Effects Models using R" exercise found at (https://rstudio-pubs-static.s3.amazonaws.com/372492_3e05f38dd3f248e89cdedd317d603b9a.html)
However, for homework I have been asked to use a different dataset containing cosmetic surgery information for patients at various clinics.
I have tried to plot my dataset using coplot like so:
coplot(y ~ Surgery|Clinic, type="b", data=cosmsur)
But I get the following error:
Error in eval(y, data, parent.frame()) : object 'y' not found
Having checked the coplot information using ?coplot I do not see how object 'y' cannot be found since it is merely defining the y axis of the plot - what is going wrong please?
This is the code I have been working with to get to this error:
# 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