Question: gmp

gmp <- read.table("gmp.dat")# download the data from Blackboard and save to your working directory. gmp$pop <- gmp$gmp/gmp$pcgmp plot(pcgmp~pop, data=gmp, xlab="Population", log="xy",ylab="Per-Capita Economic Output ($/person-year)",main="US Metropolitan Areas, 2006")

estimate.scaling.exponent. <- function(a, y0=6611, response=gmp$pcgmp, predictor = gmp$pop, maximum.iterations=100, deriv.step = 1/100, step.scale = 1e-12, stopping.deriv = 1/100) {

mse <- function(a) { mean((response - y0*predictor^a)^2) } for (iteration in 1:maximum.iterations) { deriv <- (mse(a+deriv.step) - mse(a))/deriv.step a <- a - step.scale*deriv if (abs(deriv) <= stopping.deriv) { break() } } fit <- list(a=a,iterations=iteration, converged=(iteration < maximum.iterations)) return(fit) }

How can I plot my function "estimate.scaling.exponent" as a curve along with the data points that were plotted above?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!