Calculate 2nd Degree Polynomial Trendline Coefficients In VBA Without Using Cells
Jul 17, 2014
i have a function in a cell (that works) to extract coefficients from a range of cells in a workbook:
VB: =INDEX(LINEST(CP25:CP27,CQ25:CQ27^{1,2}),1)}
i have variables for cp25:cp27 and cq25:cq27 already defined in my vba code. the values for these in the case i am working on are as follows (returns 110.5):
cp25 = 560
cp26 = 570
cp27 = 580
cq25 = .414
cq26 = .479
cq27 = .536
1) how to do this function in VBA only - this is part of a UDF and cannot have any helper cells
2) how to refer to 560,570,580 as a 'range'. is there a way to put these six variables into my ranges for later processing?
All of the google searches i have deal only with linear regression, taking from existing graphs, or say to just use the function i have above.
I have tried
VB:
Var = Application.WorksheetFunction.LinEst(Sheets("references").Range("CP25:CP27"), Sheets("references").Range("CQ25:CQ27^{1,2}"), 1)
[COLOR=#333333][/COLOR]
but return #value! errors. when i remove the ^{1,2} portion, i do return a value but it is incorrect (returns 160), what is the correct syntax for adding in the ^{1,2}? if you do that would be fantastic, but brings me back to issue #2 in that i need to refer to my variables in the vba code and not this range (as they will eventually be going away).
View 5 Replies
ADVERTISEMENT
Mar 9, 2007
I have a VBA function that calculates polynomial coefficients for a series of data pairs. One selects the range of cells that the coefficients are to be stored in, and enters the polynomial formula:
{POLFIT(Xa, Ya, N)}
Where Xa is the array of ordinate values, Ya is the array of data values, and N is the polynomial order to be fit.
It is obvious that one needs to select at least N+1 cells when the array funtion is typed in. But, it is easy to select too few cells.
I am looking for a way to test whether enough cells were selected for the range formula: The function declaration is
Function POLFIT(Xa, Ya, N As Integer) As Variant
Various means I have tried to count POLFIT do not return the correct value.
View 7 Replies
View Related
Jul 31, 2008
I have this data:
x y
310 516
320 526
325 535
330 587
335 640
340 715
345 857
350 1040
When I perform a third degree polynomial curve fit I get this equation:
y = 0.0106x3 - 10.0266x2 + 3152.3381x - 329943.8370
R2 = 0.9987
Which isnt right. On a calculator, I get negative numbers. Does excel have problems with 3rd degree polynomials?
View 9 Replies
View Related
Apr 10, 2012
I have quite a number of 4th degree polynomials and attempting to extract the variables from every equation. I used the formula below (from another thread);
=LOOKUP(99^99,--("0"&MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0 123456789")),ROW($1:$10000))))
but it only extracts the first variable.
4th degree polynomial function: f(x) = ax^4 + bx^3 + cx^2 + dx + e
Example of one of the equations: Y = -42.4276 + 319.989 X - 809.094 X^2 + 942.247 X ^3 - 397.587 X^4
I'll like to have the final result like below (Based on the Example equation above)
edcba-42.4276319.989-809.094942.247-397.587
View 4 Replies
View Related
Dec 29, 2007
I'm trying to do a binomial distribution summation as part of a VBA function, and have been using the Application.WorksheetFunction.BinomDist function, which works fine until the numbers get large - the binomial coefficients used in the calculation end up being larger than can be held in a double floating-point number in VBA, so excel can't handle it. The final result of the calculation is a probability, so it's not a huge number! I was wondering if anyone knows an alternate way of calculating binomial probabilities which avoid any huge number intermediates.
View 7 Replies
View Related
Sep 7, 2009
For Excel 2007 -
I am looking for a function [or method] to calculate a polynomial curve fit. I can do it on a graph with the existing graph and chart tools, but I need to calculate it myself. Does such software exist somewhere in my Excel 2007 package, or can anyone recommend a freeware program? I am hesitant to download an unknown, un-recommended add-in.
View 14 Replies
View Related
Dec 4, 2012
I have been doing some statistical anaylsis in excel and have been using trendlines within scatter charts quite a bit.
I know excel can display the equation of the line as well as the r-squared on the chart. Is there any way to get the values for the trendline to appear in a cell next to the corresponding chart data? Of course, I can simply enter the formula myself that is given on the chart, but I am wondering if there is a way to do it automatically.
I have included the data below along with the trendline value that I calculated by manually entering the formula from the scatter chart.
Code:
YXTrendline Value
$78.990.53$79.79
$78.730.53$79.73
$80.550.52$80.88
[Code]....
View 1 Replies
View Related
Nov 6, 2006
is it possible to export a trendline equation from a graph to a cell, or at least to export the coefficients? If yes, how?
View 4 Replies
View Related
May 23, 2007
to getting accurate regression coefficients from a dataset with *small* (standard) numbers, which contains centered predictors. More specifically, I have a dataset with 18 observed data points containing a criterion (y), a centered predictor variable (x), another centered predictor variable (z), and the interaction of the two centered predictor variables (xz). This multiple regression equation is structured to test for interactions between the two continuous predictor variables (x and z) as prescribed by Aiken and West (1991) in their classic book.
When I run the regression in Excel with the centered predictors, some of the regression coefficents in the output are estimated to be 0, although they are clealry *not* 0 as estimated by SPSS 14.0.2. I have spent many hours troubleshooting this problem (and searched many forums on the internet) and still do not know why this is happening.
Initially, I thought the problem might have to do with the cross-product of the centered predictors, but even just doing a regression with one of the centered predictors (for certain centered predictors) yields a regression coefficient of 0 (although it should be non-zero as per SPSS 14.0.2). When doing these multiple regressions with non-centered predictors, all regression coefficients are estimated accurately.
I was wondering if anyone had any insights on why I am experiencing these problems.... If anyone wants a sample of some test data I have used to troubleshoot these problems, you can download a file from: [url] and/or email me at (email deleted by Mod) for more datasets or questions.
View 5 Replies
View Related
Feb 16, 2009
I'm logging temperatures and I want to add the degree symbol "°" to the end of the numbers, how do I do that? It's easy if I just use one number (#°), but how do I do it when adding the lowest and highest in the same cell, e.g. 33-35?
View 9 Replies
View Related
May 22, 2014
Have written all the code to remove various words,numbers, etc from cells but this one symbol...I can not figure it out.
It looks like this:
Its the degree symbol, however using that symbol in VBA has proved to fail me. I have a large data set that is created for import but it will continue to fail until I remove this, Find(Replace) should work right? But using a search in VBA it deletes the entire cell.
View 4 Replies
View Related
Aug 15, 2007
I have a columb of positions which at the moment have a decimal place, I want to substitute the first decimal with a degree ie. S27.01.050 for S27°01.050 This has to apply to all cells in that columb.
View 9 Replies
View Related
Jan 22, 2009
I am using Excel 2007. I have two sets of data. y-series is 58.61, 58.66, 58.71 and 58.76. x-series is 0.8313, 0.8309, 0.8305 and 0.8301.
I am trying to fit a quadratic function to this data. When I plot a curve and fit a trendline I get the coefficients for the equation ax^2+bx+c
a=1.3939e-11
b=-125
c=162.5225
The plotted line seems to fit the data fairly well.
However, I want to use the linest function and I am using the formula:
=INDEX(LINEST(B2:B5,A2:A5^{1,2}),1,1)
I change the index column number as appropriate to get the coefficients:
a=-75.23775
b=0
c=110.603763
The coefficients from linest seem to be way out. how I can get the output from linest to be the same as the trendline?
View 4 Replies
View Related
Feb 9, 2010
I have plotted a graph which compares the miles done with the petrol used.
I'm trying find a formula which allows me to apply the petrol and would give me the miles covered.
From excel I have applied the tread line of polynomial and obtained the following formula...
y = 1E-06x5 - 0.0002x4 + 0.0161x3 - 0.4893x2 + 7.5295x - 20.87
R² = 0.9989
When is it applied to excel with the value of petrol it does not give me the miles.
I'm working out the formula in a incorrect manner?
I have attached the excel file.
View 10 Replies
View Related
May 14, 2006
y = 1.083333333x4 - 7.3333333x3 + 16.416667x2 - 6.16667x + 4
Above is the polynomial equation of a trend line as shown on my chart, I have extracted the numbers into separate cells using LINEST, so now I have in cells A20 to E20 the numbers 1.083333333, -7.333333, 16.416667, -6.16667 and 4 respectively.With a "y" value of 25 how do I go about solving for a value of "x".
I've been stubbornly struggling with this on and off for a couple of weeks now and I'm not getting any closer to working it out and the websites I've found explaining the procedure all seem to go over my head by the time I get into the fourth or fifth paragraph.
View 11 Replies
View Related
Jun 12, 2013
I'm trying to convert degree minutes and second latitude and longitude to decimal lat and long in excel (I have 100s of such conversion to undertake). When trying out dividing the minutes and second by 60 and checking my calculation on Google Maps lat/long finder or Latlong.net my calculations are not correct. However the equation to other way around - converting from decimal lat long to DMS (*60) works.
View 2 Replies
View Related
Dec 29, 2013
I have created a scatterplot with a trendline and I need a formula to represent the trendline so it can be applied to separate results. How I can create a formula and an R2 value?
View 1 Replies
View Related
Nov 21, 2008
The functions of trend lines in charts are nice, but the coefficients of the output equations are all with only one-digit for the polynomial fits. The single-digit fits by the fitting equations often result in higher deviations from what we have seen in the charts.
I also tried to use the statistical functions but it seams that I cannot get any outputs of these coefficients except for the slope of LINEST, which is not sufficient for polynomials.
I also use addins such as as regressions but cannot get anything either to help for these coefficients.
May someone tell me how to make such outputs with more digits so the equations can be more precisely fitting please?
View 6 Replies
View Related
Apr 7, 2012
I tried to record setting a trendline to 100% transparent but this action doesn't seem to record.
View 2 Replies
View Related
Feb 16, 2007
I don't actually own Excel as yet - but I'm wondering if someone could tell me whether Excel is capable of solving what I'm told are 'polynomial equations'. An example of the sort of equation I hope to solve is: d/(1.18 + d) + d/(1.86 + d) + d/(9 + d) + d/(8.8 + d) = 2
d=? {I happen to know d = 3.65(approx) in this example btw}
Often there will be many more than four terms...
View 6 Replies
View Related
Mar 4, 2008
=IF(H29=>70,"1st",IF(H29>=60AND>=69,"2:1",IF(H29>=50AND>=59,"2:2",IF(H29>=40AND<=49,"3rd"))))
The formula is to work out the class of an honours degree for a certain student.
View 14 Replies
View Related
Jan 20, 2014
I'm familiar with 2d graphs, trendlines, and regression equations. Now I have some tabular data that has 2 input variables and a result. As with my 2d data, I would like Excel to create a polynomial equation of z from the x and y inputs. Can Excel do this, or do I need a plug-in or another software package?
View 12 Replies
View Related
Feb 2, 2014
I need to solve about 450 excel sheets for my project.
The spreadsheet has X and Y data and curve is plotted. I need to split the curves into 3 parts based on slope change.
I can do it manually but I need an excel Macro which does this work.
A sample is attached : Excel forum-Lab data.xlsx‎
View 14 Replies
View Related
Feb 8, 2010
I am trying to do multivariate polynomial regression in excel, trying to correlate data of the form y=f(x1,x2) with second order polynomials:
Y = c + a1*x1 + a2*x1^2 + a3^x1^3 + b1*x2 + b2*x2^2 + b3*x2^3
Using the following command, I have achieved this:
=LINEST(A2:A10,B2:B10^{1,2,3,0,0,0}*C2:C10^{0,0,0, 1,2,3},TRUE,TRUE)
theory Excel uses for this kind of regression?
View 4 Replies
View Related
Apr 25, 2006
I need VBA to copy the values from a treadline output box on a chart to a new sheet. The macro recorder produces the code below, but I need to make the 5th line generic so that the code will apply to any workbook. The code below will not run without the "Windows("Test.xls").Activate" statement, which restricts the code to a workbook of a specifc name (Test.xls). How can I make this run for any workbook name?
Sub CopyTreadlineData()
Sheets("A").Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Trendlines(1).DataLabel.Select
ActiveWindow.Visible = False
Windows("Test.xls").Activate
Sheets("Beta").Select
Range("B15").Select
ActiveSheet.Paste
End Sub
View 2 Replies
View Related
Jun 7, 2008
I'm in the middle of designing a sheet that (amongst many other things) takes the equation of a graph trendline, pastes it, and calculates the various values along it. I can do it by hand, but when I try to record a macro, it doesn't register that I've highlighted the equation and hit copy. Here's the code I'm working with:
Sheets("Graphs").Select
ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.SeriesCollection(1).Trendlines(1).DataLabel.Select
Selection.Copy
ActiveWindow.Visible = False
Windows("Copy of HRA Design calculator1.xls").Activate
Sheets("Binder @ max. stability").Select
Range("A1").Select
ActiveSheet.paste
The problem is line 4 - it can't copy because the text isn't selected.
View 3 Replies
View Related
Feb 13, 2009
I'm trying to determine the percentage rate of change in a trendline. I've got a sales chart with 90 days worth of sales figures. I can see that the trendline is trending down, but I'm not sure exactly how much.
If you take the first data point in a trendline and subtract it from the last data point and then divide that by the first it should give you the percent change. Excel must be able to do that math for you but I can't even figure it out to save my life. I can't even figure out how to display the first and last data point much less the "rate" of change I'm looking for.
View 9 Replies
View Related
Oct 3, 2006
i have a workbook that contains a series of worksheets. the workbook is a master document list. the first worksheet contains no data. the remaining worksheets are arranged so that A1 has the document number, A2 contains the document title, and A3 contains the review date. Id like to create a search macro that can search for the string entered into textbox1. if this is a number, the macro should search A1:A50 of all but the first worksheets in the workbook, and if its text, the macro should search B1:B50 of all but the first worksheets.
the macro should then select the cell containing what was searched. then id like the macro to prompt me and ask if id like to modify the reviewed date to todays date. d like to be prompted to continue searching for other records if they exist, and after that loop has finished to set the focus back to the search textbox.
View 2 Replies
View Related
Aug 31, 2012
I have a macro which autofilters a range of cells.
I can count the number of visible rows by using the following code
Code:
lcountActive = Range("BC34:BC" & x).SpecialCells(xlCellTypeVisible).Count
What I would like to do is both calculate the Average value of the visible cells and the Sum as well. I have tried to adapt the code I have but my knowledge is just not good enough to do this.
View 1 Replies
View Related
Oct 29, 2008
I am trying to convert Degrees Minutes & Decimals of a minute (12° 34.567') to Degrees and decimals of a degree (12.57611°). I have the formula to convert latitude, that is two digits, but it doesn't want to work with longitudes, three digits. (see attachment). This is the formula that I am using:
=IF(A2="","",(INT((LEFT(A2,3)+MID(A2,4,6)/60)*100000)/100000)&"d")
View 2 Replies
View Related