我有一些似乎有效的东西,只是前后处理出了问题。这是在基础 R 中。感谢您的帮助!
if(!require(psych)){install.packages("psych")}
if(!require(likert)){install.packages("likert")}
library(readxl)
setwd("MSSE 507 Capstone Data Analysis/")
read_xls("ProcessDataMSSE.xls")
Data = read_xls("ProcessDataMSSE.xls")
str(Data) # tbl_df, tbl, and data.frame classes
### Change Likert scores to factor and specify levels; factors because numeric values are ordinal
Data <- Data[, c(3:26)] # Get rid of the other columns! (Drop multiple columns)
Data$`1Pre` <- factor(Data$`1Pre`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`1Post` = factor(Data$`1Post`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`2Pre` <- factor(Data$`2Pre`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`2Post` = factor(Data$`2Post`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`3Pre` <- factor(Data$`3Pre`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`3Post` = factor(Data$`3Post`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`4Pre` <- factor(Data$`4Pre`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`4Post` = factor(Data$`4Post`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`5Pre` <- factor(Data$`5Pre`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`5Post` = factor(Data$`5Post`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`6Pre` <- factor(Data$`6Pre`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`6Post` = factor(Data$`6Post`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`7Pre` <- factor(Data$`7Pre`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`7Post` = factor(Data$`7Post`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`8Pre` <- factor(Data$`8Pre`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`8Post` = factor(Data$`8Post`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`9Pre` <- factor(Data$`9Pre`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`9Post` = factor(Data$`9Post`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`10Pre` <- factor(Data$`10Pre`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`10Post` = factor(Data$`10Post`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`11Pre` <- factor(Data$`11Pre`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`11Post` = factor(Data$`11Post`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`12Pre` <- factor(Data$`12Pre`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data$`12Post` = factor(Data$`12Post`,
levels = c("1", "2", "3", "4"),
ordered = TRUE)
Data <- factor(Data,levels=Data[3:26])
Data
### Double check the data frame
library(psych) # Loads psych package
headTail(Data) # Displays last few and first few data
str(Data) # Shows structure of an object (observations and variables, etc.) - in this case, ordinal factors with 4 levels (1 through 4)
summary(Data) # Summary of the number of times you see a data point
Data$`1Pre` # This allows us to check how many data points are really there
str(Data)
### Remove unnecessary objects, removing the data frame in this case (we've converted that data frame into a table with the read.table function above)
library(likert)
Data <- as.data.frame(Data) # Makes the tibble a data frame
likert(Data) # This will give the percentage responses for each level and group
Result = likert(Data)
summary(Result) # This will give the mean and SD
plot(Result,
main = "Pre and Post Treatment Percentage Responses",
ylab="Questions",
type="bar")