Populate excel user form combo-box from html combo-box with vba

Question: I have a user form that I would like the html option values to populate the excel combo box. Basically I want to duplicate the values and pass them later.
What I have is smashed together from various posts but nothing seems to work.
Dim appIE As InternetExplorerMedium
Dim nam As Object
Dim sel As Object

Set appIE = New InternetExplorerMedium
sURL = "site infor goes here"
With appIE
    .navigate sURL
    .Visible = True
End With
Do While appIE.Busy Or appIE.readyState <> 4
    DoEvents
Loop
For Each f In IE.document.getElementsByTagName("select")
    If f = "suppliercode" Then
        For Each fOption In IE.document.getElementsByTagName("option")
            With Me.SupplierSite.AddItem(f.Option)
            End With
        Next fOption
    End If
Next f

ALSO TRIED:
Set Doc = IE.document.forms("NewReleaseQueueForm1")
For Each sel In Doc.getElementsByTagName("select")(0).Value
If sel.Name = "suppliercode" Then
'loop through and add each option to Me.SupplierSite
For Each opt In IE.document.forms("NewReleaseQueueForm1").getElementsByTagName("option")(0).Value
Me.SupplierSite.AddItem sel.Value
Next opt
End If
Next sel

HTML Sample:
<form id="NewReleaseQueueForm1" method="post" name="NewReleaseQueueForm1">

            Supplier Site

                <select multiple name="suppliercode" size="5">
                    <option selected value="Any">
                        <Any>
                    </option>
                    <option value="T488C">
                        T488C
                    </option>
                </select>

Comment: If f.name = "suppliercode" Then ???  Try that and step through to debug
Comment: It seems it doesn't like .additem and it skips over the if statement. Expected function or variable on .additem. I updated this thread with what I have tried
Comment: Try changing the line to "If f.NAME = "suppliercode" Then"  Some of your other code in that for loop won't work either.  The following link will take you through the process of getting the options from a select element.  It uses the GetElementById method, which you can replace with GetElementsByName("suppliercode")(0) method.  The zero is necessary because there may be more than one element named "suppliercode".  0 represents the first instance, 1 represents the 2nd instance, etc etc http://www.exceltrainingvideos.com/tag/get-option-values-from-drop-down-list-with-vba/
Answer: Please place the following HTML code into notepad and save as an HTML file.  Open that file in MSIE
Then open a new clean workbook and paste the macro code below into in a standard module.  Make sure that your webpage is open in MSIE.  Go to the editor and put your cursor some where inside the "StartHere()" subroutine.  Press PF5 to run it.  A userform will open with the names of all open browser pages that are open.  Select the one with the title "Test Get Select Options".  A msgbox will appear to say that the page has been successfully put into an Excel Object.  Then check your worksheet to see if it listed the four options in column A.
If it works then clear sheet1 and open your web page.  Try the macro again and see if 9it works with your page.
HTML:Code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Test Get Select Options</title>

<form id="NewReleaseQueueForm1" method="post" name="NewReleaseQueueForm1">

            Supplier Site

                <select multiple name="suppliercode" size="5">
                    <option selected value="Any">
                        <Any>
                    </option>
                    <option value="T488C">
                        T488C
                    </option>
                    <option value="R488C">
                        R488C
                    </option>
                    <option value="C488C">
                        C488C
                    </option>
                    <option value="Z488C">
                        Z488C
                    </option>
                </select>

</form>

Macro Code:
Global myDoc As HTMLDocument
Global IE As Object
Sub StartHere()
    On Error Resume Next
        ThisWorkbook.VBProject.References.AddFromGuid "{420B2830-E718-11CF-893D-00A0C9054228}", 0, 0    'Microsoft Scripting Runtime
        ThisWorkbook.VBProject.References.AddFromGuid "{0002E157-0000-0000-C000-000000000046}", 0, 0    'Microsoft Extensability for VBA
        ThisWorkbook.VBProject.References.AddFromGuid "{0D452EE1-E08F-101A-852E-02608C4D0BB4}", 0, 0    'Microsoft Forms
        ThisWorkbook.VBProject.References.AddFromGuid "{3050F1C5-98B5-11CF-BB82-00AA00BDCE0B}", 0, 0    'Microsoft MSHTML
        ThisWorkbook.VBProject.References.AddFromGuid "{EAB22AC0-30C1-11CF-A7EB-0000C05BAE0B}", 0, 0    'Microsoft Internet Controls
    On Error GoTo 0
Call nextSub
End Sub
Sub nextSub()
        Dim VBProj As VBIDE.VBProject
        Dim VBComp As VBIDE.VBComponent
        Dim CodeMod As VBIDE.codemodule
        Dim LineNum As Long
        Set VBProj = ActiveWorkbook.VBProject
        Set VBComp = VBProj.VBComponents("Module1")
        Set CodeMod = VBComp.codemodule
        LineNum = 1
        CodeMod.insertlines 1, "Global myDoc As HTMLDocument"
        CodeMod.insertlines 2, "Global IE As Object"
        Call getOpenBrowserCreateForm
End Sub
Sub removeCode()
        Set VBProj = ActiveWorkbook.VBProject
        Set VBComp = VBProj.VBComponents("Module1")
        Set CodeMod = VBComp.codemodule
        LineNum = 1
    For i = 34 To 4 Step -1
            CodeMod.DeleteLines i
    Next i
End Sub
Public myDoc As HTMLDocument
Public IE As Object

Sub getOpenBrowserCreateForm()
Dim myForm As Object
Dim NewFrame As MSForms.Frame
Dim NewButton As MSForms.CommandButton, newButton2 As MSForms.CommandButton
'Dim NewComboBox As MSForms.ComboBox
Dim NewListBox As MSForms.ListBox
'Dim NewTextBox As MSForms.TextBox
'Dim NewLabel As MSForms.Label
'Dim NewOptionButton As MSForms.OptionButton
'Dim NewCheckBox As MSForms.CheckBox
Dim x As Integer
Dim Line As Integer

'This is to stop screen flashing while creating form
Application.VBE.MainWindow.Visible = False

On Error Resume Next
Application.VBE.ActiveVBProject.References.AddFromFile "C:\Windows\System32\mshtml.tlb"
Application.VBE.ActiveVBProject.References.AddFromFile "C:\Windows\System32\ieframe.dll"
Application.VBE.ActiveVBProject.References.AddFromFile "C:\Windows\system32\scrrun.dll"
Application.VBE.ActiveVBProject.References.AddFromFile "C:\Windows\system32\FM20.DLL"
On Error GoTo 0
Set myForm = ThisWorkbook.VBProject.VBComponents.Add(3)

'Create the User Form
With myForm
    .Properties("Caption") = "Select Open Web Site"
    .Properties("Width") = 326
    .Properties("Height") = 280
End With

'Create ListBox
Set NewListBox = myForm.designer.Controls.Add("Forms.listbox.1")
With NewListBox
    .Name = "ListBox1"
    .Top = 12
    .Left = 12
    .Width = 297
    .Height = 207.8
    .Font.Size = 9
    .Font.Name = "Tahoma"
    .BorderStyle = fmBorderStyleOpaque
    .SpecialEffect = fmSpecialEffectSunken
End With

'Create CommandButton1 Create
Set NewButton = myForm.designer.Controls.Add("Forms.commandbutton.1")
With NewButton
    .Name = "CommandButton1"
    .Caption = "Select"
    .Accelerator = "M"
    .Top = 228
    .Left = 234
    .Width = 72
    .Height = 24
    .Font.Size = 9
    .Font.Name = "Tahoma"
    .BackStyle = fmBackStyleOpaque
End With

'Create CommandButton2 Create
Set NewButton = myForm.designer.Controls.Add("Forms.commandbutton.1")
With NewButton
    .Name = "CommandButton2"
    .Caption = "Cancel"
    .Accelerator = "M"
    .Top = 228
    .Left = 144
    .Width = 72
    .Height = 24
    .Font.Size = 9
    .Font.Name = "Tahoma"
    .BackStyle = fmBackStyleOpaque
End With

'add code for form module
myForm.codemodule.insertlines 1, "Private Sub CommandButton1_Click()"
myForm.codemodule.insertlines 2, "Dim urlLocation As String"
myForm.codemodule.insertlines 3, ""
myForm.codemodule.insertlines 4, "''////////////////////////////////////////////////////////////////////"
myForm.codemodule.insertlines 5, "''  This part gets all open web pages qand displays them on the form for user to choose"
myForm.codemodule.insertlines 6, "''"
myForm.codemodule.insertlines 7, "    Set objIterator = CreateObject(" & Chr(34) & "Shell.Application" & Chr(34) & ")"
myForm.codemodule.insertlines 8, "    For X = 0 To objIterator.Windows.Count"
myForm.codemodule.insertlines 9, "        On Error Resume Next"
myForm.codemodule.insertlines 10, "        current_title = objIterator.Windows(X).Document.Title"
myForm.codemodule.insertlines 11, "        current_url = objIterator.Windows(X).Document.Location"
myForm.codemodule.insertlines 12, "    "
myForm.codemodule.insertlines 13, "        If current_title = ListBox1.Value Then 'is this my webpage?"
myForm.codemodule.insertlines 14, "        "
myForm.codemodule.insertlines 15, "            Set IE = objIterator.Windows(X)"
myForm.codemodule.insertlines 16, "            MsgBox " & Chr(34) & "IE was properly set" & Chr(34) & ""
myForm.codemodule.insertlines 17, "            "
myForm.codemodule.insertlines 18, "             Boolean_indicator = True"
myForm.codemodule.insertlines 19, "            Exit For"
myForm.codemodule.insertlines 20, "        End If"
myForm.codemodule.insertlines 21, "    Next"
myForm.codemodule.insertlines 22, "    Set objIterator = Nothing"
myForm.codemodule.insertlines 23, "    Set myDoc = IE.Document"
myForm.codemodule.insertlines 24, "Return"
myForm.codemodule.insertlines 25, "Unload Me"
myForm.codemodule.insertlines 26, ""
myForm.codemodule.insertlines 27, "End Sub"
myForm.codemodule.insertlines 28, ""
myForm.codemodule.insertlines 29, ""
myForm.codemodule.insertlines 30, "Private Sub CommandButton2_Click()"
myForm.codemodule.insertlines 31, " Unload Me"
myForm.codemodule.insertlines 32, "End Sub"
myForm.codemodule.insertlines 33, ""
myForm.codemodule.insertlines 34, ""
myForm.codemodule.insertlines 35, "Private Sub UserForm_Activate()"
myForm.codemodule.insertlines 36, "    Dim myArray1() As String, tempNumb As Integer"
myForm.codemodule.insertlines 37, "    "
myForm.codemodule.insertlines 38, "    "
myForm.codemodule.insertlines 39, "    i = 2"
myForm.codemodule.insertlines 40, "    tempNumb = 1"
myForm.codemodule.insertlines 41, "    "
myForm.codemodule.insertlines 42, "    ReDim myArray1(1 To 1)"
myForm.codemodule.insertlines 43, "   "
myForm.codemodule.insertlines 44, "    Set objShell = CreateObject(" & Chr(34) & "Shell.Application" & Chr(34) & ")"
myForm.codemodule.insertlines 45, "    Set objAllWindows = objShell.Windows"
myForm.codemodule.insertlines 46, "    "
myForm.codemodule.insertlines 47, "    "
myForm.codemodule.insertlines 48, "    For Each ow In objAllWindows"
myForm.codemodule.insertlines 49, "        If (InStr(1, ow," & Chr(34) & "Internet Explorer" & Chr(34) & ", vbTextCompare)) Then"
myForm.codemodule.insertlines 50, "            myArray1(tempNumb) = ow.Document.Title"
myForm.codemodule.insertlines 51, "            tempNumb = tempNumb + 1"
myForm.codemodule.insertlines 52, "            If Not ow.Document.Title = " & Chr(34) & "" & Chr(34) & " Then"
myForm.codemodule.insertlines 53, "                ReDim Preserve myArray1(1 To tempNumb)"
myForm.codemodule.insertlines 54, "            Else"
myForm.codemodule.insertlines 55, "                Exit For"
myForm.codemodule.insertlines 56, "            End If"
myForm.codemodule.insertlines 57, "        End If"
myForm.codemodule.insertlines 58, "    Next"
myForm.codemodule.insertlines 59, "     "
myForm.codemodule.insertlines 60, "    Me.ListBox1.List = myArray1"
myForm.codemodule.insertlines 61, "End Sub"
myForm.codemodule.insertlines 62, ""
'Show the form
VBA.UserForms.Add(myForm.Name).Show

'Delete the form (Optional)
Application.VBE.MainWindow.Visible = True

ThisWorkbook.VBProject.VBComponents.Remove myForm

'   IE is now set to the user's choice and you can add code here to interact with it
'   myDoc is now set to IE.Document also
'
'
'

Dim drp As HTMLFormElement

Set drp = myDoc.getelementsbyname("suppliercode")(0)

Dim walekuj As Long
walekuj = myDoc.forms.Length
 MsgBox walekuj

'we get the option values into our worksheet

For x = 0 To 3
 Cells(x + 1, 1) = drp.Item(x).innerText
 Next x

'Now we select the option value of our choice

drp.selectedIndex = 2

' we free memory

Set IE = Nothing
 Application.StatusBar = ""
End Sub

Comment: user defined type not defined on `Global myDoc As HTMLDocument` and sub never exits. Always goes to expected end sub on line before end sub..
Comment: My bad.  Erase the two global variables first.  After the guid references are added it will replace them.
Answer: Just add the referecnes in a clean workbook yourself through the VB editor "Tools" - "References."  They are 'Microsoft Scripting Runtime,  'Microsoft Forms, 'Microsoft MSHTML, and 'Microsoft Internet Controls.  Then add the following code into the module and run getOpenBrowserCreateForm().  It's been working for me for years
Global myDoc As HTMLDocument
Global IE As Object

Sub getOpenBrowserCreateForm()
Dim myForm As Object
Dim NewFrame As MSForms.Frame
Dim NewButton As MSForms.CommandButton, newButton2 As MSForms.CommandButton
'Dim NewComboBox As MSForms.ComboBox
Dim NewListBox As MSForms.ListBox
'Dim NewTextBox As MSForms.TextBox
'Dim NewLabel As MSForms.Label
'Dim NewOptionButton As MSForms.OptionButton
'Dim NewCheckBox As MSForms.CheckBox
Dim x As Integer
Dim Line As Integer

'This is to stop screen flashing while creating form
Application.VBE.MainWindow.Visible = False

On Error Resume Next
Application.VBE.ActiveVBProject.References.AddFromFile "C:\Windows\System32\mshtml.tlb"
Application.VBE.ActiveVBProject.References.AddFromFile "C:\Windows\System32\ieframe.dll"
Application.VBE.ActiveVBProject.References.AddFromFile "C:\Windows\system32\scrrun.dll"
Application.VBE.ActiveVBProject.References.AddFromFile "C:\Windows\system32\FM20.DLL"
On Error GoTo 0
Set myForm = ThisWorkbook.VBProject.VBComponents.Add(3)

'Create the User Form
With myForm
    .Properties("Caption") = "Select Open Web Site"
    .Properties("Width") = 326
    .Properties("Height") = 280
End With

'Create ListBox
Set NewListBox = myForm.designer.Controls.Add("Forms.listbox.1")
With NewListBox
    .Name = "ListBox1"
    .Top = 12
    .Left = 12
    .Width = 297
    .Height = 207.8
    .Font.Size = 9
    .Font.Name = "Tahoma"
    .BorderStyle = fmBorderStyleOpaque
    .SpecialEffect = fmSpecialEffectSunken
End With

'Create CommandButton1 Create
Set NewButton = myForm.designer.Controls.Add("Forms.commandbutton.1")
With NewButton
    .Name = "CommandButton1"
    .Caption = "Select"
    .Accelerator = "M"
    .Top = 228
    .Left = 234
    .Width = 72
    .Height = 24
    .Font.Size = 9
    .Font.Name = "Tahoma"
    .BackStyle = fmBackStyleOpaque
End With

'Create CommandButton2 Create
Set NewButton = myForm.designer.Controls.Add("Forms.commandbutton.1")
With NewButton
    .Name = "CommandButton2"
    .Caption = "Cancel"
    .Accelerator = "M"
    .Top = 228
    .Left = 144
    .Width = 72
    .Height = 24
    .Font.Size = 9
    .Font.Name = "Tahoma"
    .BackStyle = fmBackStyleOpaque
End With

'add code for form module
myForm.codemodule.insertlines 1, "Private Sub CommandButton1_Click()"
myForm.codemodule.insertlines 2, "Dim urlLocation As String"
myForm.codemodule.insertlines 3, ""
myForm.codemodule.insertlines 4, "''////////////////////////////////////////////////////////////////////"
myForm.codemodule.insertlines 5, "''  This part gets all open web pages qand displays them on the form for user to choose"
myForm.codemodule.insertlines 6, "''"
myForm.codemodule.insertlines 7, "    Set objIterator = CreateObject(" & Chr(34) & "Shell.Application" & Chr(34) & ")"
myForm.codemodule.insertlines 8, "    For X = 0 To objIterator.Windows.Count"
myForm.codemodule.insertlines 9, "        On Error Resume Next"
myForm.codemodule.insertlines 10, "        current_title = objIterator.Windows(X).Document.Title"
myForm.codemodule.insertlines 11, "        current_url = objIterator.Windows(X).Document.Location"
myForm.codemodule.insertlines 12, "    "
myForm.codemodule.insertlines 13, "        If current_title = ListBox1.Value Then 'is this my webpage?"
myForm.codemodule.insertlines 14, "        "
myForm.codemodule.insertlines 15, "            Set IE = objIterator.Windows(X)"
myForm.codemodule.insertlines 16, "            MsgBox " & Chr(34) & "IE was properly set" & Chr(34) & ""
myForm.codemodule.insertlines 17, "            "
myForm.codemodule.insertlines 18, "             Boolean_indicator = True"
myForm.codemodule.insertlines 19, "            Exit For"
myForm.codemodule.insertlines 20, "        End If"
myForm.codemodule.insertlines 21, "    Next"
myForm.codemodule.insertlines 22, "    Set objIterator = Nothing"
myForm.codemodule.insertlines 23, "    Set myDoc = IE.Document"
myForm.codemodule.insertlines 24, "Return"
myForm.codemodule.insertlines 25, "Unload Me"
myForm.codemodule.insertlines 26, ""
myForm.codemodule.insertlines 27, "End Sub"
myForm.codemodule.insertlines 28, ""
myForm.codemodule.insertlines 29, ""
myForm.codemodule.insertlines 30, "Private Sub CommandButton2_Click()"
myForm.codemodule.insertlines 31, " Unload Me"
myForm.codemodule.insertlines 32, "End Sub"
myForm.codemodule.insertlines 33, ""
myForm.codemodule.insertlines 34, ""
myForm.codemodule.insertlines 35, "Private Sub UserForm_Activate()"
myForm.codemodule.insertlines 36, "    Dim myArray1() As String, tempNumb As Integer"
myForm.codemodule.insertlines 37, "    "
myForm.codemodule.insertlines 38, "    "
myForm.codemodule.insertlines 39, "    i = 2"
myForm.codemodule.insertlines 40, "    tempNumb = 1"
myForm.codemodule.insertlines 41, "    "
myForm.codemodule.insertlines 42, "    ReDim myArray1(1 To 1)"
myForm.codemodule.insertlines 43, "   "
myForm.codemodule.insertlines 44, "    Set objShell = CreateObject(" & Chr(34) & "Shell.Application" & Chr(34) & ")"
myForm.codemodule.insertlines 45, "    Set objAllWindows = objShell.Windows"
myForm.codemodule.insertlines 46, "    "
myForm.codemodule.insertlines 47, "    "
myForm.codemodule.insertlines 48, "    For Each ow In objAllWindows"
myForm.codemodule.insertlines 49, "        If (InStr(1, ow," & Chr(34) & "Internet Explorer" & Chr(34) & ", vbTextCompare)) Then"
myForm.codemodule.insertlines 50, "            myArray1(tempNumb) = ow.Document.Title"
myForm.codemodule.insertlines 51, "            tempNumb = tempNumb + 1"
myForm.codemodule.insertlines 52, "            If Not ow.Document.Title = " & Chr(34) & "" & Chr(34) & " Then"
myForm.codemodule.insertlines 53, "                ReDim Preserve myArray1(1 To tempNumb)"
myForm.codemodule.insertlines 54, "            Else"
myForm.codemodule.insertlines 55, "                Exit For"
myForm.codemodule.insertlines 56, "            End If"
myForm.codemodule.insertlines 57, "        End If"
myForm.codemodule.insertlines 58, "    Next"
myForm.codemodule.insertlines 59, "     "
myForm.codemodule.insertlines 60, "    Me.ListBox1.List = myArray1"
myForm.codemodule.insertlines 61, "End Sub"
myForm.codemodule.insertlines 62, ""
'Show the form
VBA.UserForms.Add(myForm.Name).Show

'Delete the form (Optional)
Application.VBE.MainWindow.Visible = True

ThisWorkbook.VBProject.VBComponents.Remove myForm

'   IE is now set to the user's choice and you can add code here to interact with it
'   myDoc is now set to IE.Document also
'
'
'

Dim drp As HTMLFormElement

Set drp = myDoc.getelementsbyname("suppliercode")(0)

Dim walekuj As Long
walekuj = myDoc.forms.Length
 MsgBox walekuj

'we get the option values into our worksheet

For x = 0 To 3
 Cells(x + 1, 1) = drp.Item(x).innerText
 Next x

'Now we select the option value of our choice

drp.selectedIndex = 2

' we free memory

Set IE = Nothing
 Application.StatusBar = ""
End Sub

Answer: I got this to work. Thank you for your time and effort for those that posted.
Set IE = IE.document.frames(1).document
Dim supls As Object
Dim suplsDrop As Object
 Set suplsDrop = IE.getElementsByTagName("OPTION")
 For Each supls In IE.getElementsByTagName("SELECT")
  If supls.Name = "suppliercode" Then
 For Each suplsDrop In supls
  With Me.SupplierSite
  .AddItem suplsDrop.Value
  End With
Next suplsDrop
End If
Next supls


Two versions of Taylor Series approxmiations, $f(x) \approx f(x_0) + f'(x_0)(x-x_0)$ and $f(x) \approx f(x_0) + f'(x'_0)(x-x_0)$

Question: My understanding of Taylor's Series for a function $f$ with a continuous $(n+1)$st derivative in a neighborhood of a point $x_0$ is that we can approximately have:
$$
f(x) \approx f(x_0) + f'(x_0)(x-x_0)
$$
However, I have also seen formulations whereby we have:
$$
f(x) \approx f(x_0) + f'(x_0')(x-x_0)
$$
whereby $x_0'$ is a value between $x$ and $x_0$. I am wondering why there are two different formulations and how to go between one and the other?
Comment: The second is not an approximation, it is an equality, given by Taylor's Theorem. Of course, $x'$ depends on $x$.
Comment: Mean value theorem probably, which will give $f'(x_0')$ to be a better approximation.
Comment: @GuachoPerez You should post this as an answer.
Comment: @GuachoPerez Oh right!  Wow, I am off my game XD  Well, I mean, I had the intuition, and indeed if you followed my comment...
Comment: What does $x'_0$ mean?
Comment: @MichaelMcGovern "whereby $x_0'$ is a value between $x$ and $x_0$." Last few lines
Comment: @SimplyBeautifulArt You were not off your game, if I remember correctly,  the proof of Taylor's theorem uses the mean value theorem. So you were not far off!
Comment: @GuachoPerez Yes, that's where my instinct came from, but my brain was not into it.  It appears my instinct is what I run on :D
Answer: As per Stella Biderman's comment, I will post my comment as an answer. The second expression is an equality, not an approximation, given by Taylor's theorem.
The theorem states that if $f^{(n-1)}$ is continuous on an interval $[a,b]$ and $f^{(n)}(t)$ exists for all $t \in (a,b)$, with $P(t)=\sum_{k=0}^{n-1} \frac {f^{(k)}(\alpha)}{k!}(t-\alpha)^k$, then there exists a point $x\in (\alpha,\beta)$ such that $$f(\beta)=P(\beta)+\frac {f^{(n)}(x)}{n!}(\beta-\alpha)^n$$
for $\alpha$ and $\beta$ distinct points in $[a,b]$. This $x$ is the $x_0'$ in your second expression, where the theorem is applied with $n=1$.
Comment: @user321627 It is related to the remainder formula for the Taylor polynomial.
Comment: @user321627 An interesting proof may be found here: http://math.stackexchange.com/a/20415/272831
Comment: @user321627 https://en.wikipedia.org/wiki/Taylor's_theorem#Explicit_formulas_for_the_remainder where $\xi=x_0'$.
Comment: Is this related to Taylor's Series approximation or a different thing altogether?
Comment: Do you know where on the wikipedia page it states your version? I didn't see a mention of the existence part, thanks!
Comment: Does this imply that we can choose $\xi$ to be whatever we want or only the mere existence?
Comment: @user321627 Merely existence, but it can later be used to show that a Taylor polynomial converges to $f(x)$ if you prove that for all $\xi$ the remainder approaches zero.  (We also overapproximate with our $\xi$ to get approximations of a function through the Taylor polynomial + Remainder)


Solution to a Riccati type equation

Question: I have the following Riccati type equation,
$$y'(x)-\frac{1}{4x}y(x)^{2}+\frac{y(x)}{x}-a\frac{x}{(1-x)^{2}}=0,$$
where $a$ is just a constant. I am struggling to find a substitution that makes the equation linear. I also tried to find a particular solution and use that method to solve it, but I was unable to find a solution.
Comment: $y(x)=-2xu'(x)/u(x)$ makes the equation linear.
Comment: After the edit now $y=-4xu'/u$.
Answer: Since the last term in the equation is a fraction $-\frac{a x}{(x-1)^2}$, one can guess a particular solution to be $y_1=\frac{bx+c}{x-1}$, where $b,c$ are constants which can be determined later. Then easy calculation shows
$$ (2a-2b+b^2)x^2+2b(c+2)x+c(c+2)=0$$
which holds for any $x$. So $c+2=0,2a-2b+b^2=0$ or $c=-2,b=1\pm\sqrt{1-2a}$. Then one has found a particular solution
$$y_1=\frac{(1+\sqrt{1-2a})x-2}{x-1}.$$
Now let $y=y_1+u$ to get $u$.
Comment: Thank you very much! Quick question, how does one see that a good guess is $y_1$, I can understand the $bx$ part of the numerator, but is there some hint in the equation that tells you that the $c$ is needed in $y_1$?
Comment: $c$ is needed since one can't obtain $y_1$  without $c$.

Solution to a Riccati type equation


Adding fields to Flag Lists

Question: I'm using the Flag Lists module to manage user wish lists. I need to add additional fields to the lists such as "body"
I go to /admin/structure/flags/manage/fl_template/fields add the required fields, save, rebuild flag lists, flush caches and attempt to edit existing flag lists or create new ones and I still only see the "title template."
Answer: When configuring flag(s) (using the Flag module), you can indeed attach fields to them. However when doing so, make sure to also be aware about (and do) what is described in Attaching fields to flags, i.e.:

By default, Flags use the "JavaScript toggle" link-type. While this allows entities to be flagged without reloading the page, users cannot set any field values with the Flag. In order for users to set a Flag's field values, you must use the "Form" link type.
Navigate to Administration > Structure > Flags page. Click the Edit link for the Flag. Scroll down to the Display Options box and select the Confirmation Form radio button.

If the above doesn't help (or if you've already configured your flag using a Confirmation Form), then you may want to look at Comment nr 1 in issue nr 2539868, which points to 2 more related issues.
Answer: I guess I missed something, I could not add a new field to a flag as suggested above. I'm using Drupal 9.3 with Flag 8.x-4.0-beta3 and Flag List 4.0.0-rc2
I'm trying to add a new field "Description" after "Name". Any reference link or suggestion is appreciated.
Alternative thought, do we have to write a custom module to add a new field on the form, extending the 'Flags' module

Adding fields to Flag Lists


Command line node-webkit app

Question: I would like to be able to create a node-webkit (nw.js) application and then be able to start it from the command line with arguments to pass into the application itself. I would like to be able to run the command release ./project and have it launch a GUI passing the directory from the CLI argument into node-webkit.
I've been able to compile the app thus far but have no way of opening it from a command line and then passing a completed callback back to the command line after it has closed.
How would I go about creating command line interface for a desktop app built using node-webkit?
Answer: You can use the following to get an array of command line arguments.
// Load native UI library.
var gui = require('nw.gui');
var commands = gui.App.argv;

Command line node-webkit app


Mean of target variable differs by one percent for independent variable, yet it has a coefficient of 0.43 and is highly significant in logistic reg

Question: I have a dataset that contains information on what an individual likes! The question is posed do you get energy from ..... (my X). These X variables are categories. One of these categories is whether someone gets energy from and enjoys playing sport. It is true if someone answered yes and false if they answered no.
The target variable is whether someone passed an undergraduate course. This is a binary variable 1 indicating a pass and 0 indicating a fail.
504 students indicated they enjoyed and gained energy from playing sports. 66.4% of these students passed the course. 244 students indicated they did enjoy playing sports or gained energy from it. 65.9% of these students passed the course. This seems like a very small difference and given that the dataset is not that large I would not expect this to be significant. Yet, when I perform a logistic regression on this dataset (including the other categories such as social activities, events, entertainment) it shows that sport is highly significant (z-value of 3) and has a coefficeint of 0.43. If I correct interpret this coefficient value it would mean that someone that enjoys sports has a 53% higher chance of passing the course. This value does not pass my sanity check when comparing it with the mean and the sample size of both groups. What is going on here? What am I missing?
I am using the statsmodels api with the Logit model.
Below is the model output generated by the summary method.
https://gyazo.com/0616c6eeb576d149274efdf14ad54a2a
I added gender as a control variable.
Comment: AFAICS, you don't have a constant in the model. That makes the coefficients more difficult to interpret because they include a level effect and not just a marginal effect.
Answer: If you only sports and the target, does the same thing happen? If not, then either (a) sports alone does not have that predictive power, or (b) some other variable confounds to occlude the effect of sports.
Then start from your full model and remove variables until the effect goes away. Find the smallest set of variables that recreate that effect.
Explore those variables visually together. Why does sports modify the effect of the other? Maybe ask follow-up questions of the subjects.
Without access to your data or more details on how you decided which variables to include in the model, we can't explain what has happened.


Can I manage the AlarmClock in Android from my application?

Question: I develop an application which must manage the Alarm Clock in Android. I specifically need to do the following:

execute some code in my application when the user sets an alarm (also find out the time of the alarm at the moment of execution);
cancel an alarm when the user pushes a specific button in my application;
execute some code in my application when an alarm goes off.

I must mention that I am not interested in the CPU alarms, but the Alarm Clock application, which people use to wake up.
Comment: Looks like this: http://stackoverflow.com/questions/9618748/android-how-to-set-system-alarm-clock-from-my-own-app
Answer: You can set an alarm using the intent described here.
However, you can not intercept the AlarmClock UI or ringing alarms as you seek to.
You might want to look into scheduling your own reminders, probably using AlarmManager with RTC_WAKEUP.


Tangency points of an ellipsoid with the coordinate planes

Question: Suppose you have an ellipsoid with known semi-axes, say $a,b,c$.  The ellipsoid is then rotated so that the three axes of the ellipsoid are aligned with the three columns of a known rotation matrix $R$.  Keeping this orientation, you place the ellipsoid on the $xy$ plane, in the first octant (where $ x \ge 0, y \ge 0, z \ge 0$).  Next, you drag the ellipsoid, while maintaining its spatial orientation, along the $xy$ plane, in a direction parallel to the $x$ axis, till it touches the $yz$ plane, then you drag it parallel to the $y$ axis, till it touches the $xz$ plane.  Now the ellipsoid is tangent to the $3$ coordinate planes.  The question is find the tangency points of the ellipsoid with the three coordinate planes.
As for context, this question can be considered a extension of $2D$ ellipses in general orientation, to the $3D$ case involving an ellipsoid instead of an ellipse.
My Progress:
The algebraic equation of an ellipsoid is
$ (r - r_0)^T Q (r - r_0) = 1 $
where $ r = [x , y, z ]^T $ and $ r_0 = [r_{0x}, r_{0y}, r_{0z}]^T $ is the center of the ellipsoid (unknown).  And $Q$ is known and is of the form
$ Q = R D R^T $
with $ D = \text{diag}\bigg(\  \dfrac{1}{a^2},\  \dfrac{1}{b^2}, \ \dfrac{1}{c^2} \bigg) $, and $R $ is a rotation matrix, whose columns (mutually orthogonal unit vectors) give the direction of the three axes of the ellipsoid.
From tangency to the $xy$ plane, let $r_1$ be the tangency point, then
$ (r_1 - r_0)^T Q (r_1 - r_0) = 1 $
and the gradient of the ellipsoid (which is a vector normal to its surface) points in a direction of $- \mathbf{k} $ (where $\mathbf{k} $ is the unit vector pointing in the positive $z$-direction).  Hence,
$ Q (r_1 - r_0) = -\alpha \mathbf{k} $
for some $\alpha \gt 0 $
Similar equations can written for $r_2$ and $r_3$, the tangency points with the $xz$ plane and the $ y z $ plane respectively.
Continuing with $r_1$, and from the above equation,
$ r_1 - r_0 = - \alpha Q^{-1} \mathbf{k} $
Plugging this into the equation of the ellipsoid, yields
$ \alpha = \dfrac{1}{\sqrt{ \mathbf{k}^T Q^{-1} \mathbf{k} } } $
Everything on the right hand side is known, so $\alpha$ is now known.
Recall that $r_1$ is the tangency point with $xy$ plane, so its $z$-coordinate is $0$.  Premultiplying the above equation for $r_1 - r_0$ by $ \mathbf{k}^T$ therefore, will give
$ r_{0z} = \sqrt{ \mathbf{k}^T Q^{-1} \mathbf{k} } $
Similarly, we will get
$ r_{0y} = \sqrt{ \mathbf{j}^T Q^{-1} \mathbf{j} } $
and
$ r_{0x} = \sqrt{ \mathbf{i}^T Q^{-1} \mathbf{i} } $
where $\mathbf{i}$ and $\mathbf{j} $ are the unit vectors in the positive $ x $ and $y$ directions, respectively.
Having found $r_0$ completely (the center of the ellipsoid).  Then now we can use the equations above for $(r_1 - r_0)$ , $(r_2 - r_0)$ , $(r_3 - r_0) $ to solve for $r_1, r_2, r_3$.
Comment: Your issue is well explained, but could you say what you have **attempted to do** before asking on this site ? Do you know for example how to find the implicit equation of the rotated + translated ellipsoid ?
Comment: Thank you for your remark.  Please check my edited question that includes more details.
Comment: [+1] Very good work. So you have solved your issue !
Comment: Yes. I think I did.  But I look forward to others' input on this.
Answer: Here is another point of view.
You may know in plane geometry the fact that the locus of points from which one can draw an orthogonal pair of tangents to the ellipse with equation
$$\frac{x^2}{a^2}+\frac{y^2}{b^2}=1$$ is a circle called the director circle of the ellipse with equation $$x^2+y^2=a^2+b^2.$$
This property has a straightforward equivalent in space geometry : The locus of points of intersection of 3 mutually perpendicular tangent planes to the ellipsoid with equation $$\frac{x^2}{a^2}+\frac{y^2}{b^2}+\frac{z^2}{c^2}=1$$  is a sphere with equation :
$$x^2+y^2+z^2=a^2+b^2+c^2$$
This sphere is called the director-sphere of the given ellipsoid.
I have found a reference (and a proof) of this property on p. 72 of "Elementary Treatise on Solid Geometry" by Charles Smith, Macmillan, London, 1907 (!) that you can find here.
Do you see you this property can be exploited for your issue ? (in fact, you should find back some parts of your calulations)
Comment: You know what, I think you could possibly add another solution , or update your solution, to include these ideas.  I don't think I am following.
Comment: I am aware of this property, but I don't see how it can be used to find $r_1, r_2, r_3$. (the tangency points).
Comment: Let us consider an ellipsoid that hasn't been translated (it is easy to do the translation afterwardsà. Instead of rotating the ellipsoid by rotation matrix $R$, consider the orthonormal basis $B$ constituted by the columns or $R^{-1}=R^T$. There is a unique point $M$ on the director sphere such that the intersection of the tangent planes associated with $M$ "is" basis $B$.
Comment: A fact: the conjugate plane $xx_0/a^2 + yy_0/b^2+zz_0/c^2-1=0$ of any point $M(x_0,y_0,z0)$  of the director sphere (with $x_0^2+y_0^2+z_0^2=a^2+b^2+c^2$) with respect to the ellipsoid passes through the tangency points to the system of 3 perpendicular planes attached to $M$.
Comment: Ah, I see.  Thank you.  I'll see how I can use this fact.
Comment: I have some doubts about what I just said... I have maybe too quickly extrapolated from the planar case (ellipse and its directing circle). I must check.


Why does Non-negative Matrix Factorization not give me 100% R^2 at full rank?

Question: IMPORTANT: Please read the question carefully before labeling it a "code question" & sending it to stack overflow. The question is in fact a theoretical stats question (barring the possibility of a bug in the NMF R library). Because I can do better than NMF (at full rank) on a positive matrix A, by using the identity transform! i.e. W=A,H=I (identity), s.t. A~=WH. How could NMF possibly be so bad??
I don't understand why NMF would behave like this while PCA gives perfect invertibility even at much lower rank.
I'm using the R library: NMF & NMF method: "brunet"
This is my code:
library(NMF)

mass_NMF = nmf(mass_frac_data, rank=ncol(mass_frac_data))
# NOTE: mass_NMF@fit@W==mass_PCA$x, mass_frac_data~=mass_NMF@fit@W%*%mass_NMF@fit@H
cat('NMF R^2 on original data: ', get_explained_var(mass_NMF@fit@W, mass_frac_data))

This is the output:
NMF R^2 on original data:  0.9240395 (aka 92%)
(PCA obviously gets approximately 99%, even at much lower rank)
The get_explained_var(X_df, Y_df) function (thoroughly tested) fits linear models to each of the Variables/Columns in Y_df & uses all the variables in the X_df + a bias for predictors (i.e. lm_i = lm(Y_df[,i]~X_df)) then it takes the average of all R^2 values from these linear models.
Comment: The wikipedia page for NMF indicates that "...  if the factorization worked, it is a reasonable approximation to the input matrix V", where "reasonable approximation" does not mean "$R^2 \approx 1$."   Consequently, this would be expected behavior for a non-negative matrix factorization.
Comment: How does PCA assure non-negativity??
Comment: @jbowman:
I'm basically asking this -- if PCA can do it so easily then why is it hard for NMF?
Also I'm trying to emphasize this point in particular: all the data in mass_frac_data is ALREADY positive. It could've just made each "Factor" correspond to one of the original variables (trivial) & it would've had perfect reconstruction.
Comment: @jbowman: to make things even more clear I can do better than NMF on a (positive matrix) A by doing this: W=A, H=I (identity), s.t. A~=WH. How could NMF possibly be so bad?
Comment: "Current algorithms are sub-optimal in that they only guarantee finding a local minimum, rather than a global minimum of the cost function. A provably optimal algorithm is unlikely in the near future as the problem has been shown to generalize the k-means clustering problem which is known to be NP-complete.[35] However, as in many other data mining applications, a local minimum may still prove to be useful." - from Wikipedia.   My take is that it typically uses an iterative algorithm that relies on a loss function that can have multiple minima; just not very good in this case.
Comment: @whuber It doesn't? Why do you ask?
Answer: You are correct that $X=XI$ is a zero-error NMF factorisation of any non-negative matrix $X$, so the software is not finding the correct optimum.  It's probably not a bug, though.
The NMF problem has local optima, unlike PCA. Even worse, if $X=WH$ is a solution, then $X=WAA^{-1}H$ is another solution exactly as good, as long as $(WA)$ and $(A^{-1}H)$ are non-negative, so even local optima aren't isolated.  In addition, to the extent that the problem is identifiable, it's only because the non-negativity constraints reduce the options, so that many of the optima are right up against the boundary of the parameter space.
It's quite a hard problem, which is why there are so many algorithms in the NMF package (if you have six algorithms implemented for something, it's unlikely that any of them is really satisfactory). That's not really surprising. The singular value decomposition underlying PCA is what's unusual here in having a fast globally-convergent algorithm.
The brunet algorithm is described here. It starts with randomly initialised matrices and does alternating multiplicative updates of the two factors, which apparently works well for low-rank approximations, but you can easily imagine it getting stuck on a high-rank fit.
I tried the various algorithms on a single random matrix of $U[0,1]$ values with rank=number of columns, the lee and ls-nmf did best in terms of residual mean squared error; you might try them if you want a high-rank solution.
(I worked on a variation of this problem in air pollution, where the goal was to decompose chemistry x time data into chemistry x source and source x time, but with the additional complication that the error variances were all different and poorly estimated)
Comment: In the air pollution setting the pollution sources are *real things* that they want to estimate, not just a low-rank representation, so there is a lot of interest in using any available constraints to help estimate those things.  I don't know why  more generally.
Comment: Thank you for the sensible & simple answer.
I'm also curious tho: I too am working on a chemistry problem, where I'm making "progress variables" for reduced order modeling (surrogate modeling).

Why can't chemistry people just use PCA (i.e. get negative decompositions)?


Delphi - Executável com comportamento diferente em máquinas diferentes

Question: Eu quis criar um efeito de transição para um form, então, no evento OnShow, setei a propriedade AlphaBlend := 0 e, no OnActivate:
  for i := 55 to 255 do
  begin
    AlphaBlendValue := i;
    Update;
    sleep(1);
  end;

Funciona perfeitamente em meu equipamento, fazendo com que o form fique visível gradualmente, em torno de dois décimos de segundo, o que dá um efeito mais agradável. No entanto, ao copiar o executável para outros dois equipamentos (por sinal, idênticos ao meu - mesma marca e modelo), o efeito demora cerca de dois segundos (!), dando uma impressão péssima!
Alguém tem alguma ideia do que poderia estar acontecendo?
Comment: Pode ser uma demora no processamento do comando Update. Troca ele por Application.ProcessMessages e vê se produz algum resultado.
Comment: Originalmente o comando era Application.ProcessMessages. Eu troquei para Update justamente imaginando que poderia haver uma fila de mensagens causando lentidão. Mas o efeito é o mesmo.
Comment: Tirando o hardware, os softwares nas máquinas são os mesmos (ou parecidos)? Windows? Antivírus? No gerenciador de tarefas, o processamento está parecido?
Comment: Só uma pergunta, estamos falando de VCL ou Firemonkey?
Comment: São máquinas com softwares parecidos, mesmo Windows, mesmo antivirus. Vou olhar o gerenciador de tarefas. A bliblioteca utilizada é a VCL.
Comment: Examinei o gerenciador de tarefas e o processamento desse código não parece estar pesando em nada. CPU passou de 0 para 1 durante um piscar de olhos e a memória aumenta 200k enquanto o form permanece aberto (sendo que o programa consome pouco mais de 6Mb).
Answer: Geralmente nesses casos existe algum processo sendo executado na Thread Principal, e atrasando a execução do seu Looping For. Uma possível solução seria executar o Looping em uma Thread Secundária. Ficaria assim:
Evento OnShow:
procedure TForm1.FormShow(Sender: TObject);
begin
    AlphaBlend := true;
    AlphaBlendValue := 0;
end;

Evento OnActivate:
procedure TForm1.FormActivate(Sender: TObject);
var
    MyThread: TThread;
begin
    MyThread := TThread.CreateAnonymousThread(
    procedure
    var i: Integer;
    begin
        for i := 55 to 255 do
        begin
            TThread.Synchronize(MyThread, procedure begin
                AlphaBlendValue := i;
                Update;
                sleep(1);
            end);
        end;
    end);
    MyThread.Start;
end;

No evento OnActivate criamos uma Thread Anônima, que automaticamente será finalizada após sua execução. Seu processamento ocorre em background, até que seja chamado o comando Synchronize, e somente aquele processamento ocorre na Thread Principal.
Comment: Utilizei a thread mas o efeito foi o mesmo. Somente em um computador; no meu funciona perfeitamente. Fiz, ainda, outra experiência: comentei o comando sleep(1). Nesse caso, lógico, o efeito de transição se perde, mas o objetivo era testar se o problema estaria nesse comando. O resultado foi que o form ficou visível imediatamente, mesmo no computador problemático. Fica claro que há algum problema no sleep.
Comment: Outro teste, substituindo o sleep(1) por: for k := 0 to 500000 do ;, o efeito funciona em todos os computadores. O problema é que, neste caso, iria variar conforme a velocidade do processador.


Visual SVN server Running but cannot access / browse repositories

Question: Operating System: Windows Web Server 2008 R2
Visual SVN Version: 2.5.7
Subversion: 1.7.7
Apache: 2.2.22
I freshly installed the Visual SVN latest version on the server and created one repository in it. In the server management window, it shows that the server is up and running but when I try to browse it in a web browser, it doesn't respond.
I am not able to

import my existing code into the repository: Error: Cannot connect to server
open/browse the repository with either command localhost:81/svn OR http://www.myserver.com:81/svn OR http:// myIPAddress:81/svn
Visual SVN log is clean. The last information in the server log is that "The server is listening to port 81.
Answer: A corrupt Winsock caused similar symptoms on my server (Windows Server 2008 R2 / VisualSVN v2.5.7).
The following command, executed at a command prompt, with a server reboot fixed it.

netsh winsock reset

Boy was this a pain.
Answer: On default page of VisualSVN Server Manager you have clean indication of

status of server
URL (as active link), on which server can be reached

if you can't reach server at this URL from the same host (preferably), check network connectivity and correctness of hostname
Comment: @user1783560 - as I wrote: "check network connectivity and correctness of hostname", even for localhost (tracert, ping, telnet on VisialSVN Server port, netstat -na)
Comment: Thanks Lazy Badger for your response. I also see the server status and running and corresponding server URL. when I click the server URL, it should open up in a web browser, isn't it? In my case, it doesn't happen. The browser fails to connect to the URL. I even tried using IP address. By the way, I am doing these operations on the same machine where the VisualSVN is installed..
Answer: There is a knowledge base article on this matter BTW: "Connecting to VisualSVN Server".
All details you've provided indicate that you can't even reach the VisualSVN Server. The Error: Cannot connect to server clearly states that! :) The behavior you describe is definitely caused by some network misconfiguration.
VisualSVN Server works out of the box just after you install it. It does not require any specific steps to be accessible on your LAN or from the Internet.
You should perform the common steps you usually perform to make a web service accessible (e.g. a web server) on your LAN. This leads us to a next troubleshooting step: check network settings and a firewall / proxy etc.
Also you can always contact VisualSVN support for additional troubleshooting.
Comment: Thank you for your response. But I do not know what exact network settings should I check. There is no firewall, no proxy. I am on the server and I just want to import my existing code into freshly created repository and while doing that in the command prompt, it gives me error - Cannot connect to the server. I do not understand, how can command prompt cannot connect to the server when I am on the same machine.. :(


How to avoid memcpy if number of blocks depends on device variable?

Question: I am computing a number, X, on the device. Now I need to launch a kernel with X threads. I can set the blockSize to 1024. Is there a way to set the number of blocks to ceil(X / 1024) without performing a memcpy?
Answer: I see two possibilities:

Use dynamic parallelism (if feasible). Rather than copying the result back to determine the execution parameters of the next launch, just have the device perform the next launch itself.
Use zero-copy or managed memory. In that case the GPU writes directly to CPU memory over the PCI-e bus, rather than requiring an explicit memory transfer.

Of those options, dynamic parallelism and managed memory require hardware features which are not available on all GPUs. Zero-copy memory is supported by all GPUs with compute capability >= 1.1, which in practice is just about every CUDA compatible device ever made.
Comment: @FlorentDUGUET: I am sorry if you don't understand the question. The (simple) question is: if one kernel calculates a result, and the size of the grid for the next kernel is determined by the value of that result, is it possible to avoid having to do an explicit memory transfer of that value back to the device before the next kernel launch is performed.
Comment: I honestly don't see how answer relates to question. Can you elaborate the link between the two?
Comment: Thanks for elaborating.
Answer: An example of using managed memory, as outlined by @talonmies, allowing kernel1 to determine the number of blocks for kernel2 without an explicit memcpy.
#include <stdio.h>
#include <cuda.h>

using namespace std;

__device__ __managed__ int kernel2_blocks;

__global__ void kernel1() {
    if (threadIdx.x == 0) {
        kernel2_blocks = 42;
    }
}

__global__ void kernel2() {
    if (threadIdx.x == 0) {
        printf("block: %d\n", blockIdx.x);
    }
}

int main() {
    kernel1<<<1, 1024>>>();
    cudaDeviceSynchronize();
    kernel2<<<kernel2_blocks, 1024>>>();
    cudaDeviceSynchronize();
    return 0;
}


Extracting maximum (x,y) values and initial slope of non-linear fitted glm curves

Question: I have plotted 8 curves using a log-link Gaussian model, $y=ax \times exp(bx)+ϵ$, for my data. I am not sure how to extract the $max (x,y)$ from each of the fitted curves using the equation, of which I intend to use for statistical analysis later. I am also trying to calculate the initial slope (⍺, increasing part) of each curve if that's possible at all.

If anyone had already done this before, or know of some ways around it, I could really use some help. Below are some of my data and codes I used for plotting the curves. I used 0.0000000001 instead of 0 to fulfill the argument in my codes.
rlc <- data.frame(par = c(0.0000000001,6,18,35,61,93,121,195,268, 0.0000000001,6,18,35,61,93,121,195,268),
                 tmp = c(24,24,24,24,24,24,24,24,24,27,27,27,27,27,27,27,27,27),
                 etr = c(0.06, 1.63, 4.88, 7.70, 9.47, 9.47, 8.07, 6.55, 3.60, 0.06, 1.44, 3.78, 5.06, 5.68, 5.51, 4.35, 3.21, 1.91))

rlc$tmp=as.character(rlc$tmp) #leaving tmp as numerical will result in continuous gradient

glm(etr ~ log(par) + par,
    family=gaussian(link="log"),
    subset=par>0,
    data=rlc)

rlc_plot <- ggplot(rlc, aes(x=par,y=etr, group=tmp, colour=tmp))+
  geom_point()+
  geom_smooth(data=subset(rlc,par>0),
              method="glm",
              formula=y~x + log(x),
              se = FALSE,
              method.args=list(family=gaussian(link="log")))

Comment: I'm a little confused, because isn't your "initial slope" estimate precisely the exponential of the intercept term?  Could you explain further this business with "0.0000000001"?  Is that a real observation or something you have created to help with the fitting procedure?  And since the mode is located the point $x=-1/b,$ which is readily computed from your estimate of $b,$ what exactly do you mean by "extrapolate"?
Comment: @whuber thanks for the comment. I am rather unfamiliar with the equation myself so I am not sure how to produce the parameters that I am looking for. You mean the initial slope would be `exp(bx)`? And `0.0000000001` is not a real observation (zero is the real observation), but in order to fulfill `par>0`, I made it a small number that is close to zero.
Answer: The equation for your linear predictor is $\eta = \beta_0 + \beta_1 x + \beta_2 \log(x)$. The maximum of the curve will occur at the maximum of $\eta$, so we need $d\eta/dx=0$:
$$
\begin{split}
0 & = \frac{d\eta}{dx} \\
0 & = \beta_1 + \beta_2/x \\
x & = -\beta_2/\beta_1
\end{split}
$$
The y-value at this point will be
$$
\begin{split}
& \exp(\beta_0+\beta_1 x + \beta_2 \log(x)) \\
 = & \exp(\beta_0 + \beta_1 (-\beta_2/\beta_1) + \beta_2 \log(-\beta_2/\beta_1)) \\
 = & \exp(\beta_0 + \beta_2(\log(-\beta_2/\beta_1) -1))
\end{split}
$$


Anonymous user form submission

Question: I have a situation where after doing the basic registration the user is redirected to a page where he needs to fill a small form.
I aim at implementing the hook_user_insert() and hook_menu() to do something like this
function registration_user_insert(&$edit, $account, $category){
  drupal_goto('splan/'.$edit['uid']);
}

function registration_menu() {
  $items['splan/%'] = array(
    'title' => 'Select a Plan',
    'page callback' => 'drupal_get_form',
    'page arguments' => array('selectplan_form'),
    'access callback' => TRUE,
    'type' => MENU_CALLBACK
  );

  return $items;
}

In selectplan_form() I will define my new form and then, using the user ID, I would save data into user table.
The basic user registration form is being submitted, the user is redirected to splan/uid, but I also get the following error.

You are not authorized to access this page.

I have changed permissions to allow anonymous users to create and edit webform, but the problem still persists.
Comment: Then maybe a multi-step registration form instead?
Comment: Why are you redirecting the user, instead of adding your form fields to the user profile form?
Comment: this situation is forced upon..i know i can add them in the user profile form but the requirements are not like that..
Answer: Implementing hook_user_insert() this way (calling drupal_goto() inside) is plain wrong:

if there are any other implementations of this hook in other modules meant to be called after yours, they will not get called at all
if for whatever reason hook_user_insert() from user module will not be called before your implementation, the user will not be saved at all
if you look at user_save() function in user.module, you'll see that after invoking 'insert' hook there are many other things this function is doing, so if you use drupal_goto(), they will not be done.

What you can do though is to add your own submit function to user_register_form, and in that function set $form_state['redirect'] to wherever you want (note that updating $form_state['redirect'] in hook_form_alter() will not work in this case, as user_register_submit() sets its own redirect, so you need to do it after this - hence the need for your own submit).
Answer: How about using the LoginToboggan module to create a temporary role for the user after signing up and giving that role the permissions needed?

Anonymous user form submission


Hooking into a contrib module

Question: I've installed a contrib module in Drupal 7 and would like to hook into it.  However, the documentation for the contrib module is sparse and doesn't list the available hooks, though it implies that there are some.
Is there a standard "Drupal way" of seeing what hooks a contrib module exposes?
(I've deliberately not mentioned which module this is as I'd like a generic answer if one exists.)
Answer: By convention a lot of modules include a modulename.api.php file in the root folder, which describes the hooks implemented.
They may also implement hook_hook_info() to programatically describe the hooks to Drupal.
If that file isn't there, have a look at the other documentation/non-code files included. Sometimes you'll find examples elsewhere in the folder structure.
There's nothing enforced, though, so there isn't a generic all-encompassing answer. For a low tech solution you could grep the module folders for patterns like

module_invoke('modulename
module_invoke_all('modulename
module_implements('modulename

If you use the grep method, remember to add a conditional for the quote before the module name, it could be single or double.
In case the above causes confusion:
By convention most hooks are prefixed with the module's name, so that method will work 99% of the time, and avoid false-positives when a module invokes hooks for anything other than itself.
There will be the odd instance when it doesn't, but since there's no formally enforced way for a module to define hooks, anything non-manual here is going to be a best effort however you look at it.
Comment: I also found a method in the contrib module called `hook_` which seemed to handle all possible hooks.  I don't know whether that's a common convention too?
Comment: Not one that I've seen before no...what module is it out of interest?
Comment: It's [gmap](http://drupal.org/project/gmap)
Comment: Ah yeah I see what you mean. That's really a hangover from Drupal 6 thinking (e.g. the old `hook_nodeapi()` with a bunch of different operations). In Drupal 7 (and going forward) the onus is on separating those operations out into individual hooks (e.g `hook_node_insert()`, `hook_node_update()`, `hook_node_delete()`). So yeah you probably will see that convention used here and there, but increasingly less so I'd imagine
Answer: The only way to know which hooks are used from a module is looking for any of the following function calls.

module_invoke(): The second argument is the hook name
module_invoke_all(): The first argument is the hook name
module_implements(): The first argument is the hook name
drupal_alter(): The first argument is the hook name without _alter

Some modules have their own function that calls one of those functions. For example, the User module uses user_module_invoke(), and the Node module uses node_invoke().
Comment: That's not the only way though...what about the API.php file and hook_hook_info?
Comment: Not all the modules implement `hook_hook_info()` (see [user.module](http://api.drupal.org/api/drupal/modules%21user%21user.module/7)), and in some cases a module implements it for hooks implemented also by other modules (see [system.module](http://api.drupal.org/api/drupal/modules%21system%21system.module/7)). Modules should have a file describing the hooks it uses, but that is not always the case; there is also the case that file has not been updated. Looking at the module code, you can be sure not to miss any hook.
Comment: Totally agree (I've alluded to the same thing in my answer), as far as 'foolproof' goes manually looking through the code is as good as you can get really
Comment: Thanks! Your explanation of which argument was the hook name in each case was really helpful.

Hooking into a contrib module


Access uploaded file by ID

Question: I have a webform that allows users to upload their CV/Resume's. The webform is sending me the file ID. I know that the URL for accessing those files is https:// example.com/sites/default/files/webform/myfilename.
Can I access the file using the file ID instead of its name, for example https:// example.com/sites/default/files/webform?fileid=1502?
Answer: If you're looking to do this in code, I believe that this question has already been answered:
Given a File ID (fid) how can I get the HTML that represents that fid?
You can also access the file's page at yoursiteurl/file/fid, but this isn't a direct link to the file.
Answer: Yes. You can use the drupal file_load() function to load the uploaded file.
<?php

$fid= 1502;
$file = file_load($fid);

?>

It will return the details of a file in the form of an array.
Hope it works for you!
Answer: file_load() has been deprecated
Instead, in a custom module you can use the function Drupal\file\Entity\file::load($fid) to load a file with the file ID that is present in the webform submission values
Here is an example :
  use Drupal\file\Entity;

  function student_support_form_submit(&$form, \Drupal\Core\Form\FormStateInterface $form_state){

     $values = $form_state->getValues();

       if(!empty($values['file'])){
         $file = Entity\File::load($values['file']);
         $values['file'] = $file->getFileUri();
       }
     ...
    }

Here 'file' is the key of your webform fileUpload element and $values['file'] would be an integer.
Comment: This seems a comment for a previous answer. As for answering the question, I think none of the answers really answered it, since the OP seems to ask about a link to access the uploaded file given its ID.
Comment: Welcome to Drupal Answers! :-) That's very interesting indeed. Unfortunately I doubt this answers OP's question...

Access uploaded file by ID


T-test or wilcoxon

Question: we have 2 independent groups of datas and one of them has normal distribution and the other doesn't
How  can I compare the means of this groups ?
Paired sample T-test or wilcoxon test?
Comment: You shouldn't base your choice on the results of normality testing of your data; see [this page](https://stats.stackexchange.com/q/2492/28500). See in particular [this answer](https://stats.stackexchange.com/a/30053/28500) on the problems with using this 2-step approach of choosing the test for comparing means after you run a normality test. If group are independent, you can't do a paired t-test in any event.
Answer: Comment. Here are two independent samples of size $n = 200.$ The first is normal and the second is not. Both are symmetrical with the same population variance. The first has mean/median $0.6$ and the second has mean/median $0.5.$ So a two-sample Wilcoxon test appropriately detects that the two populations do not have the
same center, with a very small P-value. Strictly speaking, a pooled two-sample t test would not be exact because one of the populations is non-normal.
<code>set.seed(1212)
x = rnorm(200, .6, sqrt(1/12))
y = runif(200, 0, 1)
wilcox.test(x,y)

        Wilcoxon rank sum test with continuity correction

data:  x and y
W = 23737, p-value = 0.00123
alternative hypothesis: true location shift is not equal to 0
</code>

T-test or wilcoxon


What is taking up all my disk space?

Question: I have a server (Windows Server 2008 R2 SP1), which is reporting only 2 GB free space on C drive.  But when I run WinDirStat or Treesize over the disk, both of them say that only 21 G is being used out of 40 GB.
I have run the Disk Cleanup tool to remove windows update backup files from winsxs folder.
I tried running "vssadmin List Shadows" on a command line, and I got the following result:

No items found that satisfy the query.

I have made sure that System files are not hidden as well as protected OS files.
If I am only using 21 GB out of 40 GB, I should have roughly 19 GB free space.  Where is the other 17 GB?  What can I do to find what is using it up?
Comment: can you tel me your chkdsk result ? i have almost same trouble:
http://serverfault.com/questions/671582/windows-2008-40-gb-inaccessible-space-used-by-system-where check the "used by system" section
Comment: I didn't use chkdsk.  I used SpaceSniffer to find out what was using up all the disk space - it was log files in the C:\Windows\system32 folder.
Answer: I found the cause of the problem - I used a tool called SpaceSniffer.  Turns out there was about 19 GB of log files in the C:\Windows\system32 folder.  I have no idea why they didn't show up in Treesize or WinDirStat, but regardless of why, I found the culprit.  I have now deleted those files and voilà - 22 GB free space!
Comment: Were you running those tools elevated ("Run as Administrator")? Not running tools like that elevated is typically the reason why they don't show complete data.
Comment: That may be it - I don't think I did run those tool elevated.
Answer: It might be trashes from users, or System Restore information, or something similar. WinDirStat or TreeSize wont be able to access those directories, at least if you don't run them with elevated privileges. And even then, you can't enter System Volume Information (that contains among others the restore points) because even not the administrator account is able to see it. On older versions of Windows there was a trick (using AT /INTERACTIVE) to run a program as the local system account so it gets access even to those protected locations, but I don't know a way to run an interactive program with such privileges on Windows 2008. One possibility would be to mount the partition (in read-only, just to be sure) from a Linux live CD, as the Linux NTFS drivers ignore all access control, and using the du command to check what takes space.
Another reason for what you observe could be that something is storing data on NTFS alternate data streams (see for example http://technet.microsoft.com/en-us/sysinternals/bb897440.aspx), I don't know whether TreeSize or WinDirStat are able to report data stored this way.
Comment: I am the only person who logs on to this server so it can't be deleted items for other users.  Also, I changed the permissions for the folder "System Volume Information" so I could see what was in it - only 6 MB of files.

What is taking up all my disk space?


Access external client IP from behind Google Compute Engine network load balancer

Question: I am running a Ruby on Rails app (using Passenger in Nginx mode) on Google Container Engine. These pods are sitting behind a GCE network load balancer. My question is how to access the external Client IP from inside the Rails app.
The Github issue here seems to present a solution, but I ran the suggested:
for node in $(kubectl get nodes -o name | cut -f2 -d/); do
  kubectl annotate node $node \
    net.beta.kubernetes.io/proxy-mode=iptables;
  gcloud compute ssh --zone=us-central1-b $node \
    --command="sudo /etc/init.d/kube-proxy restart";
done

but I am still getting a REMOTE_ADDR header of 10.140.0.1.
On ideas on how I could get access to the real Client IP (for geolocation purposes)?
Edit: To be more clear, I am aware of the ways of accessing the client IP from inside Rails, however all of these solutions are getting me the internal Kubernetes IP, I believe the GCE network load balancer is not configured (or perhaps unable) to send the real client IP.
Comment: Possible duplicate of [How to access client IP of an HTTP request from Google Container Engine?](http://stackoverflow.com/questions/36464890/how-to-access-client-ip-of-an-http-request-from-google-container-engine)
Comment: http://stackoverflow.com/questions/4465476/rails-get-client-ip-address

http://stackoverflow.com/questions/3887943/get-real-ip-address-in-local-rails-development-environment
Answer: A Googler's answer to another version of my question verifies what I am trying to do is not currently possible with the Google Container Engine Network Load Balancer currently.
EDIT (May 31, 2017): as of Kubernetes v1.5 and up this is possible on GKE with the beta annotation service.beta.kubernetes.io/external-traffic. This was answered on SO here. Please note when I added the annotation the health checks were not created on the existing nodes. Recreating the LB and restarting the nodes solved the issue.
Answer: It seems as though this is not a rails problem at all, but one of GCE. You can try the first part of
request.env["HTTP_X_FORWARDED_FOR"]

Explanation
Getting Orgin IP From Load Balancer advises that https://cloud.google.com/compute/docs/load-balancing/http/ has the text

The proxies set HTTP request/response headers as follows:

Via: 1.1 google (requests and responses)
X-Forwarded-Proto: [http | https] (requests only)
X-Forwarded-For: <client IP(s)>, <global forwarding rule external IP> (requests only)
  Can be a comma-separated list of IP addresses depending on the X-Forwarded-For entries appended by the intermediaries the client is
  traveling through. The first element in the  section
  shows the origin address.
X-Cloud-Trace-Context: <trace-id>/;<trace-options> (requests only)
  Parameters for Stackdriver Trace.
Comment: Thanks for your response. I should have been more clear in my question, I agree with you that it is not a Rails problem and it does seem possible with the HTTP load balancer, however I am currently using the _network_ load balancer which I can't find documentation on how to retrieve the original IP.
Comment: @JaredS: Thanks for the feedback. Seems like the network load balancer only works at the TCP level (for your purpose, also AH, UDP, etc, as of https://cloud.google.com/compute/docs/load-balancing/network/forwarding-rules). That makes adding the originating IP nontrivial. You might be able to redirect to a Squid proxy or the HTTP load balancer which then adds the origin-IP, as described in http://stackoverflow.com/a/8108013/1587329, but I might have misunderstood.


A convex-discrete minimax problem

Question: I faced a minimax problem with a vector and discrete set of functions as shown below.
$$ \min_{\mathbf{x}\in \mathbb{R}^{+n}\\\sum_{k=1}^n\mathbf{x}_k=1} \max_{l\in \{1,2\cdots \lceil n/2 \rceil \}} f_{l}(\mathbf{x})$$
The following is known about the problem:
Cond 1. $f_l(\mathbf{x})$ is convex with respect to $\mathbf{x}$ and has a minimum at $\mathbf{x}^{(l)}$.
Cond 2. For all pairs of  $l^\prime < l, f_l(\mathbf{x}^{(l)}) < f_{l^\prime}(\mathbf{x}^{(l^\prime)}) = f_{l}(\mathbf{x}^{(l^\prime)}) < f_{l^\prime}(\mathbf{x}^{(l)})=\infty. $ Moreover, the optimal points are in the constraint of $\min$.
Cond 3. If $\mathbf{x}=\sum_{l>l^\prime}a_{l}\mathbf{x}^{(l)}$, where $\sum_{l>l^\prime}a_{l}=1$, then
$f_{l^\prime}(\mathbf{x})=\infty$.
I want to check whether the solution of the problem is $f_1(\mathbf{x}^{(1)})$.
If you can provide the answer, it would be greately appreciated.
However, it would also be very helpful if you could check whether the following statements are true or false:
Check 1. Is the solution $\mathbf{x}^\star $ in $ \mathrm{span}(\{\mathbf{x}^{(1)} \cdots \mathbf{x}^{(\lceil n/2 \rceil)}\}) $?
Check 2. Is the solution $\mathbf{x}^\star$ located at an intersection of some pair of functions( $\exists (l^\prime, l)$ such that $f_l(\mathbf{x}^\star)=f_{l^\prime}(\mathbf{x}^\star)$) or $\mathbf{x}^\star\in\{\mathbf{x}^{(1)} \cdots \mathbf{x}^{(\lceil n/2 \rceil)}\}$?
Answer: I found my answer.
My argument turned out to be true.
Let $F(x):=\max_l f_l(x)$
Then,
$$F(x)\ge f_1(x) \ge f(x^{(1)})$$
which implies
$$\min_x F(x) \ge f(x^{(1)}).$$
Also,
$$F(x^{(1)})=\max(\{ f_l(x^{(1)}) : l\in \{1,\cdots, d\}\})=\max(\{f_1(x^{(1)})\})=f_1(x^{(1)})$$
Therefore,
$$\min_x F(x) = f(x^{(1)}).$$

A convex-discrete minimax problem


Is there a reason why Harmonic functions are defined on open sets?

Question: Whenever I see a definition of a harmonic function, it's always defined as follows

A function $f : U \to \Bbb{R}$ is called harmonic (where $U$ is an open subset of $\Bbb{R}^n$) iff it is twice continuously differentiable on $U$ and satisfies Laplace's equation $\Delta f = 0$.

Is there a reason why $U$ is always chosen to be open and what are the ramifications if $U$ is chosen to not be an open set in the context of the Laplace operator (in which we take the second partial derivatives)?

Edit: I have recently read that for a "good" subset $V$ of $\Bbb{R}^n$ i.e. a submanifold of codimension 1 with boundary, we can extend the notion of differentiability by extending $V$ for any point $v \in V$ to involve a neighbourhood around $v$ over which we can differentiate. Then the derivative of $V$ is just the derivative of the extension.

Supposedly, unless $V$ is "good", then the derivative needn't be uniquely defined. Why does this happen to be the case and what's the necessity in defining "good" as we have done?

Thanks in advance!
Comment: Probably: the Laplace operator involves derivatives; for differentiable functions, *by definition*, the domain is considered to be open set.
Comment: Whether looking at gravitational potential (or later electrostatic potential,) these functions satisfy Laplace's equation where there are no sources of potential, which would be in most of free space; and that context would have been one of the earlier applications of potential functions. That is, you would specify discrete sources or distributions of sources, and then solve for the potential in the remaining part of space.
Answer: I'll be assuming the function is real valued (as it is in the problem) but some of what I say generalizes.
The domain of the function is presumed to be an open set because derivatives and the Laplacian are defined on open sets. The reason we need to use an open set as the domain for $f$ when talking about derivatives, is because the concept of a derivative doesn't make sense when considering a point in isolation: you need to look in the neighborhood of the point. If I told you that I have a function $f:\{0,1,2,3\}\to\mathbb{R}$ and wanted to know how do calculate $f'(x)$, you'd tell me I couldn't. The concept of the derivative of a discrete function makes no sense because the the concept of $$\lim_{h\to0}\frac{f(x+h)-f(x)}{h}$$ doesn't make sense for such a function, since $f(x)$ is undefined for any value near $2$.
This is the core difficulty. Every closed set, $C$, in a metric space has the property that $\exists c\in C$ such that $\forall\varepsilon\exists x\in C^{c}$ such that $d(c,x)<\varepsilon$. This is immediate, because $C^c$ is open, so it doesn't contain its closure. Take $c$ to be some point in the closure of $C^c$ but not in $C$ and we are done.
In the particular case of the real numbers, although it's possible you'll have a one-sided limit you can calculate (say, in the example $[0,1]$), but the traditional definition of a derivative is the limit, not the one sided limit, and so you'll wind up with more differentiable functions than we normally have. Any time the left-handed limit doesn't exist, you will still get a derivative for $f(x)$ at $0$. For example, $f(x)=|x|$ is differentiable on $[0,1]$ under a one-sided limit.
Sometimes the above behavior is desirable, and so we wish to extend our notion of derivative to such places. There are two obvious ways to do this. For $f:A\to\mathbb{R}$ we can extend our definition of derivative to cover any point $x$ in the boundary of $A$ by considering the limit in the definition of a derivative to be a sequential limit, i.e.
$$f'(x)=\lim_{n\to\infty}\frac{f(a_n)-f(a)}{a_n-x}$$ where $a_n$ is a sequence converging to $x$.
This definition can cause problems from being too general, as the derivative of a function on $\{0\}\cup\{\frac{1}{n}|n\in\mathbb{n}\}$ doesn't do what we are used to doing with derivatives, since there is no neighborhood or half neighborhood of any point on which $f$ is defined everywhere. The middle ground is to do as follows: Define the derivative of $f$ at a point, $a$ to be the number, $g(a)$, that satisfies
$$f(a + h) = f(a) + g(a) h + O(|h|^2)$$
For all $h>0$. Define the function $f'(x)$ to be the formal derivative of $f(x)$ to be the function that satisfies $f'(a)=g(a)$ and which is defined exactly where the above equality holds.
This definition encapsulates the sense in which a derivative is the linear approximation of a function and so is very useful. It also always satisfies the mean value theorem, if you have an interval $f'(x)$ is defined in.
Comment: @khallil your edit surprises me, as for a point on the boundary I would think that you would always get either one value or an undefined limit, not two defined limits with different values. I added about limit extensions of derivatives, which are pretty common and Which I should have included from the start
Comment: Instead of awarding it prematurely, I'd really like to try and understand all the answers first and perhaps some insightful discussion can arise!
Comment: I've added an extra section to do with submanifolds and extensions of differentiability. Could you possibly address those too if you're comfortable with the content?
Comment: Probabilists have a definition of harmonic and subharmonic that does not use differentiability at all, but is based on the value of a strong Markov process when it hits a certain set. This stems from the fact that traditional harmonic functions have such characterisation in terms of Brownian motion.
Comment: Thanks for including the limit extension part, @StellaBiderman. May I ask why my edit surprised you?
Comment: For the reason I describe above: it seems counterintuitive that in two different neighborhoods you'd get different (but defined) values. The reason this surprises me is that the intersection of the two neighborhoods is an open set, and so it must contain an open ball. Extending the derivative on this ball should, in my intuition, match up with extending the derivative to a set containing this ball since derivative is a local property. But that would force the two extensions to have the same derivative (if they are both defined)
Comment: @khallil Is there more that you'd like me to add, or are you waiting to give out the bounty
Answer: Let $A\subseteq \mathbb{R}^n$ and $$B(x_0,\epsilon):=\left\{x\big{|}|x-x_0|<\epsilon\right\}$$ and $$D(A):=\{x|(\forall \epsilon >0)((B(x,\epsilon)\setminus \{x\})\cap A\neq \emptyset)\}.$$
More generally you can choose $U$ satisfying the following conditions:
$$U\subset\mathbb{R}^n \,\ \text{ and } \,\ D(U)\subset U$$
Comment: May I ask what $D(A)$ represents?
Comment: The set of all limit points of $A$.
Comment: Also, may I ask why we desire the limit points to be inside of U? Does something important depend on this fact?
Comment: to mention derivation.
Comment: Sorry, what do you mean by derivation?
Comment: It is possible to define the derivative of a function having a domain more general than an interval (since the point $c$ need only be an elemnet of the domain and also a cluster point of the domain) but the significance of the concept is most naturally apparent for functions defined on intervals. (Introduction to Real Analysis, Robert G. Bartle&Donald Sherbert, Page 158)
Answer: $\newcommand{\Eps}{\varepsilon}\newcommand{\Reals}{\mathbf{R}}\newcommand{\Basis}{\mathbf{e}}$Let $U \subset \Reals^{n}$ be non-empty, $f:U \to \Reals$ a function, and $x_{0}$ a point of $U$.
As you know, the definition of differentiability of $f$ at $x_{0}$ involves a limit at $x_{0}$, which strictly speaking requires $f$ to be defined in some open ball centered at $x_{0}$.
If $x_{0}$ is instead a boundary point of $U$, you can attempt to define the derivative of $f$ at $x_{0}$ by extending $f$ differentiably in a neighborhood of $x_{0}$, i.e., picking a differentiable function $F$ in some ball $B$ about $x_{0}$ in such a way that $F = f$ in $B \cap U$, and declaring that $Df(x_{0}) = DF(x_{0})$. Of course, this idea only works if $Df(x_{0})$ does not depend on $F$.
In order for $Df(x_{0})$ not to depend on the choice of extension $F$, it's necessary that "some basis $(\Basis_{i})_{i=1}^{n}$ of $\Reals^{n}$ is tangent to $U$ at $x_{0}$". In this event, $f$ itself determines directional derivatives along elements of a basis, so a linear approximation of $f$ at $x_{0}$, if one exists at all, is unique.
To give precise definitions (that are quite likely not standard), say that a vector $\Basis$ is tangent to $U$ at $x_{0}$ if there exists a smooth curve $\gamma:(-\Eps, \Eps) \to \Reals^{n}$ (for some value of smooth) such that:

$\gamma(0) = x_{0}$;
$\gamma'(0) = \Basis_{i}$;
$\gamma(t) \in U$ for $0 < t < \Eps$. (N.b., not necessarily for $-\Eps < t < 0$.)

Say that a basis $(\Basis_{i})_{i=1}^{n}$ of $\Reals^{n}$ is tangent to $U$ at $x_{0}$ if each element is tangent to $U$ at $x_{0}$.
If there exists a basis $(\Basis_{i})_{i=1}^{n}$ of $\Reals^{n}$ tangent to $U$ at $x_{0}$, and if $(\gamma_{i})_{i=1}^{n}$ is a corresponding collection of curves, say that $f$ is differentiable at $x_{0}$ if:

For each $i$, $f \circ \gamma_{i}$ is differentiable from the right at $0$, and
If $\gamma:(-\Eps, \Eps) \to \Reals^{n}$ is an arbitrary smooth curve with $\gamma(0) = x_{0}$ and $\gamma(t) \in U$ for all $t \neq 0$, then $f \circ \gamma$ is differentiable at $0$. (This ensures that if both $\Basis$ and $-\Basis$ are tangent to $U$ at $x_{0}$, then the respective directional derivatives are compatible.)

It's straightforward to check that if $M \subset \Reals^{n}$ is an open submanifold (n.b., not codimension $1$) and $U = \overline{M}$ is a manifold with boundary, then at each boundary point of $U$ there is a basis tangent to $U$. (Take a basis of the tangent space to the boundary together with an inward-pointing normal vector.)
The preceding framework runs into trouble for sets such as the following:

Submanifolds of lower dimension (e.g., plane curves).
Closures of open sets with "sharp boundaries", such as
$$
U = \{(x, y) : |y| \leq x^{2}\}.
$$
(The origin is problematic; no vector with non-vanishing second component is tangent to $U$ at the origin.)

For all the generality one gains by this type of scheme (e.g., manifolds with corners, edge-of-the-wedge results), in elementary circumstances it's adequate, and much easier, simply to assume $U$ is open.


Sample size and power calculation for randomized cluster study

Question: Stuck at a pretty weird research design and would like to get some input on how to go about calculating power.
A researcher would like to randomize four groups into four different interventions (one of them being the proposed new standard, the other three are currently used practices), followed by comparing the magnitude of improvement in each intervention. The chart below shows the scheme. The four groups are randomized as a whole cluster (aka group and treatment do not cross). However, the communities within each group are not randomly chosen, but rather enlisted based on logistical reason. All eligible individuals within each community will be enrolled, and I do have the predicted number of participants in the community level. We have also come up with expected differences between the four interventions.

I am unsure on how to approach its power calculation. Particularly, does this design qualify as a multi-level model? What would be an ideal approach to calculate the power? Any comments/referral to other materials are welcome.
Many thanks.
Answer: Yes, this would certainly entail a multilevel model.
Tom Snjiders has a multilevel modeling webpage with some resources that I think address your problem perfectly. The relevant section is here:
Tom Snjiders: Multilevel analysis: PINT program
Of the papers mentioned in this section (all of which are available in full text on the site), I think the most helpful one is:

Snijders, T.A.B., Sampling, Chapter 11 (p. 159-174) in A. Leyland
and H. Goldstein (eds.) (2001) Multilevel Modelling of Health
Statistics.

This chapter spends some time discusses different multilevel designs, and how one would approach power in each of these designs, and gives some practical guidance on estimating power using his own "PINT" program (Power analysis IN Two-level designs), which can also be downloaded from the website.


Why is it interesting that $2$ is the "only even prime"?

Question: The statement that "$2$ is the only even prime number" has always struck me as very peculiar. I do not find this statement mathematically interesting, though I do find the fact that it is presented as something interesting about $2$ or prime numbers to be itself quite interesting.
I find it interesting because this statement has secured its place as a "math-tidbit", if you will, solely because we happen to have a word for being divisible by $2$.
In other words, it is not at all clear to me why the statement "$2$ is the only even prime" is any more interesting or worth saying than the statement "$7$ is the only prime that is divisible by $7$."
Every prime $p$ is the only prime divisible by $p$. This immediately follows from the definition. So my question is, what makes the $2$ case particularly special or interesting, other than the fact that we have a word for divisibility by $2$?
Comment: It isn't interesting.  It is just a consequence of the definition of prime. It is obvious that "most" evens can't be prime, but $2$ is ¯\_(ツ)_/¯
Comment: Fields of characteristic 2 has some special properties. https://math.stackexchange.com/questions/1573308/whats-so-special-about-characteristic-2
Comment: There are, however, certain arguments that break down at the prime 2 (see:  homotopy theory), but that's a different level of interesting I think.
Comment: Look at it the other way: why do we have words for odd and even? I think the answer is more psychological than mathematical. We characterize our experiences dichotomously: good/bad; light/dark; up/down; etc. The importance of two-ness precedes any mathematical investigations, so when we start to think mathematically, we transfer our notion of the importance of $2$ and come up with concise words for those quantities (numbers) that are two-like and those that are not. Then we observe that our division of numbers into those categories leaves only one prime number in the two-like category.
Comment: Maybe this is an old one, but I still like it: "*all primes are odd, except $2$ - this is the oddest of all.*"
Comment: It's for the same reason that $3$ is the only ternary number that is prime, and the same reason that $5$ is the only quinary number that is prime. And so on.
Comment: There are at least two very different questions you might be asking: 1. Why does pop math mention that 2 is the only even prime and does that statement have any value? 2. Why is it significant to advanced mathematics that 2 is an even prime/in what ways is 2 notable among primes?
Comment: "interesting" is subjective anyway. But this statement surely isn't interesting , however often used. That $2$ is special in many contexts (reciprocity law , for example) is a completely different story.
Comment: @KeithBackman very insightful, thank you. I often wonder how much the human experience shapes our mathematics. People like to say that mathematics is "universal", and in a sense that is true, but as mathematics is one of the most creatively free and unrestrained topics there are, I suspect that our humanity influences many things, such as what we decide to designate as axioms vs what we designate as theorems, what objects we choose to define, etc. I suspect some alien civilization's mathematics would be unrecognizable to us, just through the creative choices that math affords us.
Answer: You are right that the quoted statement as such loses its charm upon a moment of consideration. After all, as you say, "$2$ is the only even prime" is not more or less surprising than "$7$ is the only prime divisible by $7$".
One could think of it this way: Why is $2$ the only prime $p$ such that we have a special word for "divisible by $p$"? -- That is a question more about language than about math, but it hints at the fact that the number $2$ holds a more special place in our psychology than all other natural numbers (although some of the other primes, especially $3, 5, 7,$ and $13$, stand out too, in some dominant cultures. $57$, not so much.)
Now, this site is not about psychology, culture, or language. But even mathematicians will sometimes utter a statement similar to the one you quote. What could they mean?
It turns out that in various theories, the prime $p=2$ (and to a lesser but notable extent, $p=3$) behaves differently than all the other primes! See: https://mathoverflow.net/q/160811/27465, and compare https://mathoverflow.net/q/915/27465. Also, the whimsically phrased Why are even primes notable?. A basic example that sets aside $p=2$ (which causes many others) is that there are two rational solutions to $x^2=1$, while for all other $p$, the equation $x^p=1$ has only one real solution. (For more advanced people: The unit group of $\mathbb Z$ is $ \simeq\mathbb Z/2$. Or: The only primitve roots of unity in $\mathbb R$ are $\pm 1$.)
Now the statement "$2$ is the only even prime" might be an exceptionally bad way to express this phenomenon. More fitting might be the old joke, as per Gottfried Helms' comment: "$2$ is the oddest prime."
Comment: +1 for Grothendieck prime
Comment: I assume you've seen this, but, just in case, for your entertainment - from John Tate, at the FLT conference a few hundred years ago: https://youtu.be/lbsniAHLY4Q?t=1457, at least until some 90 secs after, with '2-1=1' ,  but also a few seconds past https://youtu.be/lbsniAHLY4Q?t=1894.  (And what's up with this disparagement by you of the much esteemed Grothendieck prime?)
Comment: Also, while Tate and 2 are on my mind: "During a seminar at Harvard, a conjecture of Lichtenbaum's was mentioned. Someone scornfully said that for the only case that anyone had been able to test it, the powers of 2 occurring in the conjectured formula had been computed and they turned out to be wrong; thus the conjecture is false. "Only for 2" responded Tate from the audience. [And, in fact, I think the conjecture turned out to be correct except for the power of 2.]" (from https://www.jmilne.org/math/apocrypha.html)
Comment: Thank you for taking the time to write such a thoughtful answer. I agree that reframing the thought, and shifting away from the "exceptionally bad way to express this phenomenon" allows us to appreciate this little toy topic much more. I enjoyed reading through your thoughts, and the x^p = 1 example was very insightful.
Comment: "Even" means divisible by 2, and 2>1,  so there could not be more than one even prime.
Comment: Downvoter, please explain what's the issue?


Ranges of k values in quadratic for it to be positive

Question: Here is the problem
$2x^2+6x+1+k(x^2+2)$, find the condition that must be satisfied by k in order that the expression may be positive for all real values of x.
The quadratic of the form $ax^2+bx+c$ will be positive for all real values of x, if $\displaystyle{\frac{4ac-b^2}{4a} > 0}$.
Therefore, $\displaystyle{\frac{4(2+k)(2k+1)-36}{4(2+k)}>0}$
$\displaystyle{\frac{(k-1)(2k+7)}{(2+k)}}>0$
Considering the 4 ranges, with $k$ values of -14/4, -2 and 1
The inequality is true when $k<-2$ and $k>1$.
However the book answer is only $k>1$. What have I done wrong?
Thank you
Comment: what kind of number is $k$?
Comment: it does not specify, I assume it is any real number
Comment: If $2+k\le 0$, then the thing is not always positive. So we can confine attention to $k\gt -2$.
Answer: For the quadratic expression $ax^2 + bx+c$ to be greater than zero for all real $x$, two conditions must be satisfied: $a>0$ and the discriminant $b^2 - 4ac<0$
Here $a = k+2, b = 6, c = 2k+1$
The first condition gives $a > 0 \implies k+2 > 0 \implies k > -2$
The second condition gives $b^2 - 4ac < 0 \implies 36 - 4(k+2)(2k+1)<0 \implies 2k^2 + 5k - 7 > 0 \implies (2k+7)(k-1) > 0 \implies k<-\frac 72$ or $k>1$
However, note that $k<-\frac 72$ violates the previously derived condition $k>-2$
Hence the only valid condition is $k>1$
Comment: Precisely. Both roots are complex if the discriminant is less than zero. Which means there are no real roots. Which means there are no *intersections* between the curve of the quadratic and the $x$-axis. Since the curve is an upright "U"-shape (because of the positive $a$), this guarantees the curve always lies strictly above the $x$-axis, hence the expression is always positive.
Comment: @isquared-KeepitReal If, in contrast, you were required to find values of $k$ that would make the expression always negative, you would still need the discriminant to be negative. But in this case the $a$ would also have to be negative. The curve would be an "∩" shape, always lying below the $x$-axis.
Comment: @isquared-KeepitReal What you have learned seems to be completing the square (which is also what Dr Sonnhard Graubner did below). And if you think about it a little, the conditions are equivalent. You still need $a>0$. And in the second expression if $a>0$ then $4a>0$. With a positive denominator, you require a positive numerator to make the whole expression positive, so $4ac -b^2 >0$ or (just rearranging), $b^2 - 4ac < 0$. See?
Comment: I don't understand why discriminant is less than zero. That will give complex roots
Comment: This makes sense, thank you. But I am trying to put this into the perspective of what I have learned. And I learned that $\displaystyle{ax^2+bx+c \equiv a(x+\frac{b}{2a})^2 + \frac{4ac-b^2}{4a}}$. From which it follows that $a>0$ and $\displaystyle{\frac{4ac-b^2}{4a}>0}$... There that is what I have missed, the condition on $a$... I will keep in mind your method as well now. Thank you
Comment: yeap :) Perfect !
Answer: The condition $\frac{4ac-b^2}{4a}\gt 0$ is not correct because this includes the case when $a\lt 0$ and $b^2-4ac\gt 0$. (Imagine the graph of a parabola $y=-x^2+x+1$, for example.)
First of all, we need that the coefficient of $x^2$ is positive, i.e. $k+2\gt 0$. (note that $k=-2$ does not satisfy the condition.) Under this condition, you need to have $b^2-4ac\lt 0$, i.e. $9-(2+k)(2k+1)\lt 0$, i.e. $k\lt -\frac 27$ or $k\gt 1$. Thus, we have $k\gt 1$. This is sufficient.
Answer: we need a case work.
1. $k=-2$ doesn't work.
2. for $k>-2$ we have $\left(x+\frac{3}{k+2}\right)^2+\frac{2k+1}{k+2}-\frac{9}{(k+2)^2}>0$ for all $x$ The last two summands are $$\frac{(2k+7)(k-1)}{(2+k)^2}$$ this is positive if $k>1$ and the case $k<-\frac{7}{2}$ doesn't exist.
3. the case $k<-2$ is not possible. (Why?)$


itunesconnect not showing the prerelease build

Question: 1) I'm achieving the build using Xcode 6.3.
2) After Successful validation submitting the build to app store for beta testing.
Xcode is showing the status "submitted successfully".
The issues is, The build is not visible in itunesconnect under prerelease tab.
I checked the version. Version number in not same. Any suggestions are highly appreciated. Is there any issue with Xcode 6.3 or iTunesconnect.
Comment: Is it visible under *Builds*?
Comment: No it is not visible. Tried for 2 days.
Comment: I mean *Builds* in the main page of your app.
Comment: Hello Linus G. , No I mean under prerelease -> builds section. Now it started showing up. suddenly. I faced this problem for 2 days. Now its working fine. But couldn't find the reason.
Comment: @Ganesh, the most probable reason is the incompetence of the developers who coded the platform. I've had a lot of issues recently when trying to publish a prerelease build.
Answer: I was facing the same problem. I just uploaded the binary again and now it showed up in prerelease.


What kind of t-test should I use for testing the significance of a Professor's IQ?

Question: Imagining that the mean IQ of the population is 100, sd is 15.
If the calculated IQ of the academic is 125, a two way t-test fails to reject the hypothesis that the professor is significantly smarter than the average person in the 5% significant, 100+1.96*15 ~ 130 is the rejection margin.
Now a one way t-test however rejects the hypothesis with the margin being at 124.67.
My question is knowing that the academic cannot be less gifted than the lower 2.5% percentile or to that effect, even the average person, is it logical to use the one way test, in this circumstance?
Comment: A t-test is not applicable: the SD is presumed known.  All you are doing is finding the percentile corresponding to the professor's IQ.
Comment: I note crucial objections to thinking about this as a test at all. That said, it's more common to talk of a 5% significance level, not a 95% significance level, for what you are trying.
Comment: Student's t-test, obviously. Erm... I'll get my coat.
Answer: You don't need any significance tests. You already have the IQ of the professor in question, namely, 125, which is not equal to 100. The situation that you seem to have this situation confused with is when you have a sample of people from some population and you want to make an inference about the mean IQ of the population. Saying that the sample mean is "significantly" different from 100 means that you've decided that the population mean isn't 100. But there's no population to make inferences about here, since the mean IQ of the population you're comparing the professor to is already known.
Comment: I see your point. So I should simply report the percentile here. Saying that the mentioned person has a higher IQ than 95% of the population?
Comment: @Theoden Do you mean to say that you would be presuming that the IQ is measured with normally distributed measurement error, and the standard error of measurement is 15? You can then talk about estimating the professor's true IQ, yes, since you're no longer assuming his IQ is exactly what was measured (125). But significance testing would be an odd approach to that problem.
Comment: One (somewhat silly) way the OP's question could make sense is if you consider the professor's IQ to be a sample of size 1 from the population of professors, and you were interested in testing the hypothesis that the population mean for professors were different than the general population. But then you would not be doing a t-test.
Comment: @Theoden Yep, that makes sense.
Comment: Just one more thing, wouldn't the original question make sense, if we assume that the IQ test itself has a sd of let's say 15? We will have an estimated mean and a standard deviation in that case.
Answer: If the professor scored significantly below average, than that would be worth reporting. Therefore you are interested in both ends of the tails and need to perform a two tailed test.
Usually you compare your p with some alpha. That alpha is agreed upon to be 0.05 just as testing is agreed to be two tailed.
These are two reasons for two tails.
Comment: (+1) Although I think no significance test is called for here, your treatment of one- versus two-tailed tests is on the money, and that's one of the issues OP brought up.
Comment: @Kodiologist I agree, that the test is probably useless. It tests, whether any one professor is unlikely to be a random sample from the total population. Also, I would not call it a t-test but rather a z-test. The question of why we teach one tailed tests in order to use two tailed tests in science almost exclusively remain difficult to answer - I tried to cut a long story short.


Google Cloud - Communication between 2 computing Instance

Question: i've created new account for google cloud.
i have 2 computing instance, on the same region, same subnet.
this network also connected with vpn to my office.
server 1 is 192.168.1.10 / 255.255.255.0 / gw : 192.168.1.1
server 2 is 192.168.1.11 / 255.255.255.0 / gw : 192.168.1.1
Office is : 192.168.0.0/24
i've created vpn connection and now when i ping from office to servers - there is response.. from servers to office there is response.
but from server to server - no response. from server to gateway - no response.
i have internet and i can also connect to the internet from that servers.
i have rule allow 192.168.1.0/24 any thing (tcp/icmp/udp)
what i miss?
Thanks ahead
Comment: Were you able to solve this issue? I would re-check the firewall rules defined in [Google network](https://cloud.google.com/compute/docs/networking). I would also check that packets are not being dropped by a firewall inside the servers.
Comment: Did you add routes on either end for the remote subnets?
Comment: they both on the same subnet and this whole subnet have the following route : 192.168.1.0/24 |  next hop is Virtual Network.   they have access to servers located on the remote side (vpn) and from the remote to them..  but they dont have local access - from one server to the 2nd.. and no ping response from the gateway (192.168.1.1)
Answer: The VPN shouldn't interfere on the internal communication between the instances. Although the communication internally is allowed to the GCP 'internal IP', I effectively know that 192.168.x.x/x is not a range used internally at all on cloud platform. So, or you are performing the test on the wrong IPs or the firewall rule is defined for addresses that are unknown internally.