10 - Akhmad Safrin Sadad Khan - 191810101104

You might also like

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 3

---

title: "Praktikum 10"


author: "Akhmad Safrin Sadad Khan"
date: "11/2/2021"
output: html_document
---

```{r setup, include=FALSE}


knitr::opts_chunk$set(echo = TRUE)
```

```{r}
library(MASS)
data(hills)
hills
```

```{r}
model_time <- lm(formula = time ~ dist+climb, data = hills)
model_time <- lm(formula = time ~ ., data = hills)
model_time
```

```{r}
summary(model_time)
```

```{r}
model_time2 <- lm(time~dist,hills)
```

```{r}
summary(model_time2)$r.squared
summary(model_time)$r.squared
```

```{r}
summary(model_time2)$adj.r.squared
summary(model_time)$adj.r.squared
```

```{r}
insurances<-read.csv("train_insurance.csv")
str(insurances)
```
```{r}
insurance <- insurances mutate_if(is.character,as.factor)
head(insurance)
```

```{r}
anyNA(insurances)
```

```{r}
plot(insurances$bmi,insurances$charges)
```

```{r}
insurances
ggplot(aes(bmi,charges))+
geom_point()+
geom_smooth(method = "lm")+
theme_minimal()

```

```{r}
df_agg <- insurances %>%
group_by(region,sex) %>%
summarise(charges=mean(charges))%>%
ungroup()

df_agg %>%
ggplot(aes(x = region,y = sex, fill = charges)) +
geom_tile() +
scale_fill_gradient(low = "firebrick", high = "lightyellow") +
theme_minimal()
```

```{r}
model_charges <- lm(formula = charges ~ age + children + bmi,data=insurances)
summary(model_charges)
```

```{r}
model_charges2 <- lm(formula = charges ~ age + bmi,data=insurances)
summary(model_charges2)
```
```{r}
model_charges3 <- lm(formula = charges ~ age + children + bmi + sex
,data=insurances)
summary(model_charges3)
```

```{r}
levels(insurances$sex)
```

```{r}
summary()
```

```{r}
```

You might also like