Cannot convert Taylor1{Float64} to series data for plotting Julia - julia

I want to ask how do I get the value from the First-order Taylor Approximation since I want to use its value in the plot.
So I have an array of
jump_value = [-945.0, -287.55589538221216, 19.122751150095354, 113.22912169505338, 96.60890174423561, 39.60661306353262, -14.088053425973683, -42.593904767135726, -40.99191308586612, -16.478882710263225, 16.47888271026317, 40.991913085866095, 42.59390476713573, 14.088053425973682, -39.60661306353257, -96.60890174423555, -113.2291216950534, -19.122751150095276, 287.5558953822114, 945.0]
The elements in the array represents y from x = 0 to x = 10 on 2 dimensions graph.
However, I want to convert the above values to first-order Taylor Approximation.
I tried to use the function TaylorSeries to get the value, but it seems that it only gives the formula function. So how do I get the value of first-order Taylor Approximation from the array above?
using TaylorSeries
first_order = Taylor1(jump_value, 1)
println(first_order)
plot(0:jump_interval:10, first_order ,
xlabel = "X value", ylabel = "Y value", title = "Freg we love you!",
linecolor = :black,
linewidth = 3,
legend = :bottomright,
markershape = :circle,
label = "Childhood")
Thanks for anyone reply in advance.

Not familiar with this package, but the docs say that Taylor1 instances can be called to calculate values, so try plot(0:jump_interval:10, first_order.(0:jump_interval:10) ,

Related

plot create cutoff line at particular point

consider the following plot:
pwrt<-pwr.t.test(d=.8,n=c(10,20,30,40,50,60,70,80,90,100),sig.level=.05,type="two.sample",alternative="two.sided")
plot(pwrt$n,pwrt$power,type="b",xlab="sample size",ylab="power", main = "Power curve for t-test d = .8")
which creates
I would like to add a vertical line as a 'cutoff' point at power = .9 for example. And also to compute the exact x-value (sample size) for this cutoff point
How do I do this? Any help is much appreciated.
You can calculate the sample size for a given power with the same pwr.t.test function.
From help(pwr.t.test):
Exactly one of the parameters 'd','n','power' and 'sig.level' must be passed as NULL, and that parameter is determined from the others.
library(pwr)
N90 <- pwr.t.test(d=.8,power = 0.9,sig.level=.05,type="two.sample",alternative="two.sided")$n
N90
[1] 33.82555
From there, it's simple to add a line and text label.
plot(pwrt$n,pwrt$power,type="b",xlab="sample size",ylab="power", main = "Power curve for t-test d = .8")
abline(v = N90)
text(x = N90 + 7, y = 0.8, labels = paste0("N = ",round(N90,2)))

R dtw package: query and reference vectors for binary data to pass it to dtw function

I have two time series tables that look like this.
I calculated the binary column to count for specific categorical value, if this value = “x” then assign 1, else assign 0. I graphed this using ggplot like this,
p <-ggplot(x1,aes(Time, binary))
p + geom_line()+
xlab("Time in seconds (s)")+
scale_y_continuous(name="x = 1, anything else = 0", breaks=c(0, 1))+
labs(title = "Example of the duration")
I got exactly what I wanted,
I did the same for the second time series and I got this graph,
Now it is time to use dtw function to calculate the distance. I am not sure how to store this binary data into carry or matrix to pass it through dtw function here,
dtw(
x,
y = NULL,
dist.method = "Euclidean",
step.pattern = symmetric2,
window.type = "none",
keep.internals = FALSE,
distance.only = FALSE,
open.end = FALSE,
open.begin = FALSE,
...
)
where
x is the query vector or local cost matrix and y is reference vector, or NULL if x given as a local cost matrix
What I did is this,
i<-c(x1$binary)
j<-c(x2$binary)
dtw1 <-dtw(i, j, dist.method="Euclidean", keep.internals = T, step.pattern= symmetric)
plot(dtw1)
But this is not correct. The graphs for each one is not the same as shown below. The matrix cost is null. It only calculates the number of 0,1 of each column. I know this is not correct, but I don’t know how to get the query and reference vectors to calculate the dtw. How to apply that for this binary data?
What I did is this, instead of assigning the binary values to the dtw function, I used time.
i<-c(x1$Time)
j<-c(x2$Time)
dtw1 <-dtw(i, j, dist.method="Euclidean", keep.internals = T, step.pattern= asymmetric)
plot(dtw1)

How to pass arguments to contour() inside of plot.surface() [R fields package]

When using plot.surface() of the R fields package I need to change the "method" parameter of the contour() function from its default setting of "flattest" to "simple".
The contour() function is inside of plot.surface().
The plot.surface() documentation says you can pass additional parameters to two other functions appearing in plot.surface(), but no mention of how to pass parameters to contour().
I need to do this because the contour lines in my plot come out straight, resulting in no numbers on the lines. I think I could get numbers to appear on my contour lines if I can change the contour method from "flattest" to "simple" or "edge".
Here is the contour image:
The code used to generate the image:
inMat <- mat_Qe
surface <- list(x = xtick_labs,
y = ytick_labs,
z = inMat)
plot.surface(surface, type = "C",
xlab = "Mean factory efficiency (kL Ethanol / MT Root)",
ylab = "Mean farm cost (lcu / MT Root)", labcex = 1, col = mapPalette(45))
title(main = "Equilibrium Quantity Map (MT / day)", cex.main = 1)
Sorry it's not reproducible, but I think reproducibility is not really necessary in this case. I just need someone to tell me how to pass the method parameter to contour() inside of plot.surface().
Modifying the example in ?plot.surface, the following will pass method to contour. If you run plot.surface you'll see that the ellipses (...) are given to contour if type = "c" although this does not seem to be stated in the documentation. Note this is lowercase c, not C. With capital "C" argument are not passed to contour, but to image.plot.
library("fields")
# Toy data
x <- seq( -2,2,,80)
y <- seq( -2,2,,80)
z <- outer( x,y, "+")
obj <- list(x=x, y=y, z=z)
# Pass method to contour when type = "c"
plot.surface(obj, col="red", type="c", method = "simple")
plot.surface(obj, type="c", col="red", method = "edge")

How to plot an nmds with coloured/symbol points based on SIMPROF

Hi so i am trying to plot my nmds of a assemblage data which is in a bray-curtis dissimilarity matrix in R. I have been able to apply ordielipse(),ordihull() and even change the colours based on group factors created by cutree() of a hclst()
e.g using the dune data from the vegan package
data(dune)
Dune.dis <- vegdist(Dune, method = "bray)
Dune.mds <- metaMDS(Dune, distance = "bray", k=2)
#hierarchical cluster
clua <- hclust(Dune.dis, "average")
plot(clua, hang = -1)
# set groupings
rect.hclust(clua, 4)
grp <- cutree(clua, 4)
#plot mds
plot(Dune.mds, display = "sites", type = "text", cex = 1.5)
#show groupings
ordielipse(Dune.mds, group = grp, border =1, col ="red", lwd = 3)
or even colour the points just by the cutree
colvec <- c("red2", "cyan", "deeppink3", "green3")
colvec[grp]
plot(Dune.mds, display = "sites", type = "text", cex = 1.5) #or use type = "points"
points(P4.mds, col = colvec[c2], bg =colvec[c2], pch=21)
However what i really want to do is use the SIMPROF function using the package "clustsig" to then colour the points based on significant groupings - this is more of a technical coding language thing - i am sure there is a way to create a string of factors but i am sure there is a more efficient way to do it
heres my code so far for that:
simp <- simprof(Dune.dis, num.expected = 1000, num.simulated = 999, method.cluster = "average", method.distance = "braycurtis", alpha = 0.05, sample.orientation = "row")
#plot dendrogram
simprof.plot(simp, plot = TRUE)
Now i am just not sure how do the next step to plot the nmds using the groupings defined by the SIMPROF - how do i make the SIMPROF results a factor string without literally typing it my self it myself?
Thanks in advance.
You wrote you know how to get colours from an hclust object with cutree. Then read the documentation of clustsig::simprof. This says that simprof returns an hclust object within its result object. It also returns numgroups which is the suggested number of clusters. Now you have all information you need to use the cutree of hclust you already know. If your simprof result is called simp, use cutree(simp$hclust, simp$numgroups) to extract the integer vector corresponding to the clustsig::simprof result, and use this to colours.
I have never used simprof or clustsig, but I gathered all this information from its documentation.

Using user-defined functions within "curve" function in R graphics

I am needing to produce normally distributed density plots with different total areas (summing to 1). Using the following function, I can specify the lambda - which gives the relative area:
sdnorm <- function(x, mean=0, sd=1, lambda=1){lambda*dnorm(x, mean=mean, sd=sd)}
I then want to plot up the function using different parameters. Using ggplot2, this code works:
require(ggplot2)
qplot(x, geom="blank") + stat_function(fun=sdnorm,args=list(mean=8,sd=2,lambda=0.7)) +
stat_function(fun=sdnorm,args=list(mean=18,sd=4,lambda=0.30))
but I really want to do this in base R graphics, for which I think I need to use the "curve" function. However, I am struggling to get this to work.
If you take a look at the help file for ? curve, you'll see that the first argument can be a number of different things:
The name of a function, or a call or an expression written as a function of x which will evaluate to an object of the same length as x.
This means you can specify the first argument as either a function name or an expression, so you could just do:
curve(sdnorm)
to get a plot of the function with its default arguments. Otherwise, to recreate your ggplot2 representation you would want to do:
curve(sdnorm(x, mean=8,sd=2,lambda=0.7), from = 0, to = 30)
curve(sdnorm(x, mean=18,sd=4,lambda=0.30), add = TRUE)
The result:
You can do the following in base R
x <- seq(0, 50, 1)
plot(x, sdnorm(x, mean = 8, sd = 2, lambda = 0.7), type = 'l', ylab = 'y')
lines(x, sdnorm(x, mean = 18, sd = 4, lambda = 0.30))
EDIT I added ylab = 'y' and updated the picture to have the y-axis re-labeled.
This should get you started.

Resources