trendline

Plotting a trendline on a logarithmic scale

天大地大妈咪最大 提交于 2019-12-24 07:18:25
问题 I am trying to add a trendline to a semilogx plot but cannot succeed. I want the trendline between y(17) and y(20) , but it is not plotted as a straight line. This is my code: %// Define equation. x = [90868 68151 45434 34076 27261 13631 6816 3408 2273 1948 1705 1137 853 683 569 455 342 274 228 190]; y = [3680 3723 3800 3866 3920 4103 4250 4320 4340 4344 4350 4364 4373 4379 4384 4393 4398 4402 4405 4407]; %// Plot it semilogx(x,y, 'bo-', 'LineWidth', 3); grid on; %// Enlarge figure to full

Adding a weighted least squares trendline in ggplot2

☆樱花仙子☆ 提交于 2019-12-22 04:48:07
问题 I am preparing a plot using ggplot2, and I want to add a trendline that is based on a weighted least squares estimation. In base graphics this can be done by sending a WLS model to abline : mod0 <- lm(ds$dMNP~ds$MNP) mod1 <- lm(ds$dMNP~ds$MNP, weights = ds$Asset) symbols(ds$dMNP~ds$MNP, circles=ds$r, inches=0.35) #abline(mod0) abline(mod1) in ggplot2 I set the argument weight in geom_smooth but nothing changes: ggplot(ds, aes(x=MNP, y=dMNP, size=Asset) + geom_point(shape=21) + geom_smooth

Draw a trend line using ggplot

雨燕双飞 提交于 2019-12-18 04:02:49
问题 I used ggplot2 to draw a trend line based on my data. Below is something I've done using spreadsheet. But I only want to show the trend line (black line as shown in upper plot) rather than all dots as number of observation is > 20,000. So I tried to do the same thing using ggplot2. fig_a <- ggplot(df1, aes(data_x, data_y )) fig_a + stat_smooth(method=lm) fig_a + stat_smooth(method=gam) Apparently it does not work well, anyone can help? Why it gives so many lines rather than single trend line?

How do I add different trend lines in R?

别等时光非礼了梦想. 提交于 2019-12-17 17:29:22
问题 I know how to add a linear trend line using the lm and abline functions, but how do I add other trend lines, such as, logarithmic, exponential, and power trend lines? 回答1: Here's one I prepared earlier: # set the margins tmpmar <- par("mar") tmpmar[3] <- 0.5 par(mar=tmpmar) # get underlying plot x <- 1:10 y <- jitter(x^2) plot(x, y, pch=20) # basic straight line of fit fit <- glm(y~x) co <- coef(fit) abline(fit, col="blue", lwd=2) # exponential f <- function(x,a,b) {a * exp(b * x)} fit <- nls

Remove unsorted/outlier elements in nearly-sorted array

会有一股神秘感。 提交于 2019-12-07 12:13:01
问题 Given an array like [15, 14, 12, 3, 10, 4, 2, 1] . How can I determine which elements are out of order and remove them (the number 3 in this case). I don't want to sort the list, but detect outliers and remove them. Another example: [13, 12, 4, 9, 8, 6, 7, 3, 2] I want to be able to remove #4 and #7 so that I end up with: [13, 12, 9, 8, 6, 3, 2] There's also a problem that arises when you have this scenario: [15, 13, 12, 7, 10, 5, 4, 3] You could either remove 7 or 10 to make this array

Calculating a linear trend line for every row of a table in R

怎甘沉沦 提交于 2019-12-06 08:33:02
问题 is it somehow possible to conduct a linear regression for every single row of a data frame without using a loop? The output (intercept + slope) of the trend line should be added to the original data frame as new columns. To make my intention more clearly, I have prepared a very small data example: day1 <- c(1,3,1) day2 <- c(2,2,1) day3 <- c(3,1,5) output.intercept <- c(0,4,-1.66667) output.slope <- c(1,-1,2) data <- data.frame(day1,day2,day3,output.intercept,output.slope) Input variables are

Remove unsorted/outlier elements in nearly-sorted array

只谈情不闲聊 提交于 2019-12-06 02:02:01
Given an array like [15, 14, 12, 3, 10, 4, 2, 1] . How can I determine which elements are out of order and remove them (the number 3 in this case). I don't want to sort the list, but detect outliers and remove them. Another example: [13, 12, 4, 9, 8, 6, 7, 3, 2] I want to be able to remove #4 and #7 so that I end up with: [13, 12, 9, 8, 6, 3, 2] There's also a problem that arises when you have this scenario: [15, 13, 12, 7, 10, 5, 4, 3] You could either remove 7 or 10 to make this array sorted. In general, the problem I'm trying to solve, is that given a list of numerical readings (some could

Adding a weighted least squares trendline in ggplot2

隐身守侯 提交于 2019-12-05 05:18:08
I am preparing a plot using ggplot2, and I want to add a trendline that is based on a weighted least squares estimation. In base graphics this can be done by sending a WLS model to abline : mod0 <- lm(ds$dMNP~ds$MNP) mod1 <- lm(ds$dMNP~ds$MNP, weights = ds$Asset) symbols(ds$dMNP~ds$MNP, circles=ds$r, inches=0.35) #abline(mod0) abline(mod1) in ggplot2 I set the argument weight in geom_smooth but nothing changes: ggplot(ds, aes(x=MNP, y=dMNP, size=Asset) + geom_point(shape=21) + geom_smooth(method = "lm", weight="Asset", color="black", show.legend = FALSE) this gives me the same plot as ggplot

Python - calculating trendlines with errors

佐手、 提交于 2019-11-30 00:46:41
So I've got some data stored as two lists, and plotted them using plot(datasetx, datasety) Then I set a trendline trend = polyfit(datasetx, datasety) trendx = [] trendy = [] for a in range(datasetx[0], (datasetx[-1]+1)): trendx.append(a) trendy.append(trend[0]*a**2 + trend[1]*a + trend[2]) plot(trendx, trendy) But I have a third list of data, which is the error in the original datasety. I'm fine with plotting the errorbars, but what I don't know is using this, how to find the error in the coefficients of the polynomial trendline. So say my trendline came out to be 5x^2 + 3x + 4 = y, there

How do I add different trend lines in R?

拟墨画扇 提交于 2019-11-28 03:36:06
I know how to add a linear trend line using the lm and abline functions, but how do I add other trend lines, such as, logarithmic, exponential, and power trend lines? Here's one I prepared earlier: # set the margins tmpmar <- par("mar") tmpmar[3] <- 0.5 par(mar=tmpmar) # get underlying plot x <- 1:10 y <- jitter(x^2) plot(x, y, pch=20) # basic straight line of fit fit <- glm(y~x) co <- coef(fit) abline(fit, col="blue", lwd=2) # exponential f <- function(x,a,b) {a * exp(b * x)} fit <- nls(y ~ f(x,a,b), start = c(a=1, b=1)) co <- coef(fit) curve(f(x, a=co[1], b=co[2]), add = TRUE, col="green",