-
Notifications
You must be signed in to change notification settings - Fork 1
/
CurvasdeIndiferencia.R
94 lines (63 loc) · 2.45 KB
/
CurvasdeIndiferencia.R
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
93
# *------------------------------------------------------------------
# | PROGRAM NAME: INDIFFERENCE_CURVES_R
# | DATE: 3/11/11
# | CREATED BY: MATT BOGARD
# | PROJECT FILE: P:\R Code References
# *----------------------------------------------------------------
# | PURPOSE: MORE TO PLOT LEVEL SETS USING THE CONTOUR FUNCTION THAN
# | TO ACTUALLY PLOT INDIFFERENCE CURVES
# *------------------------------------------------------------------
# | COMMENTS:
# |
# | 1: references: http://stat.ethz.ch/R-manual/R-devel/library/graphics/html/contour.html
# | 2:
# | 3:
# |*------------------------------------------------------------------
# | DATA USED: http://economics.about.com/od/indifferencecurves/a/constructing3.htm
# |
# |
# |*------------------------------------------------------------------
# | CONTENTS:
# |
# | PART 1: explicit data
# | PART 2: simulated data (sort of) - not really indifference curves
# | PART 3:
# *-----------------------------------------------------------------
# | UPDATES:
# |
# |
# *------------------------------------------------------------------
# *------------------------------------------------------------------
# | PART 1: explicit data
# *-----------------------------------------------------------------
# raw data
x <- c(1,2,3,4,5,6,7,8)
y <- c(10,10,10,15,15,30,60,90)
# note- for the contour function to work below, x and y
# These must be in ascending order-based on the contour documentation
# which is the opposite of how the data was presented at
# about.com
# put x and y in a matrix
xy <- as.matrix(cbind(x,y))
# transpose xy
xyT <- t(xy)
# define function z as a matrix
z <- as.matrix(sqrt(x*y))
# plot the countour plot / specified level sets
contour(xyT,z) # all levels
contour(xyT,z, levels =c(10,20,50)) # specified levels for z
# *------------------------------------------------------------------
# | PART 2: simulated data (sort of) - not really indifference curves
# *-----------------------------------------------------------------
rm(list=ls()) # get rid of any existing data
ls() # display active data -should be null
# define x and y
x <- seq(0,100,by=10)
y <- seq(0,20,by=2)
# put x and y in a matrix
xy <- as.matrix(cbind(x,y))
# transpose xy
xyT <- t(xy)
# define function z as a matrix
z <- as.matrix(sqrt(x*y))
contour(xyT,z)