Reverse exponent regression line

I am trying to plot a regression line that is modeled by p / (1-p) = -41.828 + 0.9864x, where p is the probability of an x-dependent event. I only need to draw this with julia, so the general trend is clear. I changed the model to p = 1 / (exp (41.828-0.9864x) +1), however, whenever I draw this with julia, it returns an error. I have attached my code below and the following error. Have tried all sorts of things I can think of to work around the error, but I can't ... Any help would be appreciated! Apologies for any formatting mistakes I made when using this site for the first time, but I tried to do as asked.

using PyPlot , Distributions , StatsBase, DataFrames
 xlin = float(linspace(-50.0,50,1000)); y=1.0/float(exp(41.828-0.9864*
(float(xlin)))+1.0)
PyPlot.plot(xlin, y, color="red", linewidth=2.0, linestyle="--")
title("Regression Line Plot");
PyPlot.grid(-25:7:125);
ylabel("Y");
xlabel("X");

      

This returns an error:

MethodError: no method matching /(::Float64, ::Array{Float64,1})
Closest candidates are:
  /(::Float64, ::Float64) at float.jl:246
  /(::PyCall.PyObject, ::Any) at 
/home/juser/.julia/v0.5/PyCall/src/PyCall.jl:702
  /(::Real, ::Complex{T<:Real}) at complex.jl:182
  ...

      

+3


source to share


1 answer


He has nothing to do with the team plot

. The error is on this line:

y=1.0/float(exp(41.828-0.9864*(float(xlin)))+1.0)

      

You need to ./

, not /

as you are trying to perform a rudimentary operation. Also, there is no reason to call float

all the time. So just



y = 1.0 ./ exp(41.828 .- 0.9864 .* xlin) .+ 1.0 

      

should do it. You don't need all the dots for those operations where one of the operands is a scalar, but you do for the initial division and that makes it clearer IMHO what is going on.

+2


source







All Articles