df0 = read.csv("Sleep2.csv")
df0$before = as.numeric(df0$before_Bed_Glucose)
df0$after = as.numeric(df0$After_Bed_Glucose)
str(df0$Times)
## int [1:637] 1 2 3 4 5 6 7 8 9 10 ...
df = df0[,c(1,2,4,10,11)]
# chaniging the 1345 value to 134:
df[232, 4] = 134
summary(df$before_Bed_Glucose)
## Min. 1st Qu. Median Mean 3rd Qu. Max. NA's
## 75.0 125.0 160.0 171.1 192.0 463.0 164
attach(df)
summary(df$Times)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 1 13 25 25 37 49
# ---------------------------- Before Scores:
fit_before=lm(before_Bed_Glucose~Times,data=df)
summary(fit_before)
##
## Call:
## lm(formula = before_Bed_Glucose ~ Times, data = df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -104.89 -44.69 -11.53 24.67 278.63
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 184.9254 6.0325 30.655 < 2e-16 ***
## Times -0.5598 0.2132 -2.626 0.00893 **
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 64.7 on 471 degrees of freedom
## (164 observations deleted due to missingness)
## Multiple R-squared: 0.01443, Adjusted R-squared: 0.01233
## F-statistic: 6.894 on 1 and 471 DF, p-value: 0.008929
require(ggplot2)
ggplot(df,aes(y=before_Bed_Glucose,x=Times))+
geom_point(alpha = .45)+
xlab("Day")+
ylab("Before Bed Glucose")+
xlim(1,50)+
ylim(50,500)+
geom_smooth(method="lm")
## Warning: Removed 164 rows containing non-finite values (stat_smooth).
## Warning: Removed 164 rows containing missing values (geom_point).

—————————- After Scores:
fit_after=lm(After_Bed_Glucose~Times,data=df)
summary(fit_after)
##
## Call:
## lm(formula = After_Bed_Glucose ~ Times, data = df)
##
## Residuals:
## Min 1Q Median 3Q Max
## -84.068 -29.522 -8.638 17.338 297.629
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 158.1840 4.5753 34.574 < 2e-16 ***
## Times -0.5697 0.1673 -3.406 0.000724 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 47.15 on 411 degrees of freedom
## (224 observations deleted due to missingness)
## Multiple R-squared: 0.02745, Adjusted R-squared: 0.02508
## F-statistic: 11.6 on 1 and 411 DF, p-value: 0.0007242
ggplot(df,aes(y=After_Bed_Glucose,x=Times))+
geom_point(alpha=.45)+
xlab("Day")+
ylab("After Bed Glucose")+
xlim(1,50)+
ylim(50,500)+
geom_smooth(method="lm")
## Warning: Removed 224 rows containing non-finite values (stat_smooth).
## Warning: Removed 224 rows containing missing values (geom_point).
