0% found this document useful (0 votes)
5 views8 pages

R Notebook

The document is an R Notebook detailing the analysis of a dataset related to patient satisfaction, including loading libraries, data exploration, and visualization. It includes data cleaning steps, exploratory data analysis (EDA), and the creation of a linear regression model to predict satisfaction levels. The dataset consists of various factors affecting patient satisfaction, with visualizations and statistical summaries provided throughout the analysis.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

R Notebook

The document is an R Notebook detailing the analysis of a dataset related to patient satisfaction, including loading libraries, data exploration, and visualization. It includes data cleaning steps, exploratory data analysis (EDA), and the creation of a linear regression model to predict satisfaction levels. The dataset consists of various factors affecting patient satisfaction, with visualizations and statistical summaries provided throughout the analysis.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

22/05/2025 15:58 R Notebook

R Notebook Code

loading libraries
Hide

library(tidyverse)

── Attaching core tidyverse packages ────────────────────────────────────── tidyverse 2.0.0 ─



✔ dplyr 1.1.4 ✔ readr 2.1.5
✔ forcats 1.0.0 ✔ stringr 1.5.1
✔ ggplot2 3.5.1 ✔ tibble 3.2.1
✔ lubridate 1.9.3 ✔ tidyr 1.3.1
✔ purrr 1.0.2 ── Conflicts ──────────────────────────────────────────────────────── t
idyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag() masks stats::lag()
ℹ Use the ]8;;http://conflicted.r-lib.org/conflicted package ]8;; to force all conflicts t
o become errors

Hide

library(rsample)
library(broom)

Hide

list.files()

[1] "chromedriver-win64 (1)" "chromedriver-win64 (1).zip"


[3] "Patient.csv" "project.nb.html"
[5] "project.Rmd"

loading data
Hide

data <- read.csv("datasetsatisfaction.csv")


data

satisfaction.in.RM Check.up.appointment Time.waiting Admin.procedures Hygiene


<int> <int> <int> <int>

1 1 1 1

2 2 1 2

2 1 1 2

2 2 4 1

file:///C:/Users/THINKPAD/Desktop/cd/project.nb.html 1/8
22/05/2025 15:58 R Notebook

satisfaction.in.RM Check.up.appointment Time.waiting Admin.procedures Hygiene


<int> <int> <int> <int>

3 4 1 1

2 2 3 4

2 3 3 3

2 1 1 1

2 1 3 3

3 3 3 3

1 10 f 453 | 1 5 f 17 l P i 1 2 3 4 5 6 46 N t

Hide

glimpse(data)

Rows: 453
Columns: 17
$ satisfaction.in.RM <int> 1, 2, 2, 2, 3, 2, 2, 2, 2, 3, 3, 2, 3, 2, 2, 3…
$ Check.up.appointment <int> 1, 2, 1, 2, 4, 2, 3, 1, 1, 3, 1, 3, 2, 4, 3, 3…
$ Time.waiting <int> 1, 1, 1, 4, 1, 3, 3, 1, 3, 3, 1, 2, 1, 1, 3, 3…

$ Admin.procedures <int> 1, 2, 2, 1, 1, 4, 3, 1, 3, 3, 1, 2, 2, 1, 3, 3… 
$ Hygiene.and.cleaning <int> 1, 1, 2, 1, 2, 1, 3, 1, 3, 3, 3, 2, 3, 1, 1, 3…
$ Time.of.appointment <int> 1, 2, 2, 2, 1, 1, 3, 1, 3, 3, 1, 2, 4, 1, 3, 3…
$ Quality.experience.dr. <int> 1, 2, 4, 4, 5, 4, 2, 1, 1, 3, 4, 4, 1, 4, 1, 1…
$ Specialists.avaliable <int> 1, 1, 4, 1, 5, 2, 2, 2, 3, 3, 1, 1, 2, 4, 3, 2…
$ Communication.with.dr <int> 1, 2, 4, 1, 5, 3, 2, 4, 3, 3, 1, 2, 2, 4, 1, 3…
$ Exact.diagnosis <int> 1, 1, 4, 4, 5, 3, 2, 4, 1, 3, 4, 2, 1, 4, 1, 3…
$ Modern.equipment <int> 1, 2, 1, 1, 2, 3, 2, 1, 3, 3, 1, 2, 4, 2, 3, 1…
$ friendly.health.care.workers <int> 1, 1, 4, 1, 5, 3, 2, 4, 3, 3, 1, 1, 3, 2, 3, 3…
$ lab.services <int> 1, 1, 4, 4, 5, 4, 2, 4, 5, 3, 1, 1, 4, 1, 1, 3…
$ avaliablity.of.drugs <int> 1, 1, 1, 5, 5, 2, 4, 1, 3, 3, 2, 2, 2, 1, 3, 2…
$ waiting.rooms <int> 1, 1, 2, 4, 1, 3, 2, 1, 3, 3, 2, 2, 2, 3, 3, 3…
$ hospital.rooms.quality <int> 1, 2, 2, 1, 1, 2, 3, 1, 3, 3, 2, 2, 3, 2, 3, 3…
$ parking..playing.rooms..caffes <int> 1, 1, 2, 1, 1, 3, 3, 1, 3, 3, 3, 1, 5, 2, 3, 3…

Hide

summary(data)

file:///C:/Users/THINKPAD/Desktop/cd/project.nb.html 2/8
22/05/2025 15:58 R Notebook

satisfaction.in.RM Check.up.appointment Time.waiting Admin.procedures


Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000
1st Qu.:2.000 1st Qu.:1.000 1st Qu.:1.000 1st Qu.:1.000
Median :2.000 Median :3.000 Median :2.000 Median :2.000
Mean :2.436 Mean :2.626 Mean :2.518 Mean :2.595
3rd Qu.:3.000 3rd Qu.:4.000 3rd Qu.:4.000 3rd Qu.:4.000
Max. :3.000 Max. :5.000 Max. :5.000 Max. :5.000
NA's :1 NA's :1 NA's :1 NA's :1
Hygiene.and.cleaning Time.of.appointment Quality.experience.dr. Specialists.avaliable
Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000
1st Qu.:2.000 1st Qu.:1.000 1st Qu.:1.000 1st Qu.:1.000
Median :3.000 Median :2.000 Median :3.000 Median :2.500
Mean :2.772 Mean :2.575 Mean :2.925 Mean :2.675
3rd Qu.:4.000 3rd Qu.:4.000 3rd Qu.:4.000 3rd Qu.:4.000
Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000
NA's :1 NA's :1 NA's :1 NA's :1
Communication.with.dr Exact.diagnosis Modern.equipment friendly.health.care.workers
Min. :1.000 Min. :1.00 Min. :1.000 Min. :1.00
1st Qu.:1.000 1st Qu.:1.00 1st Qu.:1.000 1st Qu.:2.00
Median :3.000 Median :3.00 Median :2.000 Median :3.00
Mean :2.814 Mean :2.83 Mean :2.507 Mean :2.83
3rd Qu.:4.000 3rd Qu.:4.00 3rd Qu.:3.000 3rd Qu.:4.00
Max. :5.000 Max. :5.00 Max. :5.000 Max. :5.00
NA's :1 NA's :1 NA's :1 NA's :1
lab.services avaliablity.of.drugs waiting.rooms hospital.rooms.quality
Min. :1.000 Min. :1.000 Min. :1.000 Min. :1.000
1st Qu.:1.000 1st Qu.:1.000 1st Qu.:2.000 1st Qu.:2.000
Median :3.000 Median :3.000 Median :3.000 Median :3.000
Mean :2.757 Mean :2.746 Mean :2.668 Mean :2.715
3rd Qu.:4.000 3rd Qu.:4.000 3rd Qu.:3.250 3rd Qu.:3.000
Max. :5.000 Max. :5.000 Max. :5.000 Max. :5.000
NA's :1 NA's :1 NA's :1 NA's :1
parking..playing.rooms..caffes
Min. :1.000
1st Qu.:2.000
Median :3.000
Mean :2.743
3rd Qu.:3.000
Max. :5.000
NA's :1

drop missing values


Hide

data <- drop_na(data)

Explanatory Data Analysis (EDA)


Hide

data %>%
distinct(satisfaction.in.RM)

file:///C:/Users/THINKPAD/Desktop/cd/project.nb.html 3/8
22/05/2025 15:58 R Notebook

satisfaction.in.RM
<int>

3 rows

Hide

data %>%
mutate(satisfaction.in.RM = as.factor(satisfaction.in.RM)) %>%
ggplot(aes(x =fct_infreq(satisfaction.in.RM )))+
geom_bar(fill = "red")+
coord_flip()+
labs(
title = "count of satisfaction",
x = "satisfation in RM",
caption = "figure by Dr.Kebbabi Abir"
)

Hide

data <- data %>%


mutate_if(is.integer, as.factor)

Hide

file:///C:/Users/THINKPAD/Desktop/cd/project.nb.html 4/8
22/05/2025 15:58 R Notebook

data %>%
ggplot(aes(x =fct_infreq( Time.waiting)))+
geom_bar(fill = "blue")+
coord_flip()+
labs(
title = "waiting time",
x = "rate",
caption = "figure by Dr.Kebbabi Abir"

plotting function
Hide

barplots <- function(a , col) {


data %>%
ggplot(aes(x =fct_infreq(a)))+
geom_bar(fill = col)+
coord_flip()+
labs(
caption = "figure by Dr.Kebbabi Abir"
)

Hide

barplots(data$Hygiene.and.cleaning , "darkgreen")

file:///C:/Users/THINKPAD/Desktop/cd/project.nb.html 5/8
22/05/2025 15:58 R Notebook

Hide

barplots(data$Quality.experience.dr. , "darkred")

Hide

data_model <- data %>%


mutate_if(is.factor, as.integer)

file:///C:/Users/THINKPAD/Desktop/cd/project.nb.html 6/8
22/05/2025 15:58 R Notebook

creating linear regression model


Hide

set.seed(123)
data_split <- initial_split(data_model , prop = 0.8 , strata = satisfaction.in.RM )
train <- training(data_split)
test <- testing(data_split)

Hide

model <- lm(satisfaction.in.RM~. , data = train)


tidy(model)

term estimate std.error statistic p.value


<chr> <dbl> <dbl> <dbl> <dbl>

(Intercept) 2.442500383 0.08294458 29.44737684 4.825379e-96

Check.up.appointment 0.011648314 0.02589021 0.44991198 6.530573e-01

Time.waiting -0.017764726 0.02869572 -0.61907224 5.362785e-01

Admin.procedures 0.006086613 0.02865742 0.21239226 8.319268e-01

Hygiene.and.cleaning 0.013165699 0.03178706 0.41418422 6.789973e-01

Time.of.appointment -0.011171327 0.02937992 -0.38023675 7.040043e-01

Quality.experience.dr. 0.034623034 0.02798460 1.23721738 2.168503e-01

Specialists.avaliable -0.002128679 0.02871546 -0.07413008 9.409500e-01

Communication.with.dr 0.010457772 0.03221669 0.32460723 7.456757e-01

Exact.diagnosis 0.060210656 0.02865007 2.10158849 3.631622e-02

1-10 of 17 rows Previous 1 2 Next


 

Hide

pred <- predict(model , test)

accuracy function
Hide

ms <- function(actual , predicted) {


a <- mean((actual- predicted)^2)
return(a)

Hide

ms(test$satisfaction.in.RM , pred)

file:///C:/Users/THINKPAD/Desktop/cd/project.nb.html 7/8
22/05/2025 15:58 R Notebook

[1] 0.2928149

file:///C:/Users/THINKPAD/Desktop/cd/project.nb.html 8/8

You might also like