-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.Rmd
More file actions
96 lines (65 loc) · 1.77 KB
/
Main.Rmd
File metadata and controls
96 lines (65 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
---
title: "Discrete Choice Models"
output:
html_document:
df_print: paged
html_notebook: default
pdf_document: default
---
## Loading the data sets
```{r}
library(mlogit)
library(Ecdat)
data("Cracker",package="mlogit")
data("Yogurt",package="Ecdat")
```
## Viewing the data
```{r setup, include=FALSE,echo=FALSE,warning=FALSE}
knitr::opts_chunk$set(echo = FALSE,message = FALSE)
library(stargazer)
```
```{r mylatextable, results = "asis"}
Yogurtlong<-mlogit.data(Yogurt,shape = "long",varying = 2:9,choice = "choice")
head(Yogurtlong)
names(Yogurtlong)
names(Yogurtlong)[3]<-c("Brand")
Yogurtlong<-Yogurtlong[,2:5]
Yogurtlong$choice[Yogurtlong$choice=="FALSE"]=c(0)
Yogurtlong$choice[Yogurtlong$choice=="TRUE"]=c(1)
```
```{r}
library(dplyr)
MS_tab=summarise(
group_by(Yogurtlong,Brand),
mean=mean(choice),
sd=sd(choice),
)
Price_tab=summarise(
group_by(Yogurtlong,Brand),
mean=mean(price),
sd=sd(price),
)
Feat_tab=summarise(
group_by(Yogurtlong,Brand),
mean=mean(feat),
sd=sd(feat),
)
```
```{r results='asis',echo=FALSE,warning=FALSE,message=FALSE}
library(knitr)
library(kableExtra)
kable(MS_tab,digits = 4,caption = "Market Shares: Yogurt data")
kable(Price_tab,digits = 4,caption = "Prices: Yogurt data")
kable(Feat_tab,digits = 4,caption = "Feature: Yogurt data")
```
## Functions in R
```{r}
Prem <- function(beta) {
return(beta*c(2,6,8))
}
Prem(10)
```
1. Ecrire la fonction de vraisemblance dans le cas du modele logit pour les données Yogurt avec une seule variable (Price)
2. Faire un graphique pour comprendre le comportement de cette fonction
3. Où se situe graphiquement son maximum ?
4. Trouver un package qui cherche le maximum numériquement.